Skip to content

Commit

Permalink
IViewsIndexStorage; hasIncludedViewOnSelectSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Jun 29, 2017
1 parent d403e86 commit 07c840e
Show file tree
Hide file tree
Showing 17 changed files with 572 additions and 96 deletions.
14 changes: 14 additions & 0 deletions src/main/java/de/metas/ui/web/picking/PickingRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.metas.ui.web.view.IViewRow;
import de.metas.ui.web.view.IViewRowAttributes;
import de.metas.ui.web.view.IViewRowType;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.descriptor.annotation.ViewColumn;
import de.metas.ui.web.view.descriptor.annotation.ViewColumn.ViewColumnLayout;
import de.metas.ui.web.view.descriptor.annotation.ViewColumnHelper;
Expand Down Expand Up @@ -50,6 +51,7 @@
@ToString(exclude = "_fieldNameAndJsonValues")
public final class PickingRow implements IViewRow
{
private final ViewId viewId;
private final DocumentId id;
private final IViewRowType type;
private final boolean processed;
Expand All @@ -75,12 +77,15 @@ public final class PickingRow implements IViewRow
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 50)
})
private final java.util.Date preparationDate;

private final ViewId includedViewId;

private transient ImmutableMap<String, Object> _fieldNameAndJsonValues;

