Search in sources :

Example 46 with MetadataRepositoryException

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

the class JcrUserDatasource method toDetailsObject.

@Nonnull
private JcrDatasourceDetails toDetailsObject(@Nonnull final Node detailsNode) {
    // Determine type class
    final Class<? extends JcrDatasourceDetails> typeClass;
    try {
        final String typeName = detailsNode.getPrimaryNodeType().getName();
        typeClass = DETAILS_NODE_TYPES_MAP.getOrDefault(typeName, JcrDatasourceDetails.class);
    } catch (final RepositoryException e) {
        throw new MetadataRepositoryException("Failed to determine type of node: " + detailsNode, e);
    }
    // Convert node to object
    return JcrUtil.getJcrObject(detailsNode, typeClass);
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Nonnull(javax.annotation.Nonnull)

Example 47 with MetadataRepositoryException

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

the class JcrExtensibleEntityProvider method getEntities.

@Override
public List<ExtensibleEntity> getEntities() {
    List<ExtensibleEntity> list = new ArrayList<>();
    Session session = getSession();
    try {
        String path = EntityUtil.pathForExtensibleEntity();
        Node genericsNode = session.getNode(path);
        NodeIterator typeNameItr = genericsNode.getNodes();
        while (typeNameItr.hasNext()) {
            Node typeNameNode = (Node) typeNameItr.next();
            NodeIterator entityItr = typeNameNode.getNodes();
            while (entityItr.hasNext()) {
                Node entNode = (Node) entityItr.next();
                list.add(new JcrExtensibleEntity(entNode));
            }
        }
        return list;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to retrieve list of extensible entities", e);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) ExtensibleEntity(com.thinkbiganalytics.metadata.api.extension.ExtensibleEntity) Session(javax.jcr.Session)

Example 48 with MetadataRepositoryException

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

the class JcrPropertiesEntity method clearAdditionalProperties.

public void clearAdditionalProperties() {
    getPropertiesObject().ifPresent(propsObj -> {
        try {
            Node propsNode = propsObj.getNode();
            Map<String, Object> props = propsObj.getProperties();
            for (Map.Entry<String, Object> prop : props.entrySet()) {
                if (!JcrPropertyUtil.hasProperty(propsNode.getPrimaryNodeType(), prop.getKey())) {
                    try {
                        Property property = propsNode.getProperty(prop.getKey());
                        property.remove();
                    } catch (AccessDeniedException e) {
                        // Failed remove the extra property
                        log.debug("Access denied", e);
                        throw new AccessControlException("You do not have the permission to remove property \"" + prop.getKey() + "\"");
                    }
                }
            }
        } catch (RepositoryException e) {
            throw new MetadataRepositoryException("Unable to clear the Properties for this entity. ", e);
        }
    });
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) AccessDeniedException(javax.jcr.AccessDeniedException) Node(javax.jcr.Node) AccessControlException(java.security.AccessControlException) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) HashMap(java.util.HashMap) Map(java.util.Map) Property(javax.jcr.Property)

Example 49 with MetadataRepositoryException

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

the class JcrExtensibleEntityProvider method getEntity.

@Override
public ExtensibleEntity getEntity(ID id) {
    JcrExtensibleEntity.EntityId idImpl = (JcrExtensibleEntity.EntityId) id;
    try {
        Session session = getSession();
        Node node = session.getNodeByIdentifier(idImpl.getIdValue());
        if (node != null) {
            return new JcrExtensibleEntity(node);
        } else {
            return null;
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failure while finding entity by ID: " + idImpl.getIdValue(), e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 50 with MetadataRepositoryException

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

the class JcrExtensibleEntityProvider method findEntitiesMatchingProperty.

/**
 * Return a list of the ExtensibleEntity objects that match a given ExtensibleEntity property and value
 * restricting to a specific jcr extension type
 */
public List<? extends ExtensibleEntity> findEntitiesMatchingProperty(String typeName, String propName, Object value) {
    String qualifiedName = this.typeProvider.ensureTypeName(typeName);
    HashMap<String, String> params = new HashMap<>();
    String query = "SELECT * FROM [" + qualifiedName + "] as t WHERE t.[" + propName + "] = $v";
    params.put("v", value.toString());
    QueryResult result = null;
    try {
        result = JcrQueryUtil.query(getSession(), query, params);
        List<JcrExtensibleEntity> entities = JcrQueryUtil.queryResultToList(result, JcrExtensibleEntity.class);
        return entities;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to execute Criteria Query for " + typeName + ".  Query is: " + query, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) QueryResult(javax.jcr.query.QueryResult) HashMap(java.util.HashMap) 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