@RequestMapping(value = "/Instances({instanceId})/Bags({bagName})/Indexes({indexName})", method = DELETE, consumes = "application/json", produces = "application/json") public ResponseEntity<?> removeEntry(@PathVariable String instanceId, @PathVariable String bagName, @PathVariable String indexName) throws RestException { if(StringUtils.hasText(instanceId) && StringUtils.hasText(bagName)) { LOG.debug("Removing index from instance: {} bag: {} with name: {}", instanceId, bagName, indexName); try { StorageService storageService = storageServiceFactory.getStorageService(instanceId, bagName); storageService.removeIndex(indexName); return response(null, HttpStatus.NO_CONTENT); } catch(JasDBStorageException e) { throw new RestException("Unable to remove index data: " + e.getMessage()); } } else { throw new RestException("Cannot remove index without a specified bag or InstanceId"); } }
@RequestMapping(value = "/Instances", method = POST, consumes = "application/json", produces = "application/json") public RestEntity writeEntry(@RequestBody InstanceRest dbInstance) throws RestException { try { instanceFactory.addInstance(dbInstance.getInstanceId()); return getInstance(dbInstance.getInstanceId()); } catch(JasDBStorageException e) { throw new RestException("Unable to create new instance: " + e.getMessage()); } }
@RequestMapping(value = "/Instances({instanceId})/Bags({bagName})/Entities({entityId})", produces = "application/json", method = DELETE) public RestEntity removeEntry(@PathVariable String instanceId, @PathVariable String bagName, @PathVariable String entityId, HttpServletRequest request) throws RestException { if(stringNotEmpty(instanceId) && stringNotEmpty(bagName) && stringNotEmpty(entityId)) { try { LOG.debug("Doing remove of entity with id: {}", entityId); StorageService storageService = storageServiceFactory.getOrCreateStorageService(instanceId, bagName); storageService.removeEntity(getRequestContext(request), entityId); return null; } catch(JasDBStorageException e) { throw new RestException("Unable to remove entity: " + e.getMessage()); } } else { throw new SyntaxException("Cannot remove entity, invalid parameters for delete operation"); } }
@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"); } }
private RestEntity doModificationOperation(String instanceId, String bagName, String rawData, RequestContext context, OPERATION_TYPE type) throws RestException { if(stringNotEmpty(instanceId) && stringNotEmpty(bagName)) { LOG.debug("Raw entity data received: {}", rawData); StreamedEntity streamedEntity = ENTITY_HANDLER.deserialize(StreamedEntity.class, rawData); Entity storeEntity = streamedEntity.getEntity(); try { StorageService storageService = storageServiceFactory.getOrCreateStorageService(instanceId, bagName); if(type == OPERATION_TYPE.UPDATE) { LOG.debug("Updating entity with id: {}", storeEntity.getInternalId()); storageService.persistEntity(context, storeEntity); } else if(type == OPERATION_TYPE.INSERT) { LOG.debug("Inserting new entity into bag: {}", bagName); storageService.insertEntity(context, storeEntity); } return new StreamedEntity(storeEntity); } catch(JasDBStorageException e) { throw new RestException("Unable to store entity: " + e.getMessage()); } } else { throw new SyntaxException("Cannot store entity, no Bag specified"); } }