Skip to content

Commit

Permalink
solve error "Assumption failure: tableName not empty"
Browse files Browse the repository at this point in the history
* solution: extend the API to support multi-table rows (take a look at
PPOrderLinesView.getTableNameOrNull())
* also renamed IView.getTableName() to getTableNameOrNull()

Exception when opening PP Order issue / receipt
#528
  • Loading branch information
metas-ts committed Aug 10, 2017
1 parent 000794b commit 3680e6f
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 40 deletions.
21 changes: 19 additions & 2 deletions src/main/java/de/metas/ui/web/handlingunits/HUEditorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.annotation.Nullable;

import org.adempiere.ad.dao.IQueryBL;
import org.adempiere.ad.trx.api.ITrx;
import org.adempiere.model.InterfaceWrapperHelper;
Expand Down Expand Up @@ -189,9 +191,24 @@ public ITranslatableString getDescription()
return ImmutableTranslatableString.empty();
}

/**
* Always returns {@link I_M_HU#Table_Name}, even if the underlying {@link HUEditorRow}'s type is {@link HUEditorRowType#HUStorage}.<br>
* (because i don't understand it well enough)
*/
@Override
public String getTableName()
{
public String getTableNameOrNull(@Nullable final DocumentId documentId)
{
// commented out for now, see javadoc
// if (documentId == null)
// {
// return null;
// }
// final HUEditorRow huEditorRow = getById(documentId);
// final HUEditorRowType type = huEditorRow.getType();
// if (type == HUEditorRowType.HUStorage)
// {
// return I_M_HU_Storage.Table_Name;
// }
return I_M_HU.Table_Name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ private IHUProductStorage getSingleProductStorage(final I_M_HU hu)
return productStorage;
}

private HUEditorRow createHUEditorRow(final int parent_HU_ID, final int topLevelHUId, final IHUProductStorage huStorage, final boolean processed)
private HUEditorRow createHUEditorRow(
final int parent_HU_ID,
final int topLevelHUId,
@NonNull final IHUProductStorage huStorage,
final boolean processed)
{
final I_M_HU hu = huStorage.getM_HU();
final int huId = hu.getM_HU_ID();
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/de/metas/ui/web/picking/PackageableView.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.annotation.Nullable;

import org.adempiere.ad.dao.IQueryBL;
import org.adempiere.model.InterfaceWrapperHelper;
import org.adempiere.service.ISysConfigBL;
Expand Down Expand Up @@ -121,8 +123,11 @@ public Set<DocumentPath> getReferencingDocumentPaths()
return ImmutableSet.of();
}

/**
* Always returns {@link I_M_Packageable_V#Table_Name}.
*/
@Override
public String getTableName()
public String getTableNameOrNull(@Nullable final DocumentId ignored)
{
return I_M_Packageable_V.Table_Name;
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/de/metas/ui/web/picking/PickingSlotView.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.util.function.Supplier;
import java.util.stream.Stream;

import javax.annotation.Nullable;

import org.adempiere.ad.trx.api.ITrx;
import org.adempiere.util.lang.ExtendedMemorizingSupplier;
import org.adempiere.util.lang.impl.TableRecordReference;
Expand Down Expand Up @@ -128,8 +130,11 @@ public Set<DocumentPath> getReferencingDocumentPaths()
return ImmutableSet.of();
}

/**
* Always returns {@link I_M_PickingSlot#Table_Name}
*/
@Override
public String getTableName()
public String getTableNameOrNull(@Nullable final DocumentId ignored)
{
return I_M_PickingSlot.Table_Name;
}
Expand Down
53 changes: 36 additions & 17 deletions src/main/java/de/metas/ui/web/pporder/PPOrderLineType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import java.util.stream.Stream;

import org.adempiere.util.GuavaCollectors;
import org.eevolution.model.I_PP_Order;
import org.eevolution.model.I_PP_Order_BOMLine;

import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.collect.ImmutableMap;

import de.metas.handlingunits.model.I_M_HU;
import de.metas.handlingunits.model.I_M_HU_Storage;
import de.metas.ui.web.handlingunits.HUEditorRowType;
import de.metas.ui.web.view.IViewRowType;
import lombok.NonNull;

/*
* #%L
Expand All @@ -34,39 +39,48 @@

public enum PPOrderLineType implements IViewRowType
{
MainProduct("MP", true) //
, BOMLine_Component("CO", false) //
, BOMLine_ByCoProduct("BY", true) //
//
, HU_LU(HUEditorRowType.LU) //
, HU_TU(HUEditorRowType.TU) //
, HU_VHU(HUEditorRowType.VHU) //
, HU_Storage(HUEditorRowType.HUStorage) //
MainProduct("MP", true, I_PP_Order.Table_Name),
BOMLine_Component("CO", false, I_PP_Order_BOMLine.Table_Name),
BOMLine_ByCoProduct("BY", true, I_PP_Order_BOMLine.Table_Name),

HU_LU(HUEditorRowType.LU, I_M_HU.Table_Name),
HU_TU(HUEditorRowType.TU, I_M_HU.Table_Name),
HU_VHU(HUEditorRowType.VHU, I_M_HU.Table_Name),
HU_Storage(HUEditorRowType.HUStorage, I_M_HU_Storage.Table_Name)
;

private final String name;
private final String iconName;
private final HUEditorRowType huType;


private final String tableName;

private final boolean canReceive;
private final boolean canIssue;

private PPOrderLineType(final String name, final boolean canReceive)
private PPOrderLineType(
@NonNull final String name,
final boolean canReceive,
@NonNull final String tableName)
{
this.name = name;
this.iconName = canReceive ? "PP_Order_Receive" : "PP_Order_Issue"; // see https://github.com/metasfresh/metasfresh-webui-frontend/issues/675#issuecomment-297016790
this.huType = null;

this.tableName = tableName;

this.canReceive = canReceive;
this.canIssue = !canReceive;
}

private PPOrderLineType(HUEditorRowType huType)
private PPOrderLineType(
@NonNull final HUEditorRowType huType,
@NonNull final String tableName)
{
this.name = huType.getName();
this.iconName = huType.getIconName();
this.huType = huType;

this.tableName = tableName;

canReceive = false;
canIssue = false;
}
Expand All @@ -78,6 +92,11 @@ public String getName()
return name;
}

public String getTableName()
{
return tableName;
}

@Override
public String getIconName()
{
Expand All @@ -98,12 +117,12 @@ public boolean canIssue()
{
return canIssue;
}

public boolean isBOMLine()
{
return this == BOMLine_Component || this == BOMLine_ByCoProduct;
}

public boolean isHUOrHUStorage()
{
return this == HU_LU
Expand All @@ -115,13 +134,13 @@ public boolean isHUOrHUStorage()
public static final PPOrderLineType ofHUEditorRowType(final HUEditorRowType huType)
{
PPOrderLineType type = huType2type.get(huType);
if(type == null)
if (type == null)
{
throw new IllegalArgumentException("No type found for " + huType);
}
return type;
}

private static final ImmutableMap<HUEditorRowType, PPOrderLineType> huType2type = Stream.of(values())
.filter(type -> type.huType != null)
.collect(GuavaCollectors.toImmutableMapByKey(type -> type.huType));
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/de/metas/ui/web/pporder/PPOrderLinesLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.Comparator;
import java.util.List;

import javax.annotation.Nullable;

import org.adempiere.ad.trx.api.ITrx;
import org.adempiere.model.InterfaceWrapperHelper;
import org.adempiere.util.GuavaCollectors;
Expand Down Expand Up @@ -43,6 +45,7 @@
import de.metas.ui.web.window.datatypes.WindowId;
import de.metas.ui.web.window.datatypes.json.JSONLookupValue;
import lombok.Builder;
import lombok.NonNull;

/*
* #%L
Expand Down Expand Up @@ -251,10 +254,14 @@ private PPOrderLineRow createForQty(final I_PP_Order_Qty ppOrderQty, final boole
{
final HUEditorRow huEditorRow = huEditorRepo.retrieveForHUId(ppOrderQty.getM_HU_ID());
final HUEditorRow parentHUViewRecord = null;
return createForHUViewRecordRecursivelly(ppOrderQty, huEditorRow, parentHUViewRecord, readonly);
return createForHUViewRecordRecursively(ppOrderQty, huEditorRow, parentHUViewRecord, readonly);
}

private PPOrderLineRow createForHUViewRecordRecursivelly(final I_PP_Order_Qty ppOrderQty, final HUEditorRow huEditorRow, final HUEditorRow parentHUEditorRow, final boolean readonly)
private PPOrderLineRow createForHUViewRecordRecursively(
@NonNull final I_PP_Order_Qty ppOrderQty,
@NonNull final HUEditorRow huEditorRow,
@Nullable final HUEditorRow parentHUEditorRow,
final boolean readonly)
{
final PPOrderLineType type = PPOrderLineType.ofHUEditorRowType(huEditorRow.getType());

Expand Down Expand Up @@ -300,7 +307,7 @@ private PPOrderLineRow createForHUViewRecordRecursivelly(final I_PP_Order_Qty pp
.setQtyPlan(null) // always null
.setQty(qty)
//
.addIncludedDocumentFrom(huEditorRow.getIncludedRows(), includedHUEditorRow -> createForHUViewRecordRecursivelly(ppOrderQty, includedHUEditorRow, huEditorRow, readonly))
.addIncludedDocumentFrom(huEditorRow.getIncludedRows(), includedHUEditorRow -> createForHUViewRecordRecursively(ppOrderQty, includedHUEditorRow, huEditorRow, readonly))
//
.build();
}
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/de/metas/ui/web/pporder/PPOrderLinesView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.Set;
import java.util.stream.Stream;

import javax.annotation.Nullable;

import org.adempiere.util.GuavaCollectors;
import org.adempiere.util.Services;
import org.adempiere.util.lang.ExtendedMemorizingSupplier;
Expand Down Expand Up @@ -93,8 +95,7 @@ private PPOrderLinesView(
@NonNull final JSONViewDataType viewType,
final Set<DocumentPath> referencingDocumentPaths,
final int ppOrderId,
final ASIViewRowAttributesProvider asiAttributesProvider
)
final ASIViewRowAttributesProvider asiAttributesProvider)
{
this.parentViewId = parentViewId; // might be null
this.parentRowId = parentRowId; // might be null
Expand Down Expand Up @@ -140,7 +141,7 @@ public ViewId getParentViewId()
{
return parentViewId;
}

@Override
public DocumentId getParentRowId()
{
Expand All @@ -165,10 +166,23 @@ public ImmutableSet<DocumentPath> getReferencingDocumentPaths()
return referencingDocumentPaths;
}

/**
* @param may be {@code null}; in that case, the method also returns {@code null}
* @return the table name for the given row
*/
@Override
public String getTableName()
public String getTableNameOrNull(@Nullable final DocumentId documentId)
{
return null; // no particular table (i.e. we have more)
if (documentId == null)
{
return null;
}
final PPOrderLineRow ppOrderLine = getById(documentId);
if (ppOrderLine == null)
{
return null; // just be sure to avoid an NPE in here
}
return ppOrderLine.getType().getTableName();
}

public int getPP_Order_ID()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,15 @@ private ViewAsPreconditionsContext(@NonNull final IView view, @NonNull final Doc
Check.assumeNotNull(view, "Parameter view is not null");
this.view = view;
this.windowId = view.getViewId().getWindowId();
this.tableName = view.getTableName();
if (selectedDocumentIds.isSingleDocumentId())
{
this.tableName = view.getTableNameOrNull(selectedDocumentIds.getSingleDocumentId());
}
else
{
this.tableName = view.getTableNameOrNull(null);
}

this.selectedDocumentIds = selectedDocumentIds;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ private ProcessInfo createProcessInfo(@NonNull final CreateProcessInstanceReques
}
else
{
tableName = view.getTableName();
tableName = view.getTableNameOrNull(viewSingleDocumentId);
recordId = -1;
}
}
else
{
tableName = view.getTableName();
tableName = view.getTableNameOrNull(null);
recordId = -1;
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/de/metas/ui/web/view/DefaultView.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,11 @@ public ImmutableSet<DocumentPath> getReferencingDocumentPaths()
return referencingDocumentPaths;
}

/**
* Returns the table name as provided by our internal {@link IViewDataRepository}.
*/
@Override
public String getTableName()
public String getTableNameOrNull(@Nullable final DocumentId ignored)
{
return viewDataRepository.getTableName();
}
Expand Down Expand Up @@ -410,7 +413,7 @@ public <T> List<T> retrieveModelsByIds(final DocumentIdsSelection rowIds, final
@Override
public void notifyRecordsChanged(final Set<TableRecordReference> recordRefs)
{
final String viewTableName = getTableName();
final String viewTableName = getTableNameOrNull(null);

final DocumentIdsSelection rowIds = recordRefs.stream()
.filter(recordRef -> Objects.equals(viewTableName, recordRef.getTableName()))
Expand Down
Loading

0 comments on commit 3680e6f

Please sign in to comment.