Skip to content

Commit

Permalink
HUEditorProcessTemplate - methods require decision about top level
Browse files Browse the repository at this point in the history
also
* use the new method to simplify code here and there
* fix the actual problem in WEBUI_M_HU_MoveToGarbage (<= this issue)
* also potentially fix it in 
  * WEBUI_M_HU_MoveToAnotherWarehouse
  * WEBUI_M_HU_ReturnFromCustomer
  * WEBUI_M_HU_ReturnToVendor
* WEBUI_M_HU_Messages: add a new top-level related rejection message

so the hopefully the dev takes the hint and makes up their minds on
whether the need top level or all

storage error on disposal
#578
  • Loading branch information
metas-ts committed Sep 8, 2017
1 parent 80f8ccb commit 1babeb0
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import java.util.List;
import java.util.Set;

import org.adempiere.ad.dao.IQueryBL;
import org.adempiere.util.Services;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import de.metas.handlingunits.IHandlingUnitsDAO;
import de.metas.handlingunits.model.I_M_HU;
import de.metas.ui.web.handlingunits.HUEditorRow;
import de.metas.ui.web.handlingunits.HUEditorView;
import de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate;
import de.metas.ui.web.window.datatypes.DocumentIdsSelection;
import lombok.NonNull;

/*
* #%L
Expand Down Expand Up @@ -56,35 +57,63 @@ protected final HUEditorRow getSingleSelectedRow()
{
return HUEditorRow.cast(super.getSingleSelectedRow());
}

protected final List<HUEditorRow> getSelectedRows()

enum Select
{
ONLY_TOPLEVEL, ALL
}

/**
*
* @param select if {@link Select#ONLY_TOPLEVEL} then the method only returns row with {@link HUEditorRow#isTopLevel()} {@code == true};
* @return
*/
protected final List<HUEditorRow> getSelectedRows(@NonNull final Select select)
{
final DocumentIdsSelection selectedDocumentIds = getSelectedDocumentIds();
return getView().getByIds(selectedDocumentIds);
final List<HUEditorRow> allRows = getView().getByIds(selectedDocumentIds);

if (select == Select.ALL)
{
return allRows;
}
return allRows.stream()
.filter(HUEditorRow::isTopLevel)
.collect(ImmutableList.toImmutableList());

}

protected final Set<Integer> getSelectedHUIds()

/**
* Calls {@link #getSelectedRows(Select)} and returns the {@link HUEditorRow}s' {@code M_HU_ID}s.
*
* @param select
* @return
*/
protected final Set<Integer> getSelectedHUIds(@NonNull final Select select)
{
return getSelectedRows()
return getSelectedRows(select)
.stream()
.map(HUEditorRow::getM_HU_ID)
.filter(huId -> huId > 0)
.collect(ImmutableSet.toImmutableSet());
}

protected final List<I_M_HU> getSelectedHUs()
/**
* Gets <b>all</b> selected {@link HUEditorRow}s and loads the top level-HUs from those.
* I.e. this method does not rely on {@link HUEditorRow#isTopLevel()}, but checks the underlying HU.
*
* @param select
* @return
*/
protected final List<I_M_HU> getSelectedHUs(@NonNull final Select select)
{
final Set<Integer> huIds = getSelectedHUIds();
if (huIds.isEmpty())
{
return ImmutableList.of();
}
// get all IDs, we we will check for ourselves if they are toplevel or not
final Set<Integer> huIds = getSelectedHUIds(Select.ALL);

return Services.get(IQueryBL.class)
.createQueryBuilder(I_M_HU.class)
.addInArrayFilter(I_M_HU.COLUMN_M_HU_ID, huIds)
.create()
return Services.get(IHandlingUnitsDAO.class)
.createHUQueryBuilder().addOnlyHUIds(huIds)
.setOnlyTopLevelHUs(select == Select.ONLY_TOPLEVEL)
.createQuery()
.list(I_M_HU.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@
* </ul>
*/
public static final String MSG_NotEnoughTUsFound = "WEBUI_M_HU_MoveTUsToDirectWarehouse.NotEnoughTUsFound";

public static final String MSG_WEBUI_ONLY_TOP_LEVEL_HU = "WEBUI_Only_TopLevelHU";

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
*/
public class WEBUI_M_HU_MoveToAnotherWarehouse extends HUEditorProcessTemplate implements IProcessPrecondition
{
private static final String MSG_NoSelectedHU = "NoHUSelected";

private final transient IHUMovementBL huMovementBL = Services.get(IHUMovementBL.class);

@Param(parameterName = I_M_Warehouse.COLUMNNAME_M_Warehouse_ID, mandatory = true)
Expand All @@ -55,10 +53,10 @@ public class WEBUI_M_HU_MoveToAnotherWarehouse extends HUEditorProcessTemplate i
@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
final Set<Integer> huIds = getSelectedHUIds();
final Set<Integer> huIds = getSelectedHUIds(Select.ONLY_TOPLEVEL);
if (huIds.isEmpty())
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(MSG_NoSelectedHU));
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(WEBUI_M_HU_Messages.MSG_WEBUI_ONLY_TOP_LEVEL_HU));
}

