use of com.thinkbiganalytics.metadata.api.MetadataExecutionException in project kylo by Teradata.
the class DebugController method putPropertyValue.
/**
* Puts a new value into the property at the JCR path given, for debugging.
*
* @param abspath the path in JCR to a node's property
* @param value the new value for the property
* @return a print of the property showing the new current value
*/
@PUT
@Path("jcr/{abspath: .*}")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
public String putPropertyValue(@PathParam("abspath") final String abspath, @QueryParam("value") final String value) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
metadata.commit(() -> {
this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ADMIN_METADATA);
Session session = JcrMetadataAccess.getActiveSession();
java.nio.file.Path path = JcrPath.get(abspath);
try {
Item item = getItem(abspath, session);
if (item instanceof Property) {
Property property = (Property) item;
if (value != null && "null".equals(value)) {
setPropertyValue(property, null);
pw.println(" - " + property.getName() + " deleted");
} else {
// No-op if value not supplied
if (value != null) {
setPropertyValue(property, value);
}
printItem(item, pw);
}
} else {
pw.println("Item at path is not a property: " + path.toString());
}
} catch (PathNotFoundException e) {
try {
Item item = getItem(path.getParent().toString(), session);
if (item instanceof Node && value != null) {
Node node = (Node) item;
String propName = path.getFileName().toString();
item = node.setProperty(propName, value);
} else {
pw.print("Path not found: " + path.toString());
}
printItem(item, pw);
} catch (PathNotFoundException pnf) {
pw.print("Path not found: " + path.toString());
}
}
});
} catch (MetadataAccessException | MetadataExecutionException e) {
pw.println("Failed to set node property " + abspath + " = '" + value + "': " + e.getCause().getMessage());
log.error("Failed to set node property: {} = '{}'", abspath, value, e);
} catch (Exception e) {
e.printStackTrace(pw);
log.error("Failed to set node property: {} = '{}'", abspath, value, e);
}
pw.flush();
return sw.toString();
}
Aggregations