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 org.janusgraph.core.JanusGraphFactory;
24 import org.janusgraph.core.JanusGraph;
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 ResponseBuilder responseBuilder = Response.status(status);
49 log.trace("returned entity is {}", entity.toString());
50 responseBuilder = responseBuilder.entity(entity);
52 if (additionalHeaders != null) {
53 for (Entry<String, String> additionalHeader : additionalHeaders.entrySet()) {
54 String headerName = additionalHeader.getKey();
55 String headerValue = additionalHeader.getValue();
56 log.trace("Adding header {} with value {} to the response", headerName, headerValue);
57 responseBuilder.header(headerName, headerValue);
60 return responseBuilder.build();
63 public static JanusGraph openGraph(Configuration conf) {
65 JanusGraph graph = null;
68 graph = JanusGraphFactory.open(conf);
70 } catch (Exception e) {
71 log.error("Failed to start open graph", e);
78 public static boolean vertexLeftContainsRightProps(Map<String, Object> leftProps, Map<String, Object> rightProps) {
80 if (rightProps != null) {
82 for (Entry<String, Object> entry : rightProps.entrySet()) {
83 String key = entry.getKey();
84 Object leftValue = leftProps.get(key);
85 Object rightValue = entry.getValue();
86 if (leftValue == null) {
87 if (rightValue == null) {
90 log.debug("The key {} cannot be found in the properties {}",key,leftProps);
95 if (!leftValue.equals(rightValue)) {
96 log.trace("The value of key {} is differnet between properties. {} vs {}",key,leftValue,rightValue);
106 public static void setProperties(Element element, Map<String, Object> properties) {
108 if (properties != null && !properties.isEmpty()) {
110 Object[] propertyKeyValues = new Object[properties.size() * 2];
112 for (Entry<String, Object> entry : properties.entrySet()) {
113 propertyKeyValues[i++] = entry.getKey();
114 propertyKeyValues[i++] = entry.getValue();
117 ElementHelper.attachProperties(element, propertyKeyValues);
123 public static Map<String, Object> getProperties(Element element) {
125 Map<String, Object> result = new HashMap<String, Object>();
128 if (element.keys() != null && element.keys().size() > 0) {
129 Map<String, Property> propertyMap = ElementHelper.propertyMap(element,
130 element.keys().toArray(new String[element.keys().size()]));
132 for (Entry<String, Property> entry : propertyMap.entrySet()) {
133 String key = entry.getKey();
134 Object value = entry.getValue().value();
136 result.put(key, value);