Search in sources :

Example 1 with DimensionSpec

use of de.metas.dimension.DimensionSpec in project metasfresh-webui-api by metasfresh.

the class MaterialCockpitRowFactory method createEmptyRowBuckets.

@VisibleForTesting
Map<MainRowBucketId, MainRowWithSubRows> createEmptyRowBuckets(@NonNull final List<I_M_Product> products, @NonNull final Timestamp timestamp) {
    final DimensionSpec dimensionSpec = Services.get(IDimensionspecDAO.class).retrieveForInternalNameOrNull(DIM_SPEC_INTERNAL_NAME);
    Check.errorIf(dimensionSpec == null, "Unable to load DIM_Dimension_Spec record with InternalName={}", DIM_SPEC_INTERNAL_NAME);
    final List<DimensionSpecGroup> groups = dimensionSpec.retrieveGroups();
    final List<I_S_Resource> plants = retrieveCountingPlants();
    final Builder<MainRowBucketId, MainRowWithSubRows> result = ImmutableMap.builder();
    for (final I_M_Product product : products) {
        final MainRowBucketId key = MainRowBucketId.createPlainInstance(product.getM_Product_ID(), timestamp);
        final MainRowWithSubRows mainRowBucket = MainRowWithSubRows.create(key);
        for (final I_S_Resource plant : plants) {
            mainRowBucket.addEmptyCountingSubrowBucket(plant.getS_Resource_ID());
        }
        for (final DimensionSpecGroup group : groups) {
            mainRowBucket.addEmptyAttributesSubrowBucket(group);
        }
        result.put(key, mainRowBucket);
    }
    return result.build();
}
Also used : DimensionSpec(de.metas.dimension.DimensionSpec) I_S_Resource(org.compiere.model.I_S_Resource) DimensionSpecGroup(de.metas.dimension.DimensionSpecGroup) I_M_Product(org.compiere.model.I_M_Product) IDimensionspecDAO(de.metas.dimension.IDimensionspecDAO) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with DimensionSpec

use of de.metas.dimension.DimensionSpec in project metasfresh-webui-api by metasfresh.

the class MaterialCockpitRowFactory method createRows.

public List<MaterialCockpitRow> createRows(@NonNull final CreateRowsRequest request) {
    final Map<MainRowBucketId, MainRowWithSubRows> emptyRowBuckets = createEmptyRowBuckets(request.getProductsToListEvenIfEmpty(), request.getDate());
    final DimensionSpec dimensionSpec = Services.get(IDimensionspecDAO.class).retrieveForInternalNameOrNull(DIM_SPEC_INTERNAL_NAME);
    Check.errorIf(dimensionSpec == null, "Unable to load DIM_Dimension_Spec record with InternalName={}", DIM_SPEC_INTERNAL_NAME);
    final Map<MainRowBucketId, MainRowWithSubRows> result = new HashMap<>(emptyRowBuckets);
    addCockpitRowsToResult(request, dimensionSpec, result);
    addStockRowsToResult(request, dimensionSpec, result);
    return result.values().stream().map(MainRowWithSubRows::createMainRowWithSubRows).collect(ImmutableList.toImmutableList());
}
Also used : DimensionSpec(de.metas.dimension.DimensionSpec) HashMap(java.util.HashMap) IDimensionspecDAO(de.metas.dimension.IDimensionspecDAO)

Aggregations

DimensionSpec (de.metas.dimension.DimensionSpec)2 IDimensionspecDAO (de.metas.dimension.IDimensionspecDAO)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 DimensionSpecGroup (de.metas.dimension.DimensionSpecGroup)1 HashMap (java.util.HashMap)1 I_M_Product (org.compiere.model.I_M_Product)1 I_S_Resource (org.compiere.model.I_S_Resource)1