Search in sources :

Example 1 with DataSet

use of io.jmix.reports.entity.DataSet in project jmix by jmix-framework.

the class MultiEntityDataLoader method loadData.

@Override
public List<Map<String, Object>> loadData(ReportQuery dataSet, BandData parentBand, Map<String, Object> params) {
    Map<String, Object> additionalParams = dataSet.getAdditionalParams();
    String paramName = (String) additionalParams.get(DataSet.LIST_ENTITIES_PARAM_NAME);
    if (StringUtils.isBlank(paramName)) {
        paramName = DEFAULT_LIST_ENTITIES_PARAM_NAME;
    }
    boolean hasNestedCollection = paramName.contains(NESTED_COLLECTION_SEPARATOR);
    String entityParameterName = StringUtils.substringBefore(paramName, NESTED_COLLECTION_SEPARATOR);
    String nestedCollectionName = StringUtils.substringAfter(paramName, NESTED_COLLECTION_SEPARATOR);
    FetchPlan nestedCollectionFetchPLan = null;
    dataSet = ProxyWrapper.unwrap(dataSet);
    Object entities = null;
    if (params.containsKey(paramName)) {
        entities = params.get(paramName);
    } else if (hasNestedCollection && params.containsKey(entityParameterName)) {
        Entity entity = (Entity) params.get(entityParameterName);
        entity = reloadEntityByDataSetFetchPlan(dataSet, entity);
        if (entity != null) {
            entities = EntityValues.getValueEx(entity, nestedCollectionName);
            if (dataSet instanceof DataSet) {
                FetchPlan entityFetchPlan = getFetchPlan(entity, (DataSet) dataSet);
                if (entityFetchPlan != null && entityFetchPlan.getProperty(nestedCollectionName) != null) {
                    // noinspection ConstantConditions
                    nestedCollectionFetchPLan = entityFetchPlan.getProperty(nestedCollectionName).getFetchPlan();
                }
            }
        }
    }
    if (!(entities instanceof Collection)) {
        if (hasNestedCollection) {
            throw new IllegalStateException(String.format("Input parameters do not contain '%s' parameter, " + "or the entity does not contain nested collection '%s'", entityParameterName, nestedCollectionName));
        } else {
            throw new IllegalStateException(String.format("Input parameters do not contain '%s' parameter or it has type other than collection", paramName));
        }
    }
    Collection<Entity> entitiesList = (Collection) entities;
    params.put(paramName, entitiesList);
    List<Map<String, Object>> resultList = new ArrayList<>();
    for (Entity entity : entitiesList) {
        if (!hasNestedCollection) {
            entity = reloadEntityByDataSetFetchPlan(dataSet, entity);
        }
        if (dataSet instanceof DataSet) {
            if (hasNestedCollection) {
                if (nestedCollectionFetchPLan != null) {
                    resultList.add(new EntityMap(entity, nestedCollectionFetchPLan, beanFactory));
                } else {
                    resultList.add(new EntityMap(entity, beanFactory));
                }
            } else {
                resultList.add(new EntityMap(entity, getFetchPlan(entity, (DataSet) dataSet), beanFactory));
            }
        } else {
            resultList.add(new EntityMap(entity, beanFactory));
        }
    }
    return resultList;
}
Also used : Entity(io.jmix.core.Entity) DataSet(io.jmix.reports.entity.DataSet) ArrayList(java.util.ArrayList) FetchPlan(io.jmix.core.FetchPlan) EntityMap(io.jmix.reports.app.EntityMap) Collection(java.util.Collection) EntityMap(io.jmix.reports.app.EntityMap) Map(java.util.Map)

Example 2 with DataSet

use of io.jmix.reports.entity.DataSet in project jmix by jmix-framework.

the class ReportGsonSerializationSupport method readUnresolvedProperty.

@Override
protected void readUnresolvedProperty(Entity entity, String propertyName, JsonReader in) throws IOException {
    if (entity instanceof DataSet && "fetchPlan".equals(propertyName)) {
        String fetchPlanDefinition = in.nextString();
        FetchPlan fetchPlan = gsonBuilder.create().fromJson(fetchPlanDefinition, FetchPlan.class);
        ((DataSet) entity).setFetchPlan(fetchPlan);
    } else {
        super.readUnresolvedProperty(entity, propertyName, in);
    }
}
Also used : DataSet(io.jmix.reports.entity.DataSet) FetchPlan(io.jmix.core.FetchPlan)

