Skip to content

Commit

Permalink
HUsToPickViewFactory (WIP); refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Dec 5, 2017
1 parent c539e79 commit c9bc543
Show file tree
Hide file tree
Showing 15 changed files with 749 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.metas.ui.web.handlingunits;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import de.metas.ui.web.view.ViewFactory;
import de.metas.ui.web.view.json.JSONViewDataType;

/*
* #%L
* metasfresh-webui-api
* %%
* Copyright (C) 2017 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

@ViewFactory(windowId = WEBUI_HU_Constants.WEBUI_HU_Window_ID_String, viewTypes = { JSONViewDataType.grid, JSONViewDataType.includedView })
public class DefaultHUEditorViewFactory extends HUEditorViewFactoryTemplate
{
@Autowired
protected DefaultHUEditorViewFactory(final List<HUEditorViewCustomizer> viewCustomizers)
{
super(viewCustomizers);
}

}
74 changes: 61 additions & 13 deletions src/main/java/de/metas/ui/web/handlingunits/HUEditorRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -92,49 +93,70 @@ public static final HUEditorRow cast(final IViewRow viewRow)
private final boolean topLevel;
private final boolean processed;

static final String COLUMNNAME_M_HU_ID = I_M_HU.COLUMNNAME_M_HU_ID;
@ViewColumn(fieldName = COLUMNNAME_M_HU_ID, widgetType = DocumentFieldWidgetType.Integer)
public static final String FIELDNAME_M_HU_ID = I_M_HU.COLUMNNAME_M_HU_ID;
@ViewColumn(fieldName = FIELDNAME_M_HU_ID, widgetType = DocumentFieldWidgetType.Integer)
private final int huId;

@ViewColumn(captionKey = "HUCode", widgetType = DocumentFieldWidgetType.Text, layouts = {
public static final String FIELDNAME_HUCode = "HUCode";
@ViewColumn(fieldName = FIELDNAME_HUCode, widgetType = DocumentFieldWidgetType.Text, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 10),
@ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 10)
})
private final String code;

@ViewColumn(captionKey = "M_Product_ID", widgetType = DocumentFieldWidgetType.Lookup, layouts = {
public static final String FIELDNAME_Product = "M_Product_ID";
@ViewColumn(fieldName = FIELDNAME_Product, widgetType = DocumentFieldWidgetType.Lookup, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 20),
@ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 20)
})
private final JSONLookupValue product;

@ViewColumn(captionKey = "HU_UnitType", widgetType = DocumentFieldWidgetType.Text, layouts = {
public static final String FIELDNAME_HU_UnitType = "HU_UnitType";
@ViewColumn(fieldName = FIELDNAME_HU_UnitType, widgetType = DocumentFieldWidgetType.Text, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 30)
})
private final JSONLookupValue huUnitType;

@ViewColumn(captionKey = "M_HU_PI_Item_Product_ID", widgetType = DocumentFieldWidgetType.Text, layouts = {
public static final String FIELDNAME_PackingInfo = "M_HU_PI_Item_Product_ID";
@ViewColumn(fieldName = FIELDNAME_PackingInfo, widgetType = DocumentFieldWidgetType.Text, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 40),
@ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 40)
})
private final String packingInfo;

@ViewColumn(captionKey = "QtyCU", widgetType = DocumentFieldWidgetType.Quantity, layouts = {
public static final String FIELDNAME_QtyCU = "QtyCU";
@ViewColumn(fieldName = FIELDNAME_QtyCU, widgetType = DocumentFieldWidgetType.Quantity, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 50),
@ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 50)
})
private final BigDecimal qtyCU;

@ViewColumn(captionKey = "C_UOM_ID", widgetType = DocumentFieldWidgetType.Lookup, layouts = {
public static final String FIELDNAME_UOM = "C_UOM_ID";
@ViewColumn(fieldName = FIELDNAME_UOM, widgetType = DocumentFieldWidgetType.Lookup, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 60),
})
private final JSONLookupValue uom;

@ViewColumn(captionKey = "HUStatus", widgetType = DocumentFieldWidgetType.Lookup, layouts = {
public static final String FIELDNAME_HUStatus = "HUStatus";
@ViewColumn(fieldName = FIELDNAME_HUStatus, widgetType = DocumentFieldWidgetType.Lookup, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 70),
})
private final JSONLookupValue huStatus;

public static final String FIELDNAME_BestBeforeDate = "BestBeforeDate";
@ViewColumn(fieldName = FIELDNAME_BestBeforeDate, widgetType = DocumentFieldWidgetType.Date, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 80, displayed = false),
@ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 80, displayed = false)
})
private final Date bestBeforeDate;

public static final String FIELDNAME_Locator = "M_Locator_ID";
@ViewColumn(fieldName = FIELDNAME_Locator, widgetType = DocumentFieldWidgetType.Lookup, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 90, displayed = false),
@ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 90, displayed = false)
})
private final JSONLookupValue locator;

private final Supplier<HUEditorRowAttributes> attributesSupplier;

private final List<HUEditorRow> includedRows;
Expand All @@ -159,6 +181,8 @@ private HUEditorRow(final Builder builder)
product = builder.product;
uom = builder.uom;
qtyCU = builder.qtyCU;
bestBeforeDate = builder.getBestBeforeDate();
locator = builder.getLocator();

includedRows = builder.buildIncludedRows();

Expand Down Expand Up @@ -199,7 +223,7 @@ public DocumentId getId()
{
return getHURowId().toDocumentId();
}

/**
* @return {@link HUEditorRowType}; never returns null.
*/
Expand Down Expand Up @@ -284,7 +308,7 @@ private static Stream<HUEditorRow> streamRecursive(final HUEditorRow row)
.map(includedRow -> streamRecursive(includedRow))
.reduce(Stream.of(row), Stream::concat);
}

