X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=champ-lib%2Fchamp-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fchampcore%2Fie%2FGraphMLImporterExporter.java;fp=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fchamp%2Fie%2FGraphMLImporterExporter.java;h=71292ce60d41282bcfb1adc1b0139d24e9376942;hb=c74f7b13b573386e70c10721fc391624ee792ed6;hp=4e108e9e720ab915f0956f96067527fe9eec5316;hpb=9fc28cff11a4b570618c0f533ce9de6209a5dd0c;p=aai%2Fchamp.git diff --git a/src/main/java/org/onap/aai/champ/ie/GraphMLImporterExporter.java b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/ie/GraphMLImporterExporter.java similarity index 90% rename from src/main/java/org/onap/aai/champ/ie/GraphMLImporterExporter.java rename to champ-lib/champ-core/src/main/java/org/onap/aai/champcore/ie/GraphMLImporterExporter.java index 4e108e9..71292ce 100644 --- a/src/main/java/org/onap/aai/champ/ie/GraphMLImporterExporter.java +++ b/champ-lib/champ-core/src/main/java/org/onap/aai/champcore/ie/GraphMLImporterExporter.java @@ -19,7 +19,7 @@ * ============LICENSE_END============================================ * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ -package org.onap.aai.champ.ie; +package org.onap.aai.champcore.ie; import java.io.IOException; import java.io.InputStream; @@ -42,16 +42,18 @@ import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; -import org.onap.aai.champ.ChampAPI; -import org.onap.aai.champ.ChampGraph; -import org.onap.aai.champ.exceptions.ChampMarshallingException; -import org.onap.aai.champ.exceptions.ChampObjectNotExistsException; -import org.onap.aai.champ.exceptions.ChampRelationshipNotExistsException; -import org.onap.aai.champ.exceptions.ChampSchemaViolationException; -import org.onap.aai.champ.exceptions.ChampUnmarshallingException; -import org.onap.aai.champ.model.ChampObject; -import org.onap.aai.champ.model.ChampObjectIndex; -import org.onap.aai.champ.model.ChampRelationship; +import org.onap.aai.champcore.ChampAPI; +import org.onap.aai.champcore.ChampGraph; +import org.onap.aai.champcore.ChampTransaction; +import org.onap.aai.champcore.exceptions.ChampMarshallingException; +import org.onap.aai.champcore.exceptions.ChampObjectNotExistsException; +import org.onap.aai.champcore.exceptions.ChampRelationshipNotExistsException; +import org.onap.aai.champcore.exceptions.ChampSchemaViolationException; +import org.onap.aai.champcore.exceptions.ChampTransactionException; +import org.onap.aai.champcore.exceptions.ChampUnmarshallingException; +import org.onap.aai.champcore.model.ChampObject; +import org.onap.aai.champcore.model.ChampObjectIndex; +import org.onap.aai.champcore.model.ChampRelationship; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -183,25 +185,27 @@ public class GraphMLImporterExporter implements Importer, Exporter { final NodeList data = edge.getChildNodes(); final Object sourceKey = edgeAttributes.getNamedItem("source").getNodeValue(); final Object targetKey = edgeAttributes.getNamedItem("target").getNodeValue(); - final ChampObject sourceObject; - final ChampObject targetObject; - + ChampObject sourceObject=null; + ChampObject targetObject=null; + try { - final Optional source = graph.queryObjects(Collections.singletonMap("importAssignedId", sourceKey)).findFirst(); - final Optional target = graph.queryObjects(Collections.singletonMap("importAssignedId", targetKey)).findFirst(); + final Optional source = graph.queryObjects(Collections.singletonMap("importAssignedId", sourceKey), Optional.empty()).findFirst(); + final Optional target = graph.queryObjects(Collections.singletonMap("importAssignedId", targetKey), Optional.empty()).findFirst(); if (!source.isPresent()) { sourceObject = graph.storeObject(ChampObject.create() .ofType("undefined") .withoutKey() - .build()); + .build(), + Optional.empty()); } else sourceObject = source.get(); if (!target.isPresent()) { targetObject = graph.storeObject(ChampObject.create() .ofType("undefined") .withoutKey() - .build()); + .build(), + Optional.empty()); } else targetObject = target.get(); } catch (ChampMarshallingException e) { @@ -213,6 +217,8 @@ public class GraphMLImporterExporter implements Importer, Exporter { } catch (ChampObjectNotExistsException e) { LOGGER.error("Failed to update existing source/target ChampObject", e); return; + } catch (ChampTransactionException e) { + LOGGER.error("Failed to commit or rollback transaction", e); } final ChampRelationship.Builder champRelBuilder = new ChampRelationship.Builder(sourceObject, targetObject, "undefined"); @@ -256,7 +262,7 @@ public class GraphMLImporterExporter implements Importer, Exporter { final ChampRelationship relToStore = champRelBuilder.build(); try { - graph.storeRelationship(relToStore); + graph.storeRelationship(relToStore, Optional.empty()); } catch (ChampMarshallingException e) { LOGGER.warn("Failed to marshall ChampObject to backend type", e); } catch (ChampSchemaViolationException e) { @@ -267,7 +273,10 @@ public class GraphMLImporterExporter implements Importer, Exporter { LOGGER.error("Objects bound to relationship do not exist (should never happen)"); } catch (ChampUnmarshallingException e) { LOGGER.error("Failed to unmarshall ChampObject to backend type"); + } catch (ChampTransactionException e) { + LOGGER.error("Failed to commit or rollback transaction"); } + } private void writeNode(ChampGraph graph, Node node, Map> nodePropertyDefinitions, Set> nodeDefaults) { @@ -323,15 +332,17 @@ public class GraphMLImporterExporter implements Importer, Exporter { final ChampObject objectToStore = champObjBuilder.build(); - try { - graph.storeObject(objectToStore); + try { + graph.storeObject(objectToStore, Optional.empty()); } catch (ChampMarshallingException e) { LOGGER.warn("Failed to marshall ChampObject to backend type", e); } catch (ChampSchemaViolationException e) { LOGGER.error("Failed to store object (schema violated): " + objectToStore, e); } catch (ChampObjectNotExistsException e) { LOGGER.error("Failed to update existing ChampObject", e); - } + } catch (ChampTransactionException e) { + LOGGER.error("Failed to commit or rollback transaction"); + } } @Override @@ -354,7 +365,7 @@ public class GraphMLImporterExporter implements Importer, Exporter { final Map edgeKeys = new HashMap (); final AtomicInteger elementCount = new AtomicInteger(); - graph.queryObjects(Collections.emptyMap()).forEach(object -> { + graph.queryObjects(Collections.emptyMap(), Optional.empty()).forEach(object -> { nodes.add(object); for (Map.Entry property : object.getProperties().entrySet()) { @@ -366,7 +377,7 @@ public class GraphMLImporterExporter implements Importer, Exporter { nodeKeys.put("type", new GraphMLKey("d" + elementCount.incrementAndGet(), "type", String.class)); }); - graph.queryRelationships(Collections.emptyMap()).forEach(relationship -> { + graph.queryRelationships(Collections.emptyMap(), Optional.empty()).forEach(relationship -> { edges.add(relationship); for (Map.Entry property : relationship.getProperties().entrySet()) { @@ -453,7 +464,7 @@ public class GraphMLImporterExporter implements Importer, Exporter { writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); - } catch (XMLStreamException e) { + } catch (XMLStreamException | ChampTransactionException e) { throw new RuntimeException(e); } }