@Override public String toString() { return String.format("PersistentResource{type=%s, id=%s}", type, uuid.orElse(getId())); }
@Override public String toString() { return String.format("PersistentResource{type=%s, id=%s}", type, uuid.orElse(getId())); }
/** * Check whether an id matches for this persistent resource. * * @param checkId the check id * @return True if matches false otherwise */ @Override public boolean matchesId(String checkId) { if (checkId == null) { return false; } return uuid .map(checkId::equals) .orElseGet(() -> { String id = getId(); return !"0".equals(id) && checkId.equals(id); }); }
@Override public void serialize(DeferredId deferredId, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeObject(deferredId.getResource().getId()); } }
@Override public void serialize(DeferredId deferredId, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeObject(deferredId.getResource().getId()); } }
/** * Check whether an id matches for this persistent resource. * * @param checkId the check id * @return True if matches false otherwise */ @Override public boolean matchesId(String checkId) { if (checkId == null) { return false; } return uuid .map(checkId::equals) .orElseGet(() -> { String id = getId(); return !"0".equals(id) && checkId.equals(id); }); }
/** * Get relationship mappings. * * @param relationshipFunction a function to load the value of a relationship. Takes a string of the relationship * name and returns the relationship's value. * @return Relationship mapping */ protected Map<String, Relationship> getRelationshipsWithRelationshipFunction( final Function<String, Set<PersistentResource>> relationshipFunction) { final Map<String, Relationship> relationshipMap = new LinkedHashMap<>(); final Set<String> relationshipFields = filterFields(dictionary.getRelationships(obj)); for (String field : relationshipFields) { TreeMap<String, Resource> orderedById = new TreeMap<>(lengthFirstComparator); for (PersistentResource relationship : relationshipFunction.apply(field)) { orderedById.put(relationship.getId(), new ResourceIdentifier(relationship.getType(), relationship.getId()).castToResource()); } Collection<Resource> resources = orderedById.values(); Data<Resource> data; RelationshipType relationshipType = getRelationshipType(field); if (relationshipType.isToOne()) { data = resources.isEmpty() ? new Data<>((Resource) null) : new Data<>(resources.iterator().next()); } else { data = new Data<>(resources); } // TODO - links relationshipMap.put(field, new Relationship(null, data)); } return relationshipMap; }
/** * Get relationship mappings. * * @param relationshipFunction a function to load the value of a relationship. Takes a string of the relationship * name and returns the relationship's value. * @return Relationship mapping */ protected Map<String, Relationship> getRelationshipsWithRelationshipFunction( final Function<String, Set<PersistentResource>> relationshipFunction) { final Map<String, Relationship> relationshipMap = new LinkedHashMap<>(); final Set<String> relationshipFields = filterFields(dictionary.getRelationships(obj)); for (String field : relationshipFields) { TreeMap<String, Resource> orderedById = new TreeMap<>(lengthFirstComparator); for (PersistentResource relationship : relationshipFunction.apply(field)) { orderedById.put(relationship.getId(), new ResourceIdentifier(relationship.getType(), relationship.getId()).castToResource()); } Collection<Resource> resources = orderedById.values(); Data<Resource> data; RelationshipType relationshipType = getRelationshipType(field); if (relationshipType.isToOne()) { data = resources.isEmpty() ? new Data<>((Resource) null) : new Data<>(resources.iterator().next()); } else { data = new Data<>(resources); } // TODO - links relationshipMap.put(field, new Relationship(null, data)); } return relationshipMap; }