diff options
Diffstat (limited to 'catalog-be')
24 files changed, 87 insertions, 231 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java index c34a006b6c..5be54a3c88 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java @@ -1693,7 +1693,6 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { Component resource, ArtifactDefinition oldArtifact, ArtifactTemplateInfo artifactTemplateInfo, List<ArtifactDefinition> updatedArtifacts, List<ArtifactTemplateInfo> updatedRequiredArtifacts) { - Either<ArtifactDefinition, ResponseFormat> resStatus = null; String artifactFileName = artifactTemplateInfo.getFileName(); // check if artifacts already exist @@ -1705,13 +1704,11 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { BeEcompErrorManager.getInstance().logInternalDataError( ARTIFACT_FILE_IS_NOT_IN_EXPECTED_FORMAT_FILE_NAME + artifactFileName, ARTIFACT_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR); - resStatus = Either.right(componentsUtils.getResponseFormat( + return Either.right(componentsUtils.getResponseFormat( ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, artifactFileName, artifactTemplateInfo.getType(), updatedArtifact.getArtifactType())); - return resStatus; } - resStatus = Either.left(updatedArtifact); - return resStatus; + return Either.left(updatedArtifact); } } @@ -1720,8 +1717,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { .getArtifactContent(csarInfo.getCsarUUID(), csarInfo.getCsar(), CsarUtils.ARTIFACTS_PATH + artifactFileName, artifactFileName, componentsUtils); if (artifactContententStatus.isRight()) { - resStatus = Either.right(artifactContententStatus.right().value()); - return resStatus; + return Either.right(artifactContententStatus.right().value()); } Map<String, Object> json = ArtifactUtils.buildJsonForUpdateArtifact(oldArtifact.getUniqueId(), artifactFileName, @@ -1734,8 +1730,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { new ArtifactOperationInfo(false, false, ArtifactOperationEnum.UPDATE)); if (uploadArtifactToService.isRight()) { - resStatus = Either.right(uploadArtifactToService.right().value()); - return resStatus; + return Either.right(uploadArtifactToService.right().value()); } ArtifactDefinition previousInfo = uploadArtifactToService.left().value().left().value(); ArtifactDefinition currentInfo = uploadArtifactToService.left().value().left().value(); @@ -1746,15 +1741,13 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { if (updateEnvEither.isRight()) { log.debug("failed to update parameters to artifact {}", artifactFileName); - resStatus = Either.right(updateEnvEither.right().value()); - return resStatus; + return Either.right(updateEnvEither.right().value()); } artifactsBusinessLogic.updateGroupForHeat(previousInfo, updateEnvEither.left().value(), resource); updatedArtifacts.add(updateEnvEither.left().value()); - resStatus = Either.left(currentInfo); - return resStatus; + return Either.left(currentInfo); } public Either<Resource, ResponseFormat> deleteVFModules(Resource resource, CsarInfo csarInfo, boolean shouldLock, boolean inTransaction) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java index e411433baf..e5eefb43ad 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/health/HealthCheckBusinessLogic.java @@ -188,17 +188,15 @@ public class HealthCheckBusinessLogic { } private HealthCheckInfo getDmaapProducerHealthCheck() { - HealthCheckInfo healthCheckInfo = null; - if(ConfigurationManager.getConfigurationManager().getConfiguration().getDmaapConsumerConfiguration().isActive()){ + if (ConfigurationManager.getConfigurationManager().getConfiguration().getDmaapConsumerConfiguration().isActive()) { String appVersion = getAppVersion(); - dmaapProducerHealth.getHealthCheckInfo().setVersion(appVersion); - healthCheckInfo = dmaapProducerHealth.getHealthCheckInfo(); + dmaapProducerHealth.getHealthCheckInfo().setVersion(appVersion); + return dmaapProducerHealth.getHealthCheckInfo(); } else { - log.debug("Dmaap health check disabled"); + log.debug("Dmaap health check disabled"); String description = ("Dmaap health check disabled"); - healthCheckInfo = new HealthCheckInfo(HC_COMPONENT_DMAAP_PRODUCER, DOWN, null, description); + return new HealthCheckInfo(HC_COMPONENT_DMAAP_PRODUCER, DOWN, null, description); } - return healthCheckInfo; } public HealthCheckInfo getJanusGraphHealthCheck() { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java index 72aeb2b8f9..be2a45b24f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java @@ -442,22 +442,18 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { } public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(boolean isAbstractAbstract, HighestFilterEnum highestFilter, ComponentTypeEnum componentTypeEnum, String internalComponentType, String userId) { - ResponseFormat responseFormat = null; - try{ validateUserExists(userId); - Boolean isHighest = isHighest(highestFilter); Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = toscaOperationFacade.getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType); if (nonCheckoutCompResponse.isLeft()) { log.debug("Retrieved Resource successfully."); return Either.left(nonCheckoutCompResponse.left().value()); } - responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value())); + return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value()))); } finally { janusGraphDao.commit(); } - return Either.right(responseFormat); } public void setDeploymentArtifactsPlaceHolder(Component component, User user) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index 3f48328cc9..7c463ac387 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -1657,7 +1657,6 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { Either<RequirementCapabilityRelDef, ResponseFormat> resultOp = null; try { org.openecomp.sdc.be.model.Component containerComponent = null; - Either<org.openecomp.sdc.be.model.Component, ResponseFormat> validateComponentExists = null; RequirementCapabilityRelDef foundRelation = null; validateUserExists(userId); @@ -2025,12 +2024,6 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { if(getComponentRes.isRight()) { return componentsUtils.getResponseFormat(getComponentRes.right().value()); } - String propOwner; - if(!PropertiesUtils.isNodeServiceProxy(getComponentRes.left().value())) { - propOwner = componentInstanceUniqueId; - } else { - propOwner = foundResourceInstance.getSourceModelUid(); - } ResponseFormat actionStatus = updateCapPropOnContainerComponent(property, newValue, containerComponent, foundResourceInstance, capabilityType, capabilityName, componentInstanceUniqueId); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java index 0c776a16a4..fe9d44837b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java @@ -617,7 +617,6 @@ public class GroupBusinessLogic extends BaseBusinessLogic { public Either<List<GroupDefinition>, ResponseFormat> validateUpdateVfGroupNamesOnGraph(List<GroupDefinition> groups, Component component) { List<GroupDefinition> updatedGroups = new ArrayList<>(); - Either<List<GroupDefinition>, ResponseFormat> result; for (GroupDefinition group : groups) { String groupType = group.getType(); @@ -630,7 +629,6 @@ public class GroupBusinessLogic extends BaseBusinessLogic { newGroupNameRes = validateGenerateVfModuleGroupName(component.getSystemName(), group.getDescription(), counter); if (newGroupNameRes.isRight()) { log.debug("Failed to generate new vf module group name. Status is {} ", newGroupNameRes.right().value()); - result = Either.right(newGroupNameRes.right().value()); break; } newGroupName = newGroupNameRes.left().value(); @@ -641,8 +639,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic { } - result = Either.left(updatedGroups); - return result; + return Either.left(updatedGroups); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 7788066e52..4c34ddaba0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -902,19 +902,17 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { private EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> findNodeTypeArtifactsToHandle(Resource curNodeType, List<ArtifactDefinition> extractedArtifacts) { - EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = null; try { List<ArtifactDefinition> artifactsToUpload = new ArrayList<>(extractedArtifacts); List<ArtifactDefinition> artifactsToUpdate = new ArrayList<>(); List<ArtifactDefinition> artifactsToDelete = new ArrayList<>(); processExistingNodeTypeArtifacts(extractedArtifacts, artifactsToUpload, artifactsToUpdate, artifactsToDelete, collectExistingArtifacts(curNodeType)); - nodeTypeArtifactsToHandle = putFoundArtifacts(artifactsToUpload, artifactsToUpdate, artifactsToDelete); + return putFoundArtifacts(artifactsToUpload, artifactsToUpdate, artifactsToDelete); } catch (Exception e) { log.debug("Exception occurred when findNodeTypeArtifactsToHandle, error is:{}", e.getMessage(), e); throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); } - return nodeTypeArtifactsToHandle; } private EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>> putFoundArtifacts( @@ -3325,7 +3323,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName()); } } - String innerType = null; property = new ComponentInstanceInput(curPropertyDef, value, null); String validPropertyVAlue = validatePropValueBeforeCreate(property, value, isValidate, allDataTypes); @@ -3445,7 +3442,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName()); } } - String innerType = null; property = new ComponentInstanceProperty(curPropertyDef, value, null); String validatePropValue = validatePropValueBeforeCreate(property, value, isValidate, allDataTypes); @@ -4541,26 +4537,22 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { private void processDeploymentResourceArtifacts(User user, Resource resource, Map<String, ArtifactDefinition> artifactMap, String k, Object v) { - boolean shouldCreateArtifact = true; Map<String, Object> artifactDetails = (Map<String, Object>) v; Object object = artifactDetails.get(PLACE_HOLDER_RESOURCE_TYPES); if (object != null) { List<String> artifactTypes = (List<String>) object; if (!artifactTypes.contains(resource.getResourceType() .name())) { - shouldCreateArtifact = false; return; } } else { log.info("resource types for artifact placeholder {} were not defined. default is all resources", k); } - if (shouldCreateArtifact) { - if (artifactsBusinessLogic != null) { - ArtifactDefinition artifactDefinition = artifactsBusinessLogic.createArtifactPlaceHolderInfo( - resource.getUniqueId(), k, (Map<String, Object>) v, user, ArtifactGroupTypeEnum.DEPLOYMENT); - if (artifactDefinition != null && !artifactMap.containsKey(artifactDefinition.getArtifactLabel())) { - artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition); - } + if (artifactsBusinessLogic != null) { + ArtifactDefinition artifactDefinition = artifactsBusinessLogic.createArtifactPlaceHolderInfo( + resource.getUniqueId(), k, (Map<String, Object>) v, user, ArtifactGroupTypeEnum.DEPLOYMENT); + if (artifactDefinition != null && !artifactMap.containsKey(artifactDefinition.getArtifactLabel())) { + artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition); } } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index 3b19ea9d86..eba4cc947e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -813,7 +813,6 @@ public class ServiceImportBusinessLogic{ String yamlFileName, CsarInfo csarInfo, Service preparedService, NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts, boolean inTransaction, boolean shouldLock) { - String nodeName = nodeTypeInfoToUpdateArtifacts.getNodeName(); Service resource = preparedService; Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = nodeTypeInfoToUpdateArtifacts .getNodeTypesArtifactsToHandle(); @@ -1380,7 +1379,6 @@ public class ServiceImportBusinessLogic{ TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName()); } } - String innerType = null; property = new ComponentInstanceInput(curPropertyDef, value, null); String validPropertyVAlue = serviceBusinessLogic.validatePropValueBeforeCreate(property, value, isValidate, allDataTypes); property.setValue(validPropertyVAlue); @@ -1826,7 +1824,6 @@ public class ServiceImportBusinessLogic{ TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName()); } } - String innerType = null; property = new ComponentInstanceInput(curPropertyDef, value, null); String validPropertyVAlue = serviceBusinessLogic.validatePropValueBeforeCreate(property, value, isValidate, allDataTypes); property.setValue(validPropertyVAlue); @@ -1918,7 +1915,6 @@ public class ServiceImportBusinessLogic{ TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName()); } } - String innerType = null; property = new ComponentInstanceProperty(curPropertyDef, value, null); String validatePropValue = serviceBusinessLogic.validatePropValueBeforeCreate(property, value, isValidate, allDataTypes); @@ -2009,7 +2005,6 @@ public class ServiceImportBusinessLogic{ TypeUtils.ToscaTagNamesEnum.GET_INPUT.getElementName()); } } - String innerType = null; property = new ComponentInstanceProperty(curPropertyDef, value, null); String validatePropValue = serviceBusinessLogic.validatePropValueBeforeCreate(property, value, isValidate, allDataTypes); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java index 935a5d6796..cf70d39743 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java @@ -1358,7 +1358,6 @@ public class ServiceImportParseLogic { if (object != null) { List<String> artifactTypes = (List<String>) object; if (!artifactTypes.contains(resource.getResourceType().name())) { - shouldCreateArtifact = false; return; } } else { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java index 030fc46887..9d65a667fe 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java @@ -550,18 +550,13 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties String key = entry.getKey(); Object value = entry.getValue(); if (value instanceof String && ((String) value).equalsIgnoreCase(inputName) && key.equals(GET_INPUT)) { - value = ""; lhm1.remove(key); } else if (value instanceof Map) { Map<String, Object> subMap = (Map<String, Object>)value; resetInputName(subMap, inputName); } else if (value instanceof List && ((List) value).contains(inputName) && key.equals(GET_INPUT)) { - value = ""; lhm1.remove(key); - } else { - continue; } - } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/Utils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/Utils.java index 97fedffe9a..929cd46051 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/Utils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/utils/Utils.java @@ -40,9 +40,8 @@ public class Utils { if (existingValues.isEmpty()) { return 0; } - int maxCurrentCounter = 0; try { - maxCurrentCounter = existingValues.stream() + return 1 + existingValues.stream() .map(COUNTER_PATTERN::matcher) .filter(Matcher::find) .map(matcher -> matcher.group(0)) @@ -52,8 +51,7 @@ public class Utils { } catch (Exception e) { Log.warn("Failed in retrieivng counter from existing value: ", e); - maxCurrentCounter = random.nextInt(100) + 50; + return random.nextInt(100) + 50; } - return ++maxCurrentCounter; } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java index c6856eb42d..c6be01db5c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/distribution/servlet/DistributionServlet.java @@ -163,8 +163,7 @@ public class DistributionServlet extends BeGenericServlet { log.debug("failed to get ueb serbver list from cofiguration", e); responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR); getComponentsUtils().auditGetUebCluster(instanceId, responseFormat.getStatus().toString(), responseFormat.getFormattedMessage()); - response = buildErrorResponse(responseFormat); - return response; + return buildErrorResponse(responseFormat); } } @@ -267,18 +266,16 @@ public class DistributionServlet extends BeGenericServlet { @Parameter(description = "The username and password", required = true)@HeaderParam(value = Constants.ACCEPT_HEADER) String accept) { String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); - Response response = null; Wrapper<Response> responseWrapper = new Wrapper<>(); //TODO check if in use validateHeaders(responseWrapper, request, AuditingActionEnum.GET_VALID_ARTIFACT_TYPES); if (responseWrapper.isEmpty()) { - response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), ArtifactTypeEnum.values()); + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), ArtifactTypeEnum.values()); } else { - response = responseWrapper.getInnerElement(); + return responseWrapper.getInnerElement(); } - return response; } /** diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AbstractTemplateServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AbstractTemplateServlet.java index 0320a0a795..eb514bf088 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AbstractTemplateServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AbstractTemplateServlet.java @@ -154,7 +154,6 @@ public class AbstractTemplateServlet extends AbstractValidationsServlet { @Parameter(description = "The requested asset uuid", required = true) @PathParam("uuid") final String uuid) throws IOException { - Response response = null; ResponseFormat responseFormat = null; AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_TEMPLATE_ABSTRACT_STATUS; String requestURI = request.getRequestURI(); @@ -202,9 +201,7 @@ public class AbstractTemplateServlet extends AbstractValidationsServlet { getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid); - response = buildOkResponse(responseFormat, result); - return response; - + return buildOkResponse(responseFormat, result); } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Fetch abstract status of service"); log.debug("getServiceAbstractStatus: Fetch abstract status of service with exception", e); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java index db065ac223..0154284cab 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java @@ -160,7 +160,6 @@ public class AssetsDataServlet extends AbstractValidationsServlet { @Parameter(description = "The filter key (resourceType only for resources)", required = false) @QueryParam("resourceType") String resourceType) throws IOException { - Response response = null; ResponseFormat responseFormat = null; String query = request.getQueryString(); String requestURI = request.getRequestURI().endsWith("/")? @@ -224,8 +223,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet { responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId); - response = buildOkResponse(responseFormat, result); - return response; + return buildOkResponse(responseFormat, result); } } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Fetch filtered list of assets"); @@ -276,7 +274,6 @@ public class AssetsDataServlet extends AbstractValidationsServlet { @Parameter(description = "The requested asset uuid", required = true) @PathParam("uuid") final String uuid) throws IOException { - Response response = null; ResponseFormat responseFormat = null; AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_ASSET_METADATA; String requestURI = request.getRequestURI(); @@ -323,9 +320,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet { getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid); - response = buildOkResponse(responseFormat, result); - return response; - + return buildOkResponse(responseFormat, result); } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Fetch filtered list of assets"); log.debug("getAssetList: Fetch list of assets failed with exception", e); @@ -388,7 +383,6 @@ public class AssetsDataServlet extends AbstractValidationsServlet { String url = request.getRequestURI(); log.debug("Start handle request of {} {}", request.getMethod(), url); - Response response = null; ResponseFormat responseFormat = null; ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(assetType); AuditingActionEnum auditingActionEnum = AuditingActionEnum.GET_TOSCA_MODEL; @@ -416,8 +410,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet { responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid); - response = buildOkResponse(responseFormat, is, headers); - return response; + return buildOkResponse(responseFormat, is, headers); } catch (ComponentException e) { responseFormat = e.getResponseFormat(); @@ -425,7 +418,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet { resourceCommonInfo, requestId, uuid); BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get asset tosca model"); log.debug("failed to get asset tosca model", e); - response = buildErrorResponse(responseFormat); + Response response = buildErrorResponse(responseFormat); getComponentsUtils().auditExternalGetAsset(responseFormat, auditingActionEnum, distributionData, resourceCommonInfo, requestId, uuid); return response; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java index b9412f680f..97678d72fc 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java @@ -635,15 +635,13 @@ public class CrudExternalServlet extends AbstractValidationsServlet { } private Either<LifeCycleTransitionEnum, ResponseFormat> validateTransitionEnum(final String lifecycleTransition, User user) { - LifeCycleTransitionEnum transitionEnum = LifeCycleTransitionEnum.CHECKOUT; try { - transitionEnum = LifeCycleTransitionEnum.getFromDisplayName(lifecycleTransition); + return Either.left(LifeCycleTransitionEnum.getFromDisplayName(lifecycleTransition)); } catch (IllegalArgumentException e) { log.info("state operation is not valid. operations allowed are: {}", LifeCycleTransitionEnum.valuesAsString(), e); ResponseFormat error = getComponentsUtils().getInvalidContentErrorAndAudit(user, "", AuditingActionEnum.CHECKOUT_RESOURCE); return Either.right(error); } - return Either.left(transitionEnum); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/UserOperation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/UserOperation.java index c830734498..fb30826bb5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/UserOperation.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/facade/operations/UserOperation.java @@ -40,17 +40,15 @@ public class UserOperation { } public ActionStatus updateUserCache(UserOperationEnum operation, String userId, String role){ - ActionStatus result = ActionStatus.OK; - try{ + try { UserMessage message = new UserMessage(operation, userId,role); IStatus status = msProducer.pushMessage(message); - result = FacadeOperationUtils.convertStatusToActionStatus(status); + return FacadeOperationUtils.convertStatusToActionStatus(status); - }catch(Exception e){ + } catch(Exception e) { log.debug("update user cache - failed to send notification to update user cache {}", e.getMessage()); return ActionStatus.OK; } - return result; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java index 7ac20893c9..8f1f2c1c21 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java @@ -1400,35 +1400,25 @@ public class ComponentsUtils { labelOrValue = AdditionalInformationEnum.None; } - ResponseFormat responseFormat = null; switch (actionStatus) { case COMPONENT_NAME_ALREADY_EXIST: - responseFormat = getResponseFormat(actionStatus, "Additional parameter", additionalInfoParameterInfo.getKey()); - break; + return getResponseFormat(actionStatus, "Additional parameter", additionalInfoParameterInfo.getKey()); case ADDITIONAL_INFORMATION_EXCEEDS_LIMIT: - responseFormat = getResponseFormat(actionStatus, labelOrValue.name().toLowerCase(), ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH.toString()); - break; + return getResponseFormat(actionStatus, labelOrValue.name().toLowerCase(), ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH.toString()); case ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED: - responseFormat = getResponseFormat(actionStatus, nodeType.name().toLowerCase()); - break; + return getResponseFormat(actionStatus, nodeType.name().toLowerCase()); case ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED: - responseFormat = getResponseFormat(actionStatus); - break; + return getResponseFormat(actionStatus); case ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS: - responseFormat = getResponseFormat(actionStatus); - break; + return getResponseFormat(actionStatus); case ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS: - responseFormat = getResponseFormat(actionStatus); - break; + return getResponseFormat(actionStatus); case ADDITIONAL_INFORMATION_NOT_FOUND: - responseFormat = getResponseFormat(actionStatus); - break; + return getResponseFormat(actionStatus); default: - responseFormat = getResponseFormat(actionStatus); - break; + return getResponseFormat(actionStatus); } - return responseFormat; } public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java index 1a8a305d2a..382e01c60a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java @@ -534,7 +534,6 @@ public class BeGenericServlet extends BasicServlet { ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("(get) Start handle request of {}", url); - Response response = null; try { BaseBusinessLogic businessLogic = getBlForPropertyDeclaration(typeEnum, context); @@ -547,8 +546,7 @@ public class BeGenericServlet extends BasicServlet { Either<ComponentInstInputsMap, ResponseFormat> componentInstInputsMapRes = parseToComponentInstanceMap(componentInstInputsMapObj, modifier, componentTypeEnum); if (componentInstInputsMapRes.isRight()) { log.debug("failed to parse componentInstInputsMap"); - response = buildErrorResponse(componentInstInputsMapRes.right().value()); - return response; + return buildErrorResponse(componentInstInputsMapRes.right().value()); } Either<List<ToscaDataDefinition>, ResponseFormat> propertiesAfterDeclaration = businessLogic @@ -565,8 +563,7 @@ public class BeGenericServlet extends BasicServlet { } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Create inputs for service with id: " + componentId); log.debug("Properties declaration failed with exception", e); - response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); - return response; + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java index 408efa12c6..f3d18602bd 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ConsumerServlet.java @@ -152,14 +152,12 @@ public class ConsumerServlet extends BeGenericServlet { modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Response response = null; try { Either<ConsumerDefinition, ResponseFormat> actionResponse = businessLogic.getConsumer(consumerId, modifier); if (actionResponse.isRight()) { log.debug("failed to get consumer"); - response = buildErrorResponse(actionResponse.right().value()); - return response; + return buildErrorResponse(actionResponse.right().value()); } return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value()); @@ -167,7 +165,6 @@ public class ConsumerServlet extends BeGenericServlet { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Consumer"); log.debug("get consumer failed with exception", e); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); - } } @@ -184,8 +181,6 @@ public class ConsumerServlet extends BeGenericServlet { public Response deleteConsumer(@PathParam("consumerId") final String consumerId, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) { - ServletContext context = request.getSession().getServletContext(); - String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); @@ -193,14 +188,12 @@ public class ConsumerServlet extends BeGenericServlet { modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Response response = null; try { Either<ConsumerDefinition, ResponseFormat> actionResponse = businessLogic.deleteConsumer(consumerId, modifier); if (actionResponse.isRight()) { log.debug("failed to delete consumer"); - response = buildErrorResponse(actionResponse.right().value()); - return response; + return buildErrorResponse(actionResponse.right().value()); } return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value()); @@ -208,7 +201,6 @@ public class ConsumerServlet extends BeGenericServlet { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Consumer"); log.debug("delete consumer failed with exception", e); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); - } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java index 5ba56fda5b..46338c2986 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DistributionServiceServlet.java @@ -95,24 +95,15 @@ public class DistributionServiceServlet extends BeGenericServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); - Response response = null; - ResponseFormat responseFormat = null; - try { Either<DistributionStatusOfServiceListResponce, ResponseFormat> actionResponse = distributionMonitoringLogic.getListOfDistributionServiceStatus(serviceUUID, userId); if (actionResponse.isRight()) { - - responseFormat = actionResponse.right().value(); - response = buildErrorResponse(responseFormat); + return buildErrorResponse(actionResponse.right().value()); } else { - responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); - response = buildOkResponse(responseFormat, actionResponse.left().value()); + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value()); } - - return response; - } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution list for Service"); log.debug("failed to get service distribution statuses", e); @@ -138,27 +129,18 @@ public class DistributionServiceServlet extends BeGenericServlet { String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {}", url); - Response response = null; - ResponseFormat responseFormat = null; - try { Either<DistributionStatusListResponse, ResponseFormat> actionResponse = distributionMonitoringLogic.getListOfDistributionStatus(did, userId); if (actionResponse.isRight()) { - - responseFormat = actionResponse.right().value(); + ResponseFormat responseFormat = actionResponse.right().value(); log.debug("failed to fount statuses for did {} {}", did, responseFormat); - response = buildErrorResponse(responseFormat); + return buildErrorResponse(responseFormat); } else { - - responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); + ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK); log.debug("success to fount statuses for did {} {}", did, actionResponse.left().value()); - response = buildOkResponse(responseFormat, actionResponse.left().value()); - + return buildOkResponse(responseFormat, actionResponse.left().value()); } - - return response; - } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Distribution Status"); log.debug("failed to get distribution status ", e); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java index befdac48b0..9ea4a44acb 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ElementServlet.java @@ -527,7 +527,6 @@ public class ElementServlet extends BeGenericServlet { public Response getFollowedResourcesServices(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws IOException { - Response res = null; try { String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); @@ -539,13 +538,12 @@ public class ElementServlet extends BeGenericServlet { return buildErrorResponse(followedResourcesServices.right().value()); } Object data = RepresentationUtils.toRepresentation(followedResourcesServices.left().value()); - res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data); + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data); } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Followed Resources / Services Categories"); log.debug("Getting followed resources/services failed with exception", e); throw e; } - return res; } ///////////////////////////////////////////////////////////////////////////////////////////////////// @@ -566,7 +564,6 @@ public class ElementServlet extends BeGenericServlet { @HeaderParam(value = Constants.USER_ID_HEADER) String userId, @QueryParam("excludeTypes") List<OriginTypeEnum> excludeTypes) throws IOException { - Response res = null; try { String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); @@ -578,14 +575,13 @@ public class ElementServlet extends BeGenericServlet { return buildErrorResponse(catalogData.right().value()); } Object data = RepresentationUtils.toRepresentation(catalogData.left().value()); - res = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data); + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), data); } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Catalog Components"); log.debug("Getting catalog components failed with exception", e); throw e; } - return res; } @DELETE @@ -601,8 +597,6 @@ public class ElementServlet extends BeGenericServlet { modifier.setUserId(userId); log.debug("modifier id is {}", userId); - Response response = null; - NodeTypeEnum nodeType = NodeTypeEnum.getByNameIgnoreCase(componentType); if (nodeType == null) { log.info("componentType is not valid: {}", componentType); @@ -617,11 +611,9 @@ public class ElementServlet extends BeGenericServlet { if (cleanResult.isRight()) { log.debug("failed to delete marked components of type {}", nodeType); - response = buildErrorResponse(cleanResult.right().value()); - return response; + return buildErrorResponse(cleanResult.right().value()); } - response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), cleanResult.left().value()); - return response; + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), cleanResult.left().value()); } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Marked Components"); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java index 811b748ca5..d1998d841b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/GroupServlet.java @@ -218,14 +218,11 @@ public class GroupServlet extends AbstractValidationsServlet { user.setUserId(userId); log.debug("modifier id is {}", userId); - Response response = null; - try { Either<GroupDefinition, ResponseFormat> convertResponse = parseToObject(data, () -> GroupDefinition.class); if (convertResponse.isRight()) { log.debug("failed to parse group"); - response = buildErrorResponse(convertResponse.right().value()); - return response; + return buildErrorResponse(convertResponse.right().value()); } GroupDefinition updatedGroup = convertResponse.left().value(); @@ -236,8 +233,7 @@ public class GroupServlet extends AbstractValidationsServlet { if (actionResponse.isRight()) { log.debug("failed to update GroupDefinition"); - response = buildErrorResponse(actionResponse.right().value()); - return response; + return buildErrorResponse(actionResponse.right().value()); } GroupDefinition group = actionResponse.left().value(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java index 1f80b4be87..ea63218e5e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InputsServlet.java @@ -379,11 +379,8 @@ public class InputsServlet extends AbstractValidationsServlet { @Parameter(description = "ComponentIns Inputs Object to be created", required = true) String componentInstInputsMapObj) { - ServletContext context = request.getSession().getServletContext(); String url = request.getMethod() + " " + request.getRequestURI(); log.debug("#createListInput: Start handle request of {}", url); - Response response = null; - try { // get modifier id User modifier = new User(); @@ -394,8 +391,7 @@ public class InputsServlet extends AbstractValidationsServlet { parseToComponentInstListInput(componentInstInputsMapObj, modifier); if (componentInstInputsMapRes.isRight()) { log.debug("failed to parse componentInstInputsMap"); - response = buildErrorResponse(componentInstInputsMapRes.right().value()); - return response; + return buildErrorResponse(componentInstInputsMapRes.right().value()); } ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType); @@ -419,8 +415,7 @@ public class InputsServlet extends AbstractValidationsServlet { BeEcompErrorManager.getInstance() .logBeRestApiGeneralError("Create list input for service with id: " + componentId); log.debug("createListInput failed with exception", e); - response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); - return response; + return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java index 57a29566b1..f0ef7074ea 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceServlet.java @@ -189,15 +189,13 @@ public class ServiceServlet extends AbstractValidationsServlet { User modifier = new User(); modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Response response = null; try { Either<Map<String, Boolean>, ResponseFormat> actionResponse = serviceBusinessLogic.validateServiceNameExists(serviceName, userId); if (actionResponse.isRight()) { log.debug("failed to get validate service name"); - response = buildErrorResponse(actionResponse.right().value()); - return response; + return buildErrorResponse(actionResponse.right().value()); } return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), actionResponse.left().value()); } catch (Exception e) { @@ -303,7 +301,6 @@ public class ServiceServlet extends AbstractValidationsServlet { User modifier = new User(); modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Response response = null; try { String serviceIdLower = serviceId.toLowerCase(); loggerSupportability.log(LoggerSupportabilityActions.DELETE_SERVICE, StatusCode.STARTED,"Starting to delete service {} by user {} ",serviceIdLower, userId); @@ -311,12 +308,10 @@ public class ServiceServlet extends AbstractValidationsServlet { ResponseFormat actionResponse = businessLogic.deleteService(serviceIdLower, modifier); if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) { log.debug("failed to delete service"); - response = buildErrorResponse(actionResponse); - return response; + return buildErrorResponse(actionResponse); } - response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null); loggerSupportability.log(LoggerSupportabilityActions.DELETE_SERVICE,StatusCode.COMPLETE,"Ended deleting service {} by user {}",serviceIdLower, userId); - return response; + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null); } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Service"); @@ -338,28 +333,16 @@ public class ServiceServlet extends AbstractValidationsServlet { public Response deleteServiceByNameAndVersion(@PathParam("serviceName") final String serviceName, @PathParam("version") final String version, @Context final HttpServletRequest request) { - String url = request.getMethod() + " " + request.getRequestURI(); - log.debug(START_HANDLE_REQUEST_OF, url); - - // get modifier id - String userId = request.getHeader(Constants.USER_ID_HEADER); - User modifier = new User(); - modifier.setUserId(userId); - log.debug(MODIFIER_ID_IS, userId); - - Response response = null; + User modifier = getUser(request); try { ResponseFormat actionResponse = serviceBusinessLogic.deleteServiceByNameAndVersion(serviceName, version, modifier); if (actionResponse.getStatus() != HttpStatus.SC_NO_CONTENT) { log.debug("failed to delete service"); - response = buildErrorResponse(actionResponse); - return response; + return buildErrorResponse(actionResponse); } - response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null); - return response; - + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.NO_CONTENT), null); } catch (Exception e) { BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Delete Service"); log.debug("delete service failed with exception", e); @@ -367,6 +350,18 @@ public class ServiceServlet extends AbstractValidationsServlet { } } + private User getUser(HttpServletRequest request) { + String url = request.getMethod() + " " + request.getRequestURI(); + log.debug(START_HANDLE_REQUEST_OF, url); + + // get modifier id + String userId = request.getHeader(Constants.USER_ID_HEADER); + User modifier = new User(); + modifier.setUserId(userId); + log.debug(MODIFIER_ID_IS, userId); + return modifier; + } + @PUT @Path("/services/{serviceId}/metadata") @Consumes(MediaType.APPLICATION_JSON) @@ -389,24 +384,20 @@ public class ServiceServlet extends AbstractValidationsServlet { modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Response response = null; - try { String serviceIdLower = serviceId.toLowerCase(); Either<Service, ResponseFormat> convertResponse = parseToService(data, modifier); if (convertResponse.isRight()) { log.debug("failed to parse service"); - response = buildErrorResponse(convertResponse.right().value()); - return response; + return buildErrorResponse(convertResponse.right().value()); } Service updatedService = convertResponse.left().value(); Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.updateServiceMetadata(serviceIdLower, updatedService, modifier); if (actionResponse.isRight()) { log.debug("failed to update service"); - response = buildErrorResponse(actionResponse.right().value()); - return response; + return buildErrorResponse(actionResponse.right().value()); } Service service = actionResponse.left().value(); @@ -447,7 +438,6 @@ public class ServiceServlet extends AbstractValidationsServlet { @Parameter(description = "Group instance object to be Updated", required = true) String data, @Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) throws JsonProcessingException { - Response response = null; String url = request.getMethod() + " " + request.getRequestURI(); log.debug(START_HANDLE_REQUEST_OF, url); @@ -474,16 +464,15 @@ public class ServiceServlet extends AbstractValidationsServlet { updatedProperties = actionResponse.left().value(); ObjectMapper mapper = new ObjectMapper(); String result = mapper.writeValueAsString(updatedProperties); - response = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result); } else{ - response = buildErrorResponse(actionResponse.right().value()); + return buildErrorResponse(actionResponse.right().value()); } } catch (Exception e) { log.error("Exception occured during update Group Instance property values: {}", e.getMessage(), e); throw e; } - return response; } @GET @@ -508,7 +497,6 @@ public class ServiceServlet extends AbstractValidationsServlet { modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Response response = null; try { String serviceIdLower = serviceId.toLowerCase(); log.debug("get service with id {}", serviceId); @@ -516,8 +504,7 @@ public class ServiceServlet extends AbstractValidationsServlet { if (actionResponse.isRight()) { log.debug("failed to get service"); - response = buildErrorResponse(actionResponse.right().value()); - return response; + return buildErrorResponse(actionResponse.right().value()); } Service service = actionResponse.left().value(); @@ -552,13 +539,11 @@ public class ServiceServlet extends AbstractValidationsServlet { modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Response response = null; try { Either<Service, ResponseFormat> actionResponse = serviceBusinessLogic.getServiceByNameAndVersion(serviceName, serviceVersion, userId); if (actionResponse.isRight()) { - response = buildErrorResponse(actionResponse.right().value()); - return response; + return buildErrorResponse(actionResponse.right().value()); } Service service = actionResponse.left().value(); @@ -594,13 +579,11 @@ public class ServiceServlet extends AbstractValidationsServlet { modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Response response = null; Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.activateDistribution(serviceId, env, modifier, request); if (distResponse.isRight()) { log.debug("failed to activate service distribution"); - response = buildErrorResponse(distResponse.right().value()); - return response; + return buildErrorResponse(distResponse.right().value()); } Service service = distResponse.left().value(); Object result = null; @@ -638,14 +621,12 @@ public class ServiceServlet extends AbstractValidationsServlet { modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Response response = null; try { Either<Service, ResponseFormat> distResponse = serviceBusinessLogic.markDistributionAsDeployed(serviceId, did, modifier); if (distResponse.isRight()) { log.debug("failed to mark distribution as deployed"); - response = buildErrorResponse(distResponse.right().value()); - return response; + return buildErrorResponse(distResponse.right().value()); } Service service = distResponse.left().value(); Object result = RepresentationUtils.toRepresentation(service); @@ -674,13 +655,12 @@ public class ServiceServlet extends AbstractValidationsServlet { modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Response response; try { Service service = (serviceBusinessLogic.getService(serviceId, modifier)).left().value(); Either<Service, ResponseFormat> res = serviceBusinessLogic.updateDistributionStatusForActivation(service, modifier, DistributionStatusEnum.DISTRIBUTED); if (res.isRight()) { - response = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); + buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), null); } catch (Exception e) { @@ -714,7 +694,6 @@ public class ServiceServlet extends AbstractValidationsServlet { modifier.setUserId(userId); log.debug(MODIFIER_ID_IS, userId); - Response response = null; try { String serviceIdLower = serviceId.toLowerCase(); log.debug("get service components relations with id {}", serviceId); @@ -722,8 +701,7 @@ public class ServiceServlet extends AbstractValidationsServlet { if (actionResponse.isRight()) { log.debug("failed to get service relations data"); - response = buildErrorResponse(actionResponse.right().value()); - return response; + return buildErrorResponse(actionResponse.right().value()); } ServiceRelations serviceRelations = actionResponse.left().value(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java index 3e4907721d..74704caa64 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CapabilityRequirementConverter.java @@ -177,11 +177,6 @@ public class CapabilityRequirementConverter { private Object convertInstanceProperty(Map<String, DataTypeDefinition> dataTypes, ComponentInstance componentInstance, ComponentInstanceProperty prop) { logger.debug("Convert property {} for instance {}", prop.getName(), componentInstance.getUniqueId()); - String propertyType = prop.getType(); - String innerType = null; - if (prop.getSchema() != null && prop.getSchema().getProperty() != null) { - innerType = prop.getSchema().getProperty().getType(); - } String propValue = prop.getValue() == null ? prop.getDefaultValue() : prop.getValue(); return propertyConvertor.convertToToscaObject(prop, propValue, dataTypes, false); } |