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);
}
}
Aggregations