@Builder
private PickingRow(
@NonNull final DocumentId id,
@NonNull final ViewId viewId,
final IViewRowType type,
final boolean processed,
@NonNull final DocumentPath documentPath,
Expand All @@ -92,6 +97,7 @@ private PickingRow(
final Date preparationDate)
{
this.id = id;
this.viewId = viewId;
this.type = type;
this.processed = processed;
this.documentPath = documentPath;
Expand All @@ -101,6 +107,8 @@ private PickingRow(
this.qtyToDeliver = qtyToDeliver;
this.deliveryDate = deliveryDate;
this.preparationDate = preparationDate;

this.includedViewId = PickingSlotViewsIndexStorage.createViewId(viewId, id);
}

@Override
Expand Down Expand Up @@ -160,4 +168,10 @@ public boolean hasIncludedView()
{
return true;
}

@Override
public ViewId getIncludedViewId()
{
return includedViewId;
}
}
16 changes: 10 additions & 6 deletions src/main/java/de/metas/ui/web/picking/PickingSlotView.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,27 @@
* 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
* 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
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

public class PickingSlotView implements IView
{
public static PickingSlotView cast(final IView pickingSlotView)
{
return (PickingSlotView)pickingSlotView;
}

private final ViewId viewId;
private ITranslatableString description;
private final ITranslatableString description;
private final Map<DocumentId, PickingSlotRow> rows;

@Builder
Expand Down Expand Up @@ -212,5 +217,4 @@ public void notifyRecordsChanged(final Set<TableRecordReference> recordRefs)
// TODO Auto-generated method stub

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ public PickingSlotView createView(final CreateViewRequest request)
final Set<DocumentId> rowIds = request.getFilterOnlyIds().stream().map(DocumentId::of).collect(ImmutableSet.toImmutableSet());
final List<PickingSlotRow> rows = pickingSlotRepo.retrieveRowsByIds(rowIds);

final ViewId pickingViewId = request.getParentViewId();
final DocumentId pickingRowId = request.getSingleReferencingDocumentPathOrNull().getDocumentId();
final ViewId pickingSlotViewId = PickingSlotViewsIndexStorage.createViewId(pickingViewId, pickingRowId);

return PickingSlotView.builder()
.viewId(ViewId.random(request.getWindowId()))
.viewId(pickingSlotViewId)
.rows(rows)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import org.adempiere.ad.trx.api.ITrx;
import org.adempiere.util.Services;
import org.compiere.Adempiere;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -51,7 +53,8 @@ public class PickingSlotViewRepository
private final LookupDataSource bpartnerLookup;
private final LookupDataSource bpartnerLocationLookup;

public PickingSlotViewRepository()
@Autowired
public PickingSlotViewRepository(final Adempiere databaseAccess)
{
warehouseLookup = LookupDataSourceFactory.instance.getLookupDataSource(SqlLookupDescriptor.builder()
.setColumnName(I_M_PickingSlot.COLUMNNAME_M_Warehouse_ID)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package de.metas.ui.web.picking;

import java.util.stream.Stream;

import org.adempiere.exceptions.AdempiereException;
import org.springframework.stereotype.Component;

import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewsIndexStorage;
import de.metas.ui.web.view.IViewsRepository;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.window.datatypes.DocumentId;
import de.metas.ui.web.window.datatypes.WindowId;
import lombok.NonNull;

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

/**
* {@link PickingSlotView}s index storage.
*
* It's not actually a storage. It just forwards all calls to {@link PickingView} where the {@link PickingSlotView}s are storaged, one per each row.
*
* @author metas-dev <dev@metasfresh.com>
*
*/
@Component
public class PickingSlotViewsIndexStorage implements IViewsIndexStorage
{
// NOTE: avoid using @Autowired because might introduce cyclic dependency.
// We have a setter which will be called when this instance will be registered.
private IViewsRepository viewsRepository;

@Override
public void setViewsRepository(@NonNull final IViewsRepository viewsRepository)
{
this.viewsRepository = viewsRepository;
}

@NonNull
private IViewsRepository getViewsRepository()
{
return viewsRepository;
}

@Override
public WindowId getWindowId()
{
return PickingConstants.WINDOWID_PickingSlotView;
}

@Override
public void put(final IView pickingSlotView)
{
final ViewId pickingSlotViewId = pickingSlotView.getViewId();
final PickingView pickingView = getPickingViewBySlotId(pickingSlotViewId);

final DocumentId rowId = extractRowId(pickingSlotViewId);

pickingView.setPickingSlotView(rowId, PickingSlotView.cast(pickingSlotView));
}

public static ViewId createViewId(final ViewId pickingViewId, final DocumentId pickingRowId)
{
if (!PickingConstants.WINDOWID_PickingView.equals(pickingViewId.getWindowId()))
{
throw new AdempiereException("Invalid pickingViewId '" + pickingViewId + "'. WindowId not matching.")
.setParameter("expectedWindowId", PickingConstants.WINDOWID_PickingView);
}

return ViewId.ofParts(PickingConstants.WINDOWID_PickingSlotView, pickingViewId.getViewIdPart(), pickingRowId.toJson());
}

private ViewId extractPickingViewId(final ViewId pickingSlotViewId)
{
final String viewIdPart = pickingSlotViewId.getViewIdPart();
return ViewId.ofParts(PickingConstants.WINDOWID_PickingView, viewIdPart);
}

private DocumentId extractRowId(final ViewId pickingSlotViewId)
{
final String rowIdStr = pickingSlotViewId.getPart(2);
return DocumentId.of(rowIdStr);
}

private PickingView getPickingViewBySlotId(final ViewId pickingSlotViewId)
{
final ViewId pickingViewId = extractPickingViewId(pickingSlotViewId);
final PickingView view = PickingView.cast(getViewsRepository().getView(pickingViewId));
return view;
}

@Override
public PickingSlotView getByIdOrNull(final ViewId pickingSlotViewId)
{
final DocumentId rowId = extractRowId(pickingSlotViewId);
return getPickingViewBySlotId(pickingSlotViewId).getPickingSlotViewOrNull(rowId);
}

@Override
public void removeById(final ViewId pickingSlotViewId)
{
final DocumentId rowId = extractRowId(pickingSlotViewId);
getPickingViewBySlotId(pickingSlotViewId).removePickingSlotView(rowId);
}

@Override
public Stream<IView> streamAllViews()
{
// Do we really have to implement this?
return Stream.empty();
}

}
28 changes: 27 additions & 1 deletion src/main/java/de/metas/ui/web/picking/PickingView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;

import org.adempiere.ad.dao.IQueryBL;
Expand Down Expand Up @@ -61,9 +62,16 @@

public class PickingView implements IView
{
public static PickingView cast(final IView view)
{
return (PickingView)view;
}

private final ViewId viewId;
private final ITranslatableString description;
private final Map<DocumentId, PickingRow> rows;

private final ConcurrentHashMap<DocumentId, PickingSlotView> pickingSlotsViewByRowId = new ConcurrentHashMap<>();

@Builder
private PickingView(@NonNull final ViewId viewId,
Expand Down Expand Up @@ -231,6 +239,23 @@ public void notifyRecordsChanged(final Set<TableRecordReference> recordRefs)
// TODO Auto-generated method stub

}

/* package */ void setPickingSlotView(@NonNull final DocumentId rowId, @NonNull final PickingSlotView pickingSlotView)
{
pickingSlotsViewByRowId.put(rowId, pickingSlotView);
}

/* package */ void removePickingSlotView(@NonNull final DocumentId rowId)
{
pickingSlotsViewByRowId.remove(rowId);
}

/* package */ PickingSlotView getPickingSlotViewOrNull(@NonNull final DocumentId rowId)
{
return pickingSlotsViewByRowId.get(rowId);
}



@ViewAction(caption = "picking slots", defaultAction = true)
public CreateAndOpenIncludedViewAction openPickingSlots(final PickingView pickingView, final DocumentIdsSelection selectedRowIds)
Expand All @@ -243,14 +268,15 @@ public CreateAndOpenIncludedViewAction openPickingSlots(final PickingView pickin
// TODO: fetch the picking slots eligible for selected picking row
final DocumentId pickingRowId = selectedRowIds.getSingleDocumentId();
final PickingRow pickingRow = pickingView.getById(pickingRowId);

final PickingSlotViewRepository pickingSlotRepo = Adempiere.getBean(PickingSlotViewRepository.class);
final Set<Integer> pickingSlotRowIds = pickingSlotRepo.retrieveAllRowIds();

final CreateViewRequest createViewRequest = CreateViewRequest.builder(PickingConstants.WINDOWID_PickingSlotView, JSONViewDataType.includedView)
.setParentViewId(viewId)
.setReferencingDocumentPath(pickingRow.getDocumentPath())
.setFilterOnlyIds(pickingSlotRowIds)
.build();
return CreateAndOpenIncludedViewAction.of(createViewRequest);
}

}
7 changes: 5 additions & 2 deletions src/main/java/de/metas/ui/web/picking/PickingViewFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType
.setHasAttributesSupport(false)
.setHasTreeSupport(false)
.setHasIncludedViewSupport(true)
.setHasIncludedViewOnSelectSupport(true)
//
.addElementsFromViewRowClass(PickingRow.class, viewDataType)
//
Expand All @@ -84,11 +85,13 @@ public IView createView(final CreateViewRequest request)
throw new IllegalArgumentException("Invalid request's windowId: " + request);
}

final ViewId viewId = ViewId.random(PickingConstants.WINDOWID_PickingView);

final Set<DocumentId> rowIds = request.getFilterOnlyIds().stream().map(DocumentId::of).collect(ImmutableSet.toImmutableSet());
final List<PickingRow> rows = pickingViewRepo.retrieveRowsByIds(rowIds);
final List<PickingRow> rows = pickingViewRepo.retrieveRowsByIds(viewId, rowIds);

return PickingView.builder()
.viewId(ViewId.random(PickingConstants.WINDOWID_PickingView))
.viewId(viewId)
.description(ITranslatableString.empty())
.rows(rows)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.google.common.collect.ImmutableSet;

import de.metas.inoutcandidate.model.I_M_Packageable_V;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.ViewRow.DefaultRowType;
import de.metas.ui.web.window.datatypes.DocumentId;
import de.metas.ui.web.window.datatypes.DocumentPath;
Expand Down Expand Up @@ -67,7 +68,7 @@ public PickingViewRepository()
.provideForScope(LookupScope.DocumentField));
}

public List<PickingRow> retrieveRowsByIds(final Collection<DocumentId> rowIds)
public List<PickingRow> retrieveRowsByIds(final ViewId viewId, final Collection<DocumentId> rowIds)
{
final Set<Integer> shipmentScheduleIds = rowIds.stream().map(DocumentId::toInt).collect(ImmutableSet.toImmutableSet());
if (shipmentScheduleIds.isEmpty())
Expand All @@ -80,17 +81,18 @@ public List<PickingRow> retrieveRowsByIds(final Collection<DocumentId> rowIds)
.addInArrayFilter(I_M_Packageable_V.COLUMN_M_ShipmentSchedule_ID, shipmentScheduleIds)
.create()
.stream(I_M_Packageable_V.class)
.map(packageable -> createPickingRow(packageable))
.map(packageable -> createPickingRow(viewId, packageable))
.collect(ImmutableList.toImmutableList());

}

private PickingRow createPickingRow(final I_M_Packageable_V packageable)
private PickingRow createPickingRow(final ViewId viewId, final I_M_Packageable_V packageable)
{
final DocumentId rowId = DocumentId.of(packageable.getM_ShipmentSchedule_ID());
final DocumentPath documentPath = DocumentPath.rootDocumentPath(PickingConstants.WINDOWID_PickingView, rowId);
return PickingRow.builder()
.documentPath(documentPath)
.viewId(viewId)
.id(rowId)
.type(DefaultRowType.Row)
.processed(false)
Expand Down
Loading

0 comments on commit 07c840e

Please sign in to comment.