2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.sdc.asdctool;
23 import com.thinkaurelius.titan.core.TitanFactory;
24 import com.thinkaurelius.titan.core.TitanGraph;
25 import org.apache.commons.configuration.Configuration;
26 import org.apache.tinkerpop.gremlin.structure.Element;
27 import org.apache.tinkerpop.gremlin.structure.Property;
28 import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
29 import org.openecomp.sdc.common.log.wrappers.Logger;
31 import javax.ws.rs.core.Response;
32 import javax.ws.rs.core.Response.ResponseBuilder;
33 import java.util.HashMap;
35 import java.util.Map.Entry;
39 private static Logger log = Logger.getLogger(Utils.class.getName());
41 public final static String NEW_LINE = System.getProperty("line.separator");
43 public static Response buildOkResponse(
45 * ResponseFormat errorResponseWrapper,
46 */int status, Object entity, Map<String, String> additionalHeaders) {
47 // int status = errorResponseWrapper.getStatus();
48 ResponseBuilder responseBuilder = Response.status(status);
50 log.trace("returned entity is {}", entity.toString());
51 responseBuilder = responseBuilder.entity(entity);
53 if (additionalHeaders != null) {
54 for (Entry<String, String> additionalHeader : additionalHeaders.entrySet()) {
55 String headerName = additionalHeader.getKey();
56 String headerValue = additionalHeader.getValue();
57 log.trace("Adding header {} with value {} to the response", headerName, headerValue);
58 responseBuilder.header(headerName, headerValue);
61 return responseBuilder.build();
64 public static TitanGraph openGraph(Configuration conf) {
66 TitanGraph graph = null;
69 graph = TitanFactory.open(conf);
71 } catch (Exception e) {
72 log.error("Failed to start open graph", e);
79 public static boolean vertexLeftContainsRightProps(Map<String, Object> leftProps, Map<String, Object> rightProps) {
81 if (rightProps != null) {
83 for (Entry<String, Object> entry : rightProps.entrySet()) {
84 String key = entry.getKey();
85 Object leftValue = leftProps.get(key);
86 Object rightValue = entry.getValue();
87 if (leftValue == null) {
88 if (rightValue == null) {
91 log.debug("The key {} cannot be found in the properties {}",key,leftProps);
96 // if (false == leftValue instanceof Map && false == leftValue
98 if (false == leftValue.equals(rightValue)) {
99 log.trace("The value of key {} is differnet between properties. {} vs {}",key,leftValue,rightValue);
110 public static void setProperties(Element element, Map<String, Object> properties) {
112 if (properties != null && false == properties.isEmpty()) {
114 Object[] propertyKeyValues = new Object[properties.size() * 2];
116 for (Entry<String, Object> entry : properties.entrySet()) {
117 propertyKeyValues[i++] = entry.getKey();
118 propertyKeyValues[i++] = entry.getValue();
121 ElementHelper.attachProperties(element, propertyKeyValues);
127 public static Map<String, Object> getProperties(Element element) {
129 Map<String, Object> result = new HashMap<String, Object>();
132 if (element.keys() != null && element.keys().size() > 0) {
133 Map<String, Property> propertyMap = ElementHelper.propertyMap(element,
134 element.keys().toArray(new String[element.keys().size()]));
136 for (Entry<String, Property> entry : propertyMap.entrySet()) {
137 String key = entry.getKey();
138 Object value = entry.getValue().value();
140 result.put(key, value);