Skip to content

Commit

Permalink
ViewProfileId support
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Dec 3, 2017
1 parent 697a010 commit 47c9b75
Show file tree
Hide file tree
Showing 34 changed files with 742 additions and 241 deletions.
3 changes: 2 additions & 1 deletion src/main/java/de/metas/ui/web/board/BoardRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewRowOverrides;
import de.metas.ui.web.view.IViewsRepository;
import de.metas.ui.web.view.ViewProfileId;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.ViewResult;
import de.metas.ui.web.view.ViewRowOverridesHelper;
Expand Down Expand Up @@ -262,7 +263,7 @@ public JSONNewCardsViewLayout getNewCardsViewLayout(@PathVariable("boardId") fin

final BoardDescriptor boardDescriptor = boardsRepo.getBoardDescriptor(boardId);

final ViewLayout documentsViewLayout = viewsRepo.getViewLayout(boardDescriptor.getDocumentWindowId(), JSONViewDataType.list);
final ViewLayout documentsViewLayout = viewsRepo.getViewLayout(boardDescriptor.getDocumentWindowId(), JSONViewDataType.list, ViewProfileId.NULL);

final JSONOptions jsonOpts = newJSONOptions();
final String adLanguage = jsonOpts.getAD_Language();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/de/metas/ui/web/debug/DebugRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import de.metas.ui.web.process.ProcessRestController;
import de.metas.ui.web.session.UserSession;
import de.metas.ui.web.view.IViewsRepository;
import de.metas.ui.web.view.ViewProfileId;
import de.metas.ui.web.view.SqlViewFactory;
import de.metas.ui.web.view.ViewResult;
import de.metas.ui.web.view.ViewRowOverridesHelper;
import de.metas.ui.web.view.descriptor.annotation.ViewColumnHelper;
Expand Down Expand Up @@ -103,6 +105,9 @@ public class DebugRestController
@Autowired
@Lazy
private IViewsRepository viewsRepo;
@Autowired
@Lazy
private SqlViewFactory sqlViewFactory;

@Autowired
@Lazy
Expand Down Expand Up @@ -179,6 +184,12 @@ public List<JSONViewResult> getViewsList()
.map(viewResult -> JSONViewResult.of(viewResult, ViewRowOverridesHelper.NULL, adLanguage))
.collect(GuavaCollectors.toImmutableList());
}

@PostMapping("/viewDefaultProfile/{windowId}")
public void setDefaultViewProfile(@PathVariable("windowId") final String windowIdStr, @RequestBody final String profileIdStr)
{
sqlViewFactory.setDefaultProfileId(WindowId.fromJson(windowIdStr), ViewProfileId.fromJson(profileIdStr));
}

@RequestMapping(value = "/lookups/cacheStats", method = RequestMethod.GET)
public List<String> getLookupCacheStats()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import de.metas.ui.web.view.SqlViewFactory;
import de.metas.ui.web.view.ViewFactory;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.ViewProfileId;
import de.metas.ui.web.view.descriptor.SqlViewBinding;
import de.metas.ui.web.view.descriptor.ViewLayout;
import de.metas.ui.web.view.json.JSONViewDataType;
Expand Down Expand Up @@ -152,10 +153,10 @@ private SqlViewBinding createSqlViewBinding()
final List<String> displayFieldNames = ImmutableList.of(I_M_HU.COLUMNNAME_M_HU_ID);

final SqlViewBinding.Builder sqlViewBinding = SqlViewBinding.builder()
.setTableName(I_M_HU.Table_Name)
.setDisplayFieldNames(displayFieldNames)
.setSqlWhereClause(sqlWhereClause.toString())
.setRowIdsConverter(HUSqlViewRowIdsConverter.instance);
.tableName(I_M_HU.Table_Name)
.displayFieldNames(displayFieldNames)
.sqlWhereClause(sqlWhereClause.toString())
.rowIdsConverter(HUSqlViewRowIdsConverter.instance);

