import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.modelloader.gizmo.GizmoBulkPayload;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.modelloader.gizmo.GizmoBulkPayload;
public static String translate(String xmlPayload) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xmlPayload));
Document doc = builder.parse(is);
public static String translate(String xmlPayload) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xmlPayload));
Document doc = builder.parse(is);
processNode(doc.getDocumentElement(), null, null, gizmoPayload);
processNode(doc.getDocumentElement(), null, null, gizmoPayload);
case MODEL_ELEMENT_VERTEX:
case NQ_ELEMENT_VERTEX:
parentVertexOp = createGizmoVertexOp(node, GizmoBulkPayload.ADD_OP);
case MODEL_ELEMENT_VERTEX:
case NQ_ELEMENT_VERTEX:
parentVertexOp = createGizmoVertexOp(node, GizmoBulkPayload.ADD_OP);
NodeList childNodes = node.getChildNodes();
for (int ix = 0; ix < childNodes.getLength(); ix++) {
processNode(childNodes.item(ix), newParent, parentVertexOp, gizmoPayload);
NodeList childNodes = node.getChildNodes();
for (int ix = 0; ix < childNodes.getLength(); ix++) {
processNode(childNodes.item(ix), newParent, parentVertexOp, gizmoPayload);
GizmoVertex targetVertex = new GizmoVertex();
targetVertex.setType(relatedToList.item(0).getTextContent().trim());
GizmoVertex targetVertex = new GizmoVertex();
targetVertex.setType(relatedToList.item(0).getTextContent().trim());
NodeList relationData = relationshipNode.getElementsByTagName("relationship-data");
for (int ix = 0; ix < relationData.getLength(); ix++) {
Element relationNode = (Element)relationData.item(ix);
NodeList keyList = relationNode.getElementsByTagName("relationship-key");
NodeList valueList = relationNode.getElementsByTagName("relationship-value");
NodeList relationData = relationshipNode.getElementsByTagName("relationship-data");
for (int ix = 0; ix < relationData.getLength(); ix++) {
Element relationNode = (Element)relationData.item(ix);
NodeList keyList = relationNode.getElementsByTagName("relationship-key");
NodeList valueList = relationNode.getElementsByTagName("relationship-value");
if ( (keyList.getLength() != 1) || (valueList.getLength() != 1) ) {
logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Unable to resolve relationship. Missing key/value.");
return;
}
if ( (keyList.getLength() != 1) || (valueList.getLength() != 1) ) {
logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, "Unable to resolve relationship. Missing key/value.");
return;
}
String[] keyBits = keyList.item(0).getTextContent().trim().split("\\.");
String value = valueList.item(0).getTextContent().trim();
String[] keyBits = keyList.item(0).getTextContent().trim().split("\\.");
String value = valueList.item(0).getTextContent().trim();
if (keyBits[0].equalsIgnoreCase(targetVertex.getType())) {
targetVertex.setProperty(keyBits[1], value);
}
}
if (keyBits[0].equalsIgnoreCase(targetVertex.getType())) {
targetVertex.setProperty(keyBits[1], value);
}
}
gizmoPayload.addVertexOperation(new GizmoVertexOperation(GizmoBulkPayload.EXISTS_OP, getVertexId(targetVertex), targetVertex));
gizmoPayload.addVertexOperation(new GizmoVertexOperation(GizmoBulkPayload.EXISTS_OP, getVertexId(targetVertex), targetVertex));
edge.setSource("$" + getVertexId(sourceNode.getVertex()));
edge.setTarget("$" + getVertexId(targetVertex));
edge.setSource("$" + getVertexId(sourceNode.getVertex()));
edge.setTarget("$" + getVertexId(targetVertex));
gizmoPayload.addEdgeOperation(new GizmoEdgeOperation(GizmoBulkPayload.ADD_OP, edge.getSource() + "_" + edge.getTarget(), edge));
}
private static GizmoEdgeOperation createGizmoEdgeOp(Node node, Node parentNode) {
GizmoEdge edge = new GizmoEdge();
gizmoPayload.addEdgeOperation(new GizmoEdgeOperation(GizmoBulkPayload.ADD_OP, edge.getSource() + "_" + edge.getTarget(), edge));
}
private static GizmoEdgeOperation createGizmoEdgeOp(Node node, Node parentNode) {
GizmoEdge edge = new GizmoEdge();
edge.setSource("$" + getVertexId(createGizmoVertex(node)));
edge.setTarget("$" + getVertexId(createGizmoVertex(parentNode)));
edge.setSource("$" + getVertexId(createGizmoVertex(node)));
edge.setTarget("$" + getVertexId(createGizmoVertex(parentNode)));
-
- GizmoEdgeOperation edgeOp = new GizmoEdgeOperation(GizmoBulkPayload.ADD_OP, edge.getSource() + "_" + edge.getTarget(), edge);
-
- return edgeOp;
+
+ return new GizmoEdgeOperation(GizmoBulkPayload.ADD_OP, edge.getSource() + "_" + edge.getTarget(), edge);
- GizmoVertex vertex = createGizmoVertex(node);
- GizmoVertexOperation addOp = new GizmoVertexOperation(operationType, getVertexId(vertex), vertex);
- return addOp;
+ GizmoVertex vertex = createGizmoVertex(node);
+ return new GizmoVertexOperation(operationType, getVertexId(vertex), vertex);
for (Map.Entry<String, String> entry : vertex.getProperties().entrySet()) {
sb.append("-" + entry.getValue());
}
for (Map.Entry<String, String> entry : vertex.getProperties().entrySet()) {
sb.append("-" + entry.getValue());
}
// Special case for model-element, where we need to generate an id field
if (getNodeType(node).equals(NodeType.MODEL_ELEMENT_VERTEX)) {
vertex.setProperty("model-element-uuid", generateModelElementId((Element)node));
}
// Special case for model-element, where we need to generate an id field
if (getNodeType(node).equals(NodeType.MODEL_ELEMENT_VERTEX)) {
vertex.setProperty("model-element-uuid", generateModelElementId((Element)node));
}
// Special case for nq-element, where we need to generate an id field
if (getNodeType(node).equals(NodeType.NQ_ELEMENT_VERTEX)) {
vertex.setProperty("named-query-element-uuid", generateModelElementId((Element)node));
// Special case for nq-element, where we need to generate an id field
if (getNodeType(node).equals(NodeType.NQ_ELEMENT_VERTEX)) {
vertex.setProperty("named-query-element-uuid", generateModelElementId((Element)node));
// Generate a unique hash to store as the id for this node
private static String generateModelElementId(Element node) {
// Generate a unique hash to store as the id for this node
private static String generateModelElementId(Element node) {
NodeList childNodes = node.getElementsByTagName("*");
for (int ix = 0; ix < childNodes.getLength(); ix++) {
NodeType nt = getNodeType(childNodes.item(ix));
NodeList childNodes = node.getElementsByTagName("*");
for (int ix = 0; ix < childNodes.getLength(); ix++) {
NodeType nt = getNodeType(childNodes.item(ix));
if ( (childElements == 0) && (node.getTextContent() != null) && (!node.getTextContent().trim().isEmpty()) ) {
return NodeType.ATTRIBUTE;
}
if ( (childElements == 0) && (node.getTextContent() != null) && (!node.getTextContent().trim().isEmpty()) ) {
return NodeType.ATTRIBUTE;
}
for (int ix = 0; ix < childNodes.getLength(); ix++) {
if (getNodeType(childNodes.item(ix)) == NodeType.ATTRIBUTE) {
return NodeType.VERTEX;
}
}
for (int ix = 0; ix < childNodes.getLength(); ix++) {
if (getNodeType(childNodes.item(ix)) == NodeType.ATTRIBUTE) {
return NodeType.VERTEX;
}
}