summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2021-09-02 16:22:12 +0100
committerAndr� Schmid <andre.schmid@est.tech>2021-09-06 16:51:12 +0000
commitb600063182fce15ac3060e4526feaea715e7ef08 (patch)
tree11734e16794bcec5d14c8c960734246c7001dcc2 /catalog-model/src/main/java
parent528bd0cd6155bc9a3d2467969b327c2bd62d6f45 (diff)
Fix data type cache issue for model extensions
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-3713 Change-Id: I56b8de3065848942a4ba8dd8486a7d87e7d8029e
Diffstat (limited to 'catalog-model/src/main/java')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java59
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java27
2 files changed, 50 insertions, 36 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
index 158cb2569b..d6cca3f824 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
@@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -69,8 +70,40 @@ public class DataTypeOperation extends AbstractOperation {
}
return dataTypesFound;
}
+
+ public Map<String, List<String>> getAllDataTypeUidsToModels() {
+ final Map<String, List<String>> dataTypesFound = new HashMap<>();
+ final Either<List<DataTypeData>, JanusGraphOperationStatus> getAllDataTypesWithNullModel =
+ janusGraphGenericDao.getByCriteria(NodeTypeEnum.DataType, null, DataTypeData.class);
- public List<DataTypeData> getAllDataTypesWithModel() {
+ final var dataTypesValidated = validateDataType(getAllDataTypesWithNullModel, null);
+
+ for (DataTypeData dataType: dataTypesValidated) {
+ if (!dataTypesFound.containsKey(dataType.getUniqueId())){
+ dataTypesFound.put(dataType.getUniqueId(), new ArrayList<>());
+ }
+ dataTypesFound.get(dataType.getUniqueId()).add(null);
+ }
+
+ modelOperation.findAllModels()
+ .forEach(model -> {
+ for (DataTypeData dataType: getAllDataTypesWithModel(model.getName())) {
+ if (!dataTypesFound.containsKey(dataType.getUniqueId())){
+ dataTypesFound.put(dataType.getUniqueId(), new ArrayList<>());
+ }
+ dataTypesFound.get(dataType.getUniqueId()).add(model.getName());
+ }
+ });
+ return dataTypesFound;
+ }
+
+ private List<DataTypeData> getAllDataTypesWithModel(final String modelName) {
+ final Either<List<DataTypeData>, JanusGraphOperationStatus> getAllDataTypesByModel = janusGraphGenericDao
+ .getByCriteriaForModel(NodeTypeEnum.DataType, null, modelName, DataTypeData.class);
+ return validateDataType(getAllDataTypesByModel, modelName);
+ }
+
+ private List<DataTypeData> getAllDataTypesWithModel() {
final List<DataTypeData> dataTypesWithModel = new ArrayList<>();
modelOperation.findAllModels()
.forEach(model -> {
@@ -99,28 +132,4 @@ public class DataTypeOperation extends AbstractOperation {
return getDataTypes.left().value();
}
- public Map<String, Map<String, DataTypeDefinition>> mapDataTypesDefinitionByModel(final Map<String, DataTypeDefinition> allDataTypes) {
- final Map<String, DataTypeDefinition> dataTypesWithNullModelMap = new HashMap<>();
- final Map<String, DataTypeDefinition> dataTypesWithModelMap = new HashMap<>();
- final Map<String, Map<String, DataTypeDefinition>> dataTypesMappedByModel = new HashMap<>();
- allDataTypes.values().stream().forEach(dataTypeDefinition -> {
- final var model = dataTypeDefinition.getModel();
- final var dataTypeDefinitionName = dataTypeDefinition.getName();
- if (model == null) {
- dataTypesWithNullModelMap.put(dataTypeDefinitionName, dataTypeDefinition);
- } else {
- dataTypesWithModelMap.put(dataTypeDefinitionName, dataTypeDefinition);
- if (dataTypesMappedByModel.containsKey(model)) {
- dataTypesMappedByModel.get(model).put(dataTypeDefinitionName, dataTypeDefinition);
- } else {
- dataTypesMappedByModel.put(model, dataTypesWithModelMap);
- }
- }
- });
- if(MapUtils.isNotEmpty(dataTypesWithNullModelMap)) {
- dataTypesMappedByModel.put(null, dataTypesWithNullModelMap);
- }
- return dataTypesMappedByModel;
- }
-
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
index 726efcf847..01dbb07fb4 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PropertyOperation.java
@@ -1514,17 +1514,15 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
final Map<String, Map<String, DataTypeDefinition>> dataTypes = new HashMap<>();
Either<Map<String, Map<String, DataTypeDefinition>>, JanusGraphOperationStatus> result = Either.left(dataTypes);
final Map<String, DataTypeDefinition> allDataTypesFound = new HashMap<>();
- final List<DataTypeData> list = dataTypeOperation.getAllDataTypeNodes();
- if (list != null) {
- log.trace("Number of data types to load is {}", list.size());
- List<String> collect = list.stream().map(p -> p.getDataTypeDataDefinition().getName()).collect(Collectors.toList());
- log.trace("The data types to load are {}", collect);
- for (DataTypeData dataTypeData : list) {
- final String dataTypeName = dataTypeData.getDataTypeDataDefinition().getName();
- final String dataTypeUniqueId = dataTypeData.getUniqueId();
- log.trace("Going to fetch data type {}. uid is {}", dataTypeName, dataTypeUniqueId);
+
+ final Map<String, List<String>> dataTypeUidstoModels = dataTypeOperation.getAllDataTypeUidsToModels();
+
+ if (dataTypeUidstoModels != null) {
+ log.trace("Number of data types to load is {}", dataTypeUidstoModels.size());
+ for (Map.Entry<String, List<String>> entry : dataTypeUidstoModels.entrySet()) {
+ log.trace("Going to fetch data type with uid {}", entry.getKey());
Either<DataTypeDefinition, JanusGraphOperationStatus> dataTypeByUid = this
- .getAndAddDataTypeByUid(dataTypeUniqueId, allDataTypesFound);
+ .getAndAddDataTypeByUid(entry.getKey(), allDataTypesFound);
if (dataTypeByUid.isRight()) {
JanusGraphOperationStatus status = dataTypeByUid.right().value();
if (status == JanusGraphOperationStatus.NOT_FOUND) {
@@ -1532,8 +1530,15 @@ public class PropertyOperation extends AbstractOperation implements IPropertyOpe
}
return Either.right(status);
}
- result = Either.left(dataTypeOperation.mapDataTypesDefinitionByModel(allDataTypesFound));
+ for (final String model: entry.getValue()) {
+ if (!dataTypes.containsKey(model)) {
+ dataTypes.put(model, new HashMap<String, DataTypeDefinition>());
+ }
+ DataTypeDefinition dataTypeDefinition = allDataTypesFound.get(entry.getKey());
+ dataTypes.get(model).put(dataTypeDefinition.getName(), dataTypeDefinition);
+ }
}
+
}
if (log.isTraceEnabled()) {
if (result.isRight()) {