From c183513f5c5813f6a911a5ceb7ac81405007aaff Mon Sep 17 00:00:00 2001 From: vasraz Date: Wed, 18 Jan 2023 15:54:45 +0000 Subject: Fix 'Data type cache not updated when data type updated'-bug Signed-off-by: Vasyl Razinkov Change-Id: I49c50cc95a2594025eab955769cc68e7e7a23acd Issue-ID: SDC-4337 --- .../sdc/be/components/impl/BaseBusinessLogic.java | 4 +++- .../be/components/impl/DataTypeBusinessLogic.java | 21 +++++++++++++++++---- .../be/components/impl/ResourceBusinessLogic.java | 4 ---- .../openecomp/sdc/be/servlets/DataTypeServlet.java | 8 ++++++-- 4 files changed, 26 insertions(+), 11 deletions(-) (limited to 'catalog-be/src/main') 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 1f6d2a4601..8b18346bdd 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 @@ -32,6 +32,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.function.Function; +import lombok.Getter; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -118,6 +119,7 @@ public abstract class BaseBusinessLogic { protected JanusGraphGenericDao janusGraphGenericDao; protected PropertyOperation propertyOperation; protected AttributeOperation attributeOperation; + @Getter protected ApplicationDataTypeCache applicationDataTypeCache; protected ToscaOperationFacade toscaOperationFacade; protected IGroupOperation groupOperation; @@ -126,7 +128,7 @@ public abstract class BaseBusinessLogic { protected PolicyTypeOperation policyTypeOperation; protected ArtifactsOperations artifactToscaOperation; protected UserValidations userValidations; - DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance(); + private final DataTypeValidatorConverter dataTypeValidatorConverter = DataTypeValidatorConverter.getInstance(); protected BaseBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation, IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation, diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java index 687004a017..d95376ed3c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/DataTypeBusinessLogic.java @@ -23,6 +23,8 @@ import fj.data.Either; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition; +import org.openecomp.sdc.be.exception.supplier.DataTypeOperationExceptionSupplier; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.DataTypeDefinition; @@ -33,6 +35,7 @@ import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation; import org.openecomp.sdc.be.model.operations.api.IGroupOperation; import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.model.operations.impl.DataTypeOperation; import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; @@ -40,15 +43,19 @@ import org.springframework.util.CollectionUtils; @org.springframework.stereotype.Component("dataTypeBusinessLogic") public class DataTypeBusinessLogic extends BaseBusinessLogic { - final DataTypeImportManager dataTypeImportManager; + private final DataTypeImportManager dataTypeImportManager; + private final DataTypeOperation dataTypeOperation; @Autowired public DataTypeBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation, IGroupTypeOperation groupTypeOperation, InterfaceOperation interfaceOperation, - InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactsOperations artifactToscaOperation, DataTypeImportManager dataTypeImportManager) { + InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactsOperations artifactToscaOperation, + DataTypeImportManager dataTypeImportManager, + DataTypeOperation dataTypeOperation) { super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation); this.dataTypeImportManager = dataTypeImportManager; + this.dataTypeOperation = dataTypeOperation; } /** @@ -154,11 +161,17 @@ public class DataTypeBusinessLogic extends BaseBusinessLogic { * [...] * * - * @param dataTypesYaml the data types to create in yaml format. It can contain multiple data types entries. - * @param model Model name to associate with data type + * @param dataTypesYaml the data types to create in yaml format. It can contain multiple data types entries. + * @param model Model name to associate with data type * @param includeToModelDefaultImports Add data type entry to default imports for model */ public void createDataTypeFromYaml(final String dataTypesYaml, final String model, final boolean includeToModelDefaultImports) { dataTypeImportManager.createDataTypes(dataTypesYaml, model, includeToModelDefaultImports); } + + public void updateApplicationDataTypeCache(final String dataTypeId) { + DataTypeDataDefinition dataTypeDataDefinition = dataTypeOperation.getDataTypeByUid(dataTypeId).orElseThrow( + DataTypeOperationExceptionSupplier.dataTypeNotFound(dataTypeId)); + getApplicationDataTypeCache().reload(dataTypeDataDefinition.getModel(), dataTypeId); + } } 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 619a923b48..2f71959d9d 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 @@ -333,10 +333,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { this.artifactsBusinessLogic = artifactsManager; } - public ApplicationDataTypeCache getApplicationDataTypeCache() { - return applicationDataTypeCache; - } - @Autowired @Override public void setApplicationDataTypeCache(ApplicationDataTypeCache applicationDataTypeCache) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java index 711ebcbd9c..e081110486 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java @@ -45,6 +45,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; +import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic; import org.openecomp.sdc.be.components.impl.aaf.AafPermission; import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed; import org.openecomp.sdc.be.config.BeEcompErrorManager; @@ -70,11 +71,13 @@ public class DataTypeServlet extends BeGenericServlet { private static final Logger log = Logger.getLogger(DataTypeServlet.class); private final DataTypeOperation dataTypeOperation; + private final DataTypeBusinessLogic dataTypeBusinessLogic; public DataTypeServlet(final ComponentsUtils componentsUtils, - final DataTypeOperation dataTypeOperation) { + final DataTypeOperation dataTypeOperation, DataTypeBusinessLogic dataTypeBusinessLogic) { super(componentsUtils); this.dataTypeOperation = dataTypeOperation; + this.dataTypeBusinessLogic = dataTypeBusinessLogic; } @GET @@ -139,9 +142,10 @@ public class DataTypeServlet extends BeGenericServlet { }) @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE) public Response createProperty(@Parameter(in = ParameterIn.PATH, required = true, description = "The data type id") - @PathParam("id") final String id, + @PathParam("id") final String id, @RequestBody(description = "Property to add", required = true) final PropertyDefinitionDto propertyDefinitionDto) { final PropertyDefinitionDto property = dataTypeOperation.createProperty(id, propertyDefinitionDto); + dataTypeBusinessLogic.updateApplicationDataTypeCache(id); return Response.status(Status.CREATED).entity(property).build(); } -- cgit 1.2.3-korg