Skip to content

Commit

Permalink
WEBUI_Picking_OpenHUsToPick calls IHUPickingSlotBL to get pickable HUs
Browse files Browse the repository at this point in the history
Also:
* CreateViewRequest: add javadoc (thx @teosarca)
* Remove the obsolete process WEBUI_Picking_AddHUToPickingSlot
* SqlParamsCollector undeprecate collectAll(List) but made it package
only. For other uses, add collectAll(ISqlQueryFilter)
* PickingCandidateCommand: ignore inactive records
* CreateViewRequest, DocumentFilter, HUIdsFilterHelper,
WEBUI_Picking_PickSelectedHU and SqlViewFactory: minor

557: Picking Window: Open HU Selection window filtering 

Task-Url: #557
  • Loading branch information
metas-ts committed Aug 31, 2017
1 parent 9979ef4 commit 16738e5
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.List;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import org.adempiere.util.Check;
Expand Down Expand Up @@ -102,7 +103,7 @@ public String getFilterId()
return filterId;
}

public String getCaption(final String adLanguage)
public String getCaption(@Nullable final String adLanguage)
{
return caption != null ? caption.translate(adLanguage) : null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package de.metas.ui.web.document.filter.sql;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import javax.annotation.Nullable;

import org.adempiere.ad.dao.ISqlQueryFilter;
import org.compiere.util.DB;
import org.compiere.util.Env;

import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.ToString;

/*
Expand Down Expand Up @@ -84,14 +86,26 @@ public boolean isCollecting()
}

/**
* Directly append all sqlParams.
* Directly append all sqlParams from the given {@code sqlQueryFilter}.
*
* @deprecated Please avoid using it. It's used mainly to adapt with old code
* @param sqlQueryFilter
*
*/
public void collectAll(@NonNull final ISqlQueryFilter sqlQueryFilter)
{
final List<Object> sqlParams = sqlQueryFilter.getSqlParams(Env.getCtx());
collectAll(sqlParams);
}

/**
* Directly append the given {@code sqlParams}. Please prefer using {@link #placeholder(Object)} instead.<br>
* "Package" scope because currently this method is needed only by {@link SqlDefaultDocumentFilterConverter}.
*
* Please avoid using it. It's used mainly to adapt with old code
*
* @param sqlParams
*/
@Deprecated
public void collectAll(final Collection<? extends Object> sqlParams)
/* package */ void collectAll(final List<Object> sqlParams)
{
if (sqlParams == null || sqlParams.isEmpty())
{
Expand All @@ -102,7 +116,6 @@ public void collectAll(final Collection<? extends Object> sqlParams)
{
throw new IllegalStateException("Cannot append " + sqlParams + " to not collecting params");
}

params.addAll(sqlParams);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.adempiere.util.Services;
import org.compiere.util.CCache;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Util.ArrayKey;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -315,9 +314,8 @@ public String getSql(final SqlParamsCollector sqlParamsOut, final DocumentFilter

final ISqlQueryFilter sqlQueryFilter = ISqlQueryFilter.cast(queryFilter);
final String sql = sqlQueryFilter.getSql();
final List<Object> sqlParams = sqlQueryFilter.getSqlParams(Env.getCtx());

sqlParamsOut.collectAll(sqlParams);
sqlParamsOut.collectAll(sqlQueryFilter);
return sql;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import java.util.List;
import java.util.Set;

import javax.annotation.Nullable;

import org.adempiere.ad.dao.ISqlQueryFilter;
import org.adempiere.model.PlainContextAware;
import org.adempiere.util.Services;
import org.compiere.util.Env;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -81,7 +82,9 @@ public static HUIdsFilterData newEmpty()
private final Set<Integer> mustHUIds;
private final Set<Integer> shallNotHUIds;

private HUIdsFilterData(final Collection<Integer> initialHUIds, final IHUQueryBuilder initialHUQuery)
private HUIdsFilterData(
@Nullable final Collection<Integer> initialHUIds,
@Nullable final IHUQueryBuilder initialHUQuery)
{
this.initialHUIds = initialHUIds != null ? ImmutableSet.copyOf(initialHUIds) : ImmutableSet.of();
this.initialHUQuery = initialHUQuery;
Expand Down Expand Up @@ -264,10 +267,9 @@ public String getSql(final SqlParamsCollector sqlParamsOut, final DocumentFilter
huQuery.addHUIdsToExclude(huIdsFilter.getShallNotHUIds());

final ISqlQueryFilter sqlQueryFilter = ISqlQueryFilter.cast(huQuery.createQueryFilter());

final String sql = sqlQueryFilter.getSql();
final List<Object> sqlParams = sqlQueryFilter.getSqlParams(Env.getCtx());
sqlParamsOut.collectAll(sqlParams);

sqlParamsOut.collectAll(sqlQueryFilter);
return sql;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,13 @@ private I_M_Picking_Candidate getCreateCandidate(final int huId, final int picki
{
I_M_Picking_Candidate pickingCandidatePO = Services.get(IQueryBL.class)
.createQueryBuilder(I_M_Picking_Candidate.class)
.addOnlyActiveRecordsFilter()
.addEqualsFilter(I_M_Picking_Candidate.COLUMN_M_PickingSlot_ID, pickingSlotId)
.addEqualsFilter(I_M_Picking_Candidate.COLUMNNAME_M_HU_ID, huId)
.addEqualsFilter(I_M_Picking_Candidate.COLUMNNAME_M_ShipmentSchedule_ID, shipmentScheduleId)
.create()
.firstOnly(I_M_Picking_Candidate.class);

if (pickingCandidatePO == null)
{
pickingCandidatePO = InterfaceWrapperHelper.newInstance(I_M_Picking_Candidate.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import de.metas.process.IADProcessDAO;
import de.metas.process.RelatedProcessDescriptor;
import de.metas.ui.web.document.filter.DocumentFilterDescriptor;
import de.metas.ui.web.picking.process.WEBUI_Picking_AddHUToPickingSlot;
import de.metas.ui.web.picking.process.WEBUI_Picking_M_Picking_Candidate_Process;
import de.metas.ui.web.picking.process.WEBUI_Picking_M_Picking_Candidate_Unprocess;
import de.metas.ui.web.picking.process.WEBUI_Picking_OpenHUsToPick;
Expand Down Expand Up @@ -157,11 +156,6 @@ private List<RelatedProcessDescriptor> createAdditionalRelatedProcessDescriptors
.webuiQuickAction(true)
.build(),

RelatedProcessDescriptor.builder()
.processId(adProcessDAO.retriveProcessIdByClass(ctx, WEBUI_Picking_AddHUToPickingSlot.class))
.anyTable().anyWindow()
.webuiQuickAction(true)
.build(),
RelatedProcessDescriptor.builder()
.processId(adProcessDAO.retriveProcessIdByClass(ctx, WEBUI_Picking_OpenHUsToPick.class))
.anyTable().anyWindow()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package de.metas.ui.web.picking.process;

import static org.adempiere.model.InterfaceWrapperHelper.loadOutOfTrx;

import java.util.List;
import java.util.stream.Collectors;

import org.adempiere.util.Services;
import org.compiere.util.Env;
import org.springframework.beans.factory.annotation.Autowired;

import de.metas.handlingunits.IHUQueryBuilder;
import de.metas.handlingunits.IHandlingUnitsDAO;
import de.metas.handlingunits.model.X_M_HU;
import com.google.common.collect.ImmutableList;

import de.metas.handlingunits.IHUPickingSlotBL;
import de.metas.handlingunits.IHUPickingSlotBL.AvailableHUsToPickRequest;
import de.metas.handlingunits.model.I_M_HU;
import de.metas.inoutcandidate.model.I_M_ShipmentSchedule;
import de.metas.process.IADProcessDAO;
import de.metas.process.ProcessPreconditionsResolution;
import de.metas.process.RelatedProcessDescriptor;
Expand Down Expand Up @@ -44,7 +52,7 @@
*/

/**
* This process opens a HU editor window within the picking window
* This process opens a HU editor window within the picking window and registers the process {@link WEBUI_Picking_PickSelectedHU} for that window.
*
* @author metas-dev <dev@metasfresh.com>
*
Expand All @@ -56,6 +64,8 @@ public class WEBUI_Picking_OpenHUsToPick extends ViewBasedProcessTemplate

private final transient IADProcessDAO adProcessDAO = Services.get(IADProcessDAO.class);

private final transient IHUPickingSlotBL huPickingSlotBL = Services.get(IHUPickingSlotBL.class);

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
Expand All @@ -72,26 +82,30 @@ protected String doIt()
{
final PickingSlotRow pickingSlotRow = getSingleSelectedRow();
final ViewId pickingSlotViewId = getView().getViewId();
// final int pickingSlotId = pickingSlotRow.getPickingSlotId();
// final int shipmentScheduleId = getView().getShipmentScheduleId();

// TODO: refactor together with the Swing UI version of retrieving the huIds
// see de.metas.fresh.picking.terminal.FreshProductKey.findAvailableHUs(boolean)
final IHUQueryBuilder huIdsToAvailableToPickQuery = Services.get(IHandlingUnitsDAO.class)
.createHUQueryBuilder()
.setHUStatus(X_M_HU.HUSTATUS_Active)
.onlyNotLocked();

final IView husToPickView = viewsRepo.createView(CreateViewRequest.builder(WEBUI_HU_Constants.WEBUI_HU_Window_ID, JSONViewDataType.includedView)
.setParentViewId(pickingSlotViewId)
.setParentRowId(pickingSlotRow.getId())
.addStickyFilters(HUIdsFilterHelper.createFilter(huIdsToAvailableToPickQuery))

.addAdditionalRelatedProcessDescriptor(RelatedProcessDescriptor.builder()
.processId(adProcessDAO.retriveProcessIdByClassIfUnique(Env.getCtx(), WEBUI_Picking_PickSelectedHU.class))
.webuiQuickAction(true)
.build())
.build());

final int shipmentScheduleId = getView().getShipmentScheduleId();

final AvailableHUsToPickRequest request = AvailableHUsToPickRequest.builder()
.shipmentSchedules(ImmutableList.of(loadOutOfTrx(shipmentScheduleId, I_M_ShipmentSchedule.class)))
.onlyTopLevelHUs(false)
.considerAttributes(true)
.build();

final List<I_M_HU> availableHUsToPick = huPickingSlotBL.retrieveAvailableHUsToPick(request);
final List<Integer> availableHUsToPickIDs = availableHUsToPick.stream().map(hu->hu.getM_HU_ID()).collect(Collectors.toList());

final RelatedProcessDescriptor processToPickSelectedHU = RelatedProcessDescriptor.builder()
.processId(adProcessDAO.retriveProcessIdByClassIfUnique(Env.getCtx(), WEBUI_Picking_PickSelectedHU.class))
.webuiQuickAction(true)
.build();

final IView husToPickView = viewsRepo.createView(
CreateViewRequest.builder(WEBUI_HU_Constants.WEBUI_HU_Window_ID, JSONViewDataType.includedView)
.setParentViewId(pickingSlotViewId)
.setParentRowId(pickingSlotRow.getId())
.addStickyFilters(HUIdsFilterHelper.createFilter(availableHUsToPickIDs))
.addAdditionalRelatedProcessDescriptor(processToPickSelectedHU)
.build());

getResult().setWebuiIncludedViewIdToOpen(husToPickView.getViewId().getViewId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class WEBUI_Picking_PickSelectedHU extends ViewBasedProcessTemplate imple
{
@Autowired
private PickingCandidateCommand pickingCandidateCommand;

@Autowired
private IViewsRepository viewsRepo;

Expand Down
Loading

0 comments on commit 16738e5

Please sign in to comment.