summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/service/src
diff options
context:
space:
mode:
Diffstat (limited to 'ms/controllerblueprints/modules/service/src')
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java63
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java96
-rw-r--r--ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json4
3 files changed, 74 insertions, 89 deletions
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java
index 4a26119c..4c11d8c6 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoDBService.java
@@ -26,6 +26,7 @@ import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;
import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository;
import org.springframework.stereotype.Service;
+import reactor.core.publisher.Mono;
import java.util.Optional;
@@ -43,59 +44,51 @@ public class BluePrintRepoDBService implements BluePrintRepoService {
this.modelTypeRepository = modelTypeRepository;
}
-
@Override
- public NodeType getNodeType(String nodeTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(nodeTypeName), "NodeType name is missing");
- String content = getModelDefinitions(nodeTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "NodeType content is missing");
- return JacksonUtils.readValue(content, NodeType.class);
+ public Mono<NodeType> getNodeType(String nodeTypeName) throws BluePrintException {
+ return getModelType(nodeTypeName, NodeType.class);
}
-
@Override
- public DataType getDataType(String dataTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(dataTypeName), "DataType name is missing");
- String content = getModelDefinitions(dataTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "DataType content is missing");
- return JacksonUtils.readValue(content, DataType.class);
+ public Mono<DataType> getDataType(String dataTypeName) throws BluePrintException {
+ return getModelType(dataTypeName, DataType.class);
}
-
@Override
- public ArtifactType getArtifactType(String artifactTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(artifactTypeName), "ArtifactType name is missing");
- String content = getModelDefinitions(artifactTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "ArtifactType content is missing");
- return JacksonUtils.readValue(content, ArtifactType.class);
+ public Mono<ArtifactType> getArtifactType(String artifactTypeName) throws BluePrintException {
+ return getModelType(artifactTypeName, ArtifactType.class);
}
-
@Override
- public RelationshipType getRelationshipType(String relationshipTypeName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(relationshipTypeName), "RelationshipType name is missing");
- String content = getModelDefinitions(relationshipTypeName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "RelationshipType content is missing");
- return JacksonUtils.readValue(content, RelationshipType.class);
+ public Mono<RelationshipType> getRelationshipType(String relationshipTypeName) throws BluePrintException {
+ return getModelType(relationshipTypeName, RelationshipType.class);
}
-
@Override
- public CapabilityDefinition getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException {
- Preconditions.checkArgument(StringUtils.isNotBlank(capabilityDefinitionName), "CapabilityDefinition name is missing");
- String content = getModelDefinitions(capabilityDefinitionName);
- Preconditions.checkArgument(StringUtils.isNotBlank(content), "CapabilityDefinition content is missing");
- return JacksonUtils.readValue(content, CapabilityDefinition.class);
+ public Mono<CapabilityDefinition> getCapabilityDefinition(String capabilityDefinitionName) throws BluePrintException {
+ return getModelType(capabilityDefinitionName, CapabilityDefinition.class);
}
- private String getModelDefinitions(String modelName) throws BluePrintException {
+ private <T> Mono<T> getModelType(String modelName, Class<T> valueClass) throws BluePrintException {
+ Preconditions.checkArgument(StringUtils.isNotBlank(modelName),
+ "Failed to get model from repo, model name is missing");
+
+ return getModelDefinitions(modelName).map(content -> {
+ Preconditions.checkArgument(StringUtils.isNotBlank(content),
+ String.format("Failed to get model content for model name (%s)", modelName));
+ return JacksonUtils.readValue(content, valueClass);
+ }
+ );
+ }
+
+ private Mono<String> getModelDefinitions(String modelName) throws BluePrintException {
String modelDefinition = null;
- Optional<ModelType> modelTypedb = modelTypeRepository.findByModelName(modelName);
- if (modelTypedb.isPresent()) {
- modelDefinition = modelTypedb.get().getDefinition();
+ Optional<ModelType> modelTypeDb = modelTypeRepository.findByModelName(modelName);
+ if (modelTypeDb.isPresent()) {
+ modelDefinition = modelTypeDb.get().getDefinition();
} else {
throw new BluePrintException(String.format("failed to get model definition (%s) from repo", modelName));
}
- return modelDefinition;
+ return Mono.just(modelDefinition);
}
}
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
index 5420dd39..629b94c0 100644
--- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
+++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java
@@ -17,6 +17,7 @@
package org.onap.ccsdk.apps.controllerblueprints.service;
+import com.google.common.base.Preconditions;
import org.apache.commons.lang3.StringUtils;
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema;
@@ -112,60 +113,51 @@ public class ResourceDictionaryService {
*/
public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary)
throws BluePrintException {
- if (resourceDictionary != null) {
- ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary);
-
- ResourceDefinition resourceDefinition =
- JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);
- // Check the Source already Present
- resourceDictionaryValidationService.validate(resourceDefinition);
-
- if (resourceDefinition == null) {
- throw new BluePrintException(
- "Resource dictionary definition is not valid content " + resourceDictionary.getDefinition());
- }
-
- resourceDefinition.setName(resourceDictionary.getName());
- resourceDefinition.setResourcePath(resourceDictionary.getResourcePath());
- resourceDefinition.setResourceType(resourceDictionary.getResourceType());
-
- PropertyDefinition propertyDefinition = new PropertyDefinition();
- propertyDefinition.setType(resourceDictionary.getDataType());
- propertyDefinition.setDescription(resourceDictionary.getDescription());
- if (StringUtils.isNotBlank(resourceDictionary.getEntrySchema())) {
- EntrySchema entrySchema = new EntrySchema();
- entrySchema.setType(resourceDictionary.getEntrySchema());
- propertyDefinition.setEntrySchema(entrySchema);
- } else {
- propertyDefinition.setEntrySchema(null);
- }
- resourceDefinition.setTags(resourceDictionary.getTags());
- resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy());
-
- String definitionContent = JacksonUtils.getJson(resourceDefinition, true);
- resourceDictionary.setDefinition(definitionContent);
-
- Optional<ResourceDictionary> dbResourceDictionaryData =
- resourceDictionaryRepository.findByName(resourceDictionary.getName());
- if (dbResourceDictionaryData.isPresent()) {
- ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get();
-
- dbResourceDictionary.setName(resourceDictionary.getName());
- dbResourceDictionary.setDefinition(resourceDictionary.getDefinition());
- dbResourceDictionary.setDescription(resourceDictionary.getDescription());
- dbResourceDictionary.setResourceType(resourceDictionary.getResourceType());
- dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath());
- dbResourceDictionary.setDataType(resourceDictionary.getDataType());
- dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema());
- dbResourceDictionary.setTags(resourceDictionary.getTags());
- dbResourceDictionary.setValidValues(resourceDictionary.getValidValues());
- resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary);
- } else {
- resourceDictionary = resourceDictionaryRepository.save(resourceDictionary);
- }
+ Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing");
+ Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()),
+ "Resource Dictionary definition information is missing");
+
+ ResourceDefinition resourceDefinition =
+ JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);
+ // Validate the Resource Definitions
+ resourceDictionaryValidationService.validate(resourceDefinition);
+
+ resourceDictionary.setResourceType(resourceDefinition.getResourceType());
+ resourceDictionary.setResourcePath(resourceDefinition.getResourcePath());
+ resourceDictionary.setTags(resourceDefinition.getTags());
+ resourceDefinition.setUpdatedBy(resourceDictionary.getUpdatedBy());
+ // Set the Property Definitions
+ PropertyDefinition propertyDefinition = resourceDefinition.getProperty();
+ resourceDictionary.setDescription(propertyDefinition.getDescription());
+ resourceDictionary.setDataType(propertyDefinition.getType());
+ if(propertyDefinition.getEntrySchema() != null){
+ resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType());
+ }
+
+ String definitionContent = JacksonUtils.getJson(resourceDefinition, true);
+ resourceDictionary.setDefinition(definitionContent);
+
+ ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary);
+
+ Optional<ResourceDictionary> dbResourceDictionaryData =
+ resourceDictionaryRepository.findByName(resourceDictionary.getName());
+ if (dbResourceDictionaryData.isPresent()) {
+ ResourceDictionary dbResourceDictionary = dbResourceDictionaryData.get();
+
+ dbResourceDictionary.setName(resourceDictionary.getName());
+ dbResourceDictionary.setDefinition(resourceDictionary.getDefinition());
+ dbResourceDictionary.setDescription(resourceDictionary.getDescription());
+ dbResourceDictionary.setResourceType(resourceDictionary.getResourceType());
+ dbResourceDictionary.setResourcePath(resourceDictionary.getResourcePath());
+ dbResourceDictionary.setTags(resourceDictionary.getTags());
+ dbResourceDictionary.setUpdatedBy(resourceDictionary.getUpdatedBy());
+ dbResourceDictionary.setDataType(resourceDictionary.getDataType());
+ dbResourceDictionary.setEntrySchema(resourceDictionary.getEntrySchema());
+ resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary);
} else {
- throw new BluePrintException("Resource Dictionary information is missing");
+ resourceDictionary = resourceDictionaryRepository.save(resourceDictionary);
}
+
return resourceDictionary;
}
diff --git a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json
index 986ba706..198823bb 100644
--- a/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json
+++ b/ms/controllerblueprints/modules/service/src/test/resources/resourcedictionary/default_definition.json
@@ -1,5 +1,5 @@
{
- "name": "v4-aggregat-list",
+ "name": "ipaddress",
"property": {
"description": "name of the ",
"type": "list",
@@ -10,7 +10,7 @@
"updated-by": "Brinda Santh (bs2796)",
"resource-type": "ONAP",
"resource-path": "/v4-aggregat-list",
- "tags": null,
+ "tags": "ipaddress",
"sources": {
"input": {
"type": "source-input"