-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
2,080 additions
and
892 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/cifre/sap/su/goblinWeaver/Neo4jEcosystemWeaverApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.cifre.sap.su.goblinWeaver; | ||
|
||
import com.cifre.sap.su.goblinWeaver.graphDatabase.GraphDatabaseSingleton; | ||
import com.cifre.sap.su.goblinWeaver.utils.GraphUpdatedChecker; | ||
import com.cifre.sap.su.goblinWeaver.utils.OsvProceeding; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Neo4jEcosystemWeaverApplication { | ||
|
||
public static void main(String[] args) { | ||
GraphDatabaseSingleton.getInstance(); // Init database connection | ||
GraphUpdatedChecker.deleteAddedValuesIfUpdated(); // Check if database was updated | ||
OsvProceeding.initOsvData(args); // Download CVE dataset | ||
SpringApplication.run(Neo4jEcosystemWeaverApplication.class, args); // Run API | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/cifre/sap/su/goblinWeaver/api/controllers/ArtifactController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.cifre.sap.su.goblinWeaver.api.controllers; | ||
|
||
import com.cifre.sap.su.goblinWeaver.api.entities.ArtifactQuery; | ||
import com.cifre.sap.su.goblinWeaver.graphDatabase.GraphDatabaseInterface; | ||
import com.cifre.sap.su.goblinWeaver.graphDatabase.GraphDatabaseSingleton; | ||
import com.cifre.sap.su.goblinWeaver.graphEntities.InternGraph; | ||
import com.cifre.sap.su.goblinWeaver.weaver.Weaver; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.json.simple.JSONObject; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@Tag(name = "Artifacts") | ||
public class ArtifactController { | ||
|
||
@Operation( | ||
description = "Get a specific artifact from groupId:ArtifactId with added values", | ||
summary = "Get a specific artifact from GA" | ||
) | ||
@PostMapping("/artifact") | ||
public JSONObject getSpecificArtifact(@RequestBody ArtifactQuery artifactQuery) { | ||
GraphDatabaseInterface gdb = GraphDatabaseSingleton.getInstance(); | ||
InternGraph graph = gdb.executeQuery(gdb.getQueryDictionary().getSpecificArtifactQuery(artifactQuery.toString())); | ||
Weaver.weaveGraph(graph, artifactQuery.getAddedValues()); | ||
return graph.getJsonGraph(); | ||
} | ||
|
||
@Operation( | ||
description = "Get all releases of an artifact from groupId:ArtifactId with added values", | ||
summary = "Get all releases of an artifact from GA" | ||
) | ||
@PostMapping("/artifact/releases") | ||
public JSONObject getArtifactReleases(@RequestBody ArtifactQuery artifactQuery) { | ||
GraphDatabaseInterface gdb = GraphDatabaseSingleton.getInstance(); | ||
InternGraph graph = gdb.executeQuery(gdb.getQueryDictionary().getArtifactReleasesQuery(artifactQuery.toString())); | ||
Weaver.weaveGraph(graph, artifactQuery.getAddedValues()); | ||
return graph.getJsonGraph(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/cifre/sap/su/goblinWeaver/api/controllers/CypherController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.cifre.sap.su.goblinWeaver.api.controllers; | ||
|
||
import com.cifre.sap.su.goblinWeaver.api.entities.CypherQuery; | ||
import com.cifre.sap.su.goblinWeaver.graphDatabase.GraphDatabaseSingleton; | ||
import com.cifre.sap.su.goblinWeaver.graphEntities.InternGraph; | ||
import com.cifre.sap.su.goblinWeaver.weaver.Weaver; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.json.simple.JSONObject; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@Tag(name = "Cypher query") | ||
public class CypherController { | ||
|
||
@Operation( | ||
description = "Execute a cypher query to the dependency graph with added values", | ||
summary = "Execute a cypher query" | ||
) | ||
@PostMapping("/cypher") | ||
public JSONObject executeCypherQuery(@RequestBody CypherQuery queryRequest) { | ||
InternGraph graph = GraphDatabaseSingleton.getInstance().executeQuery(queryRequest.getQuery()); | ||
Weaver.weaveGraph(graph, queryRequest.getAddedValues()); | ||
return graph.getJsonGraph(); | ||
} | ||
} |
161 changes: 161 additions & 0 deletions
161
src/main/java/com/cifre/sap/su/goblinWeaver/api/controllers/GraphController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package com.cifre.sap.su.goblinWeaver.api.controllers; | ||
|
||
import com.cifre.sap.su.goblinWeaver.api.entities.ReleaseQueryList; | ||
import com.cifre.sap.su.goblinWeaver.graphDatabase.GraphDatabaseSingleton; | ||
import com.cifre.sap.su.goblinWeaver.graphEntities.InternGraph; | ||
import com.cifre.sap.su.goblinWeaver.graphEntities.edges.DependencyEdge; | ||
import com.cifre.sap.su.goblinWeaver.graphEntities.nodes.NodeObject; | ||
import com.cifre.sap.su.goblinWeaver.graphEntities.nodes.NodeType; | ||
import com.cifre.sap.su.goblinWeaver.graphEntities.nodes.ReleaseNode; | ||
import com.cifre.sap.su.goblinWeaver.weaver.Weaver; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.json.simple.JSONObject; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
@RestController | ||
@Tag(name = "Graph") | ||
public class GraphController { | ||
|
||
@Operation( | ||
description = "Get the project rooted graph", | ||
summary = "Get the project rooted all graph from releases dependencies list" | ||
) | ||
@PostMapping("/graph/rootedGraph") | ||
public JSONObject getRootedGraph(@RequestBody ReleaseQueryList releaseQueryList) { | ||
InternGraph resultGraph = new InternGraph(); | ||
resultGraph.addNode(new ReleaseNode("ROOT", "ROOT", 0, "")); | ||
for (ReleaseQueryList.Release release : releaseQueryList.getReleases()) { | ||
resultGraph.addEdge(new DependencyEdge("ROOT", release.getGa(), release.getVersion(), "compile")); | ||
} | ||
resultGraph.mergeGraph( | ||
GraphDatabaseSingleton.getInstance() | ||
.getRootedGraph( | ||
releaseQueryList.getReleases().stream().map(ReleaseQueryList.Release::getGav).collect(Collectors.toSet() | ||
) | ||
) | ||
); | ||
Weaver.weaveGraph(resultGraph, releaseQueryList.getAddedValues()); | ||
return resultGraph.getJsonGraph(); | ||
} | ||
|
||
@Operation( | ||
description = "Get the project rooted all possibilities graph", | ||
summary = "Get the project rooted all possibilities graph from releases dependencies list" | ||
) | ||
@PostMapping("/graph/allPossibilitiesRooted") | ||
public JSONObject getAllPossibilitiesRootedGraph(@RequestBody ReleaseQueryList releaseQueryList) { | ||
InternGraph resultGraph = new InternGraph(); | ||
resultGraph.addNode(new ReleaseNode("ROOT", "ROOT", 0, "")); | ||
for (ReleaseQueryList.Release release : releaseQueryList.getReleases()) { | ||
resultGraph.addEdge(new DependencyEdge("ROOT", release.getGa(), release.getVersion(), "compile")); | ||
} | ||
resultGraph.mergeGraph( | ||
GraphDatabaseSingleton.getInstance() | ||
.getAllPossibilitiesGraph( | ||
releaseQueryList.getReleases().stream().map(ReleaseQueryList.Release::getGa).collect(Collectors.toSet() | ||
) | ||
) | ||
); | ||
Weaver.weaveGraph(resultGraph, releaseQueryList.getAddedValues()); | ||
return resultGraph.getJsonGraph(); | ||
} | ||
|
||
@Operation( | ||
description = "Get the project rooted direct dependencies possibilities graph", | ||
summary = "Get the project rooted direct dependencies possibilities graph from releases dependencies list" | ||
) | ||
@PostMapping("/graph/directPossibilitiesRooted") | ||
public JSONObject getDirectPossibilitiesRootedGraph(@RequestBody ReleaseQueryList releaseQueryList) { | ||
InternGraph resultGraph = new InternGraph(); | ||
resultGraph.addNode(new ReleaseNode("ROOT", "ROOT", 0, "")); | ||
for (ReleaseQueryList.Release release : releaseQueryList.getReleases()) { | ||
resultGraph.addEdge(new DependencyEdge("ROOT", release.getGa(), release.getVersion(), "compile")); | ||
} | ||
resultGraph.mergeGraph( | ||
GraphDatabaseSingleton.getInstance() | ||
.getDirectPossibilitiesGraph( | ||
releaseQueryList.getReleases().stream().map(ReleaseQueryList.Release::getGa).collect(Collectors.toSet() | ||
) | ||
) | ||
); | ||
Weaver.weaveGraph(resultGraph, releaseQueryList.getAddedValues()); | ||
return resultGraph.getJsonGraph(); | ||
} | ||
|
||
@Operation( | ||
description = "Get the project rooted direct dependencies possibilities graph with transitive", | ||
summary = "Get the project rooted direct dependencies possibilities graph with transitive version from releases dependencies list" | ||
) | ||
@PostMapping("/graph/directPossibilitiesWithTransitiveRooted") | ||
public JSONObject getDirectPossibilitiesWithTransitiveRootedGraph(@RequestBody ReleaseQueryList releaseQueryList) { | ||
InternGraph resultGraph = new InternGraph(); | ||
resultGraph.addNode(new ReleaseNode("ROOT", "ROOT", 0, "")); | ||
for (ReleaseQueryList.Release release : releaseQueryList.getReleases()) { | ||
resultGraph.addEdge(new DependencyEdge("ROOT", release.getGa(), release.getVersion(), "compile")); | ||
} | ||
// Get direct all possibilities | ||
InternGraph directAllPossibilities = GraphDatabaseSingleton.getInstance() | ||
.getDirectPossibilitiesGraph(releaseQueryList.getReleases().stream().map(ReleaseQueryList.Release::getGa).collect(Collectors.toSet())); | ||
resultGraph.mergeGraph(directAllPossibilities); | ||
// Get Releases dependencies | ||
Map<String, Object> parameters = new HashMap<>(); | ||
Set<String> visitedReleases = new HashSet<>(); | ||
Set<String> releasesToTreat = directAllPossibilities.getGraphNodes().stream().filter(n -> n.getType().equals(NodeType.RELEASE)).map(NodeObject::getId).collect(Collectors.toSet()); | ||
while (!releasesToTreat.isEmpty()){ | ||
parameters.put("releaseIdList",releasesToTreat); | ||
InternGraph queryResult = GraphDatabaseSingleton.getInstance().executeQueryWithParameters(GraphDatabaseSingleton.getInstance().getQueryDictionary().getDependencyGraphFromReleaseIdListParameter(), parameters); | ||
resultGraph.mergeGraph(queryResult); | ||
visitedReleases.addAll(releasesToTreat); | ||
Set<String> newReleaseToTreat = resultGraph.getGraphNodes().stream().filter(node -> node instanceof ReleaseNode).map(NodeObject::getId).collect(Collectors.toSet()); | ||
newReleaseToTreat.removeAll(visitedReleases); | ||
releasesToTreat.clear(); | ||
releasesToTreat.addAll(newReleaseToTreat); | ||
} | ||
|
||
Weaver.weaveGraph(resultGraph, releaseQueryList.getAddedValues()); | ||
return resultGraph.getJsonGraph(); | ||
} | ||
|
||
@Operation( | ||
description = "Get the project rooted direct dependencies possibilities graph with transitive", | ||
summary = "Get the project rooted direct dependencies possibilities graph with transitive version from releases dependencies list" | ||
) | ||
@PostMapping("/graph/directNewPossibilitiesWithTransitiveRooted") | ||
public JSONObject getDirectNewPossibilitiesWithTransitiveRootedGraph(@RequestBody ReleaseQueryList releaseQueryList) { | ||
InternGraph resultGraph = new InternGraph(); | ||
resultGraph.addNode(new ReleaseNode("ROOT", "ROOT", 0, "")); | ||
for (ReleaseQueryList.Release release : releaseQueryList.getReleases()) { | ||
resultGraph.addEdge(new DependencyEdge("ROOT", release.getGa(), release.getVersion(), "compile")); | ||
} | ||
// Get direct all possibilities | ||
InternGraph directAllPossibilities = GraphDatabaseSingleton.getInstance() | ||
.getDirectNewPossibilitiesGraph(releaseQueryList.getReleases()); | ||
resultGraph.mergeGraph(directAllPossibilities); | ||
// Get Releases dependencies | ||
Map<String, Object> parameters = new HashMap<>(); | ||
Set<String> visitedReleases = new HashSet<>(); | ||
Set<String> releasesToTreat = directAllPossibilities.getGraphNodes().stream().filter(n -> n.getType().equals(NodeType.RELEASE)).map(NodeObject::getId).collect(Collectors.toSet()); | ||
while (!releasesToTreat.isEmpty()){ | ||
parameters.put("releaseIdList",releasesToTreat); | ||
InternGraph queryResult = GraphDatabaseSingleton.getInstance().executeQueryWithParameters(GraphDatabaseSingleton.getInstance().getQueryDictionary().getDependencyGraphFromReleaseIdListParameter(), parameters); | ||
resultGraph.mergeGraph(queryResult); | ||
visitedReleases.addAll(releasesToTreat); | ||
Set<String> newReleaseToTreat = resultGraph.getGraphNodes().stream().filter(node -> node instanceof ReleaseNode).map(NodeObject::getId).collect(Collectors.toSet()); | ||
newReleaseToTreat.removeAll(visitedReleases); | ||
releasesToTreat.clear(); | ||
releasesToTreat.addAll(newReleaseToTreat); | ||
} | ||
|
||
Weaver.weaveGraph(resultGraph, releaseQueryList.getAddedValues()); | ||
return resultGraph.getJsonGraph(); | ||
} | ||
} |
Oops, something went wrong.