Search in sources :

Example 11 with MetadataRepositoryException

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

the class JcrUtil method getPropertyObjectSet.

/**
 * Creates an object set from the nodes of a same-name sibling property
 */
public static <T extends JcrObject> Set<T> getPropertyObjectSet(Node parentNode, String property, Class<T> objClass, Object... args) {
    try {
        Set<T> set = new HashSet<>();
        NodeIterator itr = parentNode.getNodes(property);
        while (itr.hasNext()) {
            Node objNode = (Node) itr.next();
            T obj = constructNodeObject(objNode, objClass, args);
            set.add(obj);
        }
        return set;
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to create set of child objects from property: " + property, e);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) 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) HashSet(java.util.HashSet)

Example 12 with MetadataRepositoryException

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

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

the class JcrVersionUtil method getVersions.

public static List<Version> getVersions(Node node) {
    String nodeName = null;
    if (!isVersionable(node)) {
        return null;
    }
    try {
        nodeName = node.getName();
        List<Version> versions = new ArrayList<>();
        VersionHistory history = JcrVersionUtil.getVersionManager(node.getSession()).getVersionHistory(node.getPath());
        VersionIterator itr = history.getAllVersions();
        String id = history.getVersionableIdentifier();
        while (itr.hasNext()) {
            Version version = itr.nextVersion();
            versions.add(version);
        }
        return versions;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to find Version History for " + nodeName, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Version(javax.jcr.version.Version) ArrayList(java.util.ArrayList) VersionIterator(javax.jcr.version.VersionIterator) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) VersionHistory(javax.jcr.version.VersionHistory)

Example 14 with MetadataRepositoryException

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

the class JcrUserProvider method createGroup.

/**
 * Creates a new group with the specified name.
 *
 * @param groupName the name of the group
 * @param ensure    {@code true} to return the group if it already exists, or {@code false} to throw an exception
 * @return the group
 * @throws GroupAlreadyExistsException if the group already exists and {@code ensure} is {@code false}
 * @throws MetadataRepositoryException if the group could not be created
 */
@Nonnull
private UserGroup createGroup(@Nonnull final String groupName, final boolean ensure) {
    final Session session = getSession();
    final String safeGroupName = encodeGroupName(groupName);
    final String groupPath = UsersPaths.groupPath(safeGroupName).toString();
    try {
        final Node groupsNode = session.getRootNode().getNode(UsersPaths.GROUPS.toString());
        if (session.getRootNode().hasNode(groupPath)) {
            if (ensure) {
                return JcrUtil.getJcrObject(groupsNode, safeGroupName, JcrUserGroup.class);
            } else {
                throw new GroupAlreadyExistsException(groupName);
            }
        } else {
            return JcrUtil.getOrCreateNode(groupsNode, safeGroupName, JcrUserGroup.NODE_TYPE, JcrUserGroup.class);
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed attempting to create a new group with name: " + groupName, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) GroupAlreadyExistsException(com.thinkbiganalytics.metadata.api.user.GroupAlreadyExistsException) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) Nonnull(javax.annotation.Nonnull)

Example 15 with MetadataRepositoryException

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

the class JcrUserProvider method createUser.

/**
 * Creates a new user with the specified name.
 *
 * @param username the name of the user
 * @param ensure   {@code true} to return the user if it already exists, or {@code false} to throw an exception
 * @return the user
 * @throws UserAlreadyExistsException  if the user already exists and {@code ensure} is {@code false}
 * @throws MetadataRepositoryException if the user could not be created
 */
@Nonnull
private User createUser(@Nonnull final String username, final boolean ensure) {
    final Session session = getSession();
    final String safeUserName = encodeUserName(username);
    final String userPath = UsersPaths.userPath(username).toString();
    try {
        final Node usersNode = session.getRootNode().getNode(UsersPaths.USERS.toString());
        if (session.getRootNode().hasNode(userPath)) {
            if (ensure) {
                return JcrUtil.getJcrObject(usersNode, safeUserName, JcrUser.class);
            } else {
                throw new UserAlreadyExistsException(username);
            }
        } else {
            return JcrUtil.getOrCreateNode(usersNode, safeUserName, JcrUser.NODE_TYPE, JcrUser.class);
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed attempting to create a new user with name: " + username, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) UserAlreadyExistsException(com.thinkbiganalytics.metadata.api.user.UserAlreadyExistsException) Session(javax.jcr.Session) Nonnull(javax.annotation.Nonnull)

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