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=========================================================
20 package org.onap.aai.introspection.sideeffect;
22 import org.apache.tinkerpop.gremlin.structure.Vertex;
23 import org.onap.aai.db.props.AAIProperties;
24 import org.onap.aai.exceptions.AAIException;
25 import org.onap.aai.introspection.Introspector;
26 import org.onap.aai.introspection.sideeffect.exceptions.AAIMissingRequiredPropertyException;
27 import org.onap.aai.parsers.query.QueryParser;
28 import org.onap.aai.restcore.util.URITools;
29 import org.onap.aai.schema.enums.PropertyMetadata;
30 import org.onap.aai.serialization.db.DBSerializer;
31 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
33 import javax.ws.rs.core.MultivaluedMap;
34 import java.io.UnsupportedEncodingException;
36 import java.net.URISyntaxException;
37 import java.util.HashMap;
38 import java.util.List;
40 import java.util.Map.Entry;
41 import java.util.Optional;
42 import java.util.regex.Matcher;
44 public class DataLinkReader extends SideEffect {
46 public DataLinkReader(Introspector obj, Vertex self, TransactionalGraphEngine dbEngine, DBSerializer serializer) {
47 super(obj, self, dbEngine, serializer);
51 protected boolean replaceWithWildcard() {
56 protected PropertyMetadata getPropertyMetadata() {
57 return PropertyMetadata.DATA_LINK;
61 protected void processURI(Optional<String> completeUri, Entry<String, String> entry)
62 throws URISyntaxException, UnsupportedEncodingException, AAIException {
64 if (completeUri.isPresent()) {
65 URI uri = new URI(completeUri.get());
66 MultivaluedMap<String, String> map = URITools.getQueryMap(uri);
67 QueryParser uriQuery = dbEngine.getQueryBuilder(this.latestLoader).createQueryFromURI(uri, map);
68 List<Vertex> results = uriQuery.getQueryBuilder().getVerticesByProperty(AAIProperties.LINKED, true).toList();
69 if (results.size() == 1) {
70 if (results.get(0).<Boolean>property(AAIProperties.LINKED).orElse(false) && obj.getValue(entry.getKey()) == null) {
71 obj.setValue(entry.getKey(), results.get(0).property(entry.getKey()).orElse(null));
74 //log something about not being able to return any values because there was more than one
80 * always fuzzy search on reads
83 protected Map<String, String> findProperties(Introspector obj, String uriString) throws AAIMissingRequiredPropertyException {
85 final Map<String, String> result = new HashMap<>();
86 Matcher m = template.matcher(uriString);
88 String propName = m.group(1);
89 if (replaceWithWildcard()) {
90 result.put(propName, "*");