// set up response stuff
JSONObject jsonResponse = new JSONObject();
int statusCode = 400;
// initialize json collections for response
JSONArray jsonStatusMessages = new JSONArray();
JSONArray jsonNodes = new JSONArray();
JSONArray jsonEdges = new JSONArray();
// resolve given path
ResourceResolver resourceResolver = request.getResourceResolver();
Resource pageResource = resourceResolver.resolve(paramPagePath);
// check if path resolved
if(StringUtils.isNotBlank(paramPagePath) && !ResourceUtil.isNonExistingResource(pageResource)) {
// get content node
Resource jcrContentResource = pageResource.getChild(JcrConstants.JCR_CONTENT);
// keep track of categories
Set<String> categories = new HashSet<String>();
try {
// write components to JSON
for (String resourceType : ComponentUtils.getNestedComponentTypes(jcrContentResource)) {
// get dependent component
DependentComponent dependentComponent =
dependentComponentManager.getDependentComponentForResourceType(resourceType).orNull();
if(dependentComponent != null) {
// found dependent component, write it to JSON
jsonNodes.put(DomainToJSONUtil.buildJsonComponent(dependentComponent));
// add all dependencies to categories list, add edges from component to categories
String componentResourceType = dependentComponent.getResourceType();
Set<String> dependencies = dependentComponent.getDependencies();
for(String dependency : dependencies) {
JSONObject jsonEdge =
DomainToJSONUtil.buildJsonEdge(componentResourceType, dependency, EdgeType.DEPENDS_ON);
jsonEdges.put(jsonEdge);
}
categories.addAll(dependencies);
} else {
// this is not a dependent component (probably OOTB), write it to JSON with what info it has
jsonNodes.put(DomainToJSONUtil.buildJsonBareComponent(resourceType));
}
}
// get graph
DependencyGraph<ClientLibrary> dependencyGraph
= clientLibraryRepository.getClientLibraryDependencyGraph(jcrContentResource);
// write client libraries to JSON
for (ClientLibrary clientLibrary : dependencyGraph.getNodes()) {
jsonNodes.put(DomainToJSONUtil.buildJsonLibrary(clientLibrary));
String clientLibraryPath = clientLibrary.getClientLibraryPath();
// add all categories to categories list, add edges from categories to this library
Set<String> memberOfCategories = clientLibrary.getCategories();
for(String category : memberOfCategories) {
JSONObject jsonEdge =
DomainToJSONUtil.buildJsonEdge(clientLibraryPath, category, EdgeType.MEMBER_OF);
jsonEdges.put(jsonEdge);
}
categories.addAll(memberOfCategories);
// add all dependencies to categories list, add edges from categories to libraries
List<String> dependencies = clientLibrary.getDependencies();
for(String dependency : dependencies) {
JSONObject jsonEdge =
DomainToJSONUtil.buildJsonEdge(clientLibraryPath, dependency, EdgeType.DEPENDS_ON);
jsonEdges.put(jsonEdge);
}
categories.addAll(dependencies);
// add all embeds to categories list, add edges from embeds to categories
List<String> embeds = clientLibrary.getEmbeddedCategories();
for(String embed : embeds) {
JSONObject jsonEdge =
DomainToJSONUtil.buildJsonEdge(clientLibraryPath, embed, EdgeType.EMBEDS);
jsonEdges.put(jsonEdge);
}
categories.addAll(embeds);
}