use of org.modeshape.jcr.api.JcrTools in project kylo by Teradata.
the class JcrQueryUtil method findFirst.
public static <T extends Object> T findFirst(Session session, String query, Map<String, String> bindParams, Class<T> type) {
JcrTools tools = new JcrTools();
try {
QueryResult result = query(session, query, bindParams);
List<T> list = queryResultToList(result, 1, type);
if (list != null && list.size() > 0) {
return list.get(0);
} else {
return null;
}
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Unable to findFirst for query : " + query, e);
}
}
use of org.modeshape.jcr.api.JcrTools in project kylo by Teradata.
the class JcrUtil method getOrCreateNode.
/**
* Get or Create a node relative to the Parent Node and return the Wrapper JcrObject
*/
public static <T extends JcrObject> T getOrCreateNode(Node parentNode, String name, String nodeType, Class<T> type, Object... constructorArgs) {
T entity = null;
try {
JcrTools tools = new JcrTools();
// if versionable checkout
// if(isVersionable(parentNode)){
// JcrVersionUtil.checkout(parentNode);
// }
Node n = tools.findOrCreateChild(parentNode, name, nodeType);
entity = createJcrObject(n, type, constructorArgs);
// save ??
// JcrVersionUtil.checkinRecursively(n);
// if(isVersionable(parentNode)){
// JcrVersionUtil.checkin(parentNode);
// }
} catch (AccessDeniedException e) {
log.debug("Access denied", e);
throw new AccessControlException(e.getMessage());
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to retrieve the Node named" + name, e);
}
return entity;
}
use of org.modeshape.jcr.api.JcrTools in project kylo by Teradata.
the class BaseJcrProvider method findOrCreateEntityNode.
/**
* Creates a new Entity Node object for a Parent Path, relative Path and node type
*/
public Node findOrCreateEntityNode(String parentPath, String relPath, Class<? extends JcrEntity> jcrEntityType) {
Session session = getSession();
try {
Node typesNode = session.getNode(parentPath);
JcrTools tools = new JcrTool();
Node entNode = tools.findOrCreateChild(typesNode, relPath, getNodeType(jcrEntityType));
return entNode;
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to create new entity of type: " + getEntityClass(), e);
}
}
use of org.modeshape.jcr.api.JcrTools in project kylo by Teradata.
the class DebugController method printJcrTree.
/**
* Prints the nodes of the JCR path given, for debugging.
*
* @param abspath the path in JCR
* @return a printout of the JCR tree
*/
@GET
@Path("jcr/{abspath: .*}")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
public String printJcrTree(@PathParam("abspath") final String abspath) {
return metadata.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ACCESS_METADATA);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
Session session = JcrMetadataAccess.getActiveSession();
try {
Node node = Strings.isNullOrEmpty(abspath) ? session.getRootNode() : session.getRootNode().getNode(abspath);
JcrTools tools = new JcrTool(true, pw);
tools.printSubgraph(node);
} catch (PathNotFoundException pnf) {
try {
java.nio.file.Path path = JcrPath.get(abspath);
Node node = session.getRootNode().getNode(path.getParent().toString());
Object value = JcrPropertyUtil.getProperty(node, path.getFileName().toString());
pw.println(" - " + path.getFileName().toString() + "=" + value);
} catch (PathNotFoundException e) {
throw pnf;
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
pw.flush();
return sw.toString();
});
}
use of org.modeshape.jcr.api.JcrTools in project kylo by Teradata.
the class DebugController method printJcrId.
/**
* Prints the subgraph of the node in JCR with the specified ID.
*
* @param jcrId the id of the node in JCR
* @return the subgraph print out
*/
@GET
@Path("jcr")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
public String printJcrId(@QueryParam("id") final String jcrId) {
return metadata.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ACCESS_METADATA);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
// If the ID is over 36 characters long then assume it is a cache key and
// extract only the node ID portion of the key.
String nodeId = jcrId.length() > 36 ? jcrId.substring(jcrId.length() - 36, jcrId.length()) : jcrId;
try {
Session session = JcrMetadataAccess.getActiveSession();
Node node = session.getNodeByIdentifier(nodeId);
pw.print("Path: ");
pw.println(node.getPath());
JcrTools tools = new JcrTool(true, pw);
tools.printSubgraph(node);
} catch (Exception e) {
throw new RuntimeException(e);
}
pw.flush();
return sw.toString();
});
}
Aggregations