@Override public void delete(Object object, RequestScope requestScope) { if (object == null) { return; } String id = dictionary.getId(object); operations.add(new Operation(id, object, object.getClass(), true)); }
Class<?> parentType = dictionary.lookupEntityClass(relationship.getParentType()); Class<?> idType = dictionary.getIdType(parentType); Object idVal = CoerceUtil.coerce(dictionary.getId(relationship.getParent()), idType); String idField = dictionary.getIdFieldName(parentType);
@Override public void save(Object object, RequestScope requestScope) { if (object == null) { return; } String id = dictionary.getId(object); if (id == null || "null".equals(id) || "0".equals(id)) { createObject(object, requestScope); } id = dictionary.getId(object); operations.add(new Operation(id, object, object.getClass(), false)); }
/** * Get resource ID. * * @return ID id */ @Override public String getId() { return dictionary.getId(getObject()); }
@Override public void save(Object object, RequestScope requestScope) { if (object == null) { return; } String id = dictionary.getId(object); if (id == null || "null".equals(id) || "0".equals(id)) { createObject(object, requestScope); } id = dictionary.getId(object); operations.add(new Operation(id, object, object.getClass(), false)); }
/** * Get resource ID. * * @return ID id */ @Override public String getId() { return dictionary.getId(getObject()); }
@Override public void delete(Object object, RequestScope requestScope) { if (object == null) { return; } String id = dictionary.getId(object); operations.add(new Operation(id, object, object.getClass(), true)); }
@Override public int hashCode() { if (hashCode == 0) { // NOTE: UUID's are only present in the case of newly created objects. // Consequently, a known ID will never be present during processing (only after commit // assigned by the DB) and so we can assume that any newly created object can be fully // addressed by its UUID. It is possible for UUID and id to be unset upon a POST or PATCH // ext request, but it is safe to ignore these edge cases. // (1) In a POST request, you would not be referencing this newly created object in any way // so this is not an issue. // (2) In a PATCH ext request, this is also acceptable (assuming request is accepted) in the way // that it is acceptable in a POST. If you do not specify a UUID, there is no way to reference // that newly created object within the context of the request. Thus, if any such action was // required, the user would be forced to provide a UUID anyway. String id = dictionary.getId(getObject()); if (uuid.isPresent() && "0".equals(id)) { hashCode = Objects.hashCode(uuid); } else { hashCode = Objects.hashCode(id); } } return hashCode; }
@Override public int hashCode() { if (hashCode == 0) { // NOTE: UUID's are only present in the case of newly created objects. // Consequently, a known ID will never be present during processing (only after commit // assigned by the DB) and so we can assume that any newly created object can be fully // addressed by its UUID. It is possible for UUID and id to be unset upon a POST or PATCH // ext request, but it is safe to ignore these edge cases. // (1) In a POST request, you would not be referencing this newly created object in any way // so this is not an issue. // (2) In a PATCH ext request, this is also acceptable (assuming request is accepted) in the way // that it is acceptable in a POST. If you do not specify a UUID, there is no way to reference // that newly created object within the context of the request. Thus, if any such action was // required, the user would be forced to provide a UUID anyway. String id = dictionary.getId(getObject()); if (uuid.isPresent() && "0".equals(id)) { hashCode = Objects.hashCode(uuid); } else { hashCode = Objects.hashCode(id); } } return hashCode; }
@Override public Object getRelation(DataStoreTransaction relationTx, Object entity, String relationName, Optional<FilterExpression> filterExpression, Optional<Sorting> sorting, Optional<Pagination> pagination, RequestScope scope) { Object values = PersistentResource.getValue(entity, relationName, scope); // Gather list of valid id's from this parent Map<String, Object> idToChildResource = new HashMap<>(); if (dictionary.getRelationshipType(entity, relationName).isToOne()) { if (values == null) { return null; } idToChildResource.put(dictionary.getId(values), values); } else if (values instanceof Collection) { idToChildResource.putAll((Map) ((Collection) values).stream() .collect(Collectors.toMap(dictionary::getId, Function.identity()))); } else { throw new IllegalStateException("An unexpected error occurred querying a relationship"); } Class entityClass = dictionary.getParameterizedType(entity, relationName); return processData(entityClass, idToChildResource, filterExpression, sorting, pagination, scope); }
@Override public Object getRelation(DataStoreTransaction relationTx, Object entity, String relationName, Optional<FilterExpression> filterExpression, Optional<Sorting> sorting, Optional<Pagination> pagination, RequestScope scope) { Object values = PersistentResource.getValue(entity, relationName, scope); // Gather list of valid id's from this parent Map<String, Object> idToChildResource = new HashMap<>(); if (dictionary.getRelationshipType(entity, relationName).isToOne()) { if (values == null) { return null; } idToChildResource.put(dictionary.getId(values), values); } else if (values instanceof Collection) { idToChildResource.putAll((Map) ((Collection) values).stream() .collect(Collectors.toMap(dictionary::getId, Function.identity()))); } else { throw new IllegalStateException("An unexpected error occurred querying a relationship"); } Class entityClass = dictionary.getParameterizedType(entity, relationName); return processData(entityClass, idToChildResource, filterExpression, sorting, pagination, scope); }
@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; }
/** * Fetch a resource with support for lambda function for getting relationships and attributes. * @param relationshipSupplier The relationship supplier (getRelationships()) * @param attributeSupplier The attribute supplier * @return The Resource */ public Resource toResource(final Supplier<Map<String, Relationship>> relationshipSupplier, final Supplier<Map<String, Object>> attributeSupplier) { final Resource resource = new Resource(type, (obj == null) ? uuid.orElseThrow( () -> new InvalidEntityBodyException("No id found on object")) : dictionary.getId(obj)); resource.setRelationships(relationshipSupplier.get()); resource.setAttributes(attributeSupplier.get()); return resource; }
/** * Fetch a resource with support for lambda function for getting relationships and attributes. * @param relationshipSupplier The relationship supplier (getRelationships()) * @param attributeSupplier The attribute supplier * @return The Resource */ public Resource toResource(final Supplier<Map<String, Relationship>> relationshipSupplier, final Supplier<Map<String, Object>> attributeSupplier) { final Resource resource = new Resource(type, (obj == null) ? uuid.orElseThrow( () -> new InvalidEntityBodyException("No id found on object")) : dictionary.getId(obj)); resource.setRelationships(relationshipSupplier.get()); resource.setAttributes(attributeSupplier.get()); return resource; }