Skip to content

Commit d74dbdb

Browse files
committed
fix merge conflicts
2 parents 858d31d + 5598ca9 commit d74dbdb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2561
-277
lines changed

src/main/java/knox/spring/data/neo4j/controller/KnoxController.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import java.io.InputStream;
55
import java.util.*;
66

7+
import knox.spring.data.neo4j.domain.DesignSpace;
78
import knox.spring.data.neo4j.sample.DesignSampler.EnumerateType;
89
import knox.spring.data.neo4j.exception.DesignSpaceBranchesConflictException;
910
import knox.spring.data.neo4j.exception.DesignSpaceConflictException;
1011
import knox.spring.data.neo4j.exception.DesignSpaceNotFoundException;
1112
import knox.spring.data.neo4j.exception.ParameterEmptyException;
13+
import knox.spring.data.neo4j.sbol.SBOLConversion;
1214
import knox.spring.data.neo4j.services.DesignSpaceService;
1315

1416
import org.sbolstandard.core2.SBOLConversionException;
@@ -636,7 +638,7 @@ public ResponseEntity<String> mergeCSV(@RequestParam("inputCSVFiles[]") List<Mul
636638

637639
@RequestMapping(value = "/sbol/import", method = RequestMethod.POST)
638640
public ResponseEntity<String> importSBOL(@RequestParam("inputSBOLFiles[]") List<MultipartFile> inputSBOLFiles,
639-
@RequestParam(value = "outputSpaceID", required = true) String outputSpaceID) {
641+
@RequestParam(value = "outputSpaceID", required = false) String outputSpaceID) {
640642
List<SBOLDocument> sbolDocs = new ArrayList<SBOLDocument>();
641643

642644
for (MultipartFile inputSBOLFile : inputSBOLFiles) {
@@ -660,32 +662,6 @@ public ResponseEntity<String> importSBOL(@RequestParam("inputSBOLFiles[]") List<
660662
return new ResponseEntity<String>("No content", HttpStatus.NO_CONTENT);
661663
}
662664

663-
@RequestMapping(value = "/sbol/importCombinatorial", method = RequestMethod.POST)
664-
public ResponseEntity<String> importCombinatorialSBOL(@RequestParam("inputSBOLFiles[]") List<MultipartFile> inputSBOLFiles,
665-
@RequestParam(value = "outputSpaceID", required = true) String outputSpaceID) {
666-
List<SBOLDocument> sbolDocs = new ArrayList<SBOLDocument>();
667-
668-
for (MultipartFile inputSBOLFile : inputSBOLFiles) {
669-
if (!inputSBOLFile.isEmpty()) {
670-
try {
671-
sbolDocs.add(SBOLReader.read(inputSBOLFile.getInputStream()));
672-
} catch (IOException | SBOLValidationException | SBOLConversionException e) {
673-
// TODO Auto-generated catch block
674-
e.printStackTrace();
675-
}
676-
}
677-
}
678-
679-
try {
680-
designSpaceService.importCombinatorialSBOL(sbolDocs, outputSpaceID);
681-
} catch (IOException | SBOLValidationException | SBOLConversionException e) {
682-
// TODO Auto-generated catch block
683-
e.printStackTrace();
684-
}
685-
686-
return new ResponseEntity<String>("No content", HttpStatus.NO_CONTENT);
687-
}
688-
689665
@RequestMapping(value = "/branch/graph/d3", method = RequestMethod.GET)
690666
public Map<String, Object> d3GraphBranches(@RequestParam(value = "targetSpaceID", required = true) String targetSpaceID) {
691667
return designSpaceService.d3GraphBranches(targetSpaceID);

src/main/java/knox/spring/data/neo4j/domain/Edge.java

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -344,36 +344,85 @@ public boolean hasOrientation(String orientation) {
344344
}
345345

346346
public void intersectWithEdge(Edge edge, int tolerance) {
347+
// Map other component IDs to roles and other component roles to IDs
348+
347349
ArrayList<String> otherComponentIDs = edge.getComponentIDs();
348350
ArrayList<String> otherComponentRoles = edge.getComponentRoles();
349351

350-
Set<String> diffComponentIDs = new HashSet<String>(otherComponentIDs);
351-
Set<String> diffComponentRoles = new HashSet<String>(otherComponentRoles);
352+
HashMap<String, Set<String>> otherComponentIDToRoles = new HashMap<String, Set<String>>();
353+
HashMap<String, Set<String>> otherComponentRoleToIDs = new HashMap<String, Set<String>>();
354+
355+
for (int i = 0; i < otherComponentIDs.size(); i++) {
356+
if (!otherComponentIDToRoles.containsKey(otherComponentIDs.get(i))) {
357+
otherComponentIDToRoles.put(otherComponentIDs.get(i), new HashSet<String>());
358+
}
359+
360+
otherComponentIDToRoles.get(otherComponentIDs.get(i)).add(otherComponentRoles.get(i));
361+
362+
if (!otherComponentRoleToIDs.containsKey(otherComponentRoles.get(i))) {
363+
otherComponentRoleToIDs.put(otherComponentRoles.get(i), new HashSet<String>());
364+
}
352365

366+
otherComponentRoleToIDs.get(otherComponentRoles.get(i)).add(otherComponentIDs.get(i));
367+
}
368+
369+
// Remove non-intersecting component IDs and roles
370+
353371
for (int i = 0; i < componentRoles.size(); i++) {
354372
if (i < componentIDs.size()) {
355-
if (diffComponentIDs.contains(componentIDs.get(i))) {
356-
if (!componentRoles.get(i).equals(otherComponentRoles.get(i))) {
357-
componentIDs.add(0, otherComponentIDs.get(i));
358-
componentRoles.add(0, otherComponentRoles.get(i));
373+
if (!otherComponentIDToRoles.containsKey(componentIDs.get(i))
374+
&& (tolerance < 2 || !otherComponentRoleToIDs.containsKey(componentRoles.get(i)))) {
375+
componentIDs.remove(i);
376+
componentRoles.remove(i);
377+
378+
i = i - 1;
379+
}
380+
} else if (tolerance < 2 || !otherComponentRoleToIDs.containsKey(componentRoles.get(i))) {
381+
componentRoles.remove(i);
382+
383+
i = i - 1;
384+
}
385+
}
386+
387+
// Map component IDs to roles
388+
389+
HashMap<String, Set<String>> componentIDToRoles = new HashMap<String, Set<String>>();
390+
391+
for (int i = 0; i < componentIDs.size(); i++) {
392+
if (!componentIDToRoles.containsKey(componentIDs.get(i))) {
393+
componentIDToRoles.put(componentIDs.get(i), new HashSet<String>());
394+
}
395+
396+
componentIDToRoles.get(componentIDs.get(i)).add(componentRoles.get(i));
397+
}
398+
399+
// Add missing component roles associated with intersecting component IDs
400+
401+
for (String componentID : componentIDToRoles.keySet()) {
402+
for (String otherComponentRole : otherComponentIDToRoles.get(componentID)) {
403+
if (!componentIDToRoles.get(componentID).contains(otherComponentRole)) {
404+
componentIDs.add(0, componentID);
405+
componentRoles.add(0, otherComponentRole);
406+
}
407+
}
408+
}
409+
410+
// Add missing component IDs associated with intersecting component roles
411+
412+
if (tolerance >= 2) {
413+
for (int i = componentIDs.size(); i < componentRoles.size(); i++) {
414+
if (otherComponentRoleToIDs.containsKey(componentRoles.get(i))) {
415+
for (String otherComponentID : otherComponentRoleToIDs.get(componentRoles.get(i))) {
416+
componentIDs.add(0, otherComponentID);
417+
componentRoles.add(0, componentRoles.get(i));
359418

360419
i = i + 1;
361420
}
362-
} else if (tolerance >= 2 && diffComponentRoles.contains(componentRoles.get(i))) {
363-
componentIDs.add(0, otherComponentIDs.get(i));
364-
componentRoles.add(0, otherComponentRoles.get(i));
365-
366-
i = i + 1;
367-
} else {
368-
componentIDs.remove(i);
421+
369422
componentRoles.remove(i);
370423

371424
i = i - 1;
372425
}
373-
} else if (!diffComponentRoles.contains(componentRoles.get(i))) {
374-
componentRoles.remove(i);
375-
376-
i = i - 1;
377426
}
378427
}
379428
}
@@ -408,7 +457,7 @@ public void unionWithEdge(Edge edge) {
408457
}
409458

410459
public boolean isMatching(Edge edge, int tolerance, Set<String> roles) {
411-
return hasSameOrientation(edge) && (roles.isEmpty() || hasSharedComponentRoles(edge, roles))
460+
return hasSameOrientation(edge)
412461
&& (hasSharedComponentIDs(edge) || tolerance >= 2 && hasSharedComponentRoles(edge, roles));
413462
}
414463

src/main/java/knox/spring/data/neo4j/domain/Node.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,15 @@ public void copyEdges(Set<Node> nodes) {
494494
}
495495

496496
public void copyNodeType(Node node) {
497-
nodeTypes = new ArrayList<String>();
498-
499-
nodeTypes.addAll(node.getNodeTypes());
497+
if (nodeTypes == null) {
498+
nodeTypes = new ArrayList<String>(node.getNodeTypes());
499+
} else if (nodeTypes.isEmpty()) {
500+
nodeTypes.addAll(node.getNodeTypes());
501+
} else {
502+
for (String nodeType : node.getNodeTypes()) {
503+
addNodeType(nodeType);
504+
}
505+
}
500506
}
501507

502508
public Set<Edge> getOtherBlankEdges(Set<Edge> blankEdges) {

src/main/java/knox/spring/data/neo4j/domain/NodeSpace.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,12 @@ public void removeBlankCycles() {
662662

663663
if (!sourceEdges.isEmpty()) {
664664
for (Edge sourceEdge : sourceEdges) {
665+
if (sourceEdge.getTail().isAcceptNode()) {
666+
outerSink.addNodeType(NodeType.ACCEPT.getValue());
667+
} else if (sourceEdge.getTail().isStartNode()) {
668+
outerSource.addNodeType(NodeType.START.getValue());
669+
}
670+
665671
sourceEdge.delete();
666672

667673
sourceEdge.setTail(innerSource);
@@ -676,6 +682,12 @@ public void removeBlankCycles() {
676682
nodeIDToIncomingEdges.put(innerSink.getNodeID(), new HashSet<Edge>());
677683

678684
for (Edge sinkEdge : sinkEdges) {
685+
if (sinkEdge.getHead().isAcceptNode()) {
686+
outerSink.addNodeType(NodeType.ACCEPT.getValue());
687+
} else if (sinkEdge.getHead().isStartNode()) {
688+
outerSource.addNodeType(NodeType.START.getValue());
689+
}
690+
679691
nodeIDToIncomingEdges.get(sinkEdge.getHeadID()).remove(sinkEdge);
680692

681693
sinkEdge.setHead(innerSink);
@@ -690,6 +702,12 @@ public void removeBlankCycles() {
690702
nodeIDToIncomingEdges.put(outerSource.getNodeID(), new HashSet<Edge>());
691703

692704
for (Edge incomingEdge : incomingEdges) {
705+
if (incomingEdge.getHead().isAcceptNode()) {
706+
outerSink.addNodeType(NodeType.ACCEPT.getValue());
707+
} else if (incomingEdge.getHead().isStartNode()) {
708+
outerSource.addNodeType(NodeType.START.getValue());
709+
}
710+
693711
nodeIDToIncomingEdges.get(incomingEdge.getHeadID()).remove(incomingEdge);
694712

695713
incomingEdge.setHead(outerSource);
@@ -702,6 +720,12 @@ public void removeBlankCycles() {
702720

703721
if (!outgoingEdges.isEmpty()) {
704722
for (Edge outgoingEdge : outgoingEdges) {
723+
if (outgoingEdge.getTail().isAcceptNode()) {
724+
outerSink.addNodeType(NodeType.ACCEPT.getValue());
725+
} else if (outgoingEdge.getTail().isStartNode()) {
726+
outerSource.addNodeType(NodeType.START.getValue());
727+
}
728+
705729
outgoingEdge.delete();
706730

707731
outgoingEdge.setTail(outerSink);

src/main/java/knox/spring/data/neo4j/operations/ANDOperator.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package knox.spring.data.neo4j.operations;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45
import java.util.Set;
56

7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
610
import knox.spring.data.neo4j.domain.Edge;
711
import knox.spring.data.neo4j.domain.NodeSpace;
812

913
public class ANDOperator {
1014

15+
private static final Logger LOG = LoggerFactory.getLogger(NodeSpace.class);
16+
1117
public static void apply(List<NodeSpace> inputSpaces, NodeSpace outputSpace,
1218
int tolerance, boolean isComplete, Set<String> roles) {
1319
Product product = new Product(inputSpaces.get(0));
@@ -25,13 +31,17 @@ public static void apply(List<NodeSpace> inputSpaces, NodeSpace outputSpace,
2531
product.getSpace().deleteBlankEdges(blankEdges.get(j));
2632
}
2733
}
34+
35+
if (product.getSpace().hasNodes()) {
36+
Union union = new Union(product.getSpace());
2837

29-
Union union = new Union(product.getSpace());
38+
Set<Edge> blankEdges = union.apply();
3039

31-
Set<Edge> blankEdges = union.apply();
40+
union.getSpace().deleteBlankEdges(blankEdges);
3241

33-
union.getSpace().deleteBlankEdges(blankEdges);
34-
35-
outputSpace.shallowCopyNodeSpace(union.getSpace());
42+
outputSpace.shallowCopyNodeSpace(union.getSpace());
43+
} else {
44+
outputSpace.shallowCopyNodeSpace(new NodeSpace(new ArrayList<String>(), new ArrayList<String>()));
45+
}
3646
}
3747
}

0 commit comments

Comments
 (0)