diff options
author | Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com> | 2018-08-21 04:11:57 +0000 |
---|---|---|
committer | Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com> | 2018-08-21 04:11:57 +0000 |
commit | 5285007a4e66bc18c69cef96aa32326a139d7642 (patch) | |
tree | 898fb3f81a7981c0dc2332dc5d42b87523d15162 /ms/controllerblueprints/modules/resource-dict/src/main/java | |
parent | a3c9519d6aa7eb8e1f450a7d041047f2c0a5cc07 (diff) |
Controller Blueprints Microservice
Define Controllerblueprint API DataType and Error definitions for Config model, Service Template, Model Type and Resource Dictionary Services
Change-Id: I12d8d87292ec101601b0cfb7ba9670730973e318
Issue-ID: CCSDK-469
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Diffstat (limited to 'ms/controllerblueprints/modules/resource-dict/src/main/java')
10 files changed, 132 insertions, 18 deletions
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java index 15576b906..f85e5ebcd 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceAssignment.java @@ -30,10 +30,10 @@ import java.util.List; * @version 1.0
*/
public class ResourceAssignment {
-
+ @JsonProperty(value = "name", required = true)
private String name;
- @JsonProperty("property")
+ @JsonProperty(value = "property", required = true)
private PropertyDefinition property;
@JsonProperty("input-param")
@@ -58,7 +58,7 @@ public class ResourceAssignment { private String message;
@JsonProperty("updated-date")
- @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
+ @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
private Date updatedDate;
@JsonProperty("updated-by")
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java new file mode 100644 index 000000000..1af42c590 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.java @@ -0,0 +1,24 @@ +/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.resource.dict;
+
+public class ResourceDictionaryConstants {
+ public static final String SOURCE_INPUT= "input";
+ public static final String SOURCE_DEFAULT = "default";
+ public static final String SOURCE_DB = "db";
+ public static final String SOURCE_MDSAL = "mdsal";
+}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java index 4dc9c89a1..7c2d926f0 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/DictionaryDefinition.java @@ -17,7 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.List;
import java.util.Map;
@@ -29,6 +29,7 @@ import java.util.Map; public class DictionaryDefinition {
@JsonProperty(value = "name", required = true)
private String name;
+
@JsonProperty(value = "description")
private String description;
@@ -39,6 +40,7 @@ public class DictionaryDefinition { private String sampleValue;
private String tags;
+
@JsonProperty(value = "updated-by")
private String updatedBy;
@@ -58,7 +60,8 @@ public class DictionaryDefinition { private Object defaultValue;
@JsonProperty(value = "source", required = true)
- private Map<String, JsonNode> source;
+ @JsonDeserialize(using = SourceDeserializer.class, keyAs = String.class, contentAs = ResourceSource.class)
+ private Map<String, ResourceSource> source;
@JsonProperty("candidate-dependency")
private Map<String, DictionaryDependency> dependency;
@@ -154,11 +157,11 @@ public class DictionaryDefinition { this.defaultValue = defaultValue;
}
- public Map<String, JsonNode> getSource() {
+ public Map<String, ResourceSource> getSource() {
return source;
}
- public void setSource(Map<String, JsonNode> source) {
+ public void setSource(Map<String, ResourceSource> source) {
this.source = source;
}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java new file mode 100644 index 000000000..735832cb1 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/ResourceSource.java @@ -0,0 +1,22 @@ +/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data;
+
+import java.io.Serializable;
+
+public interface ResourceSource extends Serializable {
+}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java index 23d404605..724d0224e 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDb.java @@ -24,7 +24,7 @@ import java.util.Map; * SourceDb
* @author Brinda Santh
*/
-public class SourceDb {
+public class SourceDb implements ResourceSource{
@JsonProperty(value = "base", required = true)
private String base;
@JsonProperty(value = "type", required = true)
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java index 0a4351cca..d165192e9 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDefault.java @@ -20,7 +20,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; * SourceDefault
* @author Brinda Santh
*/
-public class SourceDefault {
+public class SourceDefault implements ResourceSource {
private String key;
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java new file mode 100644 index 000000000..86476e1c2 --- /dev/null +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceDeserializer.java @@ -0,0 +1,67 @@ +/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+public class SourceDeserializer extends JsonDeserializer<Map<String, ResourceSource>> {
+
+ private static final Logger log = LoggerFactory.getLogger(SourceDeserializer.class);
+
+ private Class<?> keyAs;
+
+ private Class<?> contentAs;
+
+ private static Map<String, Class<? extends ResourceSource>> registry = new HashMap<String, Class<? extends ResourceSource>>();
+
+ public static void registerSource(String uniqueAttribute, Class<? extends ResourceSource> sourceClass) {
+ registry.put(uniqueAttribute, sourceClass);
+ }
+
+ @Override
+ public Map<String, ResourceSource> deserialize(JsonParser p, DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+
+ ObjectMapper mapper = (ObjectMapper) p.getCodec();
+ ObjectNode root = (ObjectNode) mapper.readTree(p);
+ Map<String, ResourceSource> sources = new HashMap();
+ root.fields().forEachRemaining((node) -> {
+ String key = node.getKey();
+ JsonNode valueNode = node.getValue();
+ Preconditions.checkArgument(StringUtils.isNotBlank(key), "missing source key");
+ Preconditions.checkArgument(registry.containsKey(key), key +" source not registered");
+ if (StringUtils.isNotBlank(key) && registry.containsKey(key)) {
+ Class<? extends ResourceSource> sourceClass = registry.get(key);
+ ResourceSource resourceSource = JacksonUtils.readValue(valueNode.toString(), sourceClass);
+ sources.put(key, resourceSource);
+ }
+ });
+ return sources;
+ }
+}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java index 82cb769da..87184f223 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceInput.java @@ -20,7 +20,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.data; * SourceInput
* @author Brinda Santh
*/
-public class SourceInput {
+public class SourceInput implements ResourceSource {
private String key;
@@ -33,5 +33,4 @@ public class SourceInput { }
-
}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java index 9eb233e76..8a066e91a 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/data/SourceMdsal.java @@ -24,7 +24,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Map;
-public class SourceMdsal {
+public class SourceMdsal implements ResourceSource {
@JsonProperty(value = "base", required = true)
private String base;
@@ -93,5 +93,4 @@ public class SourceMdsal { }
-
}
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java index 9d51d8213..4f9467f05 100644 --- a/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java +++ b/ms/controllerblueprints/modules/resource-dict/src/main/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryUtils.java @@ -16,15 +16,15 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils;
-import com.fasterxml.jackson.databind.JsonNode;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
-import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant;
import org.onap.ccsdk.apps.controllerblueprints.core.data.EntrySchema;
import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition;
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants;
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDefinition;
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.DictionaryDependency;
+import org.onap.ccsdk.apps.controllerblueprints.resource.dict.data.ResourceSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,7 +63,7 @@ public class ResourceDictionaryUtils { // Overwrite the Property Definitions from Dictionary
setProperty(resourceAssignment, dictionaryDefinition);
- Map<String, JsonNode> dictionarySource = dictionaryDefinition.getSource();
+ Map<String, ResourceSource> dictionarySource = dictionaryDefinition.getSource();
Map<String, DictionaryDependency> dictionaryDependencyMap = dictionaryDefinition.getDependency();
if (MapUtils.isNotEmpty(dictionarySource)) {
@@ -82,7 +82,7 @@ public class ResourceDictionaryUtils { }
}
} else {
- resourceAssignment.setDictionarySource(ConfigModelConstant.SOURCE_INPUT);
+ resourceAssignment.setDictionarySource(ResourceDictionaryConstants.SOURCE_INPUT);
}
log.info("auto map resourceAssignment : {}", resourceAssignment);
}
@@ -98,7 +98,7 @@ public class ResourceDictionaryUtils { }
}
- private static String findFirstSource(Map<String, JsonNode> dictionarySource) {
+ private static String findFirstSource(Map<String, ResourceSource> dictionarySource) {
String source = null;
if (MapUtils.isNotEmpty(dictionarySource)) {
source = dictionarySource.keySet().stream().findFirst().get();
|