private static <T> Map<IResourceId, T> readConfigs(IResourceStore<T> store, List<URI> configUris) throws IResourceStore.ResourceNotFoundException, IResourceStore.ResourceStoreException { Map<IResourceId, T> ret = new LinkedHashMap<>(); for (URI uri : configUris) { IResourceId resourceId = RestUtilities.extractResourceId(uri); ret.put(resourceId, store.read(resourceId.getId(), resourceId.getVersion())); } return ret; }
protected Response create(T obj) { try { IResourceStore.IResourceId resourceId = resourceStore.create(obj); URI createdUri = RestUtilities.createURI(resourceURI, resourceId.getId(), versionQueryParam, resourceId.getVersion()); return Response.created(createdUri).location(createdUri).build(); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(); } }
protected Response delete(String id, Integer version) { version = validateParameters(id, version); try { resourceStore.delete(id, version); return Response.ok().build(); } catch (IResourceStore.ResourceModifiedException e) { throwConflictException(id, e); return null; } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(); } }
private Response throwConflictException(String id, IResourceStore.ResourceModifiedException e) { try { IResourceStore.IResourceId currentId = resourceStore.getCurrentResourceId(id); throw RestUtilities.createConflictException(resourceURI, currentId); } catch (IResourceStore.ResourceNotFoundException e1) { throw new NotFoundException(e.getLocalizedMessage(), e); } }
protected Response update(String id, Integer version, T document) { version = validateParameters(id, version); RuntimeUtilities.checkNotNull(document, "document"); try { Integer newVersion = resourceStore.update(id, version, document); URI newResourceUri = RestUtilities.createURI(resourceURI, id, versionQueryParam, newVersion); return Response.ok().location(newResourceUri).build(); } catch (IResourceStore.ResourceModifiedException e) { return throwConflictException(id, e); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(); } }
Integer highestPermittedVersion = getHighestPermittedVersion(currentVersion, permissions.getPermissions()); if (highestPermittedVersion < currentVersion) { model = resourceStore.read(id, highestPermittedVersion);
protected T read(String id, Integer version) { RuntimeUtilities.checkNotNull(id, "id"); RuntimeUtilities.checkNotNull(version, "version"); RuntimeUtilities.checkNotNegative(version, "version"); try { return resourceStore.read(id, version); } catch (IResourceStore.ResourceNotFoundException e) { throw new NotFoundException(e.getLocalizedMessage(), e); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage(), e); } }