* ============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;
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;
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<ChampObject> source = graph.queryObjects(Collections.singletonMap("importAssignedId", sourceKey)).findFirst();
- final Optional<ChampObject> target = graph.queryObjects(Collections.singletonMap("importAssignedId", targetKey)).findFirst();
+ final Optional<ChampObject> source = graph.queryObjects(Collections.singletonMap("importAssignedId", sourceKey), Optional.empty()).findFirst();
+ final Optional<ChampObject> 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) {
} 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");
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) {
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<String, Map<String, String>> nodePropertyDefinitions, Set<Map<String, String>> nodeDefaults) {
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
final Map<String, GraphMLKey> edgeKeys = new HashMap<String, GraphMLKey> ();
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<String, Object> property : object.getProperties().entrySet()) {
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<String, Object> property : relationship.getProperties().entrySet()) {
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
- } catch (XMLStreamException e) {
+ } catch (XMLStreamException | ChampTransactionException e) {
throw new RuntimeException(e);
}
}