use of com.thinkbiganalytics.metadata.modeshape.support.JcrTool in project kylo by Teradata.
the class BaseJcrProvider method findOrCreateEntityNode.
/**
* Creates a new Entity Node object for a Parent Path, relative Path and node type
*/
public Node findOrCreateEntityNode(String parentPath, String relPath, Class<? extends JcrEntity> jcrEntityType) {
Session session = getSession();
try {
Node typesNode = session.getNode(parentPath);
JcrTools tools = new JcrTool();
Node entNode = tools.findOrCreateChild(typesNode, relPath, getNodeType(jcrEntityType));
return entNode;
} catch (RepositoryException e) {
throw new MetadataRepositoryException("Failed to create new entity of type: " + getEntityClass(), e);
}
}
use of com.thinkbiganalytics.metadata.modeshape.support.JcrTool in project kylo by Teradata.
the class DebugController method printJcrTree.
/**
* Prints the nodes of the JCR path given, for debugging.
*
* @param abspath the path in JCR
* @return a printout of the JCR tree
*/
@GET
@Path("jcr/{abspath: .*}")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
public String printJcrTree(@PathParam("abspath") final String abspath) {
return metadata.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ACCESS_METADATA);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
Session session = JcrMetadataAccess.getActiveSession();
try {
Node node = Strings.isNullOrEmpty(abspath) ? session.getRootNode() : session.getRootNode().getNode(abspath);
JcrTools tools = new JcrTool(true, pw);
tools.printSubgraph(node);
} catch (PathNotFoundException pnf) {
try {
java.nio.file.Path path = JcrPath.get(abspath);
Node node = session.getRootNode().getNode(path.getParent().toString());
Object value = JcrPropertyUtil.getProperty(node, path.getFileName().toString());
pw.println(" - " + path.getFileName().toString() + "=" + value);
} catch (PathNotFoundException e) {
throw pnf;
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
pw.flush();
return sw.toString();
});
}
use of com.thinkbiganalytics.metadata.modeshape.support.JcrTool in project kylo by Teradata.
the class DebugController method printJcrId.
/**
* Prints the subgraph of the node in JCR with the specified ID.
*
* @param jcrId the id of the node in JCR
* @return the subgraph print out
*/
@GET
@Path("jcr")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
public String printJcrId(@QueryParam("id") final String jcrId) {
return metadata.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ACCESS_METADATA);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
// If the ID is over 36 characters long then assume it is a cache key and
// extract only the node ID portion of the key.
String nodeId = jcrId.length() > 36 ? jcrId.substring(jcrId.length() - 36, jcrId.length()) : jcrId;
try {
Session session = JcrMetadataAccess.getActiveSession();
Node node = session.getNodeByIdentifier(nodeId);
pw.print("Path: ");
pw.println(node.getPath());
JcrTools tools = new JcrTool(true, pw);
tools.printSubgraph(node);
} catch (Exception e) {
throw new RuntimeException(e);
}
pw.flush();
return sw.toString();
});
}
use of com.thinkbiganalytics.metadata.modeshape.support.JcrTool in project kylo by Teradata.
the class JcrDatasourceProvider method createImpl.
private <J extends JcrDatasource> J createImpl(String name, String descr, Class<? extends Datasource> type) {
try {
JcrTool tool = new JcrTool();
Class<J> implType = deriveImplType(type);
Field folderField = FieldUtils.getField(implType, "PATH_NAME", true);
String subfolderName = (String) folderField.get(null);
String dsPath = EntityUtil.pathForDataSource();
Node dsNode = getSession().getNode(dsPath);
Node subfolderNode = tool.findOrCreateChild(dsNode, subfolderName, "nt:folder");
Map<String, Object> props = new HashMap<>();
props.put(JcrDatasource.SYSTEM_NAME, name);
String encodedName = org.modeshape.jcr.value.Path.DEFAULT_ENCODER.encode(name);
final boolean isNew = !hasEntityNode(subfolderNode.getPath(), encodedName);
@SuppressWarnings("unchecked") J datasource = (J) findOrCreateEntity(subfolderNode.getPath(), encodedName, implType, props);
if (isNew && JcrUserDatasource.class.isAssignableFrom(type)) {
if (this.accessController.isEntityAccessControlled()) {
final List<SecurityRole> roles = roleProvider.getEntityRoles(SecurityRole.DATASOURCE);
actionsProvider.getAvailableActions(AllowedActions.DATASOURCE).ifPresent(actions -> ((JcrUserDatasource) datasource).enableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser(), roles));
} else {
actionsProvider.getAvailableActions(AllowedActions.DATASOURCE).ifPresent(actions -> ((JcrUserDatasource) datasource).disableAccessControl((JcrAllowedActions) actions, JcrMetadataAccess.getActiveUser()));
}
}
datasource.setTitle(name);
datasource.setDescription(descr);
return datasource;
} catch (IllegalArgumentException | IllegalAccessException | RepositoryException e) {
throw new MetadataException("Unable to create datasource: " + type, e);
}
}
Aggregations