Skip to content

Commit

Permalink
avoid class cast exceptions when the view is not HUEditorView
Browse files Browse the repository at this point in the history
because those are poluting the console/log file

#683
  • Loading branch information
teosarca committed Nov 21, 2017
1 parent de93240 commit 2ffba39
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
*/
public abstract class HUEditorProcessTemplate extends ViewBasedProcessTemplate
{
protected final boolean isHUEditorView()
{
return isViewClass(HUEditorView.class);
}

@Override
protected final HUEditorView getView()
{
Expand All @@ -61,7 +66,7 @@ protected final Stream<HUEditorRow> streamSelectedRows(@NonNull final HUEditorRo
{
return Stream.empty();
}

return getView().streamByIds(filter.andOnlyRowIds(selectedDocumentIds));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public class WEBUI_M_HU_MoveTUsToDirectWarehouse extends HUEditorProcessTemplate
@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
if(!isHUEditorView())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
}

final DocumentIdsSelection selectedRowIds = getSelectedDocumentIds();
if (!selectedRowIds.isSingleDocumentId())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public class WEBUI_M_HU_MoveToAnotherWarehouse extends HUEditorProcessTemplate i
@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
if(!isHUEditorView())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
}

if (!streamSelectedHUIds(Select.ONLY_TOPLEVEL).findAny().isPresent())
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(WEBUI_HU_Constants.MSG_WEBUI_ONLY_TOP_LEVEL_HU));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public class WEBUI_M_HU_MoveToDirectWarehouse extends HUEditorProcessTemplate im
@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
if(!isHUEditorView())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
}

final DocumentIdsSelection selectedRowIds = getSelectedDocumentIds();
if (selectedRowIds.isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class WEBUI_M_HU_MoveToGarbage extends HUEditorProcessTemplate implements
@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
if(!isHUEditorView())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
}

if (!streamSelectedHUIds(Select.ONLY_TOPLEVEL).findAny().isPresent())
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(WEBUI_HU_Constants.MSG_WEBUI_ONLY_TOP_LEVEL_HU));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public class WEBUI_M_HU_MoveToQualityWarehouse extends HUEditorProcessTemplate i
@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
if(!isHUEditorView())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
}

if (!streamSelectedHUIds(Select.ONLY_TOPLEVEL).findAny().isPresent())
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(WEBUI_HU_Constants.MSG_WEBUI_ONLY_TOP_LEVEL_HU));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public class WEBUI_M_HU_PrintReceiptLabel
@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable()
{
if(!isHUEditorView())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
}

final HUReportService huReportService = HUReportService.get();

final Properties ctx = Env.getCtx(); // note: at this point, the JavaProces's ctx was not set so we are using the global context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public class WEBUI_M_HU_ReturnFromCustomer extends HUEditorProcessTemplate imple
@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
if(!isHUEditorView())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
}

if (!streamSelectedHUIds(Select.ONLY_TOPLEVEL).findAny().isPresent())
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(WEBUI_HU_Constants.MSG_WEBUI_ONLY_TOP_LEVEL_HU));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public class WEBUI_M_HU_ReturnTUsToVendor extends HUEditorProcessTemplate implem
@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
if(!isHUEditorView())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
}

final DocumentIdsSelection selectedRowIds = getSelectedDocumentIds();
if (!selectedRowIds.isSingleDocumentId())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public class WEBUI_M_HU_ReturnToVendor extends HUEditorProcessTemplate implement
@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
if(!isHUEditorView())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("not the HU view");
}

if (!streamSelectedHUIds(Select.ONLY_TOPLEVEL).findAny().isPresent())
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(WEBUI_HU_Constants.MSG_WEBUI_ONLY_TOP_LEVEL_HU));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ protected IView getView()
Check.assumeNotNull(_view, "View loaded");
return _view;
}

protected final <T extends IView> boolean isViewClass(@NonNull final Class<T> expectedViewClass)
{
final IView view = _view;
if(view == null)
{
return false;
}

return expectedViewClass.isAssignableFrom(view.getClass());
}

protected final void invalidateView(@NonNull final ViewId viewId)
{
Expand Down

0 comments on commit 2ffba39

Please sign in to comment.