Search in sources :

Example 1 with DimensionSpecGroup

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

the class MainRowWithSubRows method findOrCreateSubRowBucket.

private List<DimensionGroupSubRowBucket> findOrCreateSubRowBucket(@NonNull final AttributesKey dataRecordAttributesKey, @NonNull final DimensionSpec dimensionSpec) {
    final ImmutableList.Builder<DimensionGroupSubRowBucket> result = ImmutableList.builder();
    DimensionSpecGroup otherGroup = null;
    boolean addedToAnyGroup = false;
    for (final DimensionSpecGroup group : dimensionSpec.retrieveGroups()) {
        final AttributesKey dimensionAttributesKey = group.getAttributesKey();
        if (DimensionSpecGroup.EMPTY_GROUP.equals(group) && AttributesKey.NONE.equals(dataRecordAttributesKey)) {
            result.add(dimensionGroupSubRows.computeIfAbsent(group, DimensionGroupSubRowBucket::create));
            addedToAnyGroup = true;
            continue;
        } else if (dataRecordAttributesKey.intersects(dimensionAttributesKey)) {
            result.add(dimensionGroupSubRows.computeIfAbsent(group, DimensionGroupSubRowBucket::create));
            addedToAnyGroup = true;
            continue;
        }
        // while iterating, also look out out for "otherGroup"
        if (DimensionSpecGroup.OTHER_GROUP.equals(group)) {
            otherGroup = group;
        }
    }
    if (!addedToAnyGroup && otherGroup != null) {
        result.add(dimensionGroupSubRows.computeIfAbsent(otherGroup, DimensionGroupSubRowBucket::create));
    }
    return result.build();
}
Also used : DimensionSpecGroup(de.metas.dimension.DimensionSpecGroup) AttributesKey(de.metas.material.event.commons.AttributesKey) ImmutableList(com.google.common.collect.ImmutableList)

Example 2 with DimensionSpecGroup

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

the class MaterialCockpitRowFactoryTest method initDimenstionSpec.

protected void initDimenstionSpec() {
    dimensionSpec = createDimensionSpec(attr1, attr1_value1, attr2);
    final List<DimensionSpecGroup> groups = dimensionSpec.retrieveGroups();
    assertThat(groups).hasSize(4);
    dimensionspecGroup_empty = groups.get(0);
    assertThat(dimensionspecGroup_empty.isEmptyGroup()).isTrue();
    dimensionspecGroup_attr1_value1 = groups.get(1);
    assertThat(dimensionspecGroup_attr1_value1.getAttributesKey()).isEqualTo(AttributesKey.ofAttributeValueIds(attr1_value1.getM_AttributeValue_ID()));
    dimensionspecGroup_attr2_value1 = groups.get(2);
    assertThat(dimensionspecGroup_attr2_value1.getAttributesKey()).isEqualTo(AttributesKey.ofAttributeValueIds(attr2_value1.getM_AttributeValue_ID()));
    final DimensionSpecGroup dimensionspecGroup_attr2_value2 = groups.get(3);
    assertThat(dimensionspecGroup_attr2_value2.getAttributesKey()).isEqualTo(AttributesKey.ofAttributeValueIds(attr2_value2.getM_AttributeValue_ID()));
}
Also used : DimensionSpecGroup(de.metas.dimension.DimensionSpecGroup)

Example 3 with DimensionSpecGroup

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

the class MaterialCockpitRowFactoryTest method createEmptyRowBuckets.

@Test
public void createEmptyRowBuckets() {
    final Timestamp today = TimeUtil.getDay(SystemTime.asTimestamp());
    // invoke method under test
    final Map<MainRowBucketId, MainRowWithSubRows> result = materialCockpitRowFactory.createEmptyRowBuckets(ImmutableList.of(product), today);
    assertThat(result).hasSize(1);
    final MainRowBucketId productIdAndDate = MainRowBucketId.createPlainInstance(product.getM_Product_ID(), today);
    assertThat(result).containsKey(productIdAndDate);
    final MainRowWithSubRows mainRowBucket = result.get(productIdAndDate);
    assertThat(mainRowBucket.getProductIdAndDate()).isEqualTo(productIdAndDate);
    final Map<DimensionSpecGroup, DimensionGroupSubRowBucket> subRowBuckets = mainRowBucket.getDimensionGroupSubRows();
    assertThat(subRowBuckets).hasSize(dimensionSpec.retrieveGroups().size());
    assertThat(subRowBuckets.keySet()).containsOnlyElementsOf(dimensionSpec.retrieveGroups());
}
Also used : DimensionSpecGroup(de.metas.dimension.DimensionSpecGroup) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 4 with DimensionSpecGroup

use of de.metas.dimension.DimensionSpecGroup 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)

Aggregations

DimensionSpecGroup (de.metas.dimension.DimensionSpecGroup)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 DimensionSpec (de.metas.dimension.DimensionSpec)1 IDimensionspecDAO (de.metas.dimension.IDimensionspecDAO)1 AttributesKey (de.metas.material.event.commons.AttributesKey)1 Timestamp (java.sql.Timestamp)1 I_M_Product (org.compiere.model.I_M_Product)1 I_S_Resource (org.compiere.model.I_S_Resource)1 Test (org.junit.Test)1