Example 3 with DataSet

use of io.jmix.reports.entity.DataSet in project jmix by jmix-framework.

the class CrossTabTableDecorator method initListeners.

protected void initListeners(CollectionContainer<DataSet> dataSetsDc, InstanceContainer<BandDefinition> bandDefinitionDc) {
    bandDefinitionDc.addItemPropertyChangeListener(e -> {
        if ("orientation".equals(e.getProperty())) {
            Orientation orientation = (Orientation) e.getValue();
            Orientation prevOrientation = (Orientation) e.getPrevValue();
            if (orientation == prevOrientation)
                return;
            if (Orientation.CROSS == orientation || Orientation.CROSS == prevOrientation) {
                onOrientationChange(dataSetsDc, bandDefinitionDc);
            }
            if (Orientation.CROSS == orientation) {
                DataSet horizontal = getOrCreateDataSet(bandDefinitionDc, dataSetsDc, Orientation.HORIZONTAL);
                DataSet vertical = getOrCreateDataSet(bandDefinitionDc, dataSetsDc, Orientation.VERTICAL);
                dataSetsDc.getMutableItems().add(horizontal);
                dataSetsDc.getMutableItems().add(vertical);
            }
        }
        if ("name".equals(e.getProperty()) && bandDefinitionDc.getItem().getOrientation() == Orientation.CROSS) {
            DataSet horizontal = getOrCreateDataSet(bandDefinitionDc, dataSetsDc, Orientation.HORIZONTAL);
            DataSet vertical = getOrCreateDataSet(bandDefinitionDc, dataSetsDc, Orientation.VERTICAL);
            onHorizontalSetChange(horizontal);
            onVerticalSetChange(vertical);
        }
    });
}
Also used : DataSet(io.jmix.reports.entity.DataSet) Orientation(io.jmix.reports.entity.Orientation)

Example 4 with DataSet

use of io.jmix.reports.entity.DataSet in project jmix by jmix-framework.

the class AbstractEntityDataLoader method reloadEntityByDataSetFetchPlan.

@Nullable
protected Entity reloadEntityByDataSetFetchPlan(ReportQuery reportQuery, Object inputObject) {
    Entity entity = null;
    if (inputObject instanceof Entity && reportQuery instanceof DataSet) {
        entity = (Entity) inputObject;
        DataSet dataSet = (DataSet) reportQuery;
        FetchPlan fetchPlan = getFetchPlan(entity, dataSet);
        if (fetchPlan != null) {
            entity = reloadEntity(entity, fetchPlan);
        }
    }
    return entity;
}
Also used : DataSet(io.jmix.reports.entity.DataSet) Nullable(javax.annotation.Nullable)

Example 5 with DataSet

use of io.jmix.reports.entity.DataSet in project jmix by jmix-framework.

the class SingleEntityDataLoader method loadData.

@Override
public List<Map<String, Object>> loadData(ReportQuery dataSet, BandData parentBand, Map<String, Object> params) {
    Map<String, Object> additionalParams = dataSet.getAdditionalParams();
    String paramName = (String) additionalParams.get(DataSet.ENTITY_PARAM_NAME);
    if (StringUtils.isBlank(paramName)) {
        paramName = DEFAULT_ENTITY_PARAM_NAME;
    }
    Object entity = params.get(paramName);
    if (entity == null) {
        throw new IllegalStateException(String.format("Input parameters do not contain '%s' parameter", paramName));
    }
    dataSet = ProxyWrapper.unwrap(dataSet);
    entity = reloadEntityByDataSetFetchPlan(dataSet, entity);
    params.put(paramName, entity);
    EntityMap result;
    if (dataSet instanceof DataSet) {
        result = new EntityMap((Entity) entity, getFetchPlan((Entity) entity, (DataSet) dataSet), beanFactory);
    } else {
        result = new EntityMap((Entity) entity, beanFactory);
    }
    return Collections.singletonList(result);
}
Also used : Entity(io.jmix.core.Entity) EntityMap(io.jmix.reports.app.EntityMap) DataSet(io.jmix.reports.entity.DataSet)

Aggregations

DataSet (io.jmix.reports.entity.DataSet)6 Entity (io.jmix.core.Entity)2 FetchPlan (io.jmix.core.FetchPlan)2 EntityMap (io.jmix.reports.app.EntityMap)2 Orientation (io.jmix.reports.entity.Orientation)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1