summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java517
1 files changed, 242 insertions, 275 deletions
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 efab8592c1..9ce54c2cc8 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
@@ -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.
@@ -19,13 +19,18 @@
* Modifications copyright (c) 2019 Nokia
* ================================================================================
*/
-
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.BooleanSupplier;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -96,51 +101,31 @@ import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-
public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
- protected ArtifactsBusinessLogic artifactsBusinessLogic;
-
+ private static final Logger log = Logger.getLogger(ComponentBusinessLogic.class.getName());
protected final GroupBusinessLogic groupBusinessLogic;
-
+ protected ArtifactsBusinessLogic artifactsBusinessLogic;
protected GenericTypeBusinessLogic genericTypeBusinessLogic;
-
protected ComponentDescriptionValidator componentDescriptionValidator;
protected ComponentProjectCodeValidator componentProjectCodeValidator;
-
protected CatalogOperation catalogOperations;
protected ComponentIconValidator componentIconValidator;
-
protected ComponentValidator componentValidator;
protected ComponentTagsValidator componentTagsValidator;
protected ComponentNameValidator componentNameValidator;
protected ComponentContactIdValidator componentContactIdValidator;
- public ComponentBusinessLogic(IElementOperation elementDao,
- IGroupOperation groupOperation,
- IGroupInstanceOperation groupInstanceOperation,
- IGroupTypeOperation groupTypeOperation,
- GroupBusinessLogic groupBusinessLogic,
- InterfaceOperation interfaceOperation,
- InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
- ArtifactsBusinessLogic artifactsBusinessLogic,
- ArtifactsOperations artifactToscaOperation,
- ComponentContactIdValidator componentContactIdValidator,
- ComponentNameValidator componentNameValidator,
- ComponentTagsValidator componentTagsValidator,
- ComponentValidator componentValidator,
- ComponentIconValidator componentIconValidator,
- ComponentProjectCodeValidator componentProjectCodeValidator,
- ComponentDescriptionValidator componentDescriptionValidator){
-
- super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
+ public ComponentBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
+ IGroupTypeOperation groupTypeOperation, GroupBusinessLogic groupBusinessLogic,
+ InterfaceOperation interfaceOperation, InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
+ ArtifactsBusinessLogic artifactsBusinessLogic, ArtifactsOperations artifactToscaOperation,
+ ComponentContactIdValidator componentContactIdValidator, ComponentNameValidator componentNameValidator,
+ ComponentTagsValidator componentTagsValidator, ComponentValidator componentValidator,
+ ComponentIconValidator componentIconValidator, ComponentProjectCodeValidator componentProjectCodeValidator,
+ ComponentDescriptionValidator componentDescriptionValidator) {
+ super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
+ artifactToscaOperation);
this.artifactsBusinessLogic = artifactsBusinessLogic;
this.groupBusinessLogic = groupBusinessLogic;
this.componentContactIdValidator = componentContactIdValidator;
@@ -152,6 +137,33 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
this.componentDescriptionValidator = componentDescriptionValidator;
}
+ private static Either<ArtifactDefinition, Operation> saveToscaArtifactAndPopulateToscaArtifactsWithResult(Component component,
+ final ComponentsUtils componentsUtils,
+ final ArtifactTypeEnum artifactEnum,
+ final BiFunction<Component, ArtifactDefinition, Either<ArtifactDefinition, Operation>> saveToscaArtifactPayloadFunction) {
+ ArtifactDefinition artifactDefinition = getToscaArtifactByTypeOrThrowException(component, artifactEnum, componentsUtils);
+ Either<ArtifactDefinition, Operation> result = saveToscaArtifactPayloadFunction.apply(component, artifactDefinition);
+ if (result.isLeft()) {
+ ArtifactDefinition def = result.left().value();
+ component.getToscaArtifacts().put(def.getArtifactLabel(), def);
+ }
+ return result;
+ }
+
+ private static Optional<ArtifactDefinition> getToscaArtifactByType(final Map<String, ArtifactDefinition> toscaArtifacts,
+ final ArtifactTypeEnum typeEnum) {
+ return toscaArtifacts.values().stream().filter(p -> p.getArtifactType().equals(typeEnum.getType())).findAny();
+ }
+
+ private static ArtifactDefinition getToscaArtifactByTypeOrThrowException(final Component component, final ArtifactTypeEnum typeEnum,
+ final ComponentsUtils componentsUtils) {
+ return Optional.ofNullable(component.getToscaArtifacts()).flatMap(toscaArtifacts -> getToscaArtifactByType(toscaArtifacts, typeEnum))
+ .orElseThrow(() -> {
+ log.debug("Impossible to find a ToscaArtifact with type '{}' for {}", typeEnum.getType(), component);
+ return new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, typeEnum.name()));
+ });
+ }
+
public void setComponentDescriptionValidator(ComponentDescriptionValidator componentDescriptionValidator) {
this.componentDescriptionValidator = componentDescriptionValidator;
}
@@ -176,27 +188,25 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
this.componentNameValidator = componentNameValidator;
}
-
@Autowired
public void setGenericTypeBusinessLogic(GenericTypeBusinessLogic genericTypeBusinessLogic) {
this.genericTypeBusinessLogic = genericTypeBusinessLogic;
}
- private static final Logger log = Logger.getLogger(ComponentBusinessLogic.class.getName());
-
public abstract Either<List<String>, ResponseFormat> deleteMarkedComponents();
public abstract ComponentInstanceBusinessLogic getComponentInstanceBL();
- public abstract Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId, String userId);
+ public abstract Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId,
+ String userId);
/**
- *
* @param componentId
* @param dataParamsToReturn
* @return
*/
- public abstract Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String componentId, List<String> dataParamsToReturn);
+ public abstract Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String componentId,
+ List<String> dataParamsToReturn);
User validateUser(User user, String ecompErrorContext, Component component, AuditingActionEnum auditAction, boolean inTransaction) {
User validatedUser;
@@ -204,14 +214,14 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
try {
validateUserNotEmpty(user, ecompErrorContext);
validatedUser = validateUserExists(user);
- } catch(ByActionStatusComponentException e){
- if(e.getActionStatus() == ActionStatus.MISSING_INFORMATION){
+ } catch (ByActionStatusComponentException e) {
+ if (e.getActionStatus() == ActionStatus.MISSING_INFORMATION) {
user.setUserId("UNKNOWN");
}
responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
componentsUtils.auditComponentAdmin(responseFormat, user, component, auditAction, component.getComponentType());
throw e;
- } catch(ByResponseFormatComponentException e){
+ } catch (ByResponseFormatComponentException e) {
responseFormat = e.getResponseFormat();
componentsUtils.auditComponentAdmin(responseFormat, user, component, auditAction, component.getComponentType());
throw e;
@@ -226,69 +236,64 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
try {
validateUserRole(user, roles);
- }catch (ByActionStatusComponentException e) {
+ } catch (ByActionStatusComponentException e) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
handleComponentException(component, comment, responseFormat, user, auditAction);
throw e;
- }catch (ByResponseFormatComponentException e) {
+ } catch (ByResponseFormatComponentException e) {
ResponseFormat responseFormat = e.getResponseFormat();
handleComponentException(component, comment, responseFormat, user, auditAction);
throw e;
}
}
- private void handleComponentException(Component component, String comment, ResponseFormat responseFormat,
- User user, AuditingActionEnum auditAction){
+ private void handleComponentException(Component component, String comment, ResponseFormat responseFormat, User user,
+ AuditingActionEnum auditAction) {
String commentStr = null;
String distrStatus = null;
ComponentTypeEnum componentType = component.getComponentType();
- if (componentType == ComponentTypeEnum.SERVICE) {
- distrStatus = ((ServiceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getDistributionStatus();
+ if (componentType == ComponentTypeEnum.SERVICE) {
+ distrStatus = ((ServiceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition())
+ .getDistributionStatus();
commentStr = comment;
}
componentsUtils.auditComponent(responseFormat, user, component, auditAction, new ResourceCommonInfo(componentType.getValue()),
ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(),
- ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(),
- commentStr, null, null);
+ ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(), commentStr, null, null);
}
public Either<Boolean, ResponseFormat> validateConformanceLevel(String componentUuid, ComponentTypeEnum componentTypeEnum, String userId) {
log.trace("validate conformance level");
-
if (componentTypeEnum != ComponentTypeEnum.SERVICE) {
log.error("conformance level validation for non service component, id {}", componentUuid);
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
return Either.right(errorResponse);
}
-
validateUserExists(userId);
-
- Either<ComponentMetadataData, StorageOperationStatus> eitherComponent = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, null);
+ Either<ComponentMetadataData, StorageOperationStatus> eitherComponent = toscaOperationFacade
+ .getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, null);
if (eitherComponent.isRight()) {
log.error("can't validate conformance level, component not found, uuid {}", componentUuid);
BeEcompErrorManager.getInstance().logBeComponentMissingError("validateConformanceLevel", componentTypeEnum.getValue(), componentUuid);
-
StorageOperationStatus status = eitherComponent.right().value();
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(status, componentTypeEnum);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus);
return Either.right(responseFormat);
}
-
String componentConformanceLevel = eitherComponent.left().value().getMetadataDataDefinition().getConformanceLevel();
if (StringUtils.isBlank(componentConformanceLevel)) {
log.error("component conformance level property is null or empty, uuid {}", componentUuid);
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
return Either.right(errorResponse);
}
-
String configConformanceLevel = ConfigurationManager.getConfigurationManager().getConfiguration().getMinToscaConformanceLevel();
Boolean result = true;
if (CommonBeUtils.conformanceLevelCompare(componentConformanceLevel, configConformanceLevel) < 0) {
- log.error("invalid asset conformance level, uuid {}, asset conformanceLevel {}, config conformanceLevel {}", componentUuid, componentConformanceLevel, configConformanceLevel);
+ log.error("invalid asset conformance level, uuid {}, asset conformanceLevel {}, config conformanceLevel {}", componentUuid,
+ componentConformanceLevel, configConformanceLevel);
result = false;
}
log.trace("conformance level validation finished");
-
return Either.left(result);
}
@@ -304,9 +309,9 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
try {
validateIcon(icon, type);
- } catch(ComponentException e){
- ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
- : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ } catch (ComponentException e) {
+ ResponseFormat responseFormat =
+ e.getResponseFormat() != null ? e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
throw e;
}
@@ -318,7 +323,6 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
log.debug("icon exceeds max length");
throw new ComponentException(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
}
-
if (!ValidationUtils.validateIcon(icon)) {
log.info("icon is invalid.");
throw new ComponentException(ActionStatus.COMPONENT_INVALID_ICON, type.getValue());
@@ -377,67 +381,70 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
log.debug("validate icon");
validateIcon(user, component, actionEnum);
}
-
- public CapReqDef getRequirementsAndCapabilities(String componentId, ComponentTypeEnum componentTypeEnum, String userId) {
+ public CapReqDef getRequirementsAndCapabilities(String componentId, ComponentTypeEnum componentTypeEnum, String userId) {
validateUserExists(userId);
ComponentParametersView filter = new ComponentParametersView(true);
filter.setIgnoreCapabilities(false);
filter.setIgnoreRequirements(false);
filter.setIgnoreComponentInstances(false);
-
try {
Component component = validateComponentExists(componentId, componentTypeEnum, filter);
return new CapReqDef(component.getRequirements(), component.getCapabilities());
- }catch (ComponentException e){
+ } catch (ComponentException e) {
BeEcompErrorManager.getInstance().logBeComponentMissingError("getRequirementsAndCapabilities", componentTypeEnum.getValue(), componentId);
throwComponentException(e.getResponseFormat());
}
return null;
}
- public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponents(boolean isAbstractAbstract, ComponentTypeEnum componentTypeEnum, String internalComponentType, List<String> componentUids,
+ public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponents(boolean isAbstractAbstract,
+ ComponentTypeEnum componentTypeEnum,
+ String internalComponentType, List<String> componentUids,
String userId) {
- try{
+ try {
validateUserExists(userId);
List<Component> result = new ArrayList<>();
List<String> componentsUidToFetch = new ArrayList<>();
componentsUidToFetch.addAll(componentUids);
if (!componentsUidToFetch.isEmpty()) {
log.debug("Number of Components to fetch from graph is {}", componentsUidToFetch.size());
- Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = toscaOperationFacade.getLatestVersionNotAbstractComponents(isAbstractAbstract, componentTypeEnum, internalComponentType, componentsUidToFetch);
-
+ Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = toscaOperationFacade
+ .getLatestVersionNotAbstractComponents(isAbstractAbstract, componentTypeEnum, internalComponentType, componentsUidToFetch);
if (nonCheckoutCompResponse.isLeft()) {
log.debug("Retrived Resource successfully.");
result.addAll(nonCheckoutCompResponse.left().value());
} else {
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value())));
+ return Either.right(
+ componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value())));
}
}
return Either.left(result);
- }
- finally{
+ } finally {
janusGraphDao.commit();
}
}
- public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(boolean isAbstractAbstract, HighestFilterEnum highestFilter, ComponentTypeEnum componentTypeEnum, String internalComponentType, String userId) {
- try{
+ public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(boolean isAbstractAbstract,
+ HighestFilterEnum highestFilter,
+ ComponentTypeEnum componentTypeEnum,
+ String internalComponentType, String userId) {
+ try {
validateUserExists(userId);
- Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = toscaOperationFacade.getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType);
-
+ Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = toscaOperationFacade
+ .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType);
if (nonCheckoutCompResponse.isLeft()) {
log.debug("Retrieved Resource successfully.");
return Either.left(nonCheckoutCompResponse.left().value());
}
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value())));
+ return Either
+ .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value())));
} finally {
janusGraphDao.commit();
}
}
public void setDeploymentArtifactsPlaceHolder(Component component, User user) {
-
}
@SuppressWarnings("unchecked")
@@ -450,141 +457,101 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
String componentSystemName = component.getSystemName();
String componentType = component.getComponentType().getValue().toLowerCase();
Map<String, Object> toscaArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts();
-
if (toscaArtifacts != null) {
for (Entry<String, Object> artifactInfoMap : toscaArtifacts.entrySet()) {
Map<String, Object> artifactInfo = (Map<String, Object>) artifactInfoMap.getValue();
- ArtifactDefinition artifactDefinition = artifactsBusinessLogic.createArtifactPlaceHolderInfo(componentUniqueId, artifactInfoMap.getKey(), artifactInfo, user, ArtifactGroupTypeEnum.TOSCA);
- artifactDefinition.setArtifactName(ValidationUtils.normalizeFileName(componentType + "-" + componentSystemName + artifactInfo.get("artifactName")));
+ ArtifactDefinition artifactDefinition = artifactsBusinessLogic
+ .createArtifactPlaceHolderInfo(componentUniqueId, artifactInfoMap.getKey(), artifactInfo, user, ArtifactGroupTypeEnum.TOSCA);
+ artifactDefinition
+ .setArtifactName(ValidationUtils.normalizeFileName(componentType + "-" + componentSystemName + artifactInfo.get("artifactName")));
artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
}
}
component.setToscaArtifacts(artifactMap);
}
- public Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest, boolean inTransaction, boolean shouldLock) {
+ public Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest,
+ boolean inTransaction, boolean shouldLock) {
return populateToscaArtifacts(component, user, isInCertificationRequest, inTransaction, shouldLock, true, true);
}
- public Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest, boolean inTransaction, boolean shouldLock, boolean retrieveResource) {
+ public Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest,
+ boolean inTransaction, boolean shouldLock, boolean retrieveResource) {
return populateToscaArtifacts(component, user, isInCertificationRequest, inTransaction, shouldLock, true, retrieveResource);
}
- private Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest, boolean inTransaction, boolean shouldLock, boolean fetchTemplatesFromDB, boolean retrieveResource) {
+ private Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest,
+ boolean inTransaction, boolean shouldLock, boolean fetchTemplatesFromDB,
+ boolean retrieveResource) {
if (retrieveResource) {
Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaFullElement(component.getUniqueId());
- if ( toscaElement.isRight() ){
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(toscaElement.right().value(), component.getComponentType()));
+ if (toscaElement.isRight()) {
+ throw new ByActionStatusComponentException(
+ componentsUtils.convertFromStorageResponse(toscaElement.right().value(), component.getComponentType()));
}
component = toscaElement.left().value();
}
-
- Either<ArtifactDefinition, Operation> generateToscaRes =
- saveToscaArtifactAndPopulateToscaArtifactsWithResult(component, componentsUtils,
- ArtifactTypeEnum.TOSCA_TEMPLATE,
- (comp, toscaArtifact) ->
- saveToscaArtifactPayload(toscaArtifact, comp, user, isInCertificationRequest, shouldLock,
- inTransaction, fetchTemplatesFromDB));
-
+ Either<ArtifactDefinition, Operation> generateToscaRes = saveToscaArtifactAndPopulateToscaArtifactsWithResult(component, componentsUtils,
+ ArtifactTypeEnum.TOSCA_TEMPLATE,
+ (comp, toscaArtifact) -> saveToscaArtifactPayload(toscaArtifact, comp, user, isInCertificationRequest, shouldLock, inTransaction,
+ fetchTemplatesFromDB));
if (!isAbstractResource(component)) {
- generateToscaRes = saveToscaArtifactAndPopulateToscaArtifactsWithResult(component, componentsUtils,
- ArtifactTypeEnum.TOSCA_CSAR,
- (comp, toscaArtifactArg) -> saveToscaArtifactPayload(toscaArtifactArg, comp, user,
- isInCertificationRequest, shouldLock, inTransaction, true));
+ generateToscaRes = saveToscaArtifactAndPopulateToscaArtifactsWithResult(component, componentsUtils, ArtifactTypeEnum.TOSCA_CSAR,
+ (comp, toscaArtifactArg) -> saveToscaArtifactPayload(toscaArtifactArg, comp, user, isInCertificationRequest, shouldLock,
+ inTransaction, true));
}
return generateToscaRes;
}
- private static Either<ArtifactDefinition, Operation> saveToscaArtifactAndPopulateToscaArtifactsWithResult(
- Component component,
- final ComponentsUtils componentsUtils,
- final ArtifactTypeEnum artifactEnum,
- final BiFunction<Component, ArtifactDefinition, Either<ArtifactDefinition, Operation>> saveToscaArtifactPayloadFunction) {
-
- ArtifactDefinition artifactDefinition = getToscaArtifactByTypeOrThrowException(component, artifactEnum,
- componentsUtils);
-
- Either<ArtifactDefinition, Operation> result =
- saveToscaArtifactPayloadFunction.apply(component, artifactDefinition);
-
- if (result.isLeft()) {
- ArtifactDefinition def = result.left().value();
- component.getToscaArtifacts().put(def.getArtifactLabel(), def);
- }
-
- return result;
- }
-
- private static Optional<ArtifactDefinition> getToscaArtifactByType(
- final Map<String, ArtifactDefinition> toscaArtifacts,
- final ArtifactTypeEnum typeEnum) {
- return toscaArtifacts.values().stream()
- .filter(p -> p.getArtifactType().equals(typeEnum.getType()))
- .findAny();
- }
-
- private static ArtifactDefinition getToscaArtifactByTypeOrThrowException(
- final Component component,
- final ArtifactTypeEnum typeEnum,
- final ComponentsUtils componentsUtils) {
-
- return Optional.ofNullable(component.getToscaArtifacts())
- .flatMap(toscaArtifacts -> getToscaArtifactByType(toscaArtifacts, typeEnum))
- .orElseThrow(() -> {
- log.debug("Impossible to find a ToscaArtifact with type '{}' for {}", typeEnum.getType(), component);
- return new ByResponseFormatComponentException(
- componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, typeEnum.name()));
- });
- }
-
private boolean isAbstractResource(Component component) {
- return component.getComponentType() == ComponentTypeEnum.RESOURCE && ((Resource)component).isAbstract();
+ return component.getComponentType() == ComponentTypeEnum.RESOURCE && ((Resource) component).isAbstract();
}
- private Either<ArtifactDefinition, Operation> saveToscaArtifactPayload(ArtifactDefinition artifactDefinition, org.openecomp.sdc.be.model.Component component, User user, boolean isInCertificationRequest, boolean shouldLock,
- boolean inTransaction, boolean fetchTemplatesFromDB) {
- return artifactsBusinessLogic.generateAndSaveToscaArtifact(artifactDefinition, component, user, isInCertificationRequest, shouldLock, inTransaction, fetchTemplatesFromDB);
+ private Either<ArtifactDefinition, Operation> saveToscaArtifactPayload(ArtifactDefinition artifactDefinition,
+ org.openecomp.sdc.be.model.Component component, User user,
+ boolean isInCertificationRequest, boolean shouldLock,
+ boolean inTransaction, boolean fetchTemplatesFromDB) {
+ return artifactsBusinessLogic
+ .generateAndSaveToscaArtifact(artifactDefinition, component, user, isInCertificationRequest, shouldLock, inTransaction,
+ fetchTemplatesFromDB);
}
- public ImmutablePair<String, byte[]> getToscaModelByComponentUuid(ComponentTypeEnum componentType, String uuid, ResourceCommonInfo resourceCommonInfo) {
-
+ public ImmutablePair<String, byte[]> getToscaModelByComponentUuid(ComponentTypeEnum componentType, String uuid,
+ ResourceCommonInfo resourceCommonInfo) {
Either<List<Component>, StorageOperationStatus> latestVersionEither = toscaOperationFacade.getComponentListByUuid(uuid, null);
-
if (latestVersionEither.isRight()) {
- throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(latestVersionEither.right().value(), componentType));
+ throw new ByActionStatusComponentException(
+ componentsUtils.convertFromStorageResponse(latestVersionEither.right().value(), componentType));
}
-
List<Component> components = latestVersionEither.left().value();
-
Component component = components.stream().filter(Component::isHighestVersion).findFirst().orElse(null);
- if(component == null){
+ if (component == null) {
component = components.stream().filter(c -> c.getLifecycleState() == LifecycleStateEnum.CERTIFIED).findFirst().orElse(null);
}
-
- if(component == null){
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, componentType)));
+ if (component == null) {
+ throw new ByResponseFormatComponentException(
+ componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, componentType)));
}
resourceCommonInfo.setResourceName(component.getName());
// TODO remove after migration - handle artifact not found(no
+
// placeholder)
if (null == component.getToscaArtifacts() || component.getToscaArtifacts().isEmpty()) {
- throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
+ throw new ByResponseFormatComponentException(
+ componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
}
ArtifactDefinition csarArtifact = component.getToscaArtifacts().values().stream()
- .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType()))
- .findAny().get();
+ .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())).findAny().get();
return artifactsBusinessLogic.handleDownloadToscaModelRequest(component, csarArtifact);
}
protected StorageOperationStatus markComponentToDelete(Component component) {
-
ComponentTypeEnum componentType = component.getComponentType();
String uniqueId = component.getUniqueId();
if (Boolean.TRUE.equals(component.getIsDeleted())) {
log.info("component {} already marked as deleted. id= {}, type={}", component.getName(), uniqueId, componentType);
return StorageOperationStatus.NOT_FOUND;
}
-
StorageOperationStatus markResourceToDelete = toscaOperationFacade.markComponentToDelete(component);
if (StorageOperationStatus.OK != markResourceToDelete) {
log.debug("failed to mark component {} of type {} for delete. error = {}", uniqueId, componentType, markResourceToDelete);
@@ -596,7 +563,8 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
}
- public Either<Boolean, ResponseFormat> validateAndUpdateDescription(User user, Component currentComponent, Component updatedComponent, AuditingActionEnum auditingAction) {
+ public Either<Boolean, ResponseFormat> validateAndUpdateDescription(User user, Component currentComponent, Component updatedComponent,
+ AuditingActionEnum auditingAction) {
String descriptionUpdated = updatedComponent.getDescription();
String descriptionCurrent = currentComponent.getDescription();
if (descriptionUpdated != null && !descriptionCurrent.equals(descriptionUpdated)) {
@@ -621,7 +589,8 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return Either.left(true);
}
- public Either<Boolean, ResponseFormat> validateAndUpdateIcon(User user, Component currentComponent, Component updatedComponent, boolean hasBeenCertified) {
+ public Either<Boolean, ResponseFormat> validateAndUpdateIcon(User user, Component currentComponent, Component updatedComponent,
+ boolean hasBeenCertified) {
String iconUpdated = updatedComponent.getIcon();
String iconCurrent = currentComponent.getIcon();
if (iconUpdated != null && !iconCurrent.equals(iconUpdated)) {
@@ -630,7 +599,8 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
currentComponent.setIcon(updatedComponent.getIcon());
} else {
log.info("icon {} cannot be updated once the component has been certified once.", iconUpdated);
- ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_PARAMETER_CANNOT_BE_CHANGED, "Icon", currentComponent.getComponentType().name().toLowerCase());
+ ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_PARAMETER_CANNOT_BE_CHANGED, "Icon",
+ currentComponent.getComponentType().name().toLowerCase());
return Either.right(errorResponse);
}
}
@@ -638,14 +608,12 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
protected Either<List<String>, ResponseFormat> deleteMarkedComponents(ComponentTypeEnum componentType) {
-
log.trace("start deleteMarkedComponents");
Either<List<String>, StorageOperationStatus> deleteMarkedElements = toscaOperationFacade.deleteMarkedElements(componentType);
-
-
- if ( deleteMarkedElements.isRight()){
+ if (deleteMarkedElements.isRight()) {
janusGraphDao.rollback();
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(deleteMarkedElements.right().value(), componentType));
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(deleteMarkedElements.right().value(), componentType));
return Either.right(responseFormat);
}
log.trace("end deleteMarkedComponents");
@@ -668,32 +636,27 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
/**
- *
* @param componentId
* @param user
* @param dataParamsToReturn - ui list of params to return
* @return
*/
-
- public Either<UiComponentDataTransfer, ResponseFormat> getComponentDataFilteredByParams(String componentId, User user, List<String> dataParamsToReturn) {
-
+ public Either<UiComponentDataTransfer, ResponseFormat> getComponentDataFilteredByParams(String componentId, User user,
+ List<String> dataParamsToReturn) {
if (user != null) {
validateUserExists(user);
}
-
- UiComponentDataTransfer result = new UiComponentDataTransfer();
-
- if(dataParamsToReturn == null || dataParamsToReturn.isEmpty()) {
+ UiComponentDataTransfer result = new UiComponentDataTransfer();
+ if (dataParamsToReturn == null || dataParamsToReturn.isEmpty()) {
Either.left(result);
-
} else {
- Either<UiComponentDataTransfer, ResponseFormat> uiDataTransferEither = getUiComponentDataTransferByComponentId(componentId, dataParamsToReturn);
- if(uiDataTransferEither.isRight()){
+ Either<UiComponentDataTransfer, ResponseFormat> uiDataTransferEither = getUiComponentDataTransferByComponentId(componentId,
+ dataParamsToReturn);
+ if (uiDataTransferEither.isRight()) {
return Either.right(uiDataTransferEither.right().value());
}
result = uiDataTransferEither.left().value();
}
-
return Either.left(result);
}
@@ -701,7 +664,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
List<InputDefinition> genericAndComponentInputs = new ArrayList<>();
List<InputDefinition> genericInputs = genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericType);
genericAndComponentInputs.addAll(genericInputs);
- if (null != component.getInputs()){
+ if (null != component.getInputs()) {
List<InputDefinition> nonGenericInputsFromComponent = getAllNonGenericInputsFromComponent(genericInputs, component.getInputs());
genericAndComponentInputs.addAll(nonGenericInputsFromComponent);
}
@@ -712,7 +675,6 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
if (genericInputs == null) {
return componentInputs;
}
-
Map<String, InputDefinition> inputByNameMap = MapUtil.toMap(genericInputs, InputDefinition::getName);
List<InputDefinition> componentNonGenericInputs = new ArrayList<>();
componentInputs.stream().forEach(input -> {
@@ -723,9 +685,9 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return componentNonGenericInputs;
}
- protected <T extends Component> Resource fetchAndSetDerivedFromGenericType(T component){
+ protected <T extends Component> Resource fetchAndSetDerivedFromGenericType(T component) {
Either<Resource, ResponseFormat> genericTypeEither = this.genericTypeBusinessLogic.fetchDerivedFromGenericType(component);
- if(genericTypeEither.isRight()){
+ if (genericTypeEither.isRight()) {
log.debug("Failed to fetch latest generic type for component {} of type", component.getName(), component.assetType());
throw new ByActionStatusComponentException(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType());
}
@@ -734,30 +696,33 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return genericTypeResource;
}
- public Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> getFilteredComponentInstanceProperties(String componentId, Map<FilterKeyEnum, List<String>> filters, String userId) {
+ public Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> getFilteredComponentInstanceProperties(String componentId,
+ Map<FilterKeyEnum, List<String>> filters,
+ String userId) {
Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> response = null;
Either<Component, StorageOperationStatus> getResourceRes = null;
- try{
- if(!filters.containsKey(FilterKeyEnum.NAME_FRAGMENT) && StringUtils.isEmpty(filters.get(FilterKeyEnum.NAME_FRAGMENT).get(0))){
+ try {
+ if (!filters.containsKey(FilterKeyEnum.NAME_FRAGMENT) && StringUtils.isEmpty(filters.get(FilterKeyEnum.NAME_FRAGMENT).get(0))) {
response = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
if (userId != null && response == null) {
validateUserExists(userId);
}
- if(response == null){
+ if (response == null) {
getResourceRes = toscaOperationFacade.getToscaElement(componentId);
- if(getResourceRes.isRight()){
- response = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getResourceRes.right().value())));
+ if (getResourceRes.isRight()) {
+ response = Either
+ .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getResourceRes.right().value())));
}
}
- if(response == null){
+ if (response == null) {
response = getFilteredComponentInstancesProperties(getResourceRes.left().value(), filters);
}
- } catch(Exception e){
+ } catch (Exception e) {
log.debug("The exception {} occured during filtered instance properties fetching. the containing component is {}. ", e, componentId);
response = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
- } finally{
- if (response != null && response.isLeft()){
+ } finally {
+ if (response != null && response.isLeft()) {
toscaOperationFacade.commit();
} else {
toscaOperationFacade.rollback();
@@ -766,22 +731,25 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return response;
}
- private Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> getFilteredComponentInstancesProperties(Component component, Map<FilterKeyEnum, List<String>> filters) {
-
- Map<String, List<IComponentInstanceConnectedElement>> filteredProperties = new HashMap<>();
+ private Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> getFilteredComponentInstancesProperties(Component component,
+ Map<FilterKeyEnum, List<String>> filters) {
+ Map<String, List<IComponentInstanceConnectedElement>> filteredProperties = new HashMap<>();
Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> result = Either.left(filteredProperties);
List<ComponentInstance> filteredInstances = getFilteredInstances(component, filters.get(FilterKeyEnum.RESOURCE_TYPE));
- String propertyNameFragment= filters.get(FilterKeyEnum.NAME_FRAGMENT).get(0);
- boolean searchByFragment = propertyNameFragment.length() > 3 ;
- if(CollectionUtils.isNotEmpty(filteredInstances)){
- for(ComponentInstance instance : filteredInstances){
- if(component.getComponentInstancesProperties()!=null &&component.getComponentInstancesProperties().containsKey(instance.getUniqueId())){
- List<IComponentInstanceConnectedElement> currProperties = getFilteredComponentInstanceProperties(component.getComponentInstancesProperties().get(instance.getUniqueId()), propertyNameFragment, searchByFragment);
+ String propertyNameFragment = filters.get(FilterKeyEnum.NAME_FRAGMENT).get(0);
+ boolean searchByFragment = propertyNameFragment.length() > 3;
+ if (CollectionUtils.isNotEmpty(filteredInstances)) {
+ for (ComponentInstance instance : filteredInstances) {
+ if (component.getComponentInstancesProperties() != null && component.getComponentInstancesProperties()
+ .containsKey(instance.getUniqueId())) {
+ List<IComponentInstanceConnectedElement> currProperties = getFilteredComponentInstanceProperties(
+ component.getComponentInstancesProperties().get(instance.getUniqueId()), propertyNameFragment, searchByFragment);
setFilteredProperties(filteredProperties, instance, currProperties);
}
- if(component.getComponentInstancesInputs()!=null && component.getComponentInstancesInputs().containsKey(instance.getUniqueId())){
- List<IComponentInstanceConnectedElement> currInputs = getFilteredComponentInstanceInputs(component.getComponentInstancesInputs().get(instance.getUniqueId()), propertyNameFragment, searchByFragment);
- if(CollectionUtils.isNotEmpty(currInputs)){
+ if (component.getComponentInstancesInputs() != null && component.getComponentInstancesInputs().containsKey(instance.getUniqueId())) {
+ List<IComponentInstanceConnectedElement> currInputs = getFilteredComponentInstanceInputs(
+ component.getComponentInstancesInputs().get(instance.getUniqueId()), propertyNameFragment, searchByFragment);
+ if (CollectionUtils.isNotEmpty(currInputs)) {
checkFilteredProperties(filteredProperties, instance, currInputs);
}
}
@@ -790,34 +758,38 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return result;
}
- private void setFilteredProperties(Map<String, List<IComponentInstanceConnectedElement>> filteredProperties, ComponentInstance instance, List<IComponentInstanceConnectedElement> currProperties) {
- if(CollectionUtils.isNotEmpty(currProperties)){
+ private void setFilteredProperties(Map<String, List<IComponentInstanceConnectedElement>> filteredProperties, ComponentInstance instance,
+ List<IComponentInstanceConnectedElement> currProperties) {
+ if (CollectionUtils.isNotEmpty(currProperties)) {
filteredProperties.put(instance.getUniqueId(), currProperties);
}
}
- private void checkFilteredProperties(Map<String, List<IComponentInstanceConnectedElement>> filteredProperties, ComponentInstance instance, List<IComponentInstanceConnectedElement> currInputs) {
- if(filteredProperties.get(instance.getUniqueId())!=null){
+ private void checkFilteredProperties(Map<String, List<IComponentInstanceConnectedElement>> filteredProperties, ComponentInstance instance,
+ List<IComponentInstanceConnectedElement> currInputs) {
+ if (filteredProperties.get(instance.getUniqueId()) != null) {
filteredProperties.get(instance.getUniqueId()).addAll(currInputs);
} else {
filteredProperties.put(instance.getUniqueId(), currInputs);
}
}
- private List<IComponentInstanceConnectedElement> getFilteredComponentInstanceInputs(List<ComponentInstanceInput> inputs, String propertyNameFragment, boolean searchByFragment) {
+ private List<IComponentInstanceConnectedElement> getFilteredComponentInstanceInputs(List<ComponentInstanceInput> inputs,
+ String propertyNameFragment, boolean searchByFragment) {
return inputs.stream().filter(i -> isMatchingInput(i, propertyNameFragment, searchByFragment)).collect(Collectors.toList());
}
- private List<IComponentInstanceConnectedElement> getFilteredComponentInstanceProperties(List<ComponentInstanceProperty> instanceProperties, String propertyNameFragment, boolean searchByFragment) {
+ private List<IComponentInstanceConnectedElement> getFilteredComponentInstanceProperties(List<ComponentInstanceProperty> instanceProperties,
+ String propertyNameFragment, boolean searchByFragment) {
return instanceProperties.stream().filter(p -> isMatchingProperty(p, propertyNameFragment, searchByFragment)).collect(Collectors.toList());
}
private boolean isMatchingInput(ComponentInstanceInput input, String propertyNameFragment, boolean searchByFragment) {
boolean isMatching = false;
- if(searchByFragment && input.getName().toLowerCase().contains(propertyNameFragment)){
+ if (searchByFragment && input.getName().toLowerCase().contains(propertyNameFragment)) {
isMatching = true;
}
- if(!searchByFragment && input.getName().equalsIgnoreCase(propertyNameFragment)){
+ if (!searchByFragment && input.getName().equalsIgnoreCase(propertyNameFragment)) {
isMatching = true;
}
return isMatching;
@@ -825,56 +797,50 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
private boolean isMatchingProperty(ComponentInstanceProperty property, String propertyNameFragment, boolean searchByFragment) {
boolean isMatching = false;
- if(searchByFragment && property.getName().toLowerCase().contains(propertyNameFragment)){
+ if (searchByFragment && property.getName().toLowerCase().contains(propertyNameFragment)) {
isMatching = true;
}
- if(!searchByFragment && property.getName().equalsIgnoreCase(propertyNameFragment)){
+ if (!searchByFragment && property.getName().equalsIgnoreCase(propertyNameFragment)) {
isMatching = true;
}
- if (!isMatching && !ToscaPropertyType.isPrimitiveType(property.getType())){
+ if (!isMatching && !ToscaPropertyType.isPrimitiveType(property.getType())) {
isMatching = isMatchingComplexPropertyByRecursively(property, propertyNameFragment, searchByFragment);
}
return isMatching;
}
- private boolean isMatchingComplexPropertyByRecursively(PropertyDataDefinition property, String propertyNameFragment, boolean searchByFragment) {
+ private boolean isMatchingComplexPropertyByRecursively(PropertyDataDefinition property, String propertyNameFragment, boolean searchByFragment) {
String propertyType;
- List<PropertyDefinition> dataTypeProperties;
+ List<PropertyDefinition> dataTypeProperties;
DataTypeDefinition currentProperty;
- if(searchByFragment && property.getName().toLowerCase().contains(propertyNameFragment.toLowerCase())){
+ if (searchByFragment && property.getName().toLowerCase().contains(propertyNameFragment.toLowerCase())) {
return true;
}
- if(!searchByFragment && property.getName().equalsIgnoreCase(propertyNameFragment)){
+ if (!searchByFragment && property.getName().equalsIgnoreCase(propertyNameFragment)) {
return true;
}
-
propertyType = isEmptyInnerType(property) ? property.getType() : property.getSchema().getProperty().getType();
-
- if(ToscaPropertyType.isScalarType(propertyType)){
+ if (ToscaPropertyType.isScalarType(propertyType)) {
return false;
}
- Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByNameRes = propertyOperation.getDataTypeByName(propertyType);
- if(getDataTypeByNameRes.isRight()){
+ Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByNameRes = propertyOperation.getDataTypeByName(propertyType);
+ if (getDataTypeByNameRes.isRight()) {
return false;
}
currentProperty = getDataTypeByNameRes.left().value();
dataTypeProperties = currentProperty.getProperties();
-
boolean dataPropertiesNotNull = CollectionUtils.isNotEmpty(dataTypeProperties);
- BooleanSupplier dataMatchesComplexProperty = () -> isMatchingComplexProperty(propertyNameFragment,
- searchByFragment, dataTypeProperties);
- BooleanSupplier parentPropertiesNotNull = () -> CollectionUtils
- .isNotEmpty(currentProperty.getDerivedFrom().getProperties());
- BooleanSupplier parentDataMatchesComplexProperty = () -> isMatchingComplexProperty(propertyNameFragment,
- searchByFragment, currentProperty.getDerivedFrom().getProperties());
-
- return ((dataPropertiesNotNull && dataMatchesComplexProperty.getAsBoolean())
- || (parentPropertiesNotNull.getAsBoolean() && parentDataMatchesComplexProperty.getAsBoolean()));
+ BooleanSupplier dataMatchesComplexProperty = () -> isMatchingComplexProperty(propertyNameFragment, searchByFragment, dataTypeProperties);
+ BooleanSupplier parentPropertiesNotNull = () -> CollectionUtils.isNotEmpty(currentProperty.getDerivedFrom().getProperties());
+ BooleanSupplier parentDataMatchesComplexProperty = () -> isMatchingComplexProperty(propertyNameFragment, searchByFragment,
+ currentProperty.getDerivedFrom().getProperties());
+ return ((dataPropertiesNotNull && dataMatchesComplexProperty.getAsBoolean()) || (parentPropertiesNotNull.getAsBoolean()
+ && parentDataMatchesComplexProperty.getAsBoolean()));
}
private boolean isMatchingComplexProperty(String propertyNameFragment, boolean searchByFragment, List<PropertyDefinition> dataTypeProperties) {
- for(PropertyDefinition prop : dataTypeProperties){
- if(isMatchingComplexPropertyByRecursively(prop, propertyNameFragment, searchByFragment)){
+ for (PropertyDefinition prop : dataTypeProperties) {
+ if (isMatchingComplexPropertyByRecursively(prop, propertyNameFragment, searchByFragment)) {
return true;
}
}
@@ -882,20 +848,22 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
}
private boolean isEmptyInnerType(PropertyDataDefinition property) {
- return property == null|| property.getSchema() == null || property.getSchema().getProperty() == null || property.getSchema().getProperty().getType() == null;
+ return property == null || property.getSchema() == null || property.getSchema().getProperty() == null
+ || property.getSchema().getProperty().getType() == null;
}
public Either<Boolean, ResponseFormat> shouldUpgradeToLatestGeneric(Component clonedComponent) {
-
- if(!clonedComponent.deriveFromGeneric())
+ if (!clonedComponent.deriveFromGeneric()) {
return Either.left(false);
+ }
Boolean shouldUpgrade = false;
String currentGenericType = clonedComponent.getDerivedFromGenericType();
String currentGenericVersion = clonedComponent.getDerivedFromGenericVersion();
Resource genericTypeResource = fetchAndSetDerivedFromGenericType(clonedComponent);
- if(null == currentGenericType || !currentGenericType.equals(genericTypeResource.getToscaResourceName()) || !currentGenericVersion.equals(genericTypeResource.getVersion())){
+ if (null == currentGenericType || !currentGenericType.equals(genericTypeResource.getToscaResourceName()) || !currentGenericVersion
+ .equals(genericTypeResource.getVersion())) {
shouldUpgrade = upgradeToLatestGeneric(clonedComponent, genericTypeResource);
- if(!shouldUpgrade) {
+ if (!shouldUpgrade) {
reverntUpdateOfGenericVersion(clonedComponent, currentGenericType, currentGenericVersion);
}
}
@@ -907,42 +875,45 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
clonedComponent.setDerivedFromGenericVersion(currentGenericVersion);
}
- private <T extends ToscaDataDefinition> Either<Map<String, T>, String> validateNoConflictingProperties(List<T> currentList, List<T> upgradedList) {
+ private <T extends ToscaDataDefinition> Either<Map<String, T>, String> validateNoConflictingProperties(List<T> currentList,
+ List<T> upgradedList) {
Map<String, T> currentMap = ToscaDataDefinition.listToMapByName(currentList);
Map<String, T> upgradedMap = ToscaDataDefinition.listToMapByName(upgradedList);
return ToscaDataDefinition.mergeDataMaps(upgradedMap, currentMap, true);
}
- private boolean shouldUpgradeNodeType(Component componentToCheckOut, Resource latestGeneric){
-
+ private boolean shouldUpgradeNodeType(Component componentToCheckOut, Resource latestGeneric) {
List<PropertyDefinition> genericTypeProps = latestGeneric.getProperties();
- Either<Map<String, PropertyDefinition>, String> validPropertiesMerge = validateNoConflictingProperties(genericTypeProps, ((Resource)componentToCheckOut).getProperties());
+ Either<Map<String, PropertyDefinition>, String> validPropertiesMerge = validateNoConflictingProperties(genericTypeProps,
+ ((Resource) componentToCheckOut).getProperties());
if (validPropertiesMerge.isRight()) {
- log.debug("property {} cannot be overriden, check out performed without upgrading to latest generic", validPropertiesMerge.right().value());
+ log.debug("property {} cannot be overriden, check out performed without upgrading to latest generic",
+ validPropertiesMerge.right().value());
return false;
}
List<AttributeDefinition> genericTypeAttributes = latestGeneric.getAttributes();
- final Either<Map<String, AttributeDefinition>, String> validAttributesMerge = validateNoConflictingProperties(
- genericTypeAttributes, ((Resource) componentToCheckOut).getAttributes());
+ final Either<Map<String, AttributeDefinition>, String> validAttributesMerge = validateNoConflictingProperties(genericTypeAttributes,
+ ((Resource) componentToCheckOut).getAttributes());
if (validAttributesMerge.isRight()) {
- log.debug("attribute {} cannot be overriden, check out performed without upgrading to latest generic", validAttributesMerge.right().value());
+ log.debug("attribute {} cannot be overriden, check out performed without upgrading to latest generic",
+ validAttributesMerge.right().value());
return false;
}
return true;
}
private boolean upgradeToLatestGeneric(Component componentToCheckOut, Resource latestGeneric) {
-
if (!componentToCheckOut.shouldGenerateInputs()) {
//node type - validate properties and attributes
return shouldUpgradeNodeType(componentToCheckOut, latestGeneric);
}
List<PropertyDefinition> genericTypeProps = latestGeneric.getProperties();
- List<InputDefinition> genericTypeInputs = null == genericTypeProps? null : genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericTypeProps, latestGeneric.getUniqueId());
+ List<InputDefinition> genericTypeInputs = null == genericTypeProps ? null
+ : genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericTypeProps, latestGeneric.getUniqueId());
List<InputDefinition> currentList = new ArrayList<>();
// nullify existing ownerId from existing list and merge into updated list
if (null != componentToCheckOut.getInputs()) {
- for(InputDefinition input : componentToCheckOut.getInputs()) {
+ for (InputDefinition input : componentToCheckOut.getInputs()) {
InputDefinition copy = new InputDefinition(input);
copy.setOwnerId(null);
currentList.add(copy);
@@ -952,7 +923,6 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
componentToCheckOut.setInputs(currentList);
return true;
}
-
Either<Map<String, InputDefinition>, String> eitherMerged = validateNoConflictingProperties(genericTypeInputs, currentList);
if (eitherMerged.isRight()) {
log.debug("input {} cannot be overriden, check out performed without upgrading to latest generic", eitherMerged.right().value());
@@ -962,17 +932,15 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return true;
}
-
private List<ComponentInstance> getFilteredInstances(Component component, List<String> resourceTypes) {
List<ComponentInstance> filteredInstances = null;
- if(CollectionUtils.isEmpty(resourceTypes)){
+ if (CollectionUtils.isEmpty(resourceTypes)) {
filteredInstances = component.getComponentInstances();
+ } else if (CollectionUtils.isNotEmpty(component.getComponentInstances())) {
+ filteredInstances = component.getComponentInstances().stream().filter(i -> isMatchingType(i.getOriginType(), resourceTypes))
+ .collect(Collectors.toList());
}
- else if(CollectionUtils.isNotEmpty(component.getComponentInstances())){
- filteredInstances = component.getComponentInstances()
- .stream().filter(i -> isMatchingType(i.getOriginType(), resourceTypes)).collect(Collectors.toList());
- }
- if(filteredInstances == null){
+ if (filteredInstances == null) {
filteredInstances = new ArrayList<>();
}
return filteredInstances;
@@ -980,8 +948,8 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
private boolean isMatchingType(OriginTypeEnum originType, List<String> resourceTypes) {
boolean isMatchingType = false;
- for(String resourceType : resourceTypes){
- if(originType == OriginTypeEnum.findByValue(resourceType.toUpperCase())){
+ for (String resourceType : resourceTypes) {
+ if (originType == OriginTypeEnum.findByValue(resourceType.toUpperCase())) {
isMatchingType = true;
break;
}
@@ -994,14 +962,14 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
return Either.right(ActionStatus.GENERAL_ERROR);
}
- protected Either<Component, ResponseFormat> updateCatalog(Component component, ChangeTypeEnum changeStatus){
- log.debug("update Catalog start with Component Type {} And Componet Name {} with change status {}", component.getComponentType().name(), component.getName(), changeStatus.name());
- ActionStatus status = catalogOperations.updateCatalog(changeStatus,component);
- if(status != ActionStatus.OK){
- return Either.right( componentsUtils.getResponseFormat(status));
+ protected Either<Component, ResponseFormat> updateCatalog(Component component, ChangeTypeEnum changeStatus) {
+ log.debug("update Catalog start with Component Type {} And Componet Name {} with change status {}", component.getComponentType().name(),
+ component.getName(), changeStatus.name());
+ ActionStatus status = catalogOperations.updateCatalog(changeStatus, component);
+ if (status != ActionStatus.OK) {
+ return Either.right(componentsUtils.getResponseFormat(status));
}
-
- return Either.left(component);
+ return Either.left(component);
}
public CatalogOperation getCatalogOperations() {
@@ -1016,5 +984,4 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
public List<GroupDefinition> throwComponentException(ResponseFormat responseFormat) {
throw new ByResponseFormatComponentException(responseFormat);
}
-
}