@RequestMapping(value = "/Instances({instanceId})/Bags({bagName})/Indexes", method = POST, consumes = "application/json", produces = "application/json") public RestEntity writeEntry(@PathVariable String instanceId, @PathVariable String bagName, @RequestBody IndexEntry indexEntry) throws RestException { if(StringUtils.hasText(instanceId) && StringUtils.hasText(bagName)) { try { StorageService storageService = storageServiceFactory.getStorageService(instanceId, bagName); KeyInfo keyInfo = new KeyInfoImpl(indexEntry.getKeyHeader(), indexEntry.getValueHeader()); List<IndexField> indexFields = keyInfo.getIndexKeyFields(); List<IndexField> indexFieldValues = keyInfo.getIndexValueFields(); IndexField[] indexFieldValueArray = indexFieldValues.toArray(new IndexField[indexFieldValues.size()]); if (indexFields.size() > SINGLE_KEY_FIELD) { CompositeIndexField compositeIndexField = new SimpleCompositeIndexField(indexFields.toArray(new IndexField[indexFields.size()])); storageService.ensureIndex(compositeIndexField, indexEntry.isUniqueConstraint(), indexFieldValueArray); } else if (indexFields.size() == SINGLE_KEY_FIELD) { storageService.ensureIndex(indexFields.get(0), indexEntry.isUniqueConstraint(), indexFieldValueArray); } else { throw new RestException("Unable to create index, no key fields specified"); } return indexEntry; } catch (JasDBStorageException e) { throw new RestException("Unable to write index data: " + e.getMessage()); } } else { throw new RestException("No InstanceId or Bag Name where specified when creating index"); } }