diff options
author | 2021-03-01 20:58:10 +0000 | |
---|---|---|
committer | 2021-03-01 21:00:16 +0000 | |
commit | dfc9cdee69426b48d683e119dda9fae9154e6fde (patch) | |
tree | 70e81d301bcc21b1d604b9f301176c9677dcb33d /catalog-be/src/main/java/org/openecomp/sdc/be/components | |
parent | 97d15f764138e0d49963f168d339fc1637cc5376 (diff) |
Improve test coverage
- remove unused code
- use lombok
Change-Id: I8c52584249347c7ca2102022457225401f95b9a5
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3490
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components')
15 files changed, 10 insertions, 397 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java index 15cde435ed..51199e62a9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java @@ -28,7 +28,6 @@ import org.openecomp.sdc.be.components.impl.CsarValidationUtils; import org.openecomp.sdc.be.components.impl.GroupBusinessLogic; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.model.Component; @@ -236,19 +235,6 @@ public class CsarBusinessLogic extends BaseBusinessLogic { throw new ByResponseFormatComponentException(errorResponse, params); } - private Map<String, byte[]> getCsar(User user, Map<String, byte[]> payload, String csarUUID) { - if (payload != null) { - return payload; - } - Either<Map<String, byte[]>, StorageOperationStatus> csar = csarOperation.getCsar(csarUUID, user); - if (csar.isRight()) { - StorageOperationStatus value = csar.right().value(); - log.debug("#getCsar - failed to fetch csar with ID {}, error: {}", csarUUID, value); - throw new StorageException(value); - } - return csar.left().value(); - } - private Either<ImmutablePair<String, String>, ResponseFormat> validateAndParseCsar(Service service, User user, Map<String, byte[]> payload, String csarUUID) { Map<String, byte[]> csar = getCsar(service, user, payload, csarUUID); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java index f4eb081b99..2fa6190c44 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngine.java @@ -32,15 +32,12 @@ import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry; import org.openecomp.sdc.common.log.wrappers.Logger; -import org.openecomp.sdc.common.util.YamlToObjectConverter; -import org.openecomp.sdc.exception.YamlConversionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.annotation.Resource; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -73,26 +70,6 @@ public class DistributionEngine implements IDistributionEngine { private Map<String, DistributionEnginePollingTask> envNamePerPollingTask = new HashMap<>(); private Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>(); - /** - * The main method for testing only - * @param args - */ - public static void main(String[] args) throws YamlConversionException { - - List<String> servers = new ArrayList<>(); - String server = "uebsb91kcdc.it.att.com:3904"; - servers.add(server); - servers.add(server); - servers.add(server); - - YamlToObjectConverter converter = new YamlToObjectConverter(); - DistributionEngineConfiguration distributionEngineConfiguration = converter.convert("src/test/resources/config/catalog-be/distribEngine1/distribution-engine-configuration.yaml", DistributionEngineConfiguration.class); - - DistributionEngineInitTask distributionEngineInitTask = new DistributionEngineInitTask(2l, distributionEngineConfiguration, "PROD", new AtomicBoolean(false), null, null, null); - distributionEngineInitTask.startTask(); - - } - @Override public boolean isActive() { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformation.java index 5d98006dec..70ec37ce48 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformation.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ActivationRequestInformation.java @@ -20,7 +20,6 @@ package org.openecomp.sdc.be.components.impl; -import com.google.common.annotations.VisibleForTesting; import org.openecomp.sdc.be.model.Service; /** @@ -31,9 +30,6 @@ public class ActivationRequestInformation { private String workloadContext; private String tenant; - @VisibleForTesting - ActivationRequestInformation() {} - public ActivationRequestInformation(Service serviceToActivate, String workloadContext, String tenant) { this.serviceToActivate = serviceToActivate; this.workloadContext = workloadContext; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java index 712cba74b7..ee6878e7d7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/AdditionalInformationBusinessLogic.java @@ -28,7 +28,6 @@ import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.AdditionalInformationDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation; @@ -43,15 +42,12 @@ import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils; import org.openecomp.sdc.be.model.tosca.converters.StringConvertor; import org.openecomp.sdc.be.model.tosca.validators.StringValidator; -import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.util.ValidationUtils; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.web.context.WebApplicationContext; -import javax.servlet.ServletContext; import java.util.List; @Component("additionalInformationBusinessLogic") @@ -84,14 +80,6 @@ public class AdditionalInformationBusinessLogic extends BaseBusinessLogic { this.additionalInformationOperation = additionalInformationOperation; } - protected static IElementOperation getElementDao(Class<IElementOperation> class1, ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - - return webApplicationContext.getBean(class1); - } - /** * Create new additional information on resource/service on graph * @param nodeType diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java index 374e98e61f..046ad22159 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java @@ -29,8 +29,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import fj.data.Either; import io.vavr.control.Option; -import java.io.ByteArrayInputStream; -import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collections; @@ -49,10 +47,6 @@ import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; -import javax.xml.XMLConstants; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; @@ -145,11 +139,6 @@ import org.openecomp.sdc.common.util.ValidationUtils; import org.openecomp.sdc.common.util.YamlToObjectConverter; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; -import org.xml.sax.XMLReader; import org.yaml.snakeyaml.Yaml; @org.springframework.stereotype.Component("artifactBusinessLogic") @@ -2068,33 +2057,6 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { } } - private boolean isValidXml(byte[] xmlToParse) { - boolean isXmlValid = true; - try { - SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); - saxParser.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); - saxParser.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); - XMLReader reader = saxParser.getXMLReader(); - setFeatures(reader); - reader.parse(new InputSource(new ByteArrayInputStream(xmlToParse))); - } - catch (ParserConfigurationException | IOException | SAXException e) { - log.debug("Xml is invalid : {}", e.getMessage(), e); - isXmlValid = false; - } - return isXmlValid; - } - - private void setFeatures(XMLReader reader) throws SAXNotSupportedException { - try { - reader.setFeature("http://apache.org/xml/features/validation/schema", false); - reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - } - catch (SAXNotRecognizedException e) { - log.debug("Xml parser couldn't set feature: \"http://apache.org/xml/features/validation/schema\", false", e.getMessage(), e); - } - } - private void validateSingleDeploymentArtifactName(final String artifactName, final Component parentComponent) { boolean artifactNameFound = false; final Iterator<ArtifactDefinition> parentDeploymentArtifactsItr = diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java index c7da584fe8..a640de0be7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java @@ -38,7 +38,6 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity; @@ -767,16 +766,6 @@ public abstract class BaseBusinessLogic { } - protected void rollbackWithException(StorageException e) { - janusGraphDao.rollback(); - throw e; - } - - protected void rollbackWithException(ComponentException e) { - janusGraphDao.rollback(); - throw e; - } - protected void unlockRollbackWithException(Component component, RuntimeException e) { janusGraphDao.rollback(); graphLockOperation.unlockComponent(component.getUniqueId(), component.getComponentType().getNodeType()); @@ -798,18 +787,10 @@ public abstract class BaseBusinessLogic { throw new StorageException(storageOperationStatus); } - protected PolicyDefinition storageExceptionPolicyDefinition(StorageOperationStatus storageOperationStatus) { - throw new StorageException(storageOperationStatus); - } - protected PolicyDefinition componentExceptionPolicyDefinition(ResponseFormat responseFormat) { throw new ByResponseFormatComponentException(responseFormat); } - protected Component componentException(ResponseFormat responseFormat) { - throw new ByResponseFormatComponentException(responseFormat); - } - protected List<ComponentInstanceProperty> componentInstancePropertyListException(StorageOperationStatus storageOperationStatus) { throw new StorageException(storageOperationStatus); } 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 0b04f70779..efab8592c1 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 @@ -23,7 +23,6 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; -import io.vavr.Function3; import java.util.Optional; import java.util.function.BiFunction; import java.util.function.BooleanSupplier; @@ -185,8 +184,6 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { private static final Logger log = Logger.getLogger(ComponentBusinessLogic.class.getName()); - private static final String TAG_FIELD_LABEL = "tag"; - public abstract Either<List<String>, ResponseFormat> deleteMarkedComponents(); public abstract ComponentInstanceBusinessLogic getComponentInstanceBL(); @@ -424,23 +421,6 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { } } - private Boolean isHighest(HighestFilterEnum highestFilter) { - Boolean isHighest = null; - switch (highestFilter) { - case ALL: - break; - case HIGHEST_ONLY: - isHighest = true; - break; - case NON_HIGHEST_ONLY: - isHighest = false; - break; - default: - break; - } - return isHighest; - } - public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(boolean isAbstractAbstract, HighestFilterEnum highestFilter, ComponentTypeEnum componentTypeEnum, String internalComponentType, String userId) { try{ validateUserExists(userId); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java index 5f1e6a100f..1e0f6863f9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java @@ -50,7 +50,7 @@ public class ComponentBusinessLogicProvider { case RESOURCE_INSTANCE: return resourceBusinessLogic; default: - BeEcompErrorManager.getInstance().logBeSystemError("getComponentBL"); + BeEcompErrorManager.getInstance().logBeSystemError("getInstance"); throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT, componentTypeEnum.getValue()); } } 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 9c092da300..631daefff8 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 @@ -208,10 +208,6 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return response; } - private Either<Map<String, Set<? extends Component>>, ResponseFormat> handleGovernor() { - return handleFollowedCertifiedServices(null); - } - private Either<Map<String, Set<? extends Component>>, ResponseFormat> handleProductStrategist() { // Should be empty list according to Ella, 13/03/16 Map<String, Set<? extends Component>> result = new HashMap<>(); @@ -232,20 +228,6 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return response; } - private Either<Map<String, Set<? extends Component>>, ResponseFormat> handleFollowedCertifiedServices(Set<DistributionStatusEnum> distStatus) { - - Either<List<Service>, StorageOperationStatus> services = toscaOperationFacade.getCertifiedServicesWithDistStatus(distStatus); - if (services.isLeft()) { - Map<String, Set<? extends Component>> result = new HashMap<>(); - Set<Service> set = new HashSet<>(); - set.addAll(services.left().value()); - result.put(SERVICES, set); - return Either.left(result); - } else { - return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(services.right().value()))); - } - } - private Either<Map<String, Set<? extends Component>>, ResponseFormat> getFollowedResourcesAndServices(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates) { try { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java index c74520f825..b8541f18f2 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java @@ -20,7 +20,6 @@ package org.openecomp.sdc.be.components.impl; -import fj.data.Either; import org.apache.commons.lang.StringUtils; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; @@ -31,8 +30,6 @@ import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.PolicyTypeDefinition; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation; -import org.openecomp.sdc.common.log.wrappers.Logger; -import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -45,7 +42,6 @@ import static java.util.Collections.emptySet; @Component public class PolicyTypeBusinessLogic { - private static final Logger log = Logger.getLogger(PolicyTypeBusinessLogic.class); private PolicyTypeOperation policyTypeOperation; private JanusGraphDao janusGraphDao; private ComponentsUtils componentsUtils; @@ -84,11 +80,6 @@ public class PolicyTypeBusinessLogic { return policyTypeOperation.getAllPolicyTypes(excludedTypes); } - private Either<List<PolicyTypeDefinition>, ResponseFormat> convertToResponseFormatOrNotFoundErrorToEmptyList(StorageOperationStatus err) { - log.debug("error when trying to fetch policy types: {}", err); - return componentsUtils.convertToResponseFormatOrNotFoundErrorToEmptyList(err); - } - private PolicyTypeDefinition failOnPolicyType(StorageOperationStatus status, String policyType) { janusGraphDao.rollback(); if (status == StorageOperationStatus.INVALID_ID) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java index b271ea0137..66a6a27e16 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PropertyBusinessLogic.java @@ -24,23 +24,19 @@ import com.google.gson.JsonElement; import fj.data.Either; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstanceInterface; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.DataTypeDefinition; -import org.openecomp.sdc.be.model.IComplexDefaultValue; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations; @@ -58,20 +54,16 @@ import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; import org.openecomp.sdc.be.model.tosca.converters.PropertyValueConverter; import org.openecomp.sdc.be.model.tosca.validators.PropertyTypeValidator; import org.openecomp.sdc.be.resources.data.EntryData; -import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.context.WebApplicationContext; -import javax.servlet.ServletContext; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.function.Supplier; @org.springframework.stereotype.Component("propertyBusinessLogic") @@ -95,14 +87,6 @@ public class PropertyBusinessLogic extends BaseBusinessLogic { interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation); } - protected static IElementOperation getElementDao(Class<IElementOperation> class1, ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - - return webApplicationContext.getBean(class1); - } - public Map<String, DataTypeDefinition> getAllDataTypes() { return getAllDataTypes(applicationDataTypeCache); } @@ -604,76 +588,6 @@ public class PropertyBusinessLogic extends BaseBusinessLogic { return propertyCandidate.isPresent(); } - private StorageOperationStatus validateAndUpdateProperty(IComplexDefaultValue propertyDefinition, Map<String, DataTypeDefinition> dataTypes) { - - log.trace("Going to validate property type and value. {}", propertyDefinition); - - String propertyType = propertyDefinition.getType(); - String value = propertyDefinition.getDefaultValue(); - - ToscaPropertyType type = getType(propertyType); - - if (type == null) { - DataTypeDefinition dataTypeDefinition = dataTypes.get(propertyType); - if (dataTypeDefinition == null) { - log.debug("The type {} of property cannot be found.", propertyType); - return StorageOperationStatus.INVALID_TYPE; - } - return validateAndUpdateComplexValue(propertyDefinition, propertyType, value, dataTypeDefinition, dataTypes); - } - String innerType; - - Either<String, JanusGraphOperationStatus> checkInnerType = getInnerType(type, propertyDefinition::getSchema); - if (checkInnerType.isRight()) { - return StorageOperationStatus.INVALID_TYPE; - } - innerType = checkInnerType.left().value(); - - log.trace("After validating property type {}", propertyType); - - boolean isValidProperty = isValidValue(type, value, innerType, dataTypes); - if (!isValidProperty) { - log.info("The value {} of property from type {} is invalid", value, type); - return StorageOperationStatus.INVALID_VALUE; - } - - PropertyValueConverter converter = type.getConverter(); - - if (isEmptyValue(value)) { - log.debug("Default value was not sent for property {}. Set default value to {}", propertyDefinition.getName(), EMPTY_VALUE); - propertyDefinition.setDefaultValue(EMPTY_VALUE); - } else if (!isEmptyValue(value)) { - String convertedValue = converter.convert(value, innerType, dataTypes); - propertyDefinition.setDefaultValue(convertedValue); - } - return StorageOperationStatus.OK; - } - - private StorageOperationStatus validateAndUpdateComplexValue(IComplexDefaultValue propertyDefinition, String propertyType, - String value, DataTypeDefinition dataTypeDefinition, Map<String, DataTypeDefinition> dataTypes) { - - ImmutablePair<JsonElement, Boolean> validateResult = dataTypeValidatorConverter.validateAndUpdate(value, dataTypeDefinition, dataTypes); - - if (validateResult.right) { - log.debug("The value {} of property from type {} is invalid", propertyType, propertyType); - return StorageOperationStatus.INVALID_VALUE; - } - - JsonElement jsonElement = validateResult.left; - - log.trace("Going to update value in property definition {} {}" , propertyDefinition.getName() , jsonElement); - - updateValue(propertyDefinition, jsonElement); - - return StorageOperationStatus.OK; - } - - private void updateValue(IComplexDefaultValue propertyDefinition, JsonElement jsonElement) { - - propertyDefinition.setDefaultValue(getValueFromJsonElement(jsonElement)); - - } - @Override protected String getValueFromJsonElement(JsonElement jsonElement) { if (jsonElement == null || jsonElement.isJsonNull()) { @@ -685,25 +599,6 @@ public class PropertyBusinessLogic extends BaseBusinessLogic { return jsonElement.toString(); } - private Either<String, JanusGraphOperationStatus> getInnerType(ToscaPropertyType type, Supplier<SchemaDefinition> schemeGen) { - String innerType = null; - if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) { - - SchemaDefinition def = schemeGen.get(); - if (def == null) { - log.debug("Schema doesn't exists for property of type {}", type); - return Either.right(JanusGraphOperationStatus.ILLEGAL_ARGUMENT); - } - PropertyDataDefinition propDef = def.getProperty(); - if (propDef == null) { - log.debug("Property in Schema Definition inside property of type {} doesn't exist", type); - return Either.right(JanusGraphOperationStatus.ILLEGAL_ARGUMENT); - } - innerType = propDef.getType(); - } - return Either.left(innerType); - } - @Override protected boolean isValidValue(ToscaPropertyType type, String value, String innerType, Map<String, DataTypeDefinition> dataTypes) { if (isEmptyValue(value)) { 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 3676844516..a3d746da89 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 @@ -50,7 +50,6 @@ import java.util.Set; import java.util.function.Function; import java.util.regex.Pattern; import java.util.stream.Collectors; -import javax.servlet.ServletContext; import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; @@ -107,7 +106,6 @@ import org.openecomp.sdc.be.datatypes.enums.CreatedFrom; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; -import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.info.NodeTypeInfoToUpdateArtifacts; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.AttributeDefinition; @@ -186,7 +184,6 @@ import org.openecomp.sdc.common.util.ValidationUtils; import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; -import org.springframework.web.context.WebApplicationContext; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; @@ -3768,17 +3765,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { resourcesInstancesMap.put(componentInstance, origResource); } - private ComponentParametersView getComponentWithInstancesFilter() { - ComponentParametersView parametersView = new ComponentParametersView(); - parametersView.disableAll(); - parametersView.setIgnoreComponentInstances(false); - parametersView.setIgnoreInputs(false); - // inputs are read when creating - // property values on instances - parametersView.setIgnoreUsers(false); - return parametersView; - } - private void setCapabilityNamesTypes(Map<String, List<CapabilityDefinition>> originCapabilities, Map<String, List<UploadCapInfo>> uploadedCapabilities) { for (Entry<String, List<UploadCapInfo>> currEntry : uploadedCapabilities.entrySet()) { @@ -5632,17 +5618,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } - /**** Auditing *******************/ - - protected static IElementOperation getElementDao(Class<IElementOperation> class1, ServletContext context) { - WebAppContextWrapper webApplicationContextWrapper = (WebAppContextWrapper) context - .getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR); - - WebApplicationContext webApplicationContext = webApplicationContextWrapper.getWebAppContext(context); - - return webApplicationContext.getBean(class1); - } - public ICapabilityTypeOperation getCapabilityTypeOperation() { return capabilityTypeOperation; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java index 383d7cda95..8ea1c2a28f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java @@ -29,7 +29,6 @@ import static org.openecomp.sdc.be.utils.TypeUtils.setField; import fj.data.Either; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -245,17 +244,6 @@ public class ResourceImportManager { return responsePair; } - private ResponseFormat getResponseFormatFromComponentException(RuntimeException e) { - if (e instanceof ComponentException) { - return ((ComponentException) e).getResponseFormat() == null ? - componentsUtils - .getResponseFormat(((ComponentException) e).getActionStatus(), ((ComponentException) e).getParams()) - : - ((ComponentException) e).getResponseFormat(); - } - return null; - } - private String getLatestCertifiedResourceId(Resource resource) { Map<String, String> allVersions = resource.getAllVersions(); Double latestCertifiedVersion = 0.0; @@ -890,17 +878,6 @@ public class ResourceImportManager { } } - private Map<String, Object> getDataTypes(final String payloadData) { - final Map<String, Object> mappedToscaTemplate = decodePayload(payloadData); - final Either<Map<String, Object>, ResultStatusEnum> findFirstToscaStringElement = - ImportUtils.findFirstToscaMapElement(mappedToscaTemplate, ToscaTagNamesEnum.DATA_TYPES); - if (findFirstToscaStringElement.isLeft()) { - return findFirstToscaStringElement.left().value(); - } else { - return Collections.EMPTY_MAP; - } - } - private void calculateResourceIsAbstract(Resource resource, List<CategoryDefinition> categories) { if (categories != null && !categories.isEmpty()) { CategoryDefinition categoryDef = categories.get(0); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java index 9eb9c3418a..ad1f818da6 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java @@ -54,6 +54,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; +import lombok.Getter; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.collections4.ListUtils; @@ -67,7 +68,6 @@ import org.openecomp.sdc.be.components.health.HealthCheckBusinessLogic; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; -import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; import org.openecomp.sdc.be.components.path.ForwardingPathValidator; import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils; import org.openecomp.sdc.be.components.utils.PropertiesUtils; @@ -114,7 +114,6 @@ import org.openecomp.sdc.be.model.ComponentInstanceInterface; import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.DistributionStatusEnum; -import org.openecomp.sdc.be.model.DistributionTransitionEnum; import org.openecomp.sdc.be.model.GroupInstance; import org.openecomp.sdc.be.model.GroupInstanceProperty; import org.openecomp.sdc.be.model.InputDefinition; @@ -170,7 +169,6 @@ import org.springframework.web.context.WebApplicationContext; @org.springframework.stereotype.Component("serviceBusinessLogic") public class ServiceBusinessLogic extends ComponentBusinessLogic { - private static final String CHANGE_SERVICE_DISTRIBUTION = "Change Service Distribution"; private static final String THE_SERVICE_WITH_SYSTEM_NAME_LOCKED = "The service with system name {} locked. "; private static final String FAILED_TO_LOCK_SERVICE_RESPONSE_IS = "Failed to lock service {}. Response is {}. "; private static final String AUDIT_BEFORE_SENDING_RESPONSE = "audit before sending response"; @@ -1698,51 +1696,6 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { return artifactInfo; } - private DistributionTransitionEnum validateTransitionEnum(String distributionTransition) { - DistributionTransitionEnum transitionEnum; - - transitionEnum = DistributionTransitionEnum.getFromDisplayName(distributionTransition); - if (transitionEnum == null) { - BeEcompErrorManager.getInstance().logBeSystemError(CHANGE_SERVICE_DISTRIBUTION); - log.info("state operation is not valid. operations allowed are: {}", DistributionTransitionEnum.valuesAsString()); - throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_DISTRIBUTION_STATUS, distributionTransition)); - } - - return transitionEnum; - } - - private String validateComment(LifecycleChangeInfoWithAction comment) { - if (comment==null || StringUtils.isEmpty(comment.getUserRemarks())) { - return ""; - } - String data = comment.getUserRemarks(); - data = ValidationUtils.removeNoneUtf8Chars(data); - data = ValidationUtils.removeHtmlTags(data); - data = ValidationUtils.normaliseWhitespace(data); - data = ValidationUtils.stripOctets(data); - - if (!ValidationUtils.validateLength(data, ValidationUtils.COMMENT_MAX_LENGTH)) { - BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CHANGE_SERVICE_DISTRIBUTION); - log.debug("user comment exceeds limit."); - throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.EXCEEDS_LIMIT, "comment", String.valueOf(ValidationUtils.COMMENT_MAX_LENGTH))); - } - if (!ValidationUtils.validateCommentPattern(data)) { - throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)); - } - - return data; - } - - private void createAudit(User user, AuditingActionEnum auditAction, String comment, Service component, ResponseFormat responseFormat) { - log.debug(AUDIT_BEFORE_SENDING_RESPONSE); - componentsUtils.auditComponent(responseFormat, user, component, auditAction, new ResourceCommonInfo(ComponentTypeEnum.SERVICE.getValue()), - ResourceVersionInfo.newBuilder() - .state(component.getLifecycleState().name()) - .version(component.getVersion()) - .build(), - comment); - } - private String getEnvNameFromConfiguration() { String configuredEnvName = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getEnvironments().get(0); log.trace("Update environment name to be {}", configuredEnvName); @@ -2101,14 +2054,15 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { } + @Getter class HeatEnvArtifactGenerator extends ArtifactGenerator<ArtifactDefinition> { - ArtifactDefinition artifactDefinition; - Service service; - String resourceInstanceName; - User modifier; - String instanceId; - boolean shouldLock; - boolean inTransaction; + private ArtifactDefinition artifactDefinition; + private Service service; + private String resourceInstanceName; + private User modifier; + private String instanceId; + private boolean shouldLock; + private boolean inTransaction; HeatEnvArtifactGenerator(ArtifactDefinition artifactDefinition, Service service, String resourceInstanceName, User modifier, boolean shouldLock, boolean inTransaction, String instanceId) { this.artifactDefinition = artifactDefinition; @@ -2125,10 +2079,6 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { return artifactsBusinessLogic.forceGenerateHeatEnvArtifact(artifactDefinition, ComponentTypeEnum.RESOURCE_INSTANCE, service, resourceInstanceName, modifier, shouldLock, inTransaction, instanceId); } - public ArtifactDefinition getArtifactDefinition() { - return artifactDefinition; - } - } class VfModuleArtifactGenerator extends ArtifactGenerator<ArtifactDefinition> { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java index 1fff794750..b876782ce4 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java @@ -121,33 +121,6 @@ public class InterfaceOperationValidation { return Either.left(Boolean.TRUE); } - private Either<Boolean, ResponseFormat> validateAllowedOperationCountOnLocalInterfaceType( - InterfaceDefinition inputInterfaceDefinition, InterfaceDefinition storedInterfaceDefinition, - Map<String, InterfaceDefinition> globalInterfaceTypes, boolean isUpdate) { - - boolean isInterfaceTypeExistInGlobalType = - globalInterfaceTypes.values().stream().map(InterfaceDefinition::getType) - .anyMatch(type -> type.equalsIgnoreCase(inputInterfaceDefinition.getType())); - if (!isInterfaceTypeExistInGlobalType - && isValidOperationOnLocalInterfaceType(inputInterfaceDefinition, storedInterfaceDefinition, - isUpdate)) { - return Either.right(getResponseFormatManager() - .getResponseFormat(ActionStatus.INTERFACE_OPERATION_INVALID_FOR_LOCAL_TYPE, - inputInterfaceDefinition.getType())); - } - - return Either.left(Boolean.TRUE); - } - - private boolean isValidOperationOnLocalInterfaceType(InterfaceDefinition inputInterfaceDefinition, - InterfaceDefinition storedInterfaceDefinition, - boolean isUpdate) { - return inputInterfaceDefinition.getOperations().size() > 1 - || (!isUpdate && storedInterfaceDefinition != null - && storedInterfaceDefinition.getType() - .equalsIgnoreCase(inputInterfaceDefinition.getType())); - } - private Either<Boolean, ResponseFormat> validateAllowedOperationsOnGlobalInterfaceType( InterfaceDefinition interfaceDefinition, Map<String, InterfaceDefinition> globalInterfaceTypes) { |