Adding an invalid index hides existing valid indexes
@@ -423,12 +423,18 @@ public class DebugController {
return metadata.commit(() -> {
this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ADMIN_METADATA);
- try {
Session session = JcrMetadataAccess.getActiveSession();
Workspace workspace = (Workspace) session.getWorkspace();
- ModeshapeIndexUtil.registerIndex(workspace.getIndexManager(), indexDefinition.getIndexName(), IndexDefinition.IndexKind.valueOf(indexDefinition.getIndexKind().toUpperCase()), "local", indexDefinition.getNodeType(), indexDefinition.getDescription(), null, indexDefinition.getPropertyName(),
+ String nodeType = indexDefinition.getNodeType();
+ try {
+ if (workspace.getNodeTypeManager().hasNodeType(nodeType)) {
+ ModeshapeIndexUtil.registerIndex(workspace.getIndexManager(), indexDefinition.getIndexName(), IndexDefinition.IndexKind.valueOf(indexDefinition.getIndexKind().toUpperCase()),
+ "local", nodeType, indexDefinition.getDescription(), null, indexDefinition.getPropertyName(),
indexDefinition.getPropertyType());
return RestResponseStatus.SUCCESS;
+ } else {
+ throw new IllegalArgumentException(String.format("Unknown Index Node Type %s", nodeType));
+ }
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