return ProcessPreconditionsResolution.accept();
Expand All @@ -68,7 +66,7 @@ protected ProcessPreconditionsResolution checkPreconditionsApplicable()
protected String doIt() throws Exception
{

final List<I_M_HU> hus = getSelectedHUs();
final List<I_M_HU> hus = getSelectedHUs(Select.ONLY_TOPLEVEL);
movementResult = huMovementBL.moveHUsToWarehouse(hus, warehouse);

return MSG_OK;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package de.metas.ui.web.handlingunits.process;

import java.util.List;
import java.util.Set;

import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.Services;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.collect.ImmutableList;

import de.metas.handlingunits.IHandlingUnitsBL;
import de.metas.handlingunits.model.I_M_HU;
import de.metas.process.IProcessPrecondition;
import de.metas.process.ProcessPreconditionsResolution;
import de.metas.process.RunOutOfTrx;
import de.metas.ui.web.handlingunits.HUEditorRow;
import de.metas.ui.web.window.datatypes.DocumentIdsSelection;
import de.metas.ui.web.window.model.DocumentCollection;

Expand Down Expand Up @@ -47,8 +43,6 @@
*/
public class WEBUI_M_HU_MoveToDirectWarehouse extends HUEditorProcessTemplate implements IProcessPrecondition
{
private final transient IHandlingUnitsBL handlingUnitsBL = Services.get(IHandlingUnitsBL.class);

@Autowired
private DocumentCollection documentsCollection;

Expand All @@ -61,14 +55,10 @@ protected ProcessPreconditionsResolution checkPreconditionsApplicable()
return ProcessPreconditionsResolution.rejectBecauseNoSelection();
}

final boolean hasTopLevelHUsSelected = getView()
.streamByIds(selectedRowIds)
.filter(HUEditorRow::isTopLevel)
.anyMatch(HUEditorRow::isTopLevel);

if (!hasTopLevelHUsSelected)
final Set<Integer> huIds = getSelectedHUIds(Select.ONLY_TOPLEVEL);
if (huIds.isEmpty())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("not a top level HU");
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(WEBUI_M_HU_Messages.MSG_WEBUI_ONLY_TOP_LEVEL_HU));
}

return ProcessPreconditionsResolution.accept();
Expand All @@ -78,10 +68,7 @@ protected ProcessPreconditionsResolution checkPreconditionsApplicable()
@RunOutOfTrx
protected String doIt()
{
final List<I_M_HU> selectedTopLevelHUs = getSelectedHUs()
.stream()
.filter(handlingUnitsBL::isTopLevel)
.collect(ImmutableList.toImmutableList());
final List<I_M_HU> selectedTopLevelHUs = getSelectedHUs(Select.ONLY_TOPLEVEL);
if (selectedTopLevelHUs.isEmpty())
{
throw new AdempiereException("@NoSelection@");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Set;

import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.Services;
import org.compiere.util.Env;

Expand Down Expand Up @@ -44,19 +45,17 @@
*/
public class WEBUI_M_HU_MoveToGarbage extends HUEditorProcessTemplate implements IProcessPrecondition
{
private static final String MSG_NoSelectedHU = "NoHUSelected";

private final transient IHUInventoryBL huInventoryBL = Services.get(IHUInventoryBL.class);

private Set<Integer> huIdsDestroyed;

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
final Set<Integer> huIds = getSelectedHUIds();
final Set<Integer> huIds = getSelectedHUIds(Select.ONLY_TOPLEVEL);
if (huIds.isEmpty())
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(MSG_NoSelectedHU));
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(WEBUI_M_HU_Messages.MSG_WEBUI_ONLY_TOP_LEVEL_HU));
}

return ProcessPreconditionsResolution.accept();
Expand All @@ -65,7 +64,12 @@ protected ProcessPreconditionsResolution checkPreconditionsApplicable()
@Override
protected String doIt() throws Exception
{
final List<I_M_HU> husToDestroy = getSelectedHUs();
final List<I_M_HU> husToDestroy = getSelectedHUs(Select.ONLY_TOPLEVEL);
if (husToDestroy.isEmpty())
{
throw new AdempiereException("@NoSelection@");
}

final Timestamp movementDate = Env.getDate(getCtx());
huInventoryBL.moveToGarbage(husToDestroy, movementDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.Set;

import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.Services;

import de.metas.handlingunits.model.I_M_HU;
Expand Down Expand Up @@ -44,8 +45,6 @@
*/
public class WEBUI_M_HU_MoveToQualityWarehouse extends HUEditorProcessTemplate implements IProcessPrecondition
{
private static final String MSG_NoSelectedHU = "NoHUSelected";

private final transient IHUMovementBL huMovementBL = Services.get(IHUMovementBL.class);

@Param(parameterName = I_M_Warehouse.COLUMNNAME_M_Warehouse_ID, mandatory = true)
Expand All @@ -56,10 +55,10 @@ public class WEBUI_M_HU_MoveToQualityWarehouse extends HUEditorProcessTemplate i
@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
final Set<Integer> huIds = getSelectedHUIds();
final Set<Integer> huIds = getSelectedHUIds(Select.ONLY_TOPLEVEL);
if (huIds.isEmpty())
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(MSG_NoSelectedHU));
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(WEBUI_M_HU_Messages.MSG_WEBUI_ONLY_TOP_LEVEL_HU));
}

return ProcessPreconditionsResolution.accept();
Expand All @@ -70,8 +69,13 @@ protected String doIt() throws Exception
{
Check.assume(warehouse.isQualityReturnWarehouse(), "not a quality returns warehouse");

final List<I_M_HU> hus = getSelectedHUs();
movementResult = huMovementBL.moveHUsToWarehouse(hus, warehouse);
final List<I_M_HU> selectedTopLevelHUs = getSelectedHUs(Select.ONLY_TOPLEVEL);
if (selectedTopLevelHUs.isEmpty())
{
throw new AdempiereException("@NoSelection@");
}

movementResult = huMovementBL.moveHUsToWarehouse(selectedTopLevelHUs, warehouse);

return MSG_OK;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import java.util.List;
import java.util.Set;

import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.Services;

import com.google.common.collect.ImmutableList;

import de.metas.handlingunits.IHandlingUnitsBL;
import de.metas.handlingunits.inout.IHUInOutBL;
import de.metas.handlingunits.model.I_M_HU;
import de.metas.process.IProcessPrecondition;
Expand All @@ -26,11 +24,11 @@
*
* 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
* 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
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
Expand All @@ -43,19 +41,15 @@
*/
public class WEBUI_M_HU_ReturnFromCustomer extends HUEditorProcessTemplate implements IProcessPrecondition
{
private static final String MSG_NoSelectedHU = "NoHUSelected";

private final transient IHandlingUnitsBL handlingUnitsBL = Services.get(IHandlingUnitsBL.class);

private List<I_M_HU> husToReturn = null;

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
final Set<Integer> huIds = getSelectedHUIds();
final Set<Integer> huIds = getSelectedHUIds(Select.ONLY_TOPLEVEL);
if (huIds.isEmpty())
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(MSG_NoSelectedHU));
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(WEBUI_M_HU_Messages.MSG_WEBUI_ONLY_TOP_LEVEL_HU));
}

return ProcessPreconditionsResolution.accept();
Expand All @@ -64,11 +58,12 @@ protected ProcessPreconditionsResolution checkPreconditionsApplicable()
@Override
protected String doIt()
{
husToReturn = getSelectedHUs()
.stream()
.filter(handlingUnitsBL::isTopLevel) // only top level HUs
.collect(ImmutableList.toImmutableList());

husToReturn = getSelectedHUs(Select.ONLY_TOPLEVEL);
if (husToReturn.isEmpty())
{
throw new AdempiereException("@NoSelection@");
}

Services.get(IHUInOutBL.class).createCustomerReturnInOutForHUs(husToReturn);
return MSG_OK;
}
Expand All @@ -78,7 +73,7 @@ protected void postProcess(final boolean success)
{
if (husToReturn != null && !husToReturn.isEmpty())
{
getView().removeHUsAndInvalidate(getSelectedHUs());
getView().removeHUsAndInvalidate(getSelectedHUs(Select.ONLY_TOPLEVEL));
}
}

Expand Down
Loading

0 comments on commit 1babeb0

Please sign in to comment.