Search in sources :

Example 1 with JcrIndexDefinition

use of com.thinkbiganalytics.metadata.rest.model.jcr.JcrIndexDefinition in project kylo by Teradata.

the class DebugController method getIndexes.

@GET
@Path("jcr-index")
@Produces(MediaType.APPLICATION_JSON)
public List<JcrIndexDefinition> getIndexes() {
    return metadata.read(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ACCESS_METADATA);
        try {
            Session session = JcrMetadataAccess.getActiveSession();
            Workspace workspace = (Workspace) session.getWorkspace();
            Map<String, IndexDefinition> indexDefinitionMap = workspace.getIndexManager().getIndexDefinitions();
            if (indexDefinitionMap != null) {
                return indexDefinitionMap.entrySet().stream().map((Map.Entry<String, IndexDefinition> e) -> {
                    JcrIndexDefinition indexDefinition = new JcrIndexDefinition();
                    StringBuffer names = new StringBuffer();
                    StringBuffer types = new StringBuffer();
                    for (int i = 0; i < e.getValue().size(); i++) {
                        if (i > 0) {
                            names.append(",");
                            types.append(",");
                        }
                        int columnType = e.getValue().getColumnDefinition(i).getColumnType();
                        String propertyName = e.getValue().getColumnDefinition(i).getPropertyName();
                        names.append(propertyName);
                        types.append(PropertyType.nameFromValue(columnType));
                    }
                    indexDefinition.setIndexKind(e.getValue().getKind().name());
                    indexDefinition.setIndexName(e.getKey());
                    indexDefinition.setNodeType(e.getValue().getNodeTypeName());
                    indexDefinition.setPropertyName(names.toString());
                    indexDefinition.setPropertyTypes(types.toString());
                    return indexDefinition;
                }).collect(Collectors.toList());
            } else {
                return Collections.emptyList();
            }
        } catch (RepositoryException e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : IndexDefinition(org.modeshape.jcr.api.index.IndexDefinition) JcrIndexDefinition(com.thinkbiganalytics.metadata.rest.model.jcr.JcrIndexDefinition) RepositoryException(javax.jcr.RepositoryException) Map(java.util.Map) JcrIndexDefinition(com.thinkbiganalytics.metadata.rest.model.jcr.JcrIndexDefinition) Session(javax.jcr.Session) Workspace(org.modeshape.jcr.api.Workspace) Path(javax.ws.rs.Path) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

JcrPath (com.thinkbiganalytics.metadata.modeshape.support.JcrPath)1 JcrIndexDefinition (com.thinkbiganalytics.metadata.rest.model.jcr.JcrIndexDefinition)1 Map (java.util.Map)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Workspace (org.modeshape.jcr.api.Workspace)1 IndexDefinition (org.modeshape.jcr.api.index.IndexDefinition)1