Search in sources :

Example 1 with JcrProject

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

the class JcrProjectProvider method createProject.

/**
 * Creates a new user with the specified name.
 *
 * @param name   the name of the Project
 * @param ensure {@code true} to return the Project if it already exists, or {@code false} to throw an exception
 * @return the Project
 * @throws MetadataRepositoryException if the user could not be created
 */
@Nonnull
private Project createProject(@Nonnull final String name, final boolean ensure) {
    final Session session = getSession();
    final String projPath = ProjectPaths.projectPath(name).toString();
    logger.debug("workspace= {}", session.getWorkspace().getName());
    try {
        Node projNode = session.getRootNode().getNode(ProjectPaths.PROJECTS.toString());
        if (session.getRootNode().hasNode(projPath)) {
            if (ensure) {
                return JcrUtil.getJcrObject(projNode, name, JcrProject.class);
            } else {
                // TODO specialize me..
                throw new RuntimeException(projPath);
            }
        } else {
            // project does not yet exist
            JcrProject newProject = JcrUtil.getOrCreateNode(projNode, name, JcrProject.NODE_TYPE, JcrProject.class);
            // grant (or deny) current user access to the project he is creating
            if (this.accessController.isEntityAccessControlled()) {
                List<SecurityRole> roles = this.roleProvider.getEntityRoles(SecurityRole.PROJECT);
                this.actionsProvider.getAvailableActions(AllowedActions.PROJECTS).ifPresent(actions -> newProject.enableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser(), roles));
            } else {
                this.actionsProvider.getAvailableActions(AllowedActions.PROJECTS).ifPresent(actions -> newProject.disableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser()));
            }
            return newProject;
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed attempting to create a new Project with name: " + name, e);
    }
}
Also used : JcrProject(com.thinkbiganalytics.metadata.modeshape.project.JcrProject) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) SecurityRole(com.thinkbiganalytics.security.role.SecurityRole) JcrAllowedActions(com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) Nonnull(javax.annotation.Nonnull)

Aggregations

MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)1 JcrProject (com.thinkbiganalytics.metadata.modeshape.project.JcrProject)1 JcrAllowedActions (com.thinkbiganalytics.metadata.modeshape.security.action.JcrAllowedActions)1 SecurityRole (com.thinkbiganalytics.security.role.SecurityRole)1 Nonnull (javax.annotation.Nonnull)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1