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