- semantic = edgeRules.getDeleteSemantic(nodeType);
- inEdges = (List<Edge>)IteratorUtils.toList(vertex.edges(Direction.IN));
- outEdges = (List<Edge>)IteratorUtils.toList(vertex.edges(Direction.OUT));
- if (semantic.equals(DeleteSemantic.CASCADE_TO_CHILDREN)) {
- result = true;
- } else if (semantic.equals(DeleteSemantic.ERROR_IF_ANY_EDGES)) {
- if (inEdges.isEmpty() && outEdges.isEmpty()) {
- result = true;
- } else {
- errorDetail = " Node cannot be deleted because it still has Edges and the " + semantic + " scope was used.\n";
- aaiExceptionCode = "AAI_6110";
- }
- } else if (semantic.equals(DeleteSemantic.ERROR_IF_ANY_IN_EDGES) || semantic.equals(DeleteSemantic.ERROR_4_IN_EDGES_OR_CASCADE)) {
-
- if (inEdges.isEmpty()) {
- result = true;
- } else {
- //are there any cousin edges?
- long children = 0;
- for (Edge e : inEdges) {
- if (e.<Boolean>property(EdgeProperties.out(EdgeProperty.IS_PARENT)).orElse(false)) {
- children++;
- }
- }
- for (Edge e : outEdges) {
- if (e.<Boolean>property(EdgeProperties.in(EdgeProperty.IS_PARENT)).orElse(false)) {
- children++;
- }
- }
-
- result = children == inEdges.size();
- }
-
- if (!result) {
- errorDetail = " Node cannot be deleted because it still has Edges and the " + semantic + " scope was used.\n";
- aaiExceptionCode = "AAI_6110";
- }
- } else if (semantic.equals(DeleteSemantic.THIS_NODE_ONLY)) {
- if (outEdges.isEmpty() && inEdges.isEmpty()) {
- result = true;
- } else {
- result = true;
- for (Edge edge : outEdges) {
- Object property = edge.<Boolean>property(EdgeProperties.out(EdgeProperty.IS_PARENT)).orElse(null);
- if (property != null && property.equals(Boolean.TRUE)) {
- Vertex v = edge.inVertex();
- String vType = v.<String>property(AAIProperties.NODE_TYPE).orElse(null);
- errorDetail = " Node cannot be deleted using scope = " + semantic +
- " another node (type = " + vType + ") depends on it for uniqueness.";
- aaiExceptionCode = "AAI_6110";
- result = false;
- break;
- }
- }
-
- for (Edge edge : inEdges) {
- Object property = edge.<Boolean>property(EdgeProperties.in(EdgeProperty.IS_PARENT)).orElse(null);
- if (property != null && property.equals(Boolean.TRUE)) {
- Vertex v = edge.outVertex();
- String vType = v.<String>property(AAIProperties.NODE_TYPE).orElse(null);
- errorDetail = " Node cannot be deleted using scope = " + semantic +
- " another node (type = " + vType + ") depends on it for uniqueness.";
- aaiExceptionCode = "AAI_6110";
- result = false;
- break;
- }
- }
- }
- }
-