Search in sources :

Example 1 with JcrTools

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);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) QueryResult(javax.jcr.query.QueryResult) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) JcrTools(org.modeshape.jcr.api.JcrTools)

Example 2 with JcrTools

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;
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) JcrTools(org.modeshape.jcr.api.JcrTools)

Example 3 with JcrTools

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);
    }
}
Also used : Node(javax.jcr.Node) JcrTool(com.thinkbiganalytics.metadata.modeshape.support.JcrTool) RepositoryException(javax.jcr.RepositoryException) JcrTools(org.modeshape.jcr.api.JcrTools) Session(javax.jcr.Session)

Example 4 with JcrTools

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();
    });
}
Also used : Path(javax.ws.rs.Path) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) StringWriter(java.io.StringWriter) Node(javax.jcr.Node) JcrTool(com.thinkbiganalytics.metadata.modeshape.support.JcrTool) PathNotFoundException(javax.jcr.PathNotFoundException) JcrTools(org.modeshape.jcr.api.JcrTools) ParseException(java.text.ParseException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) PrintWriter(java.io.PrintWriter) Session(javax.jcr.Session) Path(javax.ws.rs.Path) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with JcrTools

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();
    });
}
Also used : StringWriter(java.io.StringWriter) Node(javax.jcr.Node) JcrTool(com.thinkbiganalytics.metadata.modeshape.support.JcrTool) JcrTools(org.modeshape.jcr.api.JcrTools) ParseException(java.text.ParseException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) PrintWriter(java.io.PrintWriter) Session(javax.jcr.Session) Path(javax.ws.rs.Path) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

RepositoryException (javax.jcr.RepositoryException)7 JcrTools (org.modeshape.jcr.api.JcrTools)7 Node (javax.jcr.Node)5 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)3 JcrTool (com.thinkbiganalytics.metadata.modeshape.support.JcrTool)3 Session (javax.jcr.Session)3 JcrPath (com.thinkbiganalytics.metadata.modeshape.support.JcrPath)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 ParseException (java.text.ParseException)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 QueryResult (javax.jcr.query.QueryResult)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Project (com.thinkbiganalytics.metadata.api.project.Project)1 JcrProject (com.thinkbiganalytics.metadata.modeshape.project.JcrProject)1 IOException (java.io.IOException)1 URL (java.net.URL)1 AccessControlException (java.security.AccessControlException)1