//
// View Fields
Expand All @@ -165,39 +166,33 @@ private SqlViewBinding createSqlViewBinding()
huEntityBindings.getFields()
.stream()
.map(huField -> SqlViewFactory.createViewFieldBindingBuilder(huField, displayFieldNames).build())
.forEach(sqlViewBinding::addField);
.forEach(sqlViewBinding::field);
}

//
// View filters and converters
{
final Collection<DocumentFilterDescriptor> huStandardFilters = huEntityDescriptor.getFilterDescriptors().getAll();
sqlViewBinding
.setFilterDescriptors(ImmutableDocumentFilterDescriptorsProvider.builder()
.filterDescriptors(ImmutableDocumentFilterDescriptorsProvider.builder()
.addDescriptors(huStandardFilters)
.addDescriptor(HUBarcodeSqlDocumentFilterConverter.createDocumentFilterDescriptor())
.build())
.addFilterConverter(HUBarcodeSqlDocumentFilterConverter.FILTER_ID, HUBarcodeSqlDocumentFilterConverter.instance)
.addFilterConverter(HUIdsFilterHelper.FILTER_ID, HUIdsFilterHelper.SQL_DOCUMENT_FILTER_CONVERTER);
.filterConverter(HUBarcodeSqlDocumentFilterConverter.FILTER_ID, HUBarcodeSqlDocumentFilterConverter.instance)
.filterConverter(HUIdsFilterHelper.FILTER_ID, HUIdsFilterHelper.SQL_DOCUMENT_FILTER_CONVERTER);
}

//
return sqlViewBinding.build();
}

@Override
public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType viewDataType)
public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType viewDataType, final ViewProfileId profileId)
{
final ArrayKey key = ArrayKey.of(windowId, viewDataType);
return layouts.getOrLoad(key, () -> createHUViewLayout(windowId, viewDataType));
}

@Override
public Collection<DocumentFilterDescriptor> getViewFilterDescriptors(final WindowId windowId, final JSONViewDataType viewType)
{
return getSqlViewBinding().getViewFilterDescriptors().getAll();
}

