private List<EntityBag> getBags(DBInstance bagInstance) throws JasDBStorageException { List<Bag> bagMetas = bagInstance.getBags(); List<EntityBag> bags = new ArrayList<>(); for(Bag bagMeta : bagMetas) { bags.add(new EntityBagImpl(bagInstance.getInstanceId(), bagMeta.getName(), userSession)); } return bags; }
private EntityBag getBag(DBInstance bagInstance, String bagName) throws JasDBStorageException { Bag bagMeta = bagInstance.getBag(bagName); if(bagMeta != null) { return new EntityBagImpl(bagInstance.getInstanceId(), bagMeta.getName(), userSession); } else { return null; } }
@Override public void removeBag(String bagName) throws JasDBStorageException { instance.removeBag(bagName); }
@Override public String getInstanceId() throws JasDBStorageException { return instance != null ? instance.getInstanceId() : null; }
private List<InstanceRest> loadInstances() throws RestException { List<InstanceRest> instances = new ArrayList<>(); for(DBInstance instance : instanceFactory.listInstances()) { instances.add(new InstanceRest(instance.getPath(), "OK", engineManager.getEngineVersion(), instance.getInstanceId())); } return instances; }
@Override public EntityBag createOrGetBag(String bagName) throws JasDBStorageException { return new EntityBagImpl(instance.getInstanceId(), bagName, userSession); }
private InstanceRest loadInstance(String instanceId) throws RestException { try { DBInstance dbInstance = instanceFactory.getInstance(instanceId); return new InstanceRest(dbInstance.getPath(), "OK", engineManager.getEngineVersion(), dbInstance.getInstanceId()); } catch(ConfigurationException e) { throw new RestException("Unable to retrieve the instance", e); } }
@RequestMapping(value = "/Bags({bagName})/Entities({entityQuery:.*})") public void queryEntities(@PathVariable String bagName, @PathVariable String entityQuery, @RequestParam(required = false, defaultValue = "0") int begin, @RequestParam(required = false, defaultValue = "-1") int max, @RequestParam(required = false, defaultValue = "") String orderBy, HttpServletRequest request, HttpServletResponse response) throws JasDBException, UnsupportedEncodingException { DBInstance instance = dbInstanceFactory.getInstance(); queryEntities(instance.getInstanceId(), bagName, begin, max, orderBy, entityQuery, request, response); }
private ResponseEntity<RestEntity> handleList(String instanceId) throws RestException { LOG.debug("Retrieving full list of bags on storage instance: {}", instanceId); List<RestBag> bags = new ArrayList<>(); try { DBInstance instance = getInstance(instanceFactory, instanceId); for(Bag bag : instance.getBags()) { StorageService storageService = storageServiceFactory.getStorageService(instance.getInstanceId(), bag.getName()); bags.add(new RestBag(instance.getInstanceId(), bag.getName(), storageService.getSize(), storageService.getDiskSize())); } } catch(JasDBStorageException e) { throw new RestException("Unable to load bags", e); } return ok(new BagCollection(bags)); }
@Override public void removeBag(String instanceId, String bagName) throws JasDBStorageException { getInstance(instanceId).removeBag(bagName); }
private ResponseEntity<?> removeBag(String instanceId, String bagName) throws JasDBException { DBInstance instance = getInstance(instanceFactory, instanceId); if(storageServiceFactory.getStorageService(instance.getInstanceId(), bagName) != null) { storageServiceFactory.removeStorageService(instance.getInstanceId(), bagName); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } else { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } }
@RequestMapping(value = "/Bags({bagName})/Entities") public void getEntities(@PathVariable String bagName, @RequestParam(required = false, defaultValue = "-1") int top, HttpServletRequest request, HttpServletResponse response) throws JasDBException { String instanceId = ControllerUtil.getInstance(dbInstanceFactory, null).getInstanceId(); LOG.debug("Entity listing request instance/bag {}/{} top: {}", instanceId, bagName, top); OutputHandler.createResponse(handleCollection(request, instanceId, bagName, top), response); }
private IndexManager getIndexManager(String instanceId) throws JasDBException { DBInstance instance = ControllerUtil.getInstance(dbInstanceFactory, instanceId); return indexManagerFactory.getIndexManager(instance.getInstanceId()); }
@Override public EntityBag createOrGetBag(String instanceId, String bagName) throws JasDBStorageException { return new EntityBagImpl(getInstance(instanceId).getInstanceId(), bagName, userSession); }
@Override public Instance deleteInstance(String instanceId) throws JasDBStorageException { Instance deleteInstance = getInstance(instanceId); //in case we are deleting the current connected instance let's switch to default context if(this.instance != null && deleteInstance.getInstanceId().equals(this.instance.getInstanceId())) { this.instance = instanceFactory.getInstance(); } instanceFactory.deleteInstance(instanceId); return this.instance; }
private ResponseEntity<RestEntity> doSearch(String instanceId, String bagName) throws JasDBException { DBInstance instance = getInstance(instanceFactory, instanceId); LOG.debug("Searching for a bag on instance: {} with name: {}", instanceId, bagName); try { StorageService storageService = storageServiceFactory.getStorageService(instance.getInstanceId(), bagName); if(storageService != null) { LOG.debug("Found a bag with name: {}", bagName); return ok(new RestBag(instance.getInstanceId(), bagName, storageService.getSize(), storageService.getDiskSize())); } else { return notFound(new ErrorEntity(404, "No bag was found with name: " + bagName)); } } catch(JasDBStorageException e) { throw new RestException("Unable to load bag metadata", e); } }
private ResponseEntity<RestEntity> createBag(String instanceId, RestBag bag) throws JasDBException { DBInstance instance = getInstance(instanceFactory, instanceId); LOG.debug("Creating on instance: {} bag: {}", instanceId, bag); if(StringUtils.stringNotEmpty(bag.getName())) { StorageService storageService = storageServiceFactory.getOrCreateStorageService(instance.getInstanceId(), bag.getName()); return ok(new RestBag(instance.getInstanceId(), bag.getName(), storageService.getSize(), storageService.getDiskSize())); } else { throw new RestException("Cannot create bag, no name specified"); } }