Search in sources :

Example 66 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrUtil method getGenericJson.

public static <T extends Serializable> T getGenericJson(Node jsonNode, boolean allowClassNotFound) {
    try {
        String className = jsonNode.getProperty("tba:type").getString();
        @SuppressWarnings("unchecked") Class<T> type = (Class<T>) ClassNameChangeRegistry.findClass(className);
        return JcrPropertyUtil.getJsonObject(jsonNode, "tba:json", type);
    } catch (RepositoryException | ClassNotFoundException | ClassCastException e) {
        if (e instanceof ClassNotFoundException && allowClassNotFound) {
            // swallow this exception
            return null;
        } else {
            throw new MetadataRepositoryException("Failed to deserialize generic JSON property", e);
        }
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 67 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrUtil method getJcrObjects.

/**
 * get All Child nodes under a parentNode and create the wrapped JCRObject the second argument, name, can be null to get all the nodes under the parent
 */
public static <T extends JcrObject> List<T> getJcrObjects(Node parentNode, String name, NodeType nodeType, JcrObjectTypeResolver<T> typeResolver, Object... args) {
    List<T> list = new ArrayList<>();
    try {
        javax.jcr.NodeIterator nodeItr = null;
        if (StringUtils.isBlank(name)) {
            nodeItr = parentNode.getNodes();
        } else {
            nodeItr = parentNode.getNodes(name);
        }
        if (nodeItr != null) {
            while (nodeItr.hasNext()) {
                Node n = nodeItr.nextNode();
                if (nodeType == null || n.isNodeType(nodeType.getName())) {
                    T entity = constructNodeObject(n, typeResolver.resolve(n), args);
                    list.add(entity);
                }
            }
        }
    } 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 list;
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) NodeIterator(javax.jcr.NodeIterator)

Example 68 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrVersionUtil method isVersionable.

/**
 * @param node the node to test
 * @return true if this node is versionable
 */
public static boolean isVersionable(Node node) {
    String name = "";
    boolean versionable = false;
    try {
        name = node.getName();
        versionable = JcrUtil.hasMixinType(node, "mix:versionable");
        return versionable;
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to check if versionable for Node " + name, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 69 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrVersionUtil method getVersionedNode.

public static <T extends JcrObject> T getVersionedNode(Version version, Class<T> type, Object[] constructorArgs) {
    String nodeName = null;
    String versionName = null;
    try {
        versionName = version.getName();
        Node node = version.getFrozenNode();
        nodeName = node.getName();
        String entityId = version.getContainingHistory().getVersionableIdentifier();
        T obj = JcrUtil.constructNodeObject(node, type, constructorArgs);
        obj.setVersionName(versionName);
        obj.setVersionableIdentifier(entityId);
        return obj;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to find Version " + versionName + " for Node " + nodeName, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 70 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException 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)

Aggregations

MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)83 RepositoryException (javax.jcr.RepositoryException)79 Node (javax.jcr.Node)54 AccessDeniedException (javax.jcr.AccessDeniedException)29 AccessControlException (java.security.AccessControlException)28 Session (javax.jcr.Session)25 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)12 NodeIterator (javax.jcr.NodeIterator)12 Nonnull (javax.annotation.Nonnull)10 Value (javax.jcr.Value)10 Map (java.util.Map)9 Property (javax.jcr.Property)8 ItemNotFoundException (javax.jcr.ItemNotFoundException)7 QueryResult (javax.jcr.query.QueryResult)7 JcrObject (com.thinkbiganalytics.metadata.modeshape.common.JcrObject)6 AccessControlManager (javax.jcr.security.AccessControlManager)6 UserFieldDescriptor (com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor)5 List (java.util.List)5