@Reference
private SlingRepository repository;
private void createOrUpdateIndex(Node indexNode, IndexDefinition def) throws RepositoryException {
ValueFactory valueFactory = indexNode.getSession().getValueFactory();
indexNode.setProperty(PN_TYPE, TYPE_PROPERTY);
indexNode.setProperty(PN_PROPERTY_NAMES,
new Value[] { valueFactory.createValue(def.propertyName, PropertyType.NAME) });
if (def.async) {
indexNode.setProperty(PN_ASYNC, PN_ASYNC);
} else if (indexNode.hasProperty(PN_ASYNC)) {
indexNode.getProperty(PN_ASYNC).remove();
}
if (def.unique) {
indexNode.setProperty(PN_UNIQUE, true);
} else if (indexNode.hasProperty(PN_ASYNC)) {
indexNode.getProperty(PN_UNIQUE).remove();
}
if (def.declaringNodeTypes != null && def.declaringNodeTypes.length > 0) {
Value[] values = new Value[def.declaringNodeTypes.length];
for (int i = 0; i < def.declaringNodeTypes.length; i++) {
values[i] = valueFactory.createValue(def.declaringNodeTypes[0], PropertyType.NAME);
}
indexNode.setProperty(PN_DECLARING_NODE_TYPES, values);
} else if (indexNode.hasProperty(PN_DECLARING_NODE_TYPES)) {
indexNode.getProperty(PN_DECLARING_NODE_TYPES).remove();
}