Update the license for 2017-2018 license
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / introspection / tools / InjectKeysFromURI.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.introspection.tools;
21
22 import com.att.eelf.configuration.EELFLogger;
23 import com.att.eelf.configuration.EELFManager;
24 import org.onap.aai.introspection.Introspector;
25 import org.onap.aai.introspection.Loader;
26 import org.onap.aai.parsers.uri.URIToObject;
27
28 import java.net.URI;
29
30 public class InjectKeysFromURI  implements IssueResolver {
31         private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(InjectKeysFromURI.class);
32
33         private URI uri = null;
34         private Loader loader = null;
35         
36         /**
37          * Instantiates a new inject keys from URI.
38          *
39          * @param loader the loader
40          * @param uri the uri
41          */
42         public InjectKeysFromURI(Loader loader, URI uri) {
43                 this.loader = loader;
44                 this.uri = uri;
45         }
46         
47         /**
48          * {@inheritDoc}
49          */
50         @Override
51         public boolean resolveIssue(Issue issue) {
52                 boolean result = false;
53                 Introspector obj = issue.getIntrospector();
54                 if (issue.getType().equals(IssueType.MISSING_KEY_PROP)) {
55                         try {
56                                 URIToObject toObject = new URIToObject(loader, uri);
57                                 Introspector minimumObj = toObject.getEntity();
58                                 if (toObject.getEntityName().equals(obj.getDbName())) {
59                                         obj.setValue(issue.getPropName(), minimumObj.getValue(issue.getPropName()));
60                                         result = true;
61                                 }
62                         } catch (Exception e) {
63                 LOGGER.error(e.getMessage(),e);
64                                 result = false;
65                         }
66                 }
67                 
68                 return result;
69         }
70
71 }