From 4ff80494ce3ef425efe60ee41a4bfecdbd7e4027 Mon Sep 17 00:00:00 2001 From: "Sindhuri.A" Date: Fri, 2 Nov 2018 18:19:47 +0530 Subject: Refactor catalog-be code Code refactor : catalog-be classes Issue-ID: SDC-1880 Change-Id: Ib1153c622d2b7f9de7369d388be4d2e5fc84178f Signed-off-by: Sindhuri.A --- .../be/components/impl/CsarValidationUtils.java | 40 ++++--- .../be/components/impl/ElementBusinessLogic.java | 116 ++++++++++----------- .../sdc/be/components/impl/GroupBusinessLogic.java | 2 +- .../be/components/impl/ProductBusinessLogic.java | 11 +- .../be/components/impl/ResourceBusinessLogic.java | 13 +-- 5 files changed, 88 insertions(+), 94 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java index b008e516cb..dbfe7d8b71 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CsarValidationUtils.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -65,14 +65,15 @@ public class CsarValidationUtils { public static final String FILE_NOT_FOUND_IN_CSAR_WITH_ID = " file not found in CSAR with id "; public static final String CSAR_STRUCTURE_IS_INVALID = "CSAR structure is invalid"; public static final String ENTRY_DEFINITIONS = "Entry-Definitions "; + private static final Pattern floatPattern = Pattern.compile("^\\d{1}[.]\\d{1}$"); /** - * Validates Csar - * @param csar - * @param csarUUID - * @param componentsUtils - * @return - */ + * Validates Csar + * @param csar + * @param csarUUID + * @param componentsUtils + * @return + */ public static Either validateCsar(Map csar, String csarUUID, ComponentsUtils componentsUtils) { Either validateStatus = validateIsTOSCAMetadataExist(csar, csarUUID, componentsUtils); if (validateStatus.isRight()) { @@ -126,7 +127,7 @@ public class CsarValidationUtils { String vfcToscaName = parsedPath.length == 5 ? parsedPath[1] : null; if(artifactName.equalsIgnoreCase(otherArtifactName) && groupType.equalsIgnoreCase(otherGroupType)){ - isEqualArtifactNames = vfcToscaName == null ? true : vfcToscaName.equalsIgnoreCase(otherParsedPath[1]); + isEqualArtifactNames = vfcToscaName == null || vfcToscaName.equalsIgnoreCase(otherParsedPath[1]); } return isEqualArtifactNames; } @@ -161,7 +162,7 @@ public class CsarValidationUtils { keyOp = csar.keySet().stream().filter(k -> Pattern.compile(result).matcher(k).matches()).findAny(); if(!keyOp.isPresent()){ log.debug(ENTRY_DEFINITIONS_ENTRY_NOT_FOUND_IN_TOSCA_METADATA_TOSCA_META_FILE_CSAR_ID, csarUUID); - BeEcompErrorManager.getInstance().logInternalDataError("Entry-Definitions entry not found in TOSCA-Metadata/TOSCA.meta file in CSAR with id " + csarUUID, CSAR_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR); + BeEcompErrorManager.getInstance().logInternalDataError(ENTRY_DEFINITIONS_ENTRY_NOT_FOUND_IN_TOSCA_METADATA_TOSCA_META_FILE_CSAR_ID + csarUUID, CSAR_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR); return Either.right(componentsUtils.getResponseFormat(ActionStatus.YAML_NOT_FOUND_IN_CSAR, csarUUID, yamlFileName)); } @@ -182,7 +183,7 @@ public class CsarValidationUtils { if( !csar.containsKey(CsarUtils.ARTIFACTS_PATH + ARTIFACTS_METADATA_FILE) ) { log.debug(ENTRY_DEFINITIONS_ENTRY_NOT_FOUND_IN_TOSCA_METADATA_TOSCA_META_FILE_CSAR_ID, csarUUID); - BeEcompErrorManager.getInstance().logInternalDataError("Entry-Definitions entry not found in TOSCA-Metadata/TOSCA.meta file in CSAR with id " + csarUUID, CSAR_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR); + BeEcompErrorManager.getInstance().logInternalDataError(ENTRY_DEFINITIONS_ENTRY_NOT_FOUND_IN_TOSCA_METADATA_TOSCA_META_FILE_CSAR_ID + csarUUID, CSAR_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR); return Either.right(componentsUtils.getResponseFormat(ActionStatus.YAML_NOT_FOUND_IN_CSAR, csarUUID, ARTIFACTS_METADATA_FILE)); } @@ -202,7 +203,7 @@ public class CsarValidationUtils { public static Either, ResponseFormat> getArtifactsContent(String csarUUID, Map csar, String artifactPath, String artifactName, ComponentsUtils componentsUtils) { if (!csar.containsKey(artifactPath)) { log.debug("Entry-Definitions entry not found in Artifacts/HEAT.meta file, csar ID {}", csarUUID); - BeEcompErrorManager.getInstance().logInternalDataError("Entry-Definitions entry not found in TOSCA-Metadata/TOSCA.meta file in CSAR with id " + csarUUID, CSAR_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR); + BeEcompErrorManager.getInstance().logInternalDataError(ENTRY_DEFINITIONS_ENTRY_NOT_FOUND_IN_TOSCA_METADATA_TOSCA_META_FILE_CSAR_ID + csarUUID, CSAR_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR); return Either.right(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND_IN_CSAR, CsarUtils.ARTIFACTS_PATH + artifactName, csarUUID)); } @@ -236,16 +237,16 @@ public class CsarValidationUtils { return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, csarUUID)); } - Either block_0Status = validateBlock_0(csarUUID, splited, componentsUtils); - if (block_0Status.isRight()) { - return Either.right(block_0Status.right().value()); + Either blockStatus = validateBlock(csarUUID, splited, componentsUtils); + if (blockStatus.isRight()) { + return Either.right(blockStatus.right().value()); } return Either.left(true); } - private static Either validateBlock_0(String csarUUID, String[] splited, ComponentsUtils componentsUtils) { + private static Either validateBlock(String csarUUID, String[] splited, ComponentsUtils componentsUtils) { int index = 0; for (String toscaField : TOSCA_METADATA_FIELDS) { @@ -275,7 +276,7 @@ public class CsarValidationUtils { if ((toscaField.equals(TOSCA_META_FILE_VERSION) || toscaField.equals(CSAR_VERSION)) && !validateTOSCAMetaProperty(value)) { log.debug("TOSCA-Metadata/TOSCA.meta file contains {} in wrong format (digit.digit), csar ID {}", toscaField, csarUUID); BeEcompErrorManager.getInstance() - .logInternalDataError(TOSCA_METADATA_TOSCA_META_FILE_NOT_IN_EXPECTED_KEY_VALUE_FORM_IN_CSAR_WITH_ID + csarUUID, CSAR_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR); + .logInternalDataError(TOSCA_METADATA_TOSCA_META_FILE_NOT_IN_EXPECTED_KEY_VALUE_FORM_IN_CSAR_WITH_ID + csarUUID, CSAR_INTERNALS_ARE_INVALID, ErrorSeverity.ERROR); return Either.right(componentsUtils.getResponseFormat(ActionStatus.CSAR_INVALID_FORMAT, csarUUID)); } index++; @@ -284,10 +285,7 @@ public class CsarValidationUtils { } private static boolean validateTOSCAMetaProperty(String toscaProperty) { - final String FLOAT_STRING = "^\\d{1}[.]\\d{1}$"; - final Pattern FLOAT_PATTERN = Pattern.compile(FLOAT_STRING); - - Matcher floatMatcher = FLOAT_PATTERN.matcher(toscaProperty); + Matcher floatMatcher = floatPattern.matcher(toscaProperty); return floatMatcher.matches(); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java index 630332fd32..8e9f65fce1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -93,47 +93,41 @@ public class ElementBusinessLogic extends BaseBusinessLogic { Either>, ResponseFormat> response = null; // Getting the role String role = user.getRole(); - String userId = null; + String userId = user.getUserId(); Role currentRole = Role.valueOf(role); switch (currentRole) { - case DESIGNER: - userId = user.getUserId(); - response = handleDesigner(userId); - break; - - case TESTER: - userId = user.getUserId(); - response = handleTester(); - break; - - case GOVERNOR: - userId = user.getUserId(); - response = handleGovernor(); - break; - - case OPS: - userId = user.getUserId(); - response = handleOps(); - break; - - case PRODUCT_STRATEGIST: - userId = user.getUserId(); - response = handleProductStrategist(); - break; - - case PRODUCT_MANAGER: - userId = user.getUserId(); - response = handleProductManager(userId); - break; - - case ADMIN: - response = handleAdmin(); - break; - - default: - response = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)); - break; + case DESIGNER: + response = handleDesigner(userId); + break; + + case TESTER: + response = handleTester(); + break; + + case GOVERNOR: + response = handleGovernor(); + break; + + case OPS: + response = handleOps(); + break; + + case PRODUCT_STRATEGIST: + response = handleProductStrategist(); + break; + + case PRODUCT_MANAGER: + response = handleProductManager(userId); + break; + + case ADMIN: + response = handleAdmin(); + break; + + default: + response = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)); + break; } // converting the Set to List so the rest of the code will handle it normally (Was changed because the same element with the same uuid was returned twice) return convertedToListResponse(response); @@ -864,10 +858,10 @@ public class ElementBusinessLogic extends BaseBusinessLogic { boolean validResourceAction = componentType == ComponentTypeEnum.RESOURCE && (categoryType == CategoryTypeEnum.CATEGORY || categoryType == CategoryTypeEnum.SUBCATEGORY); boolean validServiceAction = componentType == ComponentTypeEnum.SERVICE && categoryType == CategoryTypeEnum.CATEGORY; boolean validProductAction = componentType == ComponentTypeEnum.PRODUCT; // can - // be - // any - // category - // type + // be + // any + // category + // type if (!(validResourceAction || validServiceAction || validProductAction)) { ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT); @@ -957,7 +951,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return elementOperation.getDefaultHeatTimeout(); } - public Either>, ResponseFormat> getCatalogComponents(String userId, List excludeTypes) { + public Either>, ResponseFormat> getCatalogComponents(String userId, List excludeTypes) { try { validateUserExists(userId, "get Catalog Components", true); return toscaOperationFacade.getCatalogOrArchiveComponents(true, excludeTypes) @@ -986,12 +980,12 @@ public class ElementBusinessLogic extends BaseBusinessLogic { private String cmptTypeToString(ComponentTypeEnum componentTypeEnum) { switch (componentTypeEnum) { - case RESOURCE: - return RESOURCES; - case SERVICE: - return SERVICES; - default: - throw new IllegalStateException("resources or services only"); + case RESOURCE: + return RESOURCES; + case SERVICE: + return SERVICES; + default: + throw new IllegalStateException("resources or services only"); } } @@ -1022,7 +1016,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value()), params.get(0), params.get(1), params.get(2))); } if (result.left().value().isEmpty()) {// no assets found for requested - // criteria + // criteria return Either.right(componentsUtils.getResponseFormat(ActionStatus.NO_ASSETS_FOUND, assetType, query)); } return Either.left(result.left().value()); @@ -1090,15 +1084,15 @@ public class ElementBusinessLogic extends BaseBusinessLogic { Map additionalPropertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); switch (assetTypeEnum) { - case RESOURCE: - additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); - break; - case SERVICE: - additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); - break; - default: - log.debug("getCatalogComponentsByUuidAndAssetType: Corresponding ComponentTypeEnum not allowed for this API"); - return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)); + case RESOURCE: + additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + break; + case SERVICE: + additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); + break; + default: + log.debug("getCatalogComponentsByUuidAndAssetType: Corresponding ComponentTypeEnum not allowed for this API"); + return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)); } Either, StorageOperationStatus> componentsListByUuid = toscaOperationFacade.getComponentListByUuid(uuid, additionalPropertiesToMatch); 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 f2d0d94418..c8266efd42 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 @@ -598,7 +598,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic { public Either, ResponseFormat> validateUpdateVfGroupNamesOnGraph(List groups, Component component) { List updatedGroups = new ArrayList<>(); - Either, ResponseFormat> result = Either.left(updatedGroups); + Either, ResponseFormat> result; for (GroupDefinition group : groups) { String groupType = group.getType(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java index dac241ba2f..8b22d60ce6 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java @@ -60,6 +60,12 @@ public class ProductBusinessLogic extends ComponentBusinessLogic { private static List updateRoles; private static List contactsRoles; + @Autowired + private ComponentInstanceBusinessLogic componentInstanceBusinessLogic; + + @Autowired + private ICacheMangerOperation cacheManagerOperation; + public ProductBusinessLogic() { creationRoles = new ArrayList<>(); updateRoles = new ArrayList<>(); @@ -72,11 +78,6 @@ public class ProductBusinessLogic extends ComponentBusinessLogic { contactsRoles.add(Role.PRODUCT_MANAGER); } - @Autowired - private ComponentInstanceBusinessLogic componentInstanceBusinessLogic; - - @Autowired - private ICacheMangerOperation cacheManagerOperation; public Either createProduct(Product product, User user) { AuditingActionEnum actionEnum = AuditingActionEnum.CREATE_RESOURCE; 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 4bceb0cc99..14e28f3530 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 @@ -123,12 +123,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { private static final String COMPONENT_INSTANCE_WITH_NAME = "component instance with name "; private static final String COMPONENT_INSTANCE_WITH_NAME_IN_RESOURCE = "component instance with name {} in resource {} "; - /** - * Default constructor - */ - public ResourceBusinessLogic() { - log.debug("ResourceBusinessLogic started"); - } @Autowired private ICapabilityTypeOperation capabilityTypeOperation = null; @@ -169,6 +163,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { @Autowired private CsarBusinessLogic csarBusinessLogic; + /** + * Default constructor + */ + public ResourceBusinessLogic() { + log.debug("ResourceBusinessLogic started"); + } + public LifecycleBusinessLogic getLifecycleBusinessLogic() { return lifecycleBusinessLogic; } -- cgit 1.2.3-korg