Modify Model Type and Resource Defintions persistance and access from String to JSON type for easy handling.
Change-Id: Icfe7e95abad715b0ccad16c681ed057d289a6229
Issue-ID: CCSDK-431
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
return jacksonObjectMapper().readValue(content, valueType)\r
}\r
\r
+ @JvmStatic\r
+ fun <T> readValue(node: JsonNode, valueType: Class<T>): T? {\r
+ return jacksonObjectMapper().treeToValue(node, valueType)\r
+ }\r
+\r
@JvmStatic\r
fun getContent(fileName: String): String {\r
return File(fileName).readText(Charsets.UTF_8)\r
import org.apache.commons.lang3.StringUtils;\r
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;\r
-import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;\r
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils;\r
\r
private void populateDictionaryMapping(Map<String, ResourceDictionary> dictionaryMap, ResourceAssignment resourceAssignment) {\r
ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName());\r
- if (dbDataDictionary != null && StringUtils.isNotBlank(dbDataDictionary.getDefinition())) {\r
+ if (dbDataDictionary != null && dbDataDictionary.getDefinition() != null) {\r
\r
- ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(dbDataDictionary.getDefinition(), ResourceDefinition.class);\r
+ ResourceDefinition dictionaryDefinition = dbDataDictionary.getDefinition();\r
\r
if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName())\r
&& StringUtils.isBlank(resourceAssignment.getDictionaryName())) {\r
}\r
if (dictionaries != null) {\r
for (ResourceDictionary resourcedictionary : dictionaries) {\r
- ResourceDefinition dictionaryDefinition = JacksonUtils.readValue(resourcedictionary.getDefinition(), ResourceDefinition.class);\r
+ ResourceDefinition dictionaryDefinition = resourcedictionary.getDefinition();\r
Preconditions.checkNotNull(dictionaryDefinition, "failed to get Resource Definition from dictionary definition");\r
PropertyDefinition property = new PropertyDefinition();\r
property.setRequired(true);\r
\r
package org.onap.ccsdk.apps.controllerblueprints.service;\r
\r
+import com.fasterxml.jackson.databind.JsonNode;\r
import com.google.common.base.Preconditions;\r
import org.apache.commons.lang3.StringUtils;\r
import org.jetbrains.annotations.NotNull;\r
Preconditions.checkArgument(StringUtils.isNotBlank(modelName),\r
"Failed to get model from repo, model name is missing");\r
\r
- return getModelDefinition(modelName).map(content -> {\r
- Preconditions.checkArgument(StringUtils.isNotBlank(content),\r
+ return getModelDefinition(modelName).map(modelDefinition -> {\r
+ Preconditions.checkNotNull(modelDefinition,\r
String.format("Failed to get model content for model name (%s)", modelName));\r
- return JacksonUtils.readValue(content, valueClass);\r
+ return JacksonUtils.readValue(modelDefinition, valueClass);\r
}\r
);\r
}\r
\r
- private Mono<String> getModelDefinition(String modelName) throws BluePrintException {\r
- String modelDefinition;\r
+ private Mono<JsonNode> getModelDefinition(String modelName) throws BluePrintException {\r
+ JsonNode modelDefinition;\r
Optional<ModelType> modelTypeDb = modelTypeRepository.findByModelName(modelName);\r
if (modelTypeDb.isPresent()) {\r
modelDefinition = modelTypeDb.get().getDefinition();\r
ResourceDictionary resourceDictionary = new ResourceDictionary();\r
resourceDictionary.setResourcePath(dictionaryDefinition.getResourcePath());\r
resourceDictionary.setName(dictionaryDefinition.getName());\r
- resourceDictionary.setDefinition(definitionContent);\r
+ resourceDictionary.setDefinition(dictionaryDefinition);\r
\r
resourceDictionary.setResourceType(dictionaryDefinition.getResourceType());\r
resourceDictionary.setDescription(dictionaryDefinition.getProperty().getDescription());\r
modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE);\r
modelType.setDerivedFrom(nodeType.getDerivedFrom());\r
modelType.setDescription(nodeType.getDescription());\r
- modelType.setDefinition(definitionContent);\r
+ modelType.setDefinition(JacksonUtils.jsonNode(definitionContent));\r
modelType.setModelName(nodeKey);\r
modelType.setVersion(nodeType.getVersion());\r
modelType.setUpdatedBy("System");\r
modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
modelType.setDerivedFrom(dataType.getDerivedFrom());\r
modelType.setDescription(dataType.getDescription());\r
- modelType.setDefinition(definitionContent);\r
+ modelType.setDefinition(JacksonUtils.jsonNode(definitionContent));\r
modelType.setModelName(dataKey);\r
modelType.setVersion(dataType.getVersion());\r
modelType.setUpdatedBy("System");\r
modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE);\r
modelType.setDerivedFrom(artifactType.getDerivedFrom());\r
modelType.setDescription(artifactType.getDescription());\r
- modelType.setDefinition(definitionContent);\r
+ modelType.setDefinition(JacksonUtils.jsonNode(definitionContent));\r
modelType.setModelName(dataKey);\r
modelType.setVersion(artifactType.getVersion());\r
modelType.setUpdatedBy("System");\r
*/\r
public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) {\r
Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing");\r
- Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()),\r
- "Resource Dictionary definition information is missing");\r
+ Preconditions.checkNotNull(resourceDictionary.getDefinition(),"Resource Dictionary definition information is missing");\r
\r
- ResourceDefinition resourceDefinition =\r
- JacksonUtils.readValue(resourceDictionary.getDefinition(), ResourceDefinition.class);\r
+ ResourceDefinition resourceDefinition = resourceDictionary.getDefinition();\r
Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content");\r
// Validate the Resource Definitions\r
resourceDictionaryValidationService.validate(resourceDefinition);\r
resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType());\r
}\r
\r
- String definitionContent = JacksonUtils.getJson(resourceDefinition, true);\r
- resourceDictionary.setDefinition(definitionContent);\r
-\r
ResourceDictionaryValidator.validateResourceDictionary(resourceDictionary);\r
\r
Optional<ResourceDictionary> dbResourceDictionaryData =\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.service.domain;\r
+\r
+import javax.persistence.AttributeConverter;\r
+import javax.persistence.Converter;\r
+\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
+/**\r
+ * @author Brinda Santh\r
+ */\r
+@Converter\r
+public class JpaJsonNodeConverter implements\r
+ AttributeConverter<JsonNode, String> {\r
+\r
+ @Override\r
+ public String convertToDatabaseColumn(JsonNode node) {\r
+ return JacksonUtils.getJson(node, true);\r
+ }\r
+\r
+ @Override\r
+ public JsonNode convertToEntityAttribute(String dbData) {\r
+ return JacksonUtils.jsonNode(dbData);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.onap.ccsdk.apps.controllerblueprints.service.domain;\r
+\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
+\r
+import javax.persistence.AttributeConverter;\r
+import javax.persistence.Converter;\r
+/**\r
+ * @author Brinda Santh\r
+ */\r
+@Converter\r
+public class JpaResourceDefinitionConverter implements\r
+ AttributeConverter<ResourceDefinition, String> {\r
+ @Override\r
+ public String convertToDatabaseColumn(ResourceDefinition resourceDefinition) {\r
+ return JacksonUtils.getJson(resourceDefinition);\r
+ }\r
+\r
+ @Override\r
+ public ResourceDefinition convertToEntityAttribute(String content) {\r
+ return JacksonUtils.readValue(content, ResourceDefinition.class);\r
+ }\r
+}\r
package org.onap.ccsdk.apps.controllerblueprints.service.domain;\r
\r
import com.fasterxml.jackson.annotation.JsonFormat;\r
+import com.fasterxml.jackson.databind.JsonNode;\r
import io.swagger.annotations.ApiModelProperty;\r
import org.springframework.data.annotation.LastModifiedDate;\r
import org.springframework.data.jpa.domain.support.AuditingEntityListener;\r
private String definitionType;\r
\r
@Lob\r
+ @Convert(converter = JpaJsonNodeConverter.class)\r
@Column(name = "definition", nullable = false)\r
@ApiModelProperty(required=true)\r
- private String definition;\r
+ private JsonNode definition;\r
\r
@Lob\r
@Column(name = "description", nullable = false)\r
this.definitionType = definitionType;\r
}\r
\r
- public String getDefinition() {\r
+ public JsonNode getDefinition() {\r
return definition;\r
}\r
\r
- public void setDefinition(String definition) {\r
+ public void setDefinition(JsonNode definition) {\r
this.definition = definition;\r
}\r
\r
\r
import com.fasterxml.jackson.annotation.JsonFormat;\r
import io.swagger.annotations.ApiModelProperty;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
import org.springframework.data.annotation.LastModifiedDate;\r
import org.springframework.data.jpa.domain.support.AuditingEntityListener;\r
\r
private String sampleValue;\r
\r
@Lob\r
+ @Convert(converter = JpaResourceDefinitionConverter.class)\r
@Column(name = "definition", nullable = false)\r
@ApiModelProperty(required=true)\r
- private String definition;\r
+ private ResourceDefinition definition;\r
\r
@Lob\r
@Column(name = "description", nullable = false)\r
this.sampleValue = sampleValue;\r
}\r
\r
- public String getDefinition() {\r
+ public ResourceDefinition getDefinition() {\r
return definition;\r
}\r
\r
- public void setDefinition(String definition) {\r
+ public void setDefinition(ResourceDefinition definition) {\r
this.definition = definition;\r
}\r
\r
\r
package org.onap.ccsdk.apps.controllerblueprints.service.validator;\r
\r
+import com.fasterxml.jackson.databind.JsonNode;\r
import org.apache.commons.lang3.StringUtils;\r
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;\r
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
/**\r
* This is a validateModelTypeDefinition\r
* \r
- * @param definitionType\r
- * @param definitionContent\r
+ * @param definitionType definitionType\r
+ * @param definitionContent definitionContent\r
* @return boolean\r
- * @throws BluePrintException\r
+ * @throws BluePrintException BluePrintException\r
*/\r
- public static boolean validateModelTypeDefinition(String definitionType, String definitionContent)\r
+ public static boolean validateModelTypeDefinition(String definitionType, JsonNode definitionContent)\r
throws BluePrintException {\r
- if (StringUtils.isNotBlank(definitionContent)) {\r
+ if (definitionContent != null) {\r
if (BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE.equalsIgnoreCase(definitionType)) {\r
DataType dataType = JacksonUtils.readValue(definitionContent, DataType.class);\r
if (dataType == null) {\r
/**\r
* This is a validateModelType method\r
* \r
- * @param modelType\r
+ * @param modelType modelType\r
* @return boolean\r
+ * @throws BluePrintException BluePrintException\r
*/\r
public static boolean validateModelType(ModelType modelType) throws BluePrintException {\r
if (modelType != null) {\r
throw new BluePrintException("Model Type Information is missing.");\r
}\r
\r
- if (StringUtils.isBlank(modelType.getDefinition())) {\r
+ if (modelType.getDefinition() == null) {\r
throw new BluePrintException("Model Definition Information is missing.");\r
}\r
if (StringUtils.isBlank(modelType.getDescription())) {\r
List<String> validRootTypes = getValidModelDefinitionType();\r
if (!validRootTypes.contains(modelType.getDefinitionType())) {\r
throw new BluePrintException("Not Valid Model Root Type(" + modelType.getDefinitionType()\r
- + "), It sould be " + validRootTypes);\r
+ + "), It should be " + validRootTypes);\r
}\r
\r
validateModelTypeDefinition(modelType.getDefinitionType(), modelType.getDefinition());\r
"DataDictionary Resource Name Information is missing.");\r
Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getResourceType()),\r
"DataDictionary Resource Type Information is missing.");\r
- Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDefinition()),\r
+ Preconditions.checkNotNull( resourceDictionary.getDefinition(),\r
"DataDictionary Definition Information is missing.");\r
Preconditions.checkArgument( StringUtils.isNotBlank(resourceDictionary.getDescription()),\r
"DataDictionary Description Information is missing.");\r
import org.junit.runners.MethodSorters;\r
import org.onap.ccsdk.apps.controllerblueprints.TestApplication;\r
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;\r
import com.att.eelf.configuration.EELFLogger;\r
import com.att.eelf.configuration.EELFManager;\r
modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE);\r
modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT);\r
modelType.setDescription("Definition for Sample Datatype ");\r
- modelType.setDefinition(content);\r
+ modelType.setDefinition(JacksonUtils.jsonNode(content));\r
modelType.setModelName(modelName);\r
modelType.setVersion("1.0.0");\r
modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + ","\r
import org.junit.runner.RunWith;\r
import org.junit.runners.MethodSorters;\r
import org.onap.ccsdk.apps.controllerblueprints.TestApplication;\r
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;\r
import com.att.eelf.configuration.EELFLogger;\r
import com.att.eelf.configuration.EELFManager;\r
ResourceDictionary dataDictionary = new ResourceDictionary();\r
dataDictionary.setResourcePath("test/vnf/ipaddress");\r
dataDictionary.setName("test-name");\r
- dataDictionary.setDefinition(definition);\r
+ dataDictionary.setDefinition(JacksonUtils.readValue(definition, ResourceDefinition.class));\r
dataDictionary.setValidValues("127.0.0.1");\r
dataDictionary.setResourceType("ONAP");\r
dataDictionary.setDataType("string");\r