summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java
diff options
context:
space:
mode:
authorBlackwell, Ian (ib733q) <IanB@amdocs.com>2018-04-03 17:28:44 +0100
committerBlackwell, Ian (ib733q) <IanB@amdocs.com>2018-04-03 17:28:44 +0100
commit7b1f813441f94261f43ec4f5bb0944ad2570fbdf (patch)
tree7c5a2d1f378b2a0b358905e82d21cce73f3e1d6d /src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java
parent4dd316529148d07059d844197cdb676806bdc0c6 (diff)
Revisions made to the Model Loader to use Babel
Change the Model Loader to use the Babel micro service. Responsibility for transformation of ASDC TOSCA models, the yaml files, has been moved from ASDC and placed into the Bable microservice. Model Loader will forward any CSAR received from ASDC and delegate transformation to Babel. Babel will return the transformed TOSCA models to Model Loader which will then ingest them into the A&AI Inventory. Issue-ID: AAI-987 Change-Id: I99594770b51b00cb7dcc0f30706060ae27cd94c5 Signed-off-by: Blackwell, Ian (ib733q) <IanB@amdocs.com>
Diffstat (limited to 'src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java')
-rw-r--r--src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java152
1 files changed, 62 insertions, 90 deletions
diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java b/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java
index 8188b28..5b9488e 100644
--- a/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java
+++ b/src/main/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParser.java
@@ -20,114 +20,86 @@
*/
package org.onap.aai.modelloader.entity.model;
+import java.util.List;
+
import org.onap.aai.modelloader.entity.Artifact;
import org.onap.aai.modelloader.service.ModelLoaderMsgs;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Node;
-public class NamedQueryArtifactParser implements IModelParser {
+public class NamedQueryArtifactParser extends AbstractModelArtifactParser {
- private static String NAMED_QUERY_VERSION_ID = "named-query-uuid";
- private static String RELATIONSHIP_DATA = "relationship-data";
- private static String RELATIONSHIP_KEY = "relationship-key";
- private static String RELATIONSHIP_VALUE = "relationship-value";
- private static String MODEL_ELEMENT_RELATIONSHIP_KEY = "model.model-invariant-id";
+ private static final String NAMED_QUERY_VERSION_ID = "named-query-uuid";
+ private static final String MODEL_ELEMENT_RELATIONSHIP_KEY = "model.model-invariant-id";
-
- private static Logger logger = LoggerFactory.getInstance().getLogger(NamedQueryArtifactParser.class.getName());
-
- public List<Artifact> parse(byte[] artifactPayload, String artifactName) {
- String payload = new String(artifactPayload);
- List<Artifact> modelList = new ArrayList<Artifact>();
+ private static Logger logger = LoggerFactory.getInstance().getLogger(NamedQueryArtifactParser.class.getName());
- try {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- InputSource is = new InputSource(new StringReader(payload));
- Document doc = builder.parse(is);
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ boolean processParsedModel(List<Artifact> modelList, String artifactName, IModelArtifact model) {
+ boolean valid = false;
- NamedQueryArtifact model = parseModel(doc.getDocumentElement(), payload);
+ if (model != null) {
+ logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,
+ "Named-Query parsed =====>>>> " + "Named-Query-UUID: " + ((NamedQueryArtifact) model)
+ .getNamedQueryUuid());
+ modelList.add((NamedQueryArtifact) model);
- if (model != null) {
- logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Named-Query parsed =====>>>> " + "Named-Query-UUID: "+ model.getNamedQueryUuid());
- modelList.add(model);
- }
- else {
- logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse named-query artifact " + artifactName);
- return null;
- }
- }
- catch (Exception ex) {
- logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse named-query artifact " + artifactName + ": " + ex.getLocalizedMessage());
- }
+ valid = true;
+ } else {
+ logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR,
+ "Unable to parse named-query artifact " + artifactName);
+ }
- return modelList;
- }
+ return valid;
+ }
- private NamedQueryArtifact parseModel(Node modelNode, String payload) {
- NamedQueryArtifact model = new NamedQueryArtifact();
- model.setPayload(payload);
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ String buildArtifactParseExceptionMessage(String artifactName, String localisedMessage) {
+ return "Unable to parse named-query artifact " + artifactName + ": " + localisedMessage;
+ }
- Element e = (Element)modelNode;
- model.setModelNamespace(e.getAttribute("xmlns"));
+ @Override
+ String getModelElementRelationshipKey() {
+ return MODEL_ELEMENT_RELATIONSHIP_KEY;
+ }
- parseNode(modelNode, model);
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ String getVersionIdNodeName() {
+ return NAMED_QUERY_VERSION_ID;
+ }
- if (model.getNamedQueryUuid() == null) {
- return null;
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ void setVersionId(IModelArtifact model, Node node) {
+ ((NamedQueryArtifact) model).setNamedQueryUuid(node.getTextContent().trim());
}
- return model;
- }
-
- private void parseNode(Node node, NamedQueryArtifact model) {
- if (node.getNodeName().equalsIgnoreCase(NAMED_QUERY_VERSION_ID)) {
- model.setNamedQueryUuid(node.getTextContent().trim());
- }
- else if (node.getNodeName().equalsIgnoreCase(RELATIONSHIP_DATA)) {
- parseRelationshipNode(node, model);
- }
- else {
- NodeList nodeList = node.getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node childNode = nodeList.item(i);
- parseNode(childNode, model);
- }
- }
- }
-
- private void parseRelationshipNode(Node node, NamedQueryArtifact model) {
- String key = null;
- String value = null;
-
- NodeList nodeList = node.getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node childNode = nodeList.item(i);
- if (childNode.getNodeName().equalsIgnoreCase(RELATIONSHIP_KEY)) {
- key = childNode.getTextContent().trim();
- }
- else if (childNode.getNodeName().equalsIgnoreCase(RELATIONSHIP_VALUE)) {
- value = childNode.getTextContent().trim();
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ IModelArtifact createModelArtifactInstance() {
+ return new NamedQueryArtifact();
}
-
- if ( (key != null) && (key.equalsIgnoreCase(MODEL_ELEMENT_RELATIONSHIP_KEY )) ) {
- if (value != null) {
- model.addDependentModelId(value);
- }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ boolean modelIsValid(IModelArtifact model) {
+ return ((NamedQueryArtifact) model).getNamedQueryUuid() != null;
}
- }
}