Skip to content

Commit

Permalink
#181 HUDocumentViewSelection.addHUsAndInvalidate
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Feb 24, 2017
1 parent 7f8489c commit 40ee445
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Stream;

import org.adempiere.ad.dao.IQueryBuilder;
Expand All @@ -14,8 +15,6 @@
import org.compiere.model.I_M_Product;
import org.compiere.util.Env;

import com.google.common.collect.ImmutableSet;

import de.metas.handlingunits.IHUDisplayNameBuilder;
import de.metas.handlingunits.IHandlingUnitsBL;
import de.metas.handlingunits.IHandlingUnitsDAO;
Expand Down Expand Up @@ -67,7 +66,7 @@ public static final HUDocumentViewLoader of(final JSONCreateDocumentViewRequest

private final int adWindowId;
private final String referencingTableName;
private final Set<Integer> filterOnlyIds;
private final CopyOnWriteArraySet<Integer> huIds = new CopyOnWriteArraySet<>();

private final IDocumentViewAttributesProvider _attributesProvider;

Expand All @@ -78,20 +77,13 @@ private HUDocumentViewLoader(final JSONCreateDocumentViewRequest request, final
adWindowId = request.getAD_Window_ID();
this.referencingTableName = referencingTableName;

boolean haveFilters = false;

final Set<Integer> filterOnlyIds = request.getFilterOnlyIds();
if (filterOnlyIds != null && !filterOnlyIds.isEmpty())
{
this.filterOnlyIds = ImmutableSet.copyOf(filterOnlyIds);
haveFilters = true;
}
else
{
this.filterOnlyIds = ImmutableSet.of();
huIds.addAll(filterOnlyIds);
}

if (!haveFilters)
if (huIds.isEmpty())
{
throw new IllegalArgumentException("No filters specified for " + request);
}
Expand All @@ -104,9 +96,18 @@ public IDocumentViewAttributesProvider getAttributesProvider()
return _attributesProvider;
}

public void addHUs(final Collection<I_M_HU> husToAdd)
{
final Set<Integer> huIdsToAdd = husToAdd.stream()
.map(I_M_HU::getM_HU_ID)
.collect(GuavaCollectors.toImmutableSet());

this.huIds.addAll(huIdsToAdd);
}

public List<HUDocumentView> retrieveDocumentViews()
{
return retrieveTopLevelHUs(filterOnlyIds)
return retrieveTopLevelHUs(huIds)
.stream()
.map(hu -> createDocumentView(hu))
.collect(GuavaCollectors.toImmutableList());
Expand All @@ -133,7 +134,7 @@ private static List<I_M_HU> retrieveTopLevelHUs(final Collection<Integer> filter
private HUDocumentView createDocumentView(final I_M_HU hu)
{
final boolean aggregateHU = Services.get(IHandlingUnitsBL.class).isAggregateHU(hu);

final String huUnitTypeCode = hu.getM_HU_PI_Version().getHU_UnitType();
final HUDocumentViewType huRecordType;
if (aggregateHU)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private static final Comparator<HUDocumentView> createComparatorOrNull(final Lis
}

@Override
public IDocumentView getById(final DocumentId documentId) throws EntityNotFoundException
public HUDocumentView getById(final DocumentId documentId) throws EntityNotFoundException
{
return getRecords().getById(documentId);
}
Expand Down Expand Up @@ -248,6 +248,17 @@ private void invalidateAllNoNotify()
_recordsSupplier.forget();
documentViewsLoader.getAttributesProvider().invalidateAll();
}

public void addHUsAndInvalidate(final Collection<I_M_HU> husToAdd)
{
if(husToAdd.isEmpty())
{
return;
}

documentViewsLoader.addHUs(husToAdd);
invalidateAll();
}

@Override
public void notifyRecordsChanged(final Set<TableRecordReference> recordRefs)
Expand Down

0 comments on commit 40ee445

Please sign in to comment.