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();
}
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()));
}
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());
}
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();
}
Aggregations