From 597bc127b6fc91c77fe2c5c759c194a6e50b9c4e Mon Sep 17 00:00:00 2001 From: "andre.schmid" <andre.schmid@est.tech> Date: Wed, 13 May 2020 15:25:30 +0100 Subject: Expose generic Service properties as properties During the Service creation, the properties declared in the Generic Service Type are being parsed to inputs, but not to properties. The change parses the properties also to properties, keeping the previous input logic. Change-Id: I3ceba3adeaab56cd49fc8fbd657b02aa7c93e79b Issue-ID: SDC-3061 Signed-off-by: andre.schmid <andre.schmid@est.tech> --- .../be/components/impl/ServiceBusinessLogic.java | 45 ++++++++++++++++------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'catalog-be/src/main') 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 f4ccb868d9..552fbb0b16 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 @@ -845,7 +845,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { if (createServiceResponse.isRight()) { return createServiceResponse; } - return createServiceByDao(service, AuditingActionEnum.CREATE_RESOURCE, user) + return createServiceByDao(service, user) .left() .bind(c -> updateCatalog(c, ChangeTypeEnum.LIFECYCLE) .left() @@ -859,42 +859,42 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { } } - private Either<Service, ResponseFormat> createServiceByDao(Service service, AuditingActionEnum actionEnum, User user) { + private Either<Service, ResponseFormat> createServiceByDao(final Service service, final User user) { log.debug("send service {} to dao for create", service.getComponentMetadataDefinition().getMetadataDataDefinition().getName()); Either<Boolean, ResponseFormat> lockResult = lockComponentByName(service.getSystemName(), service, "Create Service"); if (lockResult.isRight()) { ResponseFormat responseFormat = lockResult.right().value(); - componentsUtils.auditComponentAdmin(responseFormat, user, service, actionEnum, ComponentTypeEnum.SERVICE); + componentsUtils.auditComponentAdmin(responseFormat, user, service, AuditingActionEnum.CREATE_RESOURCE, + ComponentTypeEnum.SERVICE); return Either.right(responseFormat); } log.debug("System name locked is {}, status = {}", service.getSystemName(), lockResult); try { - createMandatoryArtifactsData(service, user); createServiceApiArtifactsData(service, user); setToscaArtifactsPlaceHolders(service, user); - generateAndAddInputsFromGenericTypeProperties(service, fetchAndSetDerivedFromGenericType(service)); + final Resource genericType = fetchAndSetDerivedFromGenericType(service); + generatePropertiesFromGenericType(service, genericType); + generateAndAddInputsFromGenericTypeProperties(service, genericType); beforeCreate(service); Either<Service, StorageOperationStatus> dataModelResponse = toscaOperationFacade.createToscaComponent(service); - - // service created successfully!!! if (dataModelResponse.isLeft()) { - log.debug("Service created successfully!!!"); + log.debug("Service '{}' created successfully", service.getName()); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED); - componentsUtils.auditComponentAdmin(responseFormat, user, service, actionEnum, ComponentTypeEnum.SERVICE); + componentsUtils.auditComponentAdmin(responseFormat, user, service, AuditingActionEnum.CREATE_RESOURCE, + ComponentTypeEnum.SERVICE); ASDCKpiApi.countCreatedServicesKPI(); return Either.left(dataModelResponse.left().value()); } - ResponseFormat responseFormat = componentsUtils.getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(dataModelResponse.right().value()), service, ComponentTypeEnum.SERVICE); log.debug(AUDIT_BEFORE_SENDING_RESPONSE); - componentsUtils.auditComponentAdmin(responseFormat, user, service, actionEnum, ComponentTypeEnum.SERVICE); + componentsUtils.auditComponentAdmin(responseFormat, user, service, AuditingActionEnum.CREATE_RESOURCE, + ComponentTypeEnum.SERVICE); return Either.right(responseFormat); - } finally { graphLockOperation.unlockComponentByName(service.getSystemName(), service.getUniqueId(), NodeTypeEnum.Service); } @@ -916,6 +916,27 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { }); } + private void generatePropertiesFromGenericType(final Service service, final Resource genericType) { + if (CollectionUtils.isEmpty(genericType.getProperties())) { + return; + } + final List<PropertyDefinition> genericTypePropertyList = genericType.getProperties().stream() + .map(PropertyDefinition::new) + .peek(propertyDefinition -> propertyDefinition.setUniqueId(null)) + .collect(Collectors.toList()); + if (service.getProperties() == null) { + service.setProperties(new ArrayList<>(genericTypePropertyList)); + } else { + List<PropertyDefinition> servicePropertyList = service.getProperties(); + genericTypePropertyList.stream() + .filter(property -> servicePropertyList.stream() + .noneMatch(property1 -> property1.getName().equals(property.getName()))) + .forEach(servicePropertyList::add); + } + + service.getProperties().forEach(propertyDefinition -> propertyDefinition.setUniqueId(null)); + } + @SuppressWarnings("unchecked") private void createServiceApiArtifactsData(Service service, User user) { // create mandatory artifacts -- cgit 1.2.3-korg