Search in sources :

Example 51 with MetadataRepositoryException

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

the class JcrExtensibleEntityProvider method cleanupDeletedType.

protected static boolean cleanupDeletedType(Session session, String typeName) {
    try {
        String path = EntityUtil.pathForExtensibleEntity();
        Node entitiesNode = session.getNode(path);
        if (entitiesNode.hasNode(typeName)) {
            Node typesNode = entitiesNode.getNode(typeName);
            typesNode.remove();
            return true;
        } else {
            return false;
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to cleanup for deleted entity type: " + typeName, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 52 with MetadataRepositoryException

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

the class JcrExtensibleTypeProvider method getType.

@Override
public ExtensibleType getType(final ID id) {
    final JcrExtensibleType.TypeId typeId = (JcrExtensibleType.TypeId) id;
    final Session session = getSession();
    try {
        final Node typeNode = session.getNodeByIdentifier(typeId.getIdValue());
        final NodeType nodeType = session.getWorkspace().getNodeTypeManager().getNodeType(typeNode.getName());
        return new JcrExtensibleType(typeNode, nodeType);
    } catch (ItemNotFoundException e) {
        return null;
    } catch (NoSuchNodeTypeException | PathNotFoundException e) {
        return null;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failure retriving exstenible type with ID: " + id, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) Node(javax.jcr.Node) NodeType(javax.jcr.nodetype.NodeType) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 53 with MetadataRepositoryException

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

the class JcrExtensibleTypeProvider method getTypesList.

private List<ExtensibleType> getTypesList(final String typeName) {
    final Session session = getSession();
    try {
        final List<ExtensibleType> list = new ArrayList<>();
        final NodeTypeManager typeMgr = session.getWorkspace().getNodeTypeManager();
        final NodeTypeIterator typeItr = typeMgr.getPrimaryNodeTypes();
        final NodeType extensibleType = typeMgr.getNodeType(typeName);
        while (typeItr.hasNext()) {
            final NodeType nodeType = (NodeType) typeItr.next();
            if (nodeType.isNodeType(extensibleType.getName()) && !nodeType.equals(extensibleType)) {
                String nodeTypePath = ExtensionsConstants.TYPES + "/" + nodeType.getName();
                if (session.getRootNode().hasNode(nodeTypePath)) {
                    final Node typeNode = session.getRootNode().getNode(nodeTypePath);
                    list.add(new JcrExtensibleType(typeNode, nodeType));
                }
            }
        }
        return list;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to lookup all extensible types", e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeType(javax.jcr.nodetype.NodeType) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) NodeTypeIterator(javax.jcr.nodetype.NodeTypeIterator) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) Session(javax.jcr.Session)

Example 54 with MetadataRepositoryException

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

the class JcrExtensibleTypeProvider method buildType.

/**
 * Builds the type defined by the specified builder.
 *
 * @param builder the builder for the type
 * @return the type
 * @throws MetadataRepositoryException if the repository is unavailable
 * @throws TypeAlreadyExistsException  if a type with the same name already exists
 */
@Nonnull
private ExtensibleType buildType(@Nonnull final TypeBuilder builder) {
    try {
        // Remove existing type and subgraph
        if (builder.node != null) {
            builder.node.remove();
        }
        // Get or create the type node
        final Session session = getSession();
        final Node typeNode;
        if (!session.nodeExists(JcrUtil.path(session.getRootNode().getPath(), ExtensionsConstants.TYPES + "/" + builder.name).toString())) {
            typeNode = session.getRootNode().addNode(ExtensionsConstants.TYPES + "/" + builder.name, ExtensionsConstants.TYPE_DESCRIPTOR_TYPE);
        } else {
            throw new TypeAlreadyExistsException(builder.name);
        }
        // Update type metadata
        if (builder.displayName != null) {
            typeNode.setProperty(JcrExtensibleType.NAME, builder.displayName);
        }
        if (builder.description != null) {
            typeNode.setProperty(JcrExtensibleType.DESCRIPTION, builder.description);
        }
        // Update type definition
        final NodeTypeManager typeMgr = session.getWorkspace().getNodeTypeManager();
        final NodeTypeTemplate nodeTemplate = typeMgr.createNodeTypeTemplate();
        nodeTemplate.setName(builder.name);
        if (builder.supertype != null) {
            final JcrExtensibleType superImpl = (JcrExtensibleType) builder.supertype;
            final String supername = superImpl.getJcrName();
            nodeTemplate.setDeclaredSuperTypeNames(new String[] { ExtensionsConstants.EXTENSIBLE_ENTITY_TYPE, supername });
        } else {
            nodeTemplate.setDeclaredSuperTypeNames(new String[] { ExtensionsConstants.EXTENSIBLE_ENTITY_TYPE });
        }
        // Update field definitions
        @SuppressWarnings("unchecked") final List<PropertyDefinitionTemplate> propertyDefinitionTemplates = nodeTemplate.getPropertyDefinitionTemplates();
        for (final FieldBuilder bldr : builder.fieldBuilders) {
            // Create field
            PropertyDefinitionTemplate propDef = typeMgr.createPropertyDefinitionTemplate();
            propDef.setName(bldr.name);
            propDef.setRequiredType(asCode(bldr.type));
            propDef.setMandatory(bldr.required);
            propDef.setMultiple(bldr.collection);
            propertyDefinitionTemplates.add(propDef);
            // Set field metadata
            Node fieldNode = typeNode.addNode(bldr.name, ExtensionsConstants.FIELD_DESCRIPTOR_TYPE);
            for (final Map.Entry<String, String> entry : bldr.metadata.entrySet()) {
                fieldNode.setProperty(entry.getKey(), entry.getValue());
            }
        }
        NodeType nodeType = typeMgr.registerNodeType(nodeTemplate, true);
        return new JcrExtensibleType(typeNode, nodeType);
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to create type: " + builder.name, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) TypeAlreadyExistsException(com.thinkbiganalytics.metadata.modeshape.TypeAlreadyExistsException) NodeType(javax.jcr.nodetype.NodeType) HashMap(java.util.HashMap) Map(java.util.Map) Session(javax.jcr.Session) Nonnull(javax.annotation.Nonnull)

Example 55 with MetadataRepositoryException

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

the class JcrExtensibleTypeProvider method getType.

@Override
public ExtensibleType getType(final String name) {
    final Session session = getSession();
    final String typeName = ensureTypeName(name);
    try {
        final NodeType nodeType = session.getWorkspace().getNodeTypeManager().getNodeType(typeName);
        final Node typeNode = session.getRootNode().getNode(ExtensionsConstants.TYPES + "/" + typeName);
        return new JcrExtensibleType(typeNode, nodeType);
    } catch (NoSuchNodeTypeException | PathNotFoundException e) {
        return null;
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to lookup extensible type: " + name, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) NodeType(javax.jcr.nodetype.NodeType) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) Session(javax.jcr.Session) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

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