Search in sources :

Example 6 with MetadataAccessException

use of com.thinkbiganalytics.metadata.api.MetadataAccessException 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();
}
Also used : MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) Node(javax.jcr.Node) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) VersionException(javax.jcr.version.VersionException) ParseException(java.text.ParseException) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) ValueFormatException(javax.jcr.ValueFormatException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) Item(javax.jcr.Item) StringWriter(java.io.StringWriter) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property) PrintWriter(java.io.PrintWriter) Session(javax.jcr.Session) Path(javax.ws.rs.Path) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

MetadataAccessException (com.thinkbiganalytics.metadata.api.MetadataAccessException)6 MetadataExecutionException (com.thinkbiganalytics.metadata.api.MetadataExecutionException)6 RepositoryException (javax.jcr.RepositoryException)6 LockException (javax.jcr.lock.LockException)6 JcrPath (com.thinkbiganalytics.metadata.modeshape.support.JcrPath)4 PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4 ParseException (java.text.ParseException)4 PathNotFoundException (javax.jcr.PathNotFoundException)4 Session (javax.jcr.Session)4 ValueFormatException (javax.jcr.ValueFormatException)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)4 VersionException (javax.jcr.version.VersionException)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Item (javax.jcr.Item)3 MetadataLockException (com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException)2 Node (javax.jcr.Node)2 NotSupportedException (javax.transaction.NotSupportedException)2 SystemException (javax.transaction.SystemException)2