2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.introspection.sideeffect;
23 import java.io.UnsupportedEncodingException;
25 import java.net.URISyntaxException;
26 import java.util.HashMap;
27 import java.util.List;
29 import java.util.Map.Entry;
30 import java.util.Optional;
31 import java.util.regex.Matcher;
33 import javax.ws.rs.core.MultivaluedMap;
35 import org.apache.tinkerpop.gremlin.structure.Vertex;
36 import org.onap.aai.db.props.AAIProperties;
37 import org.onap.aai.exceptions.AAIException;
38 import org.onap.aai.introspection.Introspector;
39 import org.onap.aai.introspection.sideeffect.exceptions.AAIMissingRequiredPropertyException;
40 import org.onap.aai.parsers.query.QueryParser;
41 import org.onap.aai.restcore.util.URITools;
42 import org.onap.aai.schema.enums.PropertyMetadata;
43 import org.onap.aai.serialization.db.DBSerializer;
44 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
46 public class DataLinkReader extends SideEffect {
48 public DataLinkReader(Introspector obj, Vertex self, TransactionalGraphEngine dbEngine, DBSerializer serializer) {
49 super(obj, self, dbEngine, serializer);
53 protected boolean replaceWithWildcard() {
58 protected PropertyMetadata getPropertyMetadata() {
59 return PropertyMetadata.DATA_LINK;
63 protected void processURI(Optional<String> completeUri, Entry<String, String> entry)
64 throws URISyntaxException, UnsupportedEncodingException, AAIException {
66 if (completeUri.isPresent()) {
67 URI uri = new URI(completeUri.get());
68 MultivaluedMap<String, String> map = URITools.getQueryMap(uri);
69 QueryParser uriQuery = dbEngine.getQueryBuilder(this.latestLoader).createQueryFromURI(uri, map);
70 List<Vertex> results =
71 uriQuery.getQueryBuilder().getVerticesByProperty(AAIProperties.LINKED, true).toList();
72 if (results.size() == 1) {
73 if (results.get(0).<Boolean>property(AAIProperties.LINKED).orElse(false)
74 && obj.getValue(entry.getKey()) == null) {
75 obj.setValue(entry.getKey(), results.get(0).property(entry.getKey()).orElse(null));
78 // log something about not being able to return any values because there was more than one
84 * always fuzzy search on reads
87 protected Map<String, String> findProperties(Introspector obj, String uriString)
88 throws AAIMissingRequiredPropertyException {
90 final Map<String, String> result = new HashMap<>();
91 Matcher m = template.matcher(uriString);
93 String propName = m.group(1);
94 if (replaceWithWildcard()) {
95 result.put(propName, "*");