Search in sources :

Example 6 with ExtensibleType

use of com.thinkbiganalytics.metadata.api.extension.ExtensibleType in project kylo by Teradata.

the class ExtensionsController method updateType.

/**
 * an endpoint to allow updating of an extensible type
 *
 * @param id    the id of the extensible type
 * @param descr a descriptor with the type info
 * @return the extensible type as persisted to the metadata store
 */
@Path("type/{id}")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ExtensibleTypeDescriptor updateType(@PathParam("id") String id, ExtensibleTypeDescriptor descr) {
    return metadata.read(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ADMIN_METADATA);
        ExtensibleType.ID domainId = this.typeProvider.resolve(id);
        ExtensibleType type = ExtensiblesModel.updateType(descr, domainId, this.typeProvider);
        return ExtensiblesModel.DOMAIN_TO_TYPE.apply(type);
    });
}
Also used : ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 7 with ExtensibleType

use of com.thinkbiganalytics.metadata.api.extension.ExtensibleType in project kylo by Teradata.

the class ExtensionsController method getType.

/**
 * gets an extensible type descriptor by its' name or ID
 *
 * @param id the name or id of the desired extensible type descriptor
 * @return the extensible type descriptor
 */
@Path("type/{nameOrId}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public ExtensibleTypeDescriptor getType(@PathParam("nameOrId") String id) {
    return metadata.read(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ACCESS_METADATA);
        ExtensibleType.ID domainId = null;
        String name = null;
        ExtensibleType type = null;
        try {
            domainId = this.typeProvider.resolve(id);
        } catch (IllegalArgumentException e) {
            name = id;
        }
        if (domainId != null) {
            type = this.typeProvider.getType(domainId);
        } else {
            type = this.typeProvider.getType(name);
        }
        if (type != null) {
            return ExtensiblesModel.DOMAIN_TO_TYPE.apply(type);
        } else {
            throw new WebApplicationException("No type with the given ID exists: " + id, Response.SC_NOT_FOUND);
        }
    });
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with ExtensibleType

use of com.thinkbiganalytics.metadata.api.extension.ExtensibleType 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 9 with ExtensibleType

use of com.thinkbiganalytics.metadata.api.extension.ExtensibleType in project kylo by Teradata.

the class JcrPropertyTest method testGetPropertyTypes.

@Test
public void testGetPropertyTypes() throws RepositoryException {
    Map<String, FieldDescriptor.Type> propertyTypeMap = metadata.commit(() -> {
        provider.ensureTypeDescriptors();
        ExtensibleType feedType = provider.getType("tba:feed");
        Set<FieldDescriptor> fields = feedType.getFieldDescriptors();
        Map<String, FieldDescriptor.Type> map = new HashMap<>();
        for (FieldDescriptor field : fields) {
            map.put(field.getName(), field.getType());
        }
        return map;
    }, MetadataAccess.SERVICE);
    log.info("Property Types {} ", propertyTypeMap);
}
Also used : ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) HashMap(java.util.HashMap) ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) FieldDescriptor(com.thinkbiganalytics.metadata.api.extension.FieldDescriptor) Test(org.junit.Test)

Example 10 with ExtensibleType

use of com.thinkbiganalytics.metadata.api.extension.ExtensibleType in project kylo by Teradata.

the class JcrExtensibleProvidersTest method testGetPersonType.

@Test(dependsOnMethods = "testCreatePersonType")
public void testGetPersonType() {
    final ExtensibleType.ID id = metadata.commit(() -> {
        ExtensibleType type = typeProvider.getType("Person");
        return type.getId();
    }, MetadataAccess.SERVICE);
    assertThat(id).isNotNull();
    Map<String, FieldDescriptor.Type> fields = metadata.commit(() -> {
        ExtensibleType type = typeProvider.getType("Person");
        Map<String, FieldDescriptor.Type> map = new HashMap<>();
        for (FieldDescriptor descr : type.getFieldDescriptors()) {
            map.put(descr.getName(), descr.getType());
        }
        return map;
    }, MetadataAccess.SERVICE);
    assertThat(fields).isNotNull();
    assertThat(fields).containsEntry("name", FieldDescriptor.Type.STRING);
    assertThat(fields).containsEntry("description", FieldDescriptor.Type.STRING);
    assertThat(fields).containsEntry("age", FieldDescriptor.Type.LONG);
}
Also used : ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) HashMap(java.util.HashMap) ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) FieldDescriptor(com.thinkbiganalytics.metadata.api.extension.FieldDescriptor) Test(org.testng.annotations.Test)

Aggregations

ExtensibleType (com.thinkbiganalytics.metadata.api.extension.ExtensibleType)10 Test (org.testng.annotations.Test)4 HashMap (java.util.HashMap)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 FieldDescriptor (com.thinkbiganalytics.metadata.api.extension.FieldDescriptor)2 Consumes (javax.ws.rs.Consumes)2 ExtensibleEntity (com.thinkbiganalytics.metadata.api.extension.ExtensibleEntity)1 ExtensibleTypeBuilder (com.thinkbiganalytics.metadata.api.extension.ExtensibleTypeBuilder)1 FieldDescriptorBuilder (com.thinkbiganalytics.metadata.api.extension.FieldDescriptorBuilder)1 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 NodeType (javax.jcr.nodetype.NodeType)1 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 GET (javax.ws.rs.GET)1