Search in sources :

Example 61 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrPropertyUtil method asValue.

@SuppressWarnings("unchecked")
public static <T> T asValue(Property prop) {
    // STRING, BOOLEAN, LONG, DOUBLE, PATH, ENTITY
    try {
        int code = prop.getType();
        if (prop.isMultiple()) {
            List<T> list = new ArrayList<>();
            Value[] values = prop.getValues();
            if (values != null) {
                for (Value value : values) {
                    try {
                        T o = asValue(value, prop.getSession());
                        if (o != null) {
                            list.add(o);
                        }
                    } catch (AccessDeniedException e) {
                    // We are not allowd to see the value (likely a node reference) then
                    // just ignore this value in the result list.
                    }
                }
            }
            if (list.size() > 0) {
                return (T) list;
            } else {
                return (T) Collections.emptyList();
            }
        } else {
            if (code == PropertyType.BOOLEAN) {
                return (T) Boolean.valueOf(prop.getBoolean());
            } else if (code == PropertyType.STRING) {
                return (T) prop.getString();
            } else if (code == PropertyType.LONG) {
                return (T) Long.valueOf(prop.getLong());
            } else if (code == PropertyType.DOUBLE) {
                return (T) Double.valueOf(prop.getDouble());
            } else if (code == PropertyType.PATH) {
                return (T) prop.getPath();
            } else if (code == PropertyType.REFERENCE || code == PropertyType.WEAKREFERENCE) {
                try {
                    return (T) prop.getNode();
                } catch (AccessDeniedException e) {
                    // We are not allowd to see the referenced node so return null;
                    return null;
                }
            } else {
                return (T) asValue(prop.getValue(), prop.getSession());
            }
        }
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to access property type", e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) ArrayList(java.util.ArrayList) Value(javax.jcr.Value) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 62 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrPropertyUtil method setJsonObject.

public static <T> void setJsonObject(Node node, String name, Object value) {
    try {
        String json = writer.forType(value.getClass()).writeValueAsString(value);
        setProperty(node, name, json);
    } catch (IOException e) {
        throw new MetadataRepositoryException("Failed to serialize JSON property: " + value, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) IOException(java.io.IOException)

Example 63 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrPropertyUtil method removeAllFromSetProperty.

public static boolean removeAllFromSetProperty(Node node, String name) {
    try {
        // JcrVersionUtil.ensureCheckoutNode(node);
        if (node == null) {
            throw new IllegalArgumentException("Cannot remove a property from a null-node!");
        }
        if (name == null) {
            throw new IllegalArgumentException("Cannot remove a property without a provided name");
        }
        Set<Value> values = new HashSet<>();
        node.setProperty(name, (Value[]) values.stream().toArray(size -> new Value[size]));
        return true;
    } catch (AccessDeniedException e) {
        log.debug("Access denied", e);
        throw new AccessControlException(e.getMessage());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to remove set property: " + name, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) Value(javax.jcr.Value) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) HashSet(java.util.HashSet)

Example 64 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrQueryUtil method queryRowItrNodeResultToList.

public static <T extends Object> List<T> queryRowItrNodeResultToList(QueryResult result, Class<T> type, String nodeName, Integer fetchSize) {
    List<T> entities = new ArrayList<>();
    if (result != null) {
        try {
            RowIterator rowIterator = result.getRows();
            int cntr = 0;
            while (rowIterator.hasNext()) {
                Row row = rowIterator.nextRow();
                Node node = row.getNode(nodeName);
                T entity = JcrUtil.constructNodeObject(node, type, null);
                entities.add(entity);
                cntr++;
                if (fetchSize != null && cntr == fetchSize) {
                    break;
                }
            }
        } catch (RepositoryException e) {
            throw new MetadataRepositoryException("Unable to parse QueryResult to List Row Iteration for type" + type + " and Node: " + nodeName, e);
        }
    }
    return entities;
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RowIterator(javax.jcr.query.RowIterator) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Row(javax.jcr.query.Row)

Example 65 with MetadataRepositoryException

use of com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException in project kylo by Teradata.

the class JcrUtil method getNodesOfType.

public static List<Node> getNodesOfType(Node parentNode, String nodeType) {
    try {
        List<Node> list = new ArrayList<>();
        NodeIterator itr = parentNode.getNodes();
        while (itr.hasNext()) {
            Node node = (Node) itr.next();
            if (node.isNodeType(nodeType)) {
                list.add(node);
            }
        }
        return list;
    } 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 nodes of type: " + nodeType, e);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Aggregations

MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)83 RepositoryException (javax.jcr.RepositoryException)79 Node (javax.jcr.Node)54 AccessDeniedException (javax.jcr.AccessDeniedException)29 AccessControlException (java.security.AccessControlException)28 Session (javax.jcr.Session)25 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)12 NodeIterator (javax.jcr.NodeIterator)12 Nonnull (javax.annotation.Nonnull)10 Value (javax.jcr.Value)10 Map (java.util.Map)9 Property (javax.jcr.Property)8 ItemNotFoundException (javax.jcr.ItemNotFoundException)7 QueryResult (javax.jcr.query.QueryResult)7 JcrObject (com.thinkbiganalytics.metadata.modeshape.common.JcrObject)6 AccessControlManager (javax.jcr.security.AccessControlManager)6 UserFieldDescriptor (com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor)5 List (java.util.List)5