/** * Constructor. * * @param value singleton resource */ public Data(T value) { this.values = new SingleElementSet<>(value); this.relationshipType = RelationshipType.MANY_TO_ONE; // Any "toOne" }
/** * Convert Resource to resource identifier. * * @return linkage */ public ResourceIdentifier toResourceIdentifier() { return new ResourceIdentifier(type, id); }
/** * Clear all properties except the relationships. */ private static void clearAllExceptRelationships(Resource resource) { resource.setAttributes(null); resource.setLinks(null); resource.setMeta(null); }
@Override public Supplier<Pair<Integer, JsonNode>> handlePatch(StateContext state) { JsonApiDocument jsonApiDocument = state.getJsonApiDocument(); Data<Resource> data = jsonApiDocument.getData(); if (data == null) { throw new InvalidEntityBodyException("Expected data but found null"); } if (!data.isToOne()) { throw new InvalidEntityBodyException("Expected single element but found list"); } Resource resource = data.getSingleValue(); if (!record.matchesId(resource.getId())) { throw new InvalidEntityBodyException("Id in response body does not match requested id to update from path"); } patch(resource, state.getRequestScope()); return constructPatchResponse(record, state); }
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; }
@SuppressWarnings("unchecked") public Collection<ResourceIdentifier> toResourceIdentifiers() { return ((Collection<Resource>) get()).stream() .map(object -> object != null ? object.toResourceIdentifier() : null) .collect(Collectors.toList()); } }
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; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Data<Resource> that = ((Relationship) o).getData(); if (that == null || data == null) { return that == data; } Collection<ResourceIdentifier> resourceIdentifiers = data.toResourceIdentifiers(); Collection<ResourceIdentifier> theirIdentifiers = that.toResourceIdentifiers(); return resourceIdentifiers.stream().allMatch(theirIdentifiers::contains); }
public Resource castToResource() { return new Resource(type, id); }
@Override public Supplier<Pair<Integer, JsonNode>> handlePatch(StateContext state) { JsonApiDocument jsonApiDocument = state.getJsonApiDocument(); Data<Resource> data = jsonApiDocument.getData(); if (data == null) { throw new InvalidEntityBodyException("Expected data but found null"); } if (!data.isToOne()) { throw new InvalidEntityBodyException("Expected single element but found list"); } Resource resource = data.getSingleValue(); if (!record.matchesId(resource.getId())) { throw new InvalidEntityBodyException("Id in response body does not match requested id to update from path"); } patch(resource, state.getRequestScope()); return constructPatchResponse(record, state); }
/** * Clear all properties except the relationships. */ private static void clearAllExceptRelationships(Resource resource) { resource.setAttributes(null); resource.setLinks(null); resource.setMeta(null); }
@SuppressWarnings("unchecked") public Collection<ResourceIdentifier> toResourceIdentifiers() { return ((Collection<Resource>) get()).stream() .map(object -> object != null ? object.toResourceIdentifier() : null) .collect(Collectors.toList()); } }
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; }
/** * Constructor. * * @param value singleton resource */ public Data(T value) { this.values = new SingleElementSet<>(value); this.relationshipType = RelationshipType.MANY_TO_ONE; // Any "toOne" }
/** * Convert Resource to resource identifier. * * @return linkage */ public ResourceIdentifier toResourceIdentifier() { return new ResourceIdentifier(type, id); }
public Resource castToResource() { return new Resource(type, id); }