Convert project from AJSC to Spring Boot
[aai/model-loader.git] / src / main / java / org / onap / aai / modelloader / entity / model / NamedQueryArtifactParser.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 European Software Marketing Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.modelloader.entity.model;
22
23 import java.util.List;
24 import org.onap.aai.cl.api.Logger;
25 import org.onap.aai.cl.eelf.LoggerFactory;
26 import org.onap.aai.modelloader.entity.Artifact;
27 import org.onap.aai.modelloader.service.ModelLoaderMsgs;
28 import org.w3c.dom.Node;
29
30 public class NamedQueryArtifactParser extends AbstractModelArtifactParser {
31
32     private static final String NAMED_QUERY_VERSION_ID = "named-query-uuid";
33     private static final String MODEL_ELEMENT_RELATIONSHIP_KEY = "model.model-invariant-id";
34
35     private static Logger logger = LoggerFactory.getInstance().getLogger(NamedQueryArtifactParser.class.getName());
36
37     /**
38      * {@inheritDoc}
39      */
40     @Override
41     boolean processParsedModel(List<Artifact> modelList, String artifactName, IModelArtifact model) {
42         boolean valid = false;
43
44         if (model != null) {
45             logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Named-Query parsed =====>>>> " + "Named-Query-UUID: "
46                     + ((NamedQueryArtifact) model).getNamedQueryUuid());
47             modelList.add((NamedQueryArtifact) model);
48
49             valid = true;
50         } else {
51             logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR, "Unable to parse named-query artifact " + artifactName);
52         }
53
54         return valid;
55     }
56
57     /**
58      * {@inheritDoc}
59      */
60     @Override
61     String buildArtifactParseExceptionMessage(String artifactName, String localisedMessage) {
62         return "Unable to parse named-query artifact " + artifactName + ": " + localisedMessage;
63     }
64
65     @Override
66     String getModelElementRelationshipKey() {
67         return MODEL_ELEMENT_RELATIONSHIP_KEY;
68     }
69
70     /**
71      * {@inheritDoc}
72      */
73     @Override
74     String getVersionIdNodeName() {
75         return NAMED_QUERY_VERSION_ID;
76     }
77
78     /**
79      * {@inheritDoc}
80      */
81     @Override
82     void setVersionId(IModelArtifact model, Node node) {
83         ((NamedQueryArtifact) model).setNamedQueryUuid(node.getTextContent().trim());
84     }
85
86     /**
87      * {@inheritDoc}
88      */
89     @Override
90     IModelArtifact createModelArtifactInstance() {
91         return new NamedQueryArtifact();
92     }
93
94     /**
95      * {@inheritDoc}
96      */
97     @Override
98     boolean modelIsValid(IModelArtifact model) {
99         return ((NamedQueryArtifact) model).getNamedQueryUuid() != null;
100     }
101 }