Skip to content

Commit

Permalink
HUEditorViewRepository distinguish between "no restriction" and "no HUs"
Browse files Browse the repository at this point in the history
..in retrieveHUIdsEffective()

Also 
* HUIdsFilterHelper: minor javadoc

557: Picking Window: Open HU Selection window filtering 

Task-Url: #557
  • Loading branch information
metas-ts committed Aug 31, 2017
1 parent 2e01d97 commit 44285f5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ SqlViewBinding getSqlViewBinding()
{
return sqlViewBinding;
}

SqlViewRowIdsConverter getRowIdsConverter()
{
return getSqlViewBinding().getRowIdsConverter();
Expand Down Expand Up @@ -186,7 +186,7 @@ private HUEditorRow createHUEditorRow(
.setProcessed(processed)
.setAttributesProvider(attributesProvider)
//
//.setHUId(huId)
// .setHUId(huId)
.setCode(hu.getValue())
.setHUUnitType(huUnitTypeLookupValue)
.setHUStatus(huStatus)
Expand Down Expand Up @@ -307,9 +307,9 @@ private IHUProductStorage getSingleProductStorage(final I_M_HU hu)
}

private HUEditorRow createHUEditorRow(
final int parent_HU_ID,
final int topLevelHUId,
@NonNull final IHUProductStorage huStorage,
final int parent_HU_ID,
final int topLevelHUId,
@NonNull final IHUProductStorage huStorage,
final boolean processed)
{
final I_M_HU hu = huStorage.getM_HU();
Expand All @@ -324,7 +324,7 @@ private HUEditorRow createHUEditorRow(
.setProcessed(processed)
.setAttributesProvider(attributesProviderEffective)
//
//.setHUId(huId)
// .setHUId(huId)
// .setCode(hu.getValue()) // NOTE: don't show value on storage level
.setHUUnitType(JSONLookupValue.of(X_M_HU_PI_Version.HU_UNITTYPE_VirtualPI, "CU"))
.setHUStatus(createHUStatusLookupValue(hu))
Expand Down Expand Up @@ -364,16 +364,19 @@ private static JSONLookupValue createUOMLookupValue(final I_C_UOM uom)
return JSONLookupValue.of(uom.getC_UOM_ID(), uom.getUOMSymbol());
}

public List<Integer> retrieveHUIdsEffective(final HUIdsFilterData huIdsFilter, final List<DocumentFilter> filters)
public List<Integer> retrieveHUIdsEffective(
@NonNull final HUIdsFilterData huIdsFilter,
@NonNull final List<DocumentFilter> filters)
{
final ImmutableList<Integer> onlyHUIds = ImmutableList.copyOf(Iterables.concat(huIdsFilter.getInitialHUIds(), huIdsFilter.getMustHUIds()));

final ImmutableList<Integer> onlyHUIds = createListOfCombinedIDs(huIdsFilter);

if (filters.isEmpty() && !huIdsFilter.hasInitialHUQuery())
if (filters.isEmpty() && !huIdsFilter.hasInitialHUQuery() && onlyHUIds != null)
{
// shortcut: don't bother the DB but return the list of IDs that we already have
return onlyHUIds;
}

//
// Create HU query
IHUQueryBuilder huQuery = huIdsFilter.getInitialHUQueryOrNull();
if (huQuery == null)
Expand All @@ -383,7 +386,7 @@ public List<Integer> retrieveHUIdsEffective(final HUIdsFilterData huIdsFilter, f
huQuery.setContext(PlainContextAware.newOutOfTrx());

// Only HUs
if (!onlyHUIds.isEmpty())
if (onlyHUIds != null)
{
huQuery.addOnlyHUIds(onlyHUIds);
}
Expand All @@ -403,4 +406,26 @@ public List<Integer> retrieveHUIdsEffective(final HUIdsFilterData huIdsFilter, f

return huQuery.createQuery().listIds();
}

private ImmutableList<Integer> createListOfCombinedIDs(@NonNull final HUIdsFilterData huIdsFilter)
{
final ImmutableList<Integer> onlyHUIds;
if (huIdsFilter.getInitialHUIds() != null && huIdsFilter.getMustHUIds() != null)
{
onlyHUIds = ImmutableList.copyOf(Iterables.concat(huIdsFilter.getInitialHUIds(), huIdsFilter.getMustHUIds()));
}
else if (huIdsFilter.getInitialHUIds() != null)
{
onlyHUIds = ImmutableList.copyOf(huIdsFilter.getInitialHUIds());
}
else if (huIdsFilter.getMustHUIds() != null)
{
onlyHUIds = ImmutableList.copyOf(huIdsFilter.getMustHUIds());
}
else
{
onlyHUIds = null; // both are null => no restriction
}
return onlyHUIds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public final class HUIdsFilterHelper
public static final class HUIdsFilterData
{
/**
* Creates a new instance with the given {@code huIds} as {@link #getInitialHUIds()}.
*
* @param huIds may be empty, but not null. Empty means that <b>no</b> HU will be matched.
* @return
Expand Down Expand Up @@ -191,6 +192,7 @@ public static final DocumentFilter findExistingOrNull(final Collection<DocumentF
}

/**
*
* @param huIds huIds may be empty, but not null. Empty means that <b>no</b> HU will be matched.
*
* @return
Expand Down

0 comments on commit 44285f5

Please sign in to comment.