private final ViewLayout createHUViewLayout(final WindowId windowId, final JSONViewDataType viewDataType)
{
if (viewDataType == JSONViewDataType.includedView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import javax.annotation.Nullable;

import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.Check;
import org.adempiere.util.GuavaCollectors;
Expand All @@ -32,6 +34,7 @@
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewFactory;
import de.metas.ui.web.view.IViewsIndexStorage;
import de.metas.ui.web.view.ViewProfileId;
import de.metas.ui.web.view.ViewCloseReason;
import de.metas.ui.web.view.ViewFactory;
import de.metas.ui.web.view.ViewId;
Expand Down Expand Up @@ -91,7 +94,7 @@ public WindowId getWindowId()
}

@Override
public ViewLayout getViewLayout(@NonNull final WindowId windowId, @NonNull final JSONViewDataType viewDataType)
public ViewLayout getViewLayout(@NonNull final WindowId windowId, @NonNull final JSONViewDataType viewDataType, @Nullable final ViewProfileId profileId)
{
final ArrayKey key = ArrayKey.of(windowId, viewDataType);
return viewLayoutCache.getOrLoad(key, () -> createViewLayout(windowId, viewDataType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.Set;
import java.util.function.Supplier;

import javax.annotation.Nullable;

import com.google.common.collect.ImmutableSet;

import de.metas.handlingunits.picking.PickingCandidateService;
Expand All @@ -12,6 +14,7 @@
import de.metas.ui.web.view.CreateViewRequest;
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewFactory;
import de.metas.ui.web.view.ViewProfileId;
import de.metas.ui.web.view.ViewFactory;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.descriptor.IncludedViewLayout;
Expand Down Expand Up @@ -73,7 +76,8 @@ public PackageableViewFactory(
@Override
public ViewLayout getViewLayout(
@NonNull final WindowId windowId,
@NonNull final JSONViewDataType viewDataType)
@NonNull final JSONViewDataType viewDataType,
@Nullable final ViewProfileId profileId)
{
// TODO: cache it

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import de.metas.ui.web.picking.process.WEBUI_Picking_ReturnQtyToSourceHU;
import de.metas.ui.web.view.CreateViewRequest;
import de.metas.ui.web.view.IViewFactory;
import de.metas.ui.web.view.ViewProfileId;
import de.metas.ui.web.view.ViewFactory;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.descriptor.ViewLayout;
Expand Down Expand Up @@ -72,7 +73,7 @@ public class PickingSlotViewFactory implements IViewFactory
private PickingSlotViewRepository pickingSlotRepo;

@Override
public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType viewDataType)
public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType viewDataType, @Nullable final ViewProfileId profileId)
{
if (!PickingConstants.WINDOWID_PickingSlotView.equals(windowId))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.stream.Stream;

import javax.annotation.Nullable;

import org.adempiere.util.Services;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -15,6 +17,7 @@
import de.metas.ui.web.view.IViewFactory;
import de.metas.ui.web.view.IViewsIndexStorage;
import de.metas.ui.web.view.IViewsRepository;
import de.metas.ui.web.view.ViewProfileId;
import de.metas.ui.web.view.ViewFactory;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.descriptor.ViewLayout;
Expand Down Expand Up @@ -53,9 +56,9 @@ public class AfterPickingHUViewFactory implements IViewFactory, IViewsIndexStora
private HUEditorViewFactory huEditorViewFactory;

@Override
public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType viewDataType)
public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType viewDataType, @Nullable final ViewProfileId profileId)
{
return huEditorViewFactory.getViewLayout(windowId, viewDataType);
return huEditorViewFactory.getViewLayout(windowId, viewDataType, profileId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.List;
import java.util.Properties;

import javax.annotation.Nullable;

import org.adempiere.ad.window.api.IADWindowDAO;
import org.adempiere.util.Services;
import org.compiere.util.Env;
Expand All @@ -17,6 +19,7 @@
import de.metas.ui.web.pickingslot.process.WEBUI_PickingSlot_TakeOutHU;
import de.metas.ui.web.view.CreateViewRequest;
import de.metas.ui.web.view.IViewFactory;
import de.metas.ui.web.view.ViewProfileId;
import de.metas.ui.web.view.ViewFactory;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.descriptor.IncludedViewLayout;
Expand Down Expand Up @@ -62,7 +65,7 @@ public class AggregationPickingSlotsViewFactory implements IViewFactory
private PickingSlotViewRepository pickingSlotRepo;

@Override
public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType viewDataType)
public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType viewDataType, @Nullable final ViewProfileId profileId)
{
// TODO: cache it

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package de.metas.ui.web.pporder;

import java.util.Collection;
import java.util.List;

import javax.annotation.Nullable;

import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.Services;
import org.compiere.util.CCache;
Expand All @@ -14,13 +15,13 @@

import de.metas.process.IADProcessDAO;
import de.metas.process.RelatedProcessDescriptor;
import de.metas.ui.web.document.filter.DocumentFilterDescriptor;
import de.metas.ui.web.handlingunits.HUEditorViewFactory;
import de.metas.ui.web.pattribute.ASIRepository;
import de.metas.ui.web.view.ASIViewRowAttributesProvider;
import de.metas.ui.web.view.CreateViewRequest;
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewFactory;
import de.metas.ui.web.view.ViewProfileId;
import de.metas.ui.web.view.ViewFactory;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.descriptor.IncludedViewLayout;
Expand Down Expand Up @@ -105,17 +106,11 @@ public IView deleteStickyFilter(final IView view, final String filterId)
}

@Override
public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType viewDataType_NOTUSED)
public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType viewDataType_NOTUSED, @Nullable final ViewProfileId profileId_NOTUSED)
{
return layouts.getOrLoad(windowId, () -> createViewLayout(windowId));
}

@Override
public Collection<DocumentFilterDescriptor> getViewFilterDescriptors(final WindowId windowId, final JSONViewDataType viewType)
{
return null; // not supported
}

