use of org.eclipse.persistence.internal.jpa.rs.weaving.PersistenceWeavedRest in project eclipselink by eclipse-ee4j.
the class PersistenceContext method setRelationshipInfo.
private void setRelationshipInfo(Object entity) {
if ((entity != null) && (entity instanceof PersistenceWeavedRest)) {
ClassDescriptor descriptor = getServerSession().getClassDescriptor(entity.getClass());
if (descriptor != null) {
((PersistenceWeavedRest) entity)._persistence_setRelationships(new ArrayList<>());
for (DatabaseMapping mapping : descriptor.getMappings()) {
if (mapping.isForeignReferenceMapping()) {
ForeignReferenceMapping frMapping = (ForeignReferenceMapping) mapping;
RelationshipInfo info = new RelationshipInfo();
info.setAttributeName(frMapping.getAttributeName());
info.setOwningEntity(entity);
info.setOwningEntityAlias(descriptor.getAlias());
info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity, (AbstractSession) getServerSession()));
((PersistenceWeavedRest) entity)._persistence_getRelationships().add(info);
} else if (mapping.isEISMapping()) {
if (mapping instanceof EISCompositeCollectionMapping) {
EISCompositeCollectionMapping eisMapping = (EISCompositeCollectionMapping) mapping;
RelationshipInfo info = new RelationshipInfo();
info.setAttributeName(eisMapping.getAttributeName());
info.setOwningEntity(entity);
info.setOwningEntityAlias(descriptor.getAlias());
info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity, (AbstractSession) getServerSession()));
((PersistenceWeavedRest) entity)._persistence_getRelationships().add(info);
}
}
}
}
}
}
use of org.eclipse.persistence.internal.jpa.rs.weaving.PersistenceWeavedRest in project eclipselink by eclipse-ee4j.
the class SelfLinksResponseBuilder method generateLinksForRelationships.
private void generateLinksForRelationships(PersistenceContext context, PersistenceWeavedRest entity) {
final ClassDescriptor classDescriptor = context.getServerSession().getProject().getDescriptor(entity.getClass());
final String entityClassName = classDescriptor.getAlias();
final String entityId = IdHelper.stringifyId(entity, entityClassName, context);
for (final Field field : entity.getClass().getDeclaredFields()) {
if (PersistenceWeavedRest.class.isAssignableFrom(field.getType())) {
final PersistenceWeavedRest obj = (PersistenceWeavedRest) callGetterForProperty(entity, field.getName());
if (obj != null) {
final String fieldClassName = context.getJAXBDescriptorForClass(field.getType()).getAlias();
final String fieldId = IdHelper.stringifyId(obj, fieldClassName, context);
final ItemLinks links = (new ItemLinksBuilder()).addSelf(HrefHelper.buildEntityFieldHref(context, entityClassName, entityId, field.getName())).addCanonical(HrefHelper.buildEntityHref(context, fieldClassName, fieldId)).build();
obj._persistence_setLinks(links);
}
}
}
}
use of org.eclipse.persistence.internal.jpa.rs.weaving.PersistenceWeavedRest in project eclipselink by eclipse-ee4j.
the class PagingResponseBuilder method populatePagedReadAllQueryItemLinks.
private Object populatePagedReadAllQueryItemLinks(PersistenceContext context, Object result) {
// populate links for the entity
ClassDescriptor descriptor = context.getJAXBDescriptorForClass(result.getClass());
if ((result instanceof PersistenceWeavedRest) && (descriptor != null)) {
final PersistenceWeavedRest entity = (PersistenceWeavedRest) result;
final String href = HrefHelper.buildEntityHref(context, descriptor.getAlias(), IdHelper.stringifyId(result, descriptor.getAlias(), context));
final ItemLinks itemLinks = (new ItemLinksBuilder()).addSelf(href).addCanonical(href).build();
entity._persistence_setLinks(itemLinks);
return entity;
}
return result;
}
use of org.eclipse.persistence.internal.jpa.rs.weaving.PersistenceWeavedRest in project eclipselink by eclipse-ee4j.
the class SelfLinksResponseBuilder method collectionResponse.
private Object collectionResponse(PersistenceContext context, List<Object> results, UriInfo uriInfo) {
if ((results != null) && (!results.isEmpty())) {
final ReadAllQueryResultCollection response = new ReadAllQueryResultCollection();
for (Object item : results) {
if (item instanceof PersistenceWeavedRest) {
final PersistenceWeavedRest entity = (PersistenceWeavedRest) item;
final ClassDescriptor classDescriptor = context.getServerSession().getProject().getDescriptor(item.getClass());
final String entityClassName = classDescriptor.getAlias();
final String entityId = IdHelper.stringifyId(entity, entityClassName, context);
final String href = HrefHelper.buildEntityHref(context, entityClassName, entityId);
final ItemLinksBuilder itemLinksBuilder = (new ItemLinksBuilder()).addCanonical(href);
entity._persistence_setLinks(itemLinksBuilder.build());
generateLinksForRelationships(context, entity);
response.addItem(entity);
} else {
response.addItem(item);
}
}
response.addLink(new LinkV2(ReservedWords.JPARS_REL_SELF, uriInfo.getRequestUri().toString()));
return response;
}
return results;
}
use of org.eclipse.persistence.internal.jpa.rs.weaving.PersistenceWeavedRest in project eclipselink by eclipse-ee4j.
the class SelfLinksResponseBuilder method generateLinksInElementsList.
private void generateLinksInElementsList(PersistenceContext context, List<JAXBElement<?>> fields) {
for (JAXBElement<?> field : fields) {
if (field.getValue() instanceof PersistenceWeavedRest) {
final PersistenceWeavedRest entity = (PersistenceWeavedRest) field.getValue();
final ClassDescriptor classDescriptor = context.getServerSession().getProject().getDescriptor(entity.getClass());
final String entityClassName = classDescriptor.getAlias();
final String entityId = IdHelper.stringifyId(entity, entityClassName, context);
// No links for embedded objects
if (!classDescriptor.isAggregateDescriptor()) {
final String href = HrefHelper.buildEntityHref(context, entityClassName, entityId);
final ItemLinksBuilder itemLinksBuilder = (new ItemLinksBuilder()).addSelf(href).addCanonical(href);
entity._persistence_setLinks(itemLinksBuilder.build());
}
}
}
}
Aggregations