Search in sources :

Example 6 with JcrTools

use of org.modeshape.jcr.api.JcrTools in project kylo by Teradata.

the class TagProvider method findByTag.

public List<JcrObject> findByTag(String tag) {
    String query = "SELECT * FROM [tba:taggable] AS taggable\n" + "WHERE taggable.[tba:tags] = $tag ";
    JcrTools tools = new JcrTools();
    Map<String, String> params = new HashMap<>();
    params.put("tag", tag);
    try {
        QueryResult result = JcrQueryUtil.query(getSession(), query, params);
        return JcrQueryUtil.queryResultToList(result, JcrObject.class);
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to find objects by tag " + tag, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) QueryResult(javax.jcr.query.QueryResult) HashMap(java.util.HashMap) RepositoryException(javax.jcr.RepositoryException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) JcrTools(org.modeshape.jcr.api.JcrTools)

Example 7 with JcrTools

use of org.modeshape.jcr.api.JcrTools in project kylo by Teradata.

the class JcrNotebooksApp method main.

public static void main(String... args) throws RepositoryException, IOException {
    ModeShapeEngine engine = new ModeShapeEngine();
    engine.start();
    Repository repository = null;
    String repositoryName = null;
    URL url = JcrNotebooksApp.class.getClassLoader().getResource("sandbox/notebook-test-repository.json");
    RepositoryConfiguration config = RepositoryConfiguration.read(url);
    // Verify the configuration for the repository ...
    Problems problems = config.validate();
    if (problems.hasErrors()) {
        System.err.println("Problems starting the engine.");
        System.err.println(problems);
        System.exit(-1);
    }
    // Deploy the repository ...
    repository = engine.deploy(config);
    repositoryName = config.getName();
    Session session = null;
    JcrTools tools = new JcrTools();
    tools.setDebug(true);
    // get the repository
    repository = engine.getRepository(repositoryName);
    Project p;
    session = repository.login("default");
    // Create the '/files' node that is an 'nt:folder' ...
    Node root = session.getRootNode();
    /*
        Node filesNode = root.addNode("notebooks", "nt:folder");

        InputStream stream =
            new BufferedInputStream(new FileInputStream("/Users/th186036/filesystemconnector/hello.txt"));

        // Create an 'nt:file' node at the supplied path ...
        Node fileNode = filesNode.addNode("hello.txt", "nt:file");

        // Upload the file to that node ...
        Node contentNode = fileNode.addNode("jcr:content", "nt:resource");
        Binary binary = session.getValueFactory().createBinary(stream);
        contentNode.setProperty("jcr:data", binary);

        session.save();
        */
    session = repository.login("default");
    Node project = JcrUtil.getOrCreateNode(root, "Project1", JcrProject.NODE_TYPE);
    List<Node> nodes = JcrUtil.getNodesOfType(root, JcrProject.NODE_TYPE);
    logger.debug("Node list {}", nodes);
    // List<JcrEntity> fileNodes = JcrUtil.getChildrenMatchingNodeType(root, JcrProject.NODE_TYPE, JcrEntity.class, null);
    // logger.debug("Node list {}", nodes );
    logger.debug("Modeshape subgraph");
    tools.printSubgraph(root);
    if (session != null) {
        session.logout();
    }
    logger.info("Shutting down engine ...");
    try {
        engine.shutdown().get();
        logger.info("Success!");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Node(javax.jcr.Node) ModeShapeEngine(org.modeshape.jcr.ModeShapeEngine) URL(java.net.URL) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) Problems(org.modeshape.common.collection.Problems) JcrProject(com.thinkbiganalytics.metadata.modeshape.project.JcrProject) Project(com.thinkbiganalytics.metadata.api.project.Project) Repository(org.modeshape.jcr.api.Repository) RepositoryConfiguration(org.modeshape.jcr.RepositoryConfiguration) JcrTools(org.modeshape.jcr.api.JcrTools) Session(org.modeshape.jcr.api.Session)

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