5b9488e02565ac355cf3f2e399094c2291967c5d
[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 Amdocs
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
25 import org.onap.aai.modelloader.entity.Artifact;
26 import org.onap.aai.modelloader.service.ModelLoaderMsgs;
27 import org.onap.aai.cl.api.Logger;
28 import org.onap.aai.cl.eelf.LoggerFactory;
29
30 import org.w3c.dom.Node;
31
32 public class NamedQueryArtifactParser extends AbstractModelArtifactParser {
33
34     private static final String NAMED_QUERY_VERSION_ID = "named-query-uuid";
35     private static final String MODEL_ELEMENT_RELATIONSHIP_KEY = "model.model-invariant-id";
36
37     private static Logger logger = LoggerFactory.getInstance().getLogger(NamedQueryArtifactParser.class.getName());
38
39     /**
40      * {@inheritDoc}
41      */
42     @Override
43     boolean processParsedModel(List<Artifact> modelList, String artifactName, IModelArtifact model) {
44         boolean valid = false;
45
46         if (model != null) {
47             logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT,
48                     "Named-Query parsed =====>>>> " + "Named-Query-UUID: " + ((NamedQueryArtifact) model)
49                             .getNamedQueryUuid());
50             modelList.add((NamedQueryArtifact) model);
51
52             valid = true;
53         } else {
54             logger.error(ModelLoaderMsgs.ARTIFACT_PARSE_ERROR,
55                     "Unable to parse named-query artifact " + artifactName);
56         }
57
58         return valid;
59     }
60
61     /**
62      * {@inheritDoc}
63      */
64     @Override
65     String buildArtifactParseExceptionMessage(String artifactName, String localisedMessage) {
66         return "Unable to parse named-query artifact " + artifactName + ": " + localisedMessage;
67     }
68
69     @Override
70     String getModelElementRelationshipKey() {
71         return MODEL_ELEMENT_RELATIONSHIP_KEY;
72     }
73
74     /**
75      * {@inheritDoc}
76      */
77     @Override
78     String getVersionIdNodeName() {
79         return NAMED_QUERY_VERSION_ID;
80     }
81
82     /**
83      * {@inheritDoc}
84      */
85     @Override
86     void setVersionId(IModelArtifact model, Node node) {
87         ((NamedQueryArtifact) model).setNamedQueryUuid(node.getTextContent().trim());
88     }
89
90     /**
91      * {@inheritDoc}
92      */
93     @Override
94     IModelArtifact createModelArtifactInstance() {
95         return new NamedQueryArtifact();
96     }
97
98     /**
99      * {@inheritDoc}
100      */
101     @Override
102     boolean modelIsValid(IModelArtifact model) {
103         return ((NamedQueryArtifact) model).getNamedQueryUuid() != null;
104     }
105 }