Search in sources :

Example 1 with ReportQueryResultCollection

use of org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultCollection in project eclipselink by eclipse-ee4j.

the class PersistenceContext method preMarshallIndividualEntity.

/**
 * Add any data required prior to marshalling an entity to XML or JSON
 * In general, this will only affect fields that have been weaved into the object
 */
@SuppressWarnings("rawtypes")
protected void preMarshallIndividualEntity(Object entity) {
    if (entity instanceof ReportQueryResultListItem) {
        ReportQueryResultListItem item = (ReportQueryResultListItem) entity;
        for (JAXBElement field : item.getFields()) {
            // one or more fields in the MultiResultQueryListItem might be a domain object,
            // so, we need to set the relationshipInfo for those domain objects.
            setRelationshipInfo(field.getValue());
        }
    } else if (entity instanceof SingleResultQueryList) {
        SingleResultQueryList item = (SingleResultQueryList) entity;
        for (JAXBElement field : item.getFields()) {
            // one or more fields in the SingleResultQueryList might be a domain object,
            // so, we need to set the relationshipInfo for those domain objects.
            setRelationshipInfo(field.getValue());
        }
    } else if (entity instanceof ReportQueryResultList) {
        ReportQueryResultList list = (ReportQueryResultList) entity;
        for (ReportQueryResultListItem item : list.getItems()) {
            for (JAXBElement field : item.getFields()) {
                // one or more fields in the MultiResultQueryList might be a domain object,
                // so, we need to set the relationshipInfo for those domain objects.
                setRelationshipInfo(field.getValue());
            }
        }
    } else if (entity instanceof ReadAllQueryResultCollection) {
        ReadAllQueryResultCollection list = (ReadAllQueryResultCollection) entity;
        List<Object> items = list.getItems();
        if ((items != null) && (!items.isEmpty())) {
            for (Object item : items) {
                setRelationshipInfo(item);
            }
        }
    } else if (entity instanceof ReportQueryResultCollection) {
        ReportQueryResultCollection list = (ReportQueryResultCollection) entity;
        List<ReportQueryResultListItem> items = list.getItems();
        if ((items != null) && (!items.isEmpty())) {
            for (ReportQueryResultListItem item : items) {
                setRelationshipInfo(item);
            }
        }
    } else {
        setRelationshipInfo(entity);
    }
}
Also used : ReportQueryResultListItem(org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultListItem) ReportQueryResultList(org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultList) ReadAllQueryResultCollection(org.eclipse.persistence.jpa.rs.util.list.ReadAllQueryResultCollection) ArrayList(java.util.ArrayList) List(java.util.List) SingleResultQueryList(org.eclipse.persistence.jpa.rs.util.list.SingleResultQueryList) ReportQueryResultList(org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultList) JAXBElement(jakarta.xml.bind.JAXBElement) SingleResultQueryList(org.eclipse.persistence.jpa.rs.util.list.SingleResultQueryList) ReportQueryResultCollection(org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultCollection)

Example 2 with ReportQueryResultCollection

use of org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultCollection in project eclipselink by eclipse-ee4j.

the class SelfLinksResponseBuilder method buildReportQueryResponse.

@Override
public Object buildReportQueryResponse(PersistenceContext context, Map<String, Object> queryParams, List<Object[]> results, List<ReportItem> items, UriInfo uriInfo) {
    ReportQueryResultCollection response = new ReportQueryResultCollection();
    for (Object result : results) {
        ReportQueryResultListItem queryResultListItem = new ReportQueryResultListItem();
        List<JAXBElement<?>> jaxbFields = createShellJAXBElementList(items, result);
        generateLinksInElementsList(context, jaxbFields);
        queryResultListItem.setFields(jaxbFields);
        response.addItem(queryResultListItem);
    }
    response.addLink(new LinkV2(ReservedWords.JPARS_REL_SELF, uriInfo.getRequestUri().toString()));
    return response;
}
Also used : ReportQueryResultListItem(org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultListItem) JAXBElement(jakarta.xml.bind.JAXBElement) LinkV2(org.eclipse.persistence.internal.jpa.rs.metadata.model.LinkV2) ReportQueryResultCollection(org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultCollection)

Example 3 with ReportQueryResultCollection

use of org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultCollection in project eclipselink by eclipse-ee4j.

the class PagingResponseBuilder method populatePagedReportQueryCollectionLinks.

/**
 * Populate paged report query collection links.
 *
 * @param queryParams the query params
 * @param results the results
 * @param reportItems the report items
 * @param uriInfo the uri info
 * @return the pageable collection
 */
@SuppressWarnings({ "rawtypes" })
private PageableCollection populatePagedReportQueryCollectionLinks(Map<String, Object> queryParams, List<Object[]> results, List<ReportItem> reportItems, UriInfo uriInfo) {
    ReportQueryResultCollection response = new ReportQueryResultCollection();
    for (Object result : results) {
        ReportQueryResultListItem queryResultListItem = new ReportQueryResultListItem();
        List<JAXBElement<?>> jaxbFields = createShellJAXBElementList(reportItems, result);
        // We don't have a way of determining self links for the report query responses
        // so, no links array will be inserted into individual items in the response
        queryResultListItem.setFields(jaxbFields);
        response.addItem(queryResultListItem);
    }
    response.setCount(results.size());
    return populatePagedCollectionLinks(queryParams, uriInfo, response);
}
Also used : ReportQueryResultListItem(org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultListItem) JAXBElement(jakarta.xml.bind.JAXBElement) ReportQueryResultCollection(org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultCollection)

Example 4 with ReportQueryResultCollection

use of org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultCollection in project eclipselink by eclipse-ee4j.

the class ObjectGraphBuilder method createNodeForPageableCollection.

private void createNodeForPageableCollection(PageableCollection<?> collection, Node node) {
    node.addAttributeNode("hasMore");
    node.addAttributeNode("count");
    node.addAttributeNode("offset");
    node.addAttributeNode("limit");
    node.addAttributeNode("links");
    if (collection.getItems() != null && !collection.getItems().isEmpty()) {
        final Node subNode = node.addSubNode("items");
        if (collection instanceof ReportQueryResultCollection) {
            final ReportQueryResultCollection reportQueryResultCollection = (ReportQueryResultCollection) collection;
            processFieldsList(subNode.addSubNode("fields"), reportQueryResultCollection.getItems().get(0).getFields());
        } else {
            createNodeForEntity(collection.getItems().get(0), subNode);
        }
    }
}
Also used : ReportQueryResultCollection(org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultCollection)

Aggregations

ReportQueryResultCollection (org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultCollection)4 JAXBElement (jakarta.xml.bind.JAXBElement)3 ReportQueryResultListItem (org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultListItem)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 LinkV2 (org.eclipse.persistence.internal.jpa.rs.metadata.model.LinkV2)1 ReadAllQueryResultCollection (org.eclipse.persistence.jpa.rs.util.list.ReadAllQueryResultCollection)1 ReportQueryResultList (org.eclipse.persistence.jpa.rs.util.list.ReportQueryResultList)1 SingleResultQueryList (org.eclipse.persistence.jpa.rs.util.list.SingleResultQueryList)1