public Optional<HUEditorRow> getIncludedRowById(final DocumentId rowId)
{
return streamRecursive()
Expand Down Expand Up @@ -376,7 +400,7 @@ public boolean isLU()
{
return getType() == HUEditorRowType.LU;
}

public boolean hasIncludedTUs()
{
return getIncludedRows().stream().anyMatch(HUEditorRow::isTU);
Expand Down Expand Up @@ -533,6 +557,8 @@ public static final class Builder
private JSONLookupValue product;
private JSONLookupValue uom;
private BigDecimal qtyCU;
private Date bestBeforeDate;
private JSONLookupValue locator;

private List<HUEditorRow> includedRows = null;

Expand Down Expand Up @@ -566,7 +592,7 @@ private HUEditorRowId getRowId()
Check.assumeNotNull(_rowId, "Parameter rowId is not null");
return _rowId;
}

private HUEditorRowType getType()
{
Check.assumeNotNull(type, "Parameter type is not null");
Expand Down Expand Up @@ -653,6 +679,28 @@ public Builder setQtyCU(final BigDecimal qtyCU)
return this;
}

public Builder setBestBeforeDate(final Date bestBeforeDate)
{
this.bestBeforeDate = bestBeforeDate;
return this;
}

private Date getBestBeforeDate()
{
return bestBeforeDate != null ? (Date)bestBeforeDate.clone() : null;
}

public Builder setLocator(final JSONLookupValue locator)
{
this.locator = locator;
return this;
}

private JSONLookupValue getLocator()
{
return locator;
}

private HUEditorRowAttributesProvider getAttributesProviderOrNull()
{
return attributesProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package de.metas.ui.web.handlingunits;

import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.adempiere.mm.attributes.api.IAttributeDAO;
import org.adempiere.mm.attributes.spi.IAttributeValueContext;
import org.adempiere.mm.attributes.spi.impl.DefaultAttributeValueContext;
import org.adempiere.util.Check;
Expand All @@ -19,6 +21,7 @@
import com.google.common.base.MoreObjects;

import de.metas.handlingunits.IHUAware;
import de.metas.handlingunits.attribute.Constants;
import de.metas.handlingunits.attribute.IAttributeValue;
import de.metas.handlingunits.attribute.storage.IAttributeStorage;
import de.metas.handlingunits.attribute.storage.IAttributeStorageListener;
Expand Down Expand Up @@ -73,7 +76,7 @@ public static final HUEditorRowAttributes cast(final IViewRowAttributes attribut
{
return (HUEditorRowAttributes)attributes;
}

private final DocumentPath documentPath;
private final IAttributeStorage attributesStorage;

Expand All @@ -85,7 +88,7 @@ public static final HUEditorRowAttributes cast(final IViewRowAttributes attribut
{
this.documentPath = documentPath;
this.attributesStorage = attributesStorage;

this.layoutSupplier = ExtendedMemorizingSupplier.of(() -> HUEditorRowAttributesHelper.createLayout(attributesStorage));

//
Expand Down Expand Up @@ -134,7 +137,7 @@ public String toString()
.add("attributesStorage", attributesStorage)
.toString();
}

@Override
public ViewRowAttributesLayout getLayout()
{
Expand Down Expand Up @@ -171,8 +174,7 @@ private final JSONDocumentField toJSONDocumentField(final IAttributeValue attrib
.setDisplayed(true)
.setMandatory(false)
.setReadonly(isReadonly(fieldName))
.setWidgetType(JSONLayoutWidgetType.fromNullable(widgetType))
;
.setWidgetType(JSONLayoutWidgetType.fromNullable(widgetType));
}

private boolean isReadonly(final String attributeName)
Expand Down Expand Up @@ -254,7 +256,7 @@ public LookupValuesList getAttributeDropdown(final String attributeName)
.map(itemNP -> LookupValue.fromNamePair(itemNP))
.collect(LookupValuesList.collect());
}

public Optional<String> getSSCC18()
{
final I_M_Attribute sscc18Attribute = Services.get(ISSCC18CodeDAO.class).retrieveSSCC18Attribute(Env.getCtx());
Expand All @@ -263,14 +265,26 @@ public Optional<String> getSSCC18()
return Optional.empty();
}
final String sscc18 = attributesStorage.getValueAsString(sscc18Attribute);
if(Check.isEmpty(sscc18, true))
if (Check.isEmpty(sscc18, true))
{
return Optional.empty();
}

return Optional.of(sscc18.trim());
}

public Optional<Date> getBestBeforeDate()
{
final I_M_Attribute bestBeforeDateAttribute = Services.get(IAttributeDAO.class).retrieveAttributeByValue(Constants.ATTR_BestBeforeDate);
if (!attributesStorage.hasAttribute(bestBeforeDateAttribute))
{
return Optional.empty();
}

Date bestBeforeDate = attributesStorage.getValueAsDate(bestBeforeDateAttribute);
return Optional.ofNullable(bestBeforeDate);
}

/**
* Intercepts {@link IAttributeStorage} events and forwards them to {@link Execution#getCurrentDocumentChangesCollector()}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ class HUEditorViewBuffer_FullyCached implements HUEditorViewBuffer
private final HUIdsFilterData huIdsFilterData;
private final Supplier<Set<Integer>> huIdsSupplier;
private final ExtendedMemorizingSupplier<IndexedHUEditorRows> rowsSupplier = ExtendedMemorizingSupplier.of(() -> retrieveHUEditorRows());

private final ImmutableList<DocumentQueryOrderBy> defaultOrderBys;

HUEditorViewBuffer_FullyCached(
@NonNull final ViewId viewId,
@NonNull final HUEditorViewRepository huEditorRepo,
final List<DocumentFilter> stickyFilters,
final List<DocumentFilter> filters)
final List<DocumentFilter> filters,
final List<DocumentQueryOrderBy> orderBys)
{
this.viewId = viewId;
this.huEditorRepo = huEditorRepo;
Expand All @@ -97,6 +100,8 @@ class HUEditorViewBuffer_FullyCached implements HUEditorViewBuffer
final List<DocumentFilter> filtersAll = ImmutableList.copyOf(Iterables.concat(stickyFiltersWithoutHUIdsFilter, filters));

huIdsSupplier = Suppliers.memoize(() -> new CopyOnWriteArraySet<>(huEditorRepo.retrieveHUIdsEffective(this.huIdsFilterData, filtersAll)));

this.defaultOrderBys = orderBys != null ? ImmutableList.copyOf(orderBys) : ImmutableList.of();
}

@Override
Expand Down Expand Up @@ -150,12 +155,13 @@ public Stream<HUEditorRow> streamAllRecursive(@NonNull final HUEditorRowFilter f
@Override
public Stream<HUEditorRow> streamPage(final int firstRow, final int pageLength, @NonNull final HUEditorRowFilter filter, final List<DocumentQueryOrderBy> orderBys)
{
final List<DocumentQueryOrderBy> orderBysEffective = !orderBys.isEmpty() ? orderBys : defaultOrderBys;
Stream<HUEditorRow> stream = getRows().stream()
.skip(firstRow)
.limit(pageLength)
.filter(HUEditorRowFilters.toPredicate(filter));

final Comparator<HUEditorRow> comparator = createComparatorOrNull(orderBys);
final Comparator<HUEditorRow> comparator = createComparatorOrNull(orderBysEffective);
if (comparator != null)
{
stream = stream.sorted(comparator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ public class HUEditorViewBuffer_HighVolume implements HUEditorViewBuffer
final ViewId viewId,
final HUEditorViewRepository huEditorRepo,
final List<DocumentFilter> stickyFilters,
final List<DocumentFilter> filters)
final List<DocumentFilter> filters,
final List<DocumentQueryOrderBy> orderBys)
{
this.huEditorRepo = huEditorRepo;
this.stickyFilters = ImmutableList.copyOf(stickyFilters);

final List<DocumentFilter> filtersAll = ImmutableList.copyOf(Iterables.concat(stickyFilters, filters));
final ViewRowIdsOrderedSelection defaultSelection = huEditorRepo.createDefaultSelection(viewId, filtersAll);
final ViewRowIdsOrderedSelection defaultSelection = huEditorRepo.createSelection(viewId, filtersAll, orderBys);
defaultSelectionRef = new AtomicReference<>(defaultSelection);
}

Expand Down
Loading

0 comments on commit c9bc543

Please sign in to comment.