X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-be%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fcomponents%2Fimpl%2FComponentBusinessLogic.java;h=0b60a3671d1bfca5596fa12309630ab07379d852;hb=438650c3a958c9176db3720204ec1ff9af94fc3a;hp=7d4ba3bf77baa4f7a0d2b6fb1383e99ce054aec6;hpb=50619616a9bd803bb9bb820fe83d999f26ba3f34;p=sdc.git 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 7d4ba3bf77..0b60a3671d 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 @@ -104,6 +104,7 @@ import org.springframework.beans.factory.annotation.Autowired; public abstract class ComponentBusinessLogic extends BaseBusinessLogic { private static final Logger log = Logger.getLogger(ComponentBusinessLogic.class.getName()); + protected final GroupBusinessLogic groupBusinessLogic; protected ArtifactsBusinessLogic artifactsBusinessLogic; protected GenericTypeBusinessLogic genericTypeBusinessLogic; @@ -205,6 +206,10 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { */ public abstract Either getUiComponentDataTransferByComponentId(String componentId, List dataParamsToReturn); + + public Either getComponentMetadata(final String componentId) { + return toscaOperationFacade.getComponentMetadata(componentId); + } User validateUser(User user, String ecompErrorContext, Component component, AuditingActionEnum auditAction, boolean inTransaction) { User validatedUser; @@ -299,7 +304,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { log.debug("validate Icon"); ComponentTypeEnum type = component.getComponentType(); String icon = component.getIcon(); - if (!ValidationUtils.validateStringNotEmpty(icon)) { + if (StringUtils.isEmpty(icon)) { log.info("icon is missing."); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_ICON, type.getValue()); componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type); @@ -423,16 +428,18 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { } } - public Either, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(boolean isAbstractAbstract, - HighestFilterEnum highestFilter, - ComponentTypeEnum componentTypeEnum, - String internalComponentType, String userId, - String modelName) { + public Either, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(final boolean isAbstractAbstract, + final HighestFilterEnum highestFilter, + final ComponentTypeEnum componentTypeEnum, + final String internalComponentType, String userId, + final String modelName, + final boolean includeNormativeExtensionModels) { Either, StorageOperationStatus> nonCheckoutCompResponse = null; try { validateUserExists(userId); - nonCheckoutCompResponse = toscaOperationFacade - .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType, modelName); + nonCheckoutCompResponse = toscaOperationFacade + .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType, modelName, + includeNormativeExtensionModels); if (nonCheckoutCompResponse.isLeft()) { log.debug("Retrieved Resource successfully."); return Either.left(nonCheckoutCompResponse.left().value()); @@ -440,7 +447,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { return Either .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value()))); } finally { - if(nonCheckoutCompResponse != null && nonCheckoutCompResponse.isLeft() ) { + if (nonCheckoutCompResponse != null && nonCheckoutCompResponse.isLeft()) { janusGraphDao.commit(); } } @@ -542,8 +549,12 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { 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(); + + final ArtifactDefinition csarArtifact = component.getToscaArtifacts().values().stream() + .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())).findAny().orElseThrow(() -> { + throw new ByResponseFormatComponentException( + componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name())); + }); return artifactsBusinessLogic.handleDownloadToscaModelRequest(component, csarArtifact); } @@ -686,7 +697,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { }); return componentNonGenericInputs; } - + protected void generatePropertiesFromGenericType(final Component component, final Resource genericType) { if (CollectionUtils.isEmpty(genericType.getProperties())) { return; @@ -703,21 +714,27 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { } component.getProperties().forEach(propertyDefinition -> propertyDefinition.setUniqueId(null)); } + protected Resource fetchAndSetDerivedFromGenericType(final T component) { return fetchAndSetDerivedFromGenericType(component, null); } protected Resource fetchAndSetDerivedFromGenericType(final T component, final String toscaType) { + final Resource genericTypeResource = fetchDerivedFromGenericType(component, toscaType); + component.setDerivedFromGenericInfo(genericTypeResource); + return genericTypeResource; + } + + public Resource fetchDerivedFromGenericType(final T component, final String toscaType) { final Either genericTypeEither = this.genericTypeBusinessLogic.fetchDerivedFromGenericType(component, toscaType); if (genericTypeEither.isRight()) { - log.debug("Failed to fetch latest generic type for component {} of type", component.getName(), component.assetType()); + 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()); } - final Resource genericTypeResource = genericTypeEither.left().value(); - component.setDerivedFromGenericInfo(genericTypeResource); - return genericTypeResource; + return genericTypeEither.left().value(); } + public Either>, ResponseFormat> getFilteredComponentInstanceProperties(String componentId, Map> filters, String userId) { @@ -911,7 +928,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { if (validPropertiesMerge.isRight()) { if (log.isDebugEnabled()) { log.debug("property {} cannot be overriden, check out performed without upgrading to latest generic", - validPropertiesMerge.right().value()); + validPropertiesMerge.right().value()); } return false; } @@ -921,7 +938,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { if (validAttributesMerge.isRight()) { if (log.isDebugEnabled()) { log.debug("attribute {} cannot be overriden, check out performed without upgrading to latest generic", - validAttributesMerge.right().value()); + validAttributesMerge.right().value()); } return false; } @@ -993,7 +1010,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { protected Either updateCatalog(Component component, ChangeTypeEnum changeStatus) { if (log.isDebugEnabled()) { log.debug("update Catalog start with Component Type {} And Componet Name {} with change status {}", - component.getComponentType().name(),component.getName(), changeStatus.name()); + component.getComponentType().name(), component.getName(), changeStatus.name()); } ActionStatus status = catalogOperations.updateCatalog(changeStatus, component); if (status != ActionStatus.OK) {