Search in sources :

Example 16 with MetadataRepositoryException

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

the class JcrExtensibleEntityProvider method getEntities.

public List<ExtensibleEntity> getEntities(String typeName) {
    String qualifiedName = this.typeProvider.ensureTypeName(typeName);
    List<ExtensibleEntity> list = new ArrayList<>();
    Session session = getSession();
    try {
        String path = EntityUtil.pathForExtensibleEntity(qualifiedName);
        if (session.nodeExists(path)) {
            Node typeNameNode = session.getNode(path);
            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 17 with MetadataRepositoryException

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

the class JcrExtensibleEntityProvider method createEntity.

@Override
public ExtensibleEntity createEntity(ExtensibleType type, Map<String, Object> props) {
    JcrExtensibleType typeImpl = (JcrExtensibleType) type;
    Session session = getSession();
    try {
        String path = EntityUtil.pathForExtensibleEntity();
        Node entitiesNode = session.getNode(path);
        Node typesNode = null;
        if (entitiesNode.hasNode(typeImpl.getJcrName())) {
            typesNode = entitiesNode.getNode(typeImpl.getJcrName());
        } else {
            typesNode = entitiesNode.addNode(typeImpl.getJcrName(), "nt:folder");
        }
        Node entNode = typesNode.addNode(typeImpl.getName() + "-" + UUID.randomUUID().toString(), typeImpl.getJcrName());
        Map<String, Object> reassignedProps = mapCollectionProperties(typeImpl, props);
        entNode = JcrPropertyUtil.setProperties(session, entNode, reassignedProps);
        return new JcrExtensibleEntity(entNode);
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to create new extensible entity of type: " + typeImpl.getJcrName(), 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 18 with MetadataRepositoryException

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

the class JcrExtensibleType method getFieldDescriptors.

@Override
public Set<FieldDescriptor> getFieldDescriptors() {
    try {
        Set<FieldDescriptor> set = new HashSet<>();
        for (PropertyDefinition def : this.nodeType.getPropertyDefinitions()) {
            if (this.typeNode.hasNode(def.getName())) {
                Node descrNode = this.typeNode.getNode(def.getName());
                set.add(new JcrFieldDescriptor(descrNode, def));
            }
        }
        return set;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to get property descriptors for type: " + this.nodeType.getName(), e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) FieldDescriptor(com.thinkbiganalytics.metadata.api.extension.FieldDescriptor) UserFieldDescriptor(com.thinkbiganalytics.metadata.api.extension.UserFieldDescriptor) HashSet(java.util.HashSet)

Example 19 with MetadataRepositoryException

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

the class JcrExtensibleTypeProvider method ensureTypeDescriptors.

public void ensureTypeDescriptors() {
    try {
        Session session = JcrMetadataAccess.getActiveSession();
        Node typesNode = session.getRootNode().getNode(ExtensionsConstants.TYPES);
        NodeTypeManager typeMgr = (NodeTypeManager) session.getWorkspace().getNodeTypeManager();
        NodeTypeIterator typeItr = typeMgr.getPrimaryNodeTypes();
        NodeType extensionsType = typeMgr.getNodeType(ExtensionsConstants.EXTENSIBLE_ENTITY_TYPE);
        while (typeItr.hasNext()) {
            NodeType type = (NodeType) typeItr.next();
            if (type.isNodeType(ExtensionsConstants.EXTENSIBLE_ENTITY_TYPE) && !type.equals(extensionsType) && !typesNode.hasNode(type.getName())) {
                Node descrNode = typesNode.addNode(type.getName(), ExtensionsConstants.TYPE_DESCRIPTOR_TYPE);
                descrNode.setProperty("jcr:title", simpleName(type.getName()));
                descrNode.setProperty("jcr:description", "");
                PropertyDefinition[] defs = type.getPropertyDefinitions();
                for (PropertyDefinition def : defs) {
                    String fieldName = def.getName();
                    String prefix = namePrefix(fieldName);
                    if (!ExtensionsConstants.STD_PREFIXES.contains(prefix) && !descrNode.hasNode(fieldName)) {
                        Node propNode = descrNode.addNode(def.getName(), ExtensionsConstants.FIELD_DESCRIPTOR_TYPE);
                        propNode.setProperty("jcr:title", def.getName().replace("^.*:", ""));
                        propNode.setProperty("jcr:description", "");
                    }
                }
            }
        }
        NodeIterator nodeItr = typesNode.getNodes();
        while (nodeItr.hasNext()) {
            Node typeNode = (Node) nodeItr.next();
            if (!typeMgr.hasNodeType(typeNode.getName())) {
                typeNode.remove();
            }
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to ensure extensible type metadata", e);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Session(javax.jcr.Session)

Example 20 with MetadataRepositoryException

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

the class JcrExtensibleTypeProvider method deleteType.

@Override
public boolean deleteType(final ID id) {
    final Session session = getSession();
    final JcrExtensibleType.TypeId typeId = (JcrExtensibleType.TypeId) id;
    try {
        final Node typeNode = session.getNodeByIdentifier(typeId.getIdValue());
        final String typeName = typeNode.getName();
        session.getWorkspace().getNodeTypeManager().unregisterNodeType(typeName);
        session.getRootNode().getNode(ExtensionsConstants.TYPES + "/" + typeName).remove();
        return JcrExtensibleEntityProvider.cleanupDeletedType(session, typeName);
    } catch (ItemNotFoundException | NoSuchNodeTypeException | NullPointerException e) {
        // KYLO-8: Ignore NPE caused by unregistering a node type
        return true;
    } catch (UnsupportedRepositoryOperationException e) {
        return false;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to retrieve extensible type: " + id, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException)

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