private final ViewLayout createViewLayout(final WindowId windowId)
{
return ViewLayout.builder()
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/de/metas/ui/web/view/CreateViewRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public static final Builder filterViewBuilder(
final List<JSONDocumentFilter> jsonFilters = filterViewRequest.getFilters();

return builder(view.getViewId().getWindowId(), view.getViewType())
.setProfileId(view.getProfileId())
.setParentViewId(view.getParentViewId())
.setParentRowId(view.getParentRowId())
.setReferencingDocumentPaths(view.getReferencingDocumentPaths())
Expand All @@ -103,6 +104,7 @@ public static final Builder deleteStickyFilterBuilder(
final Set<DocumentPath> referencingDocumentPaths = ImmutableSet.of(); // view.getReferencingDocumentPaths();

return builder(view.getViewId().getWindowId(), view.getViewType())
.setProfileId(view.getProfileId())
.setParentViewId(view.getParentViewId())
.setParentRowId(view.getParentRowId())
.setReferencingDocumentPaths(referencingDocumentPaths)
Expand All @@ -116,6 +118,7 @@ public static final Builder deleteStickyFilterBuilder(

ViewId viewId;
JSONViewDataType viewType;
ViewProfileId profileId;

ViewId parentViewId;
DocumentId parentRowId;
Expand Down Expand Up @@ -155,6 +158,7 @@ private CreateViewRequest(final Builder builder)
{
viewId = builder.getViewId();
viewType = builder.getViewType();
profileId = builder.getProfileId();

parentViewId = builder.getParentViewId();
parentRowId = builder.getParentRowId();
Expand Down Expand Up @@ -220,6 +224,7 @@ public static final class Builder
{
private final ViewId viewId;
private final JSONViewDataType viewType;
private ViewProfileId profileId = ViewProfileId.NULL;

private ViewId parentViewId;
private DocumentId parentRowId;
Expand Down Expand Up @@ -261,6 +266,17 @@ private JSONViewDataType getViewType()
{
return viewType;
}

public Builder setProfileId(ViewProfileId profileId)
{
this.profileId = profileId;
return this;
}

private ViewProfileId getProfileId()
{
return profileId;
}

public Builder setParentViewId(final ViewId parentViewId)
{
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/de/metas/ui/web/view/DefaultView.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public static final Builder builder(final IViewDataRepository viewDataRepository
private final ViewId parentViewId;
private final DocumentId parentRowId;
private final JSONViewDataType viewType;
private final ViewProfileId profileId;
private final ImmutableSet<DocumentPath> referencingDocumentPaths;

private final transient ViewRowIdsOrderedSelection defaultSelection;
Expand Down Expand Up @@ -119,6 +120,7 @@ private DefaultView(final Builder builder)
parentViewId = builder.getParentViewId();
parentRowId = builder.getParentRowId();
viewType = builder.getViewType();
profileId = builder.getProfileId();
referencingDocumentPaths = builder.getReferencingDocumentPaths();

//
Expand Down Expand Up @@ -191,6 +193,12 @@ public JSONViewDataType getViewType()
return viewType;
}

@Override
public ViewProfileId getProfileId()
{
return profileId;
}

@Override
public ITranslatableString getDescription()
{
Expand Down Expand Up @@ -514,6 +522,7 @@ public static final class Builder
{
private ViewId viewId;
private JSONViewDataType viewType;
private ViewProfileId profileId;
private Set<DocumentPath> referencingDocumentPaths;
private ViewId parentViewId;
private DocumentId parentRowId;
Expand Down Expand Up @@ -572,6 +581,17 @@ public JSONViewDataType getViewType()
return viewType;
}

public Builder setProfileId(ViewProfileId profileId)
{
this.profileId = profileId;
return this;
}

public ViewProfileId getProfileId()
{
return profileId;
}

public Builder setReferencingDocumentPaths(final Set<DocumentPath> referencingDocumentPaths)
{
this.referencingDocumentPaths = referencingDocumentPaths;
Expand Down
Loading

0 comments on commit 47c9b75

Please sign in to comment.