/** * Get relation looking for a _single_ id. * * NOTE: Filter expressions for this type are _not_ applied at this level. * * @param relation relation name * @param id single id to lookup * @return The PersistentResource of the sought id or null if does not exist. */ public PersistentResource getRelation(String relation, String id) { Set<PersistentResource> resources = getRelation(relation, Collections.singletonList(id), Optional.empty(), Optional.empty(), Optional.empty()); if (resources.isEmpty()) { return null; } // If this is an in-memory object (i.e. UUID being created within tx), datastore may not be able to filter. // If we get multiple results back, make sure we find the right id first. for (PersistentResource resource : resources) { if (resource.matchesId(id)) { return resource; } } return null; }
/** * Get relation looking for a _single_ id. * * NOTE: Filter expressions for this type are _not_ applied at this level. * * @param relation relation name * @param id single id to lookup * @return The PersistentResource of the sought id or null if does not exist. */ public PersistentResource getRelation(String relation, String id) { Set<PersistentResource> resources = getRelation(relation, Collections.singletonList(id), Optional.empty(), Optional.empty(), Optional.empty()); if (resources.isEmpty()) { return null; } // If this is an in-memory object (i.e. UUID being created within tx), datastore may not be able to filter. // If we get multiple results back, make sure we find the right id first. for (PersistentResource resource : resources) { if (resource.matchesId(id)) { return resource; } } return null; }
@Override public boolean equals(Object obj) { if (obj instanceof PersistentResource) { PersistentResource that = (PersistentResource) obj; if (this.getObject() == that.getObject()) { return true; } String theirId = dictionary.getId(that.getObject()); return this.matchesId(theirId) && Objects.equals(this.type, that.type); } return false; }
@Override public boolean equals(Object obj) { if (obj instanceof PersistentResource) { PersistentResource that = (PersistentResource) obj; if (this.getObject() == that.getObject()) { return true; } String theirId = dictionary.getId(that.getObject()); return this.matchesId(theirId) && Objects.equals(this.type, that.type); } return false; }
@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); }
@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); }