private boolean post(Data<Resource> data, RequestScope requestScope) { if (data == null) { throw new InvalidEntityBodyException("Expected data but received null"); } Collection<Resource> resources = data.get(); if (resources == null) { return false; } resources.stream().forEachOrdered(resource -> record.addRelation(relationshipName, resource.toPersistentResource(requestScope))); return true; }
private boolean post(Data<Resource> data, RequestScope requestScope) { if (data == null) { throw new InvalidEntityBodyException("Expected data but received null"); } Collection<Resource> resources = data.get(); if (resources == null) { return false; } resources.stream().forEachOrdered(resource -> record.addRelation(relationshipName, resource.toPersistentResource(requestScope))); return true; }
public Set<PersistentResource> toPersistentResources(RequestScope requestScope) throws ForbiddenAccessException, InvalidObjectIdentifierException { Set<PersistentResource> res = new LinkedHashSet<>(); if (data == null) { return null; } Collection<Resource> resources = data.get(); if (resources != null) { for (Resource resource : resources) { try { if (data.isToOne() && resource == null) { continue; } res.add(resource.toPersistentResource(requestScope)); } catch (ForbiddenAccessException e) { //skip resource } } } return res.isEmpty() ? (data.isToOne() ? null : res) : res; }
private boolean delete(Data<Resource> data, RequestScope requestScope) { if (data == null) { throw new InvalidEntityBodyException("Expected data but received null"); } Collection<Resource> resources = data.get(); if (resources == null || resources.isEmpty()) { // As per: http://jsonapi.org/format/#crud-updating-relationship-responses-403 throw new ForbiddenAccessException("Unknown update"); } resources.stream().forEachOrdered(resource -> record.removeRelation(relationshipName, resource.toPersistentResource(requestScope))); return true; } }
private boolean delete(Data<Resource> data, RequestScope requestScope) { if (data == null) { throw new InvalidEntityBodyException("Expected data but received null"); } Collection<Resource> resources = data.get(); if (resources == null || resources.isEmpty()) { // As per: http://jsonapi.org/format/#crud-updating-relationship-responses-403 throw new ForbiddenAccessException("Unknown update"); } resources.stream().forEachOrdered(resource -> record.removeRelation(relationshipName, resource.toPersistentResource(requestScope))); return true; } }
public Set<PersistentResource> toPersistentResources(RequestScope requestScope) throws ForbiddenAccessException, InvalidObjectIdentifierException { Set<PersistentResource> res = new LinkedHashSet<>(); if (data == null) { return null; } Collection<Resource> resources = data.get(); if (resources != null) { for (Resource resource : resources) { try { if (data.isToOne() && resource == null) { continue; } res.add(resource.toPersistentResource(requestScope)); } catch (ForbiddenAccessException e) { //skip resource } } } return res.isEmpty() ? (data.isToOne() ? null : res) : res; }