Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when opening PP Order issue / receipt #528 #552

Merged
merged 7 commits into from
Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ private static final String buildSqlWhereClause_Equals(final String sqlColumnExp
}

return new StringBuilder()
.append(sqlColumnExpr).append(negate ? " <> ?" : " = ").append(sqlParams.placeholder(sqlValue))
.append(sqlColumnExpr)
.append(negate ? " <> " : " = ")
.append(sqlParams.placeholder(sqlValue))
.toString();
}

Expand All @@ -233,13 +235,13 @@ private static final String buildSqlWhereClause_Compare(final String sqlColumnEx

private static final String buildSqlWhereClause_InArray(final String sqlColumnExpr, final List<Object> sqlValues, final SqlParamsCollector sqlParams)
{
if(sqlValues == null || sqlValues.isEmpty())
if (sqlValues == null || sqlValues.isEmpty())
{
// TODO log a warning or throw exception?!
return null;
}
if(sqlParams.isCollecting())

if (sqlParams.isCollecting())
{
final List<Object> sqlValuesEffective = new ArrayList<>();
final String sql = DB.buildSqlList(sqlColumnExpr, sqlValues, sqlValuesEffective);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.GuavaCollectors;
import org.adempiere.util.Services;
import org.adempiere.util.lang.MutableInt;
import org.adempiere.util.lang.impl.TableRecordReference;
import org.compiere.Adempiere;
import org.compiere.model.IQuery;
Expand All @@ -21,15 +20,12 @@
import de.metas.handlingunits.model.I_M_ReceiptSchedule;
import de.metas.handlingunits.receiptschedule.IHUReceiptScheduleBL;
import de.metas.process.IProcessPrecondition;
import de.metas.process.IProcessPreconditionsContext;
import de.metas.process.JavaProcess;
import de.metas.process.Param;
import de.metas.process.ProcessPreconditionsResolution;
import de.metas.process.RunOutOfTrx;
import de.metas.ui.web.WebRestApiApplication;
import de.metas.ui.web.handlingunits.HUEditorRow;
import de.metas.ui.web.handlingunits.HUEditorView;
import de.metas.ui.web.process.ViewAsPreconditionsContext;
import de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate;
import de.metas.ui.web.view.IViewsRepository;
import de.metas.ui.web.view.ViewId;
Expand Down Expand Up @@ -57,56 +53,8 @@
* #L%
*/
@Profile(WebRestApiApplication.PROFILE_Webui)
public class WEBUI_M_HU_CreateMaterialReceipt extends JavaProcess implements IProcessPrecondition
public class WEBUI_M_HU_CreateMaterialReceipt extends WEBUI_M_HU_Receipt_Base implements IProcessPrecondition
{
@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable(final IProcessPreconditionsContext context)
{
final ViewAsPreconditionsContext viewContext = ViewAsPreconditionsContext.castOrNull(context);
if (viewContext == null)
{
return ProcessPreconditionsResolution.rejectWithInternalReason("webui view not available");
}

if (viewContext.isNoSelection())
{
return ProcessPreconditionsResolution.rejectBecauseNoSelection();
}

final MutableInt checkedDocumentsCount = new MutableInt(0);
final ProcessPreconditionsResolution firstRejection = viewContext.getView(HUEditorView.class)
.streamByIds(viewContext.getSelectedDocumentIds())
.filter(document -> document.isPureHU())
//
.peek(document -> checkedDocumentsCount.incrementAndGet()) // count checked documents
.map(document -> rejectResolutionOrNull(document)) // create reject resolution if any
.filter(resolution -> resolution != null) // filter out those which are not errors
.findFirst()
.orElse(null);
if (firstRejection != null)
{
// found a record which is not eligible => don't run the process
return firstRejection;
}
if (checkedDocumentsCount.getValue() <= 0)
{
return ProcessPreconditionsResolution.rejectWithInternalReason("no eligible rows");
}

// Safe to run the process
return ProcessPreconditionsResolution.accept();
}

private static final ProcessPreconditionsResolution rejectResolutionOrNull(final HUEditorRow document)
{
if (!document.isHUStatusPlanning())
{
return ProcessPreconditionsResolution.reject("Only planning HUs can be received"); // TODO: trl
}

return null;
}

@Autowired
private IViewsRepository viewsRepo;
@Autowired
Expand All @@ -120,10 +68,22 @@ private static final ProcessPreconditionsResolution rejectResolutionOrNull(final

public WEBUI_M_HU_CreateMaterialReceipt()
{
super();
Adempiere.autowire(this);
}

/**
* Only allows rows whose HU is in the "planning" status.
*/
@Override
final ProcessPreconditionsResolution rejectResolutionOrNull(final HUEditorRow document)
{
if (!document.isHUStatusPlanning())
{
return ProcessPreconditionsResolution.reject("Only planning HUs can be received"); // TODO: trl
}
return null;
}

@Override
@RunOutOfTrx
protected String doIt() throws Exception
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package de.metas.ui.web.handlingunits.process;

import org.adempiere.util.lang.MutableInt;

/*
* #%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%
*/

import de.metas.process.IProcessPrecondition;
import de.metas.process.IProcessPreconditionsContext;
import de.metas.process.JavaProcess;
import de.metas.process.ProcessPreconditionsResolution;
import de.metas.ui.web.handlingunits.HUEditorRow;
import de.metas.ui.web.handlingunits.HUEditorView;
import de.metas.ui.web.process.ViewAsPreconditionsContext;

/**
* Common base class to dedupliate code.
*
* @author metas-dev <dev@metasfresh.com>
*
*/
public abstract class WEBUI_M_HU_Receipt_Base extends JavaProcess implements IProcessPrecondition
{
@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable(final IProcessPreconditionsContext context)
{
final ViewAsPreconditionsContext viewContext = ViewAsPreconditionsContext.castOrNull(context);
if (viewContext == null)
{
return ProcessPreconditionsResolution.rejectWithInternalReason("webui view not available");
}

final boolean isHUView = viewContext.getView() instanceof HUEditorView;
if (!isHUView)
{
return ProcessPreconditionsResolution.rejectWithInternalReason("The current view is not an HUEditorView; view=" + viewContext.getView() + ";");
}

if (viewContext.isNoSelection())
{
return ProcessPreconditionsResolution.rejectBecauseNoSelection();
}

final MutableInt checkedDocumentsCount = new MutableInt(0);
final ProcessPreconditionsResolution firstRejection = viewContext.getView(HUEditorView.class)
.streamByIds(viewContext.getSelectedDocumentIds())
.filter(document -> document.isPureHU())
//
.peek(document -> checkedDocumentsCount.incrementAndGet()) // count checked documents
.map(document -> rejectResolutionOrNull(document)) // create reject resolution if any
.filter(resolution -> resolution != null) // filter out those which are not errors
.findFirst()
.orElse(null);
if (firstRejection != null)
{
// found a record which is not eligible => don't run the process
return firstRejection;
}
if (checkedDocumentsCount.getValue() <= 0)
{
return ProcessPreconditionsResolution.rejectWithInternalReason("no eligible rows");
}

return ProcessPreconditionsResolution.accept();
}

/**
* Check the individual given row, to find out if this process can be applied to it or not.
*
* @param document
* @return
*/
abstract ProcessPreconditionsResolution rejectResolutionOrNull(HUEditorRow document);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.GuavaCollectors;
import org.adempiere.util.Services;
import org.adempiere.util.lang.MutableInt;
import org.adempiere.util.lang.impl.TableRecordReference;
import org.compiere.Adempiere;
import org.compiere.model.I_M_InOut;
Expand All @@ -19,15 +18,12 @@
import de.metas.handlingunits.model.I_M_HU;
import de.metas.handlingunits.model.I_M_ReceiptSchedule;
import de.metas.process.IProcessPrecondition;
import de.metas.process.IProcessPreconditionsContext;
import de.metas.process.JavaProcess;
import de.metas.process.Param;
import de.metas.process.ProcessPreconditionsResolution;
import de.metas.process.RunOutOfTrx;
import de.metas.ui.web.WebRestApiApplication;
import de.metas.ui.web.handlingunits.HUEditorRow;
import de.metas.ui.web.handlingunits.HUEditorView;
import de.metas.ui.web.process.ViewAsPreconditionsContext;
import de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate;
import de.metas.ui.web.view.IViewsRepository;
import de.metas.ui.web.view.ViewId;
Expand Down Expand Up @@ -62,55 +58,8 @@
*
*/
@Profile(value = WebRestApiApplication.PROFILE_Webui)
public class WEBUI_M_HU_ReverseReceipt extends JavaProcess implements IProcessPrecondition
public class WEBUI_M_HU_ReverseReceipt extends WEBUI_M_HU_Receipt_Base implements IProcessPrecondition
{
@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable(final IProcessPreconditionsContext context)
{
final ViewAsPreconditionsContext viewContext = ViewAsPreconditionsContext.castOrNull(context);
if (viewContext == null)
{
return ProcessPreconditionsResolution.rejectWithInternalReason("webui view not available");
}

if (viewContext.isNoSelection())
{
return ProcessPreconditionsResolution.rejectBecauseNoSelection();
}

final MutableInt checkedDocumentsCount = new MutableInt(0);
final ProcessPreconditionsResolution firstRejection = viewContext.getView(HUEditorView.class)
.streamByIds(viewContext.getSelectedDocumentIds())
.filter(document -> document.isPureHU())
//
.peek(document -> checkedDocumentsCount.incrementAndGet()) // count checked documents
.map(document -> rejectResolutionOrNull(document)) // create reject resolution if any
.filter(resolution -> resolution != null) // filter out those which are not errors
.findFirst()
.orElse(null);
if (firstRejection != null)
{
// found a record which is not eligible => don't run the process
return firstRejection;
}
if (checkedDocumentsCount.getValue() <= 0)
{
return ProcessPreconditionsResolution.rejectWithInternalReason("no eligible rows");
}

return ProcessPreconditionsResolution.accept();
}

private static final ProcessPreconditionsResolution rejectResolutionOrNull(final HUEditorRow document)
{
if (!document.isHUStatusActive())
{
return ProcessPreconditionsResolution.reject("Only active HUs can be reversed"); // TODO: trl
}

return null;
}

@Autowired
private IViewsRepository viewsRepo;
@Autowired
Expand All @@ -123,10 +72,21 @@ private static final ProcessPreconditionsResolution rejectResolutionOrNull(final

public WEBUI_M_HU_ReverseReceipt()
{
super();
Adempiere.autowire(this);
}

/**
* Only allows rows whose HUs are in the "active" status.
*/
final ProcessPreconditionsResolution rejectResolutionOrNull(final HUEditorRow document)
{
if (!document.isHUStatusActive())
{
return ProcessPreconditionsResolution.reject("Only active HUs can be reversed"); // TODO: trl
}
return null;
}

@Override
@RunOutOfTrx
protected String doIt() throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private LookupValuesList getLULookupValues(final LookupDataSourceContext context
*
* @return a list of HU PI items that link the currently selected TU with a TUperLU-qty and a LU packing instruction.
*/
@ProcessParamLookupValuesProvider(parameterName = PARAM_M_HU_PI_Item_ID, dependsOn = { PARAM_Action }, numericKey = true, lookupTableName = I_M_HU_PI_Item.Table_Name)
@ProcessParamLookupValuesProvider(parameterName = PARAM_M_HU_PI_Item_ID, dependsOn = PARAM_Action , numericKey = true, lookupTableName = I_M_HU_PI_Item.Table_Name)
private LookupValuesList getM_HU_PI_Item_ID()
{
return newParametersFiller().getM_HU_PI_Item_IDs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public class WebuiHUTransformCommand
public static enum ActionType
{
/**
* Invokes {@link HUTransferService#cuToNewCU(I_M_HU, BigDecimal)}.
* Invokes {@link HUTransformService#cuToNewCU(I_M_HU, BigDecimal)}.
*/
CU_To_NewCU,

/**
* Invokes {@link HUTransferService#cuToNewTUs(I_M_HU, BigDecimal, I_M_HU_PI_Item_Product, boolean)}.
* Invokes {@link HUTransformService#cuToNewTUs(I_M_HU, BigDecimal, I_M_HU_PI_Item_Product, boolean)}.
*/
CU_To_NewTUs,

Expand All @@ -92,22 +92,22 @@ public static enum ActionType
TU_Set_Ownership,

/**
* Invokes {@link HUTransferService#cuToExistingTU(I_M_HU, BigDecimal, I_M_HU)}.
* Invokes {@link HUTransformService#cuToExistingTU(I_M_HU, BigDecimal, I_M_HU)}.
*/
CU_To_ExistingTU,

/**
* Invokes {@link HUTransferService#tuToNewTUs(I_M_HU, BigDecimal, boolean)}.
* Invokes {@link HUTransformService#tuToNewTUs(I_M_HU, BigDecimal, boolean)}.
*/
TU_To_NewTUs,

/**
* Invokes {@link HUTransferService#tuToNewLUs(I_M_HU, BigDecimal, I_M_HU_PI_Item, boolean)}.
* Invokes {@link HUTransformService#tuToNewLUs(I_M_HU, BigDecimal, I_M_HU_PI_Item, boolean)}.
*/
TU_To_NewLUs,

/**
* Invokes {@link HUTransferService#tuToExistingLU(I_M_HU, BigDecimal, I_M_HU).
* Invokes {@link HUTransformService#tuToExistingLU(I_M_HU, BigDecimal, I_M_HU).
*/
TU_To_ExistingLU,

Expand Down
Loading