Search in sources :

Example 1 with CreateViewRequest

use of de.metas.ui.web.view.CreateViewRequest in project metasfresh-webui-api by metasfresh.

the class ADProcessPostProcessService method createViewRequest.

private static final CreateViewRequest createViewRequest(final RecordsToOpen recordsToOpen, final Set<DocumentPath> referencingDocumentPaths, final ViewId parentViewId) {
    final List<TableRecordReference> recordRefs = recordsToOpen.getRecords();
    if (recordRefs.isEmpty()) {
        // shall not happen
        return null;
    }
    // optional
    final WindowId windowId_Override = WindowId.fromNullableJson(recordsToOpen.getWindowIdString());
    // 
    // Create view create request builders from current records
    final Map<WindowId, CreateViewRequest.Builder> viewRequestBuilders = new HashMap<>();
    for (final TableRecordReference recordRef : recordRefs) {
        final WindowId recordWindowId = windowId_Override != null ? windowId_Override : WindowId.ofIntOrNull(RecordZoomWindowFinder.findAD_Window_ID(recordRef));
        final CreateViewRequest.Builder viewRequestBuilder = viewRequestBuilders.computeIfAbsent(recordWindowId, key -> CreateViewRequest.builder(recordWindowId, JSONViewDataType.grid));
        viewRequestBuilder.addFilterOnlyId(recordRef.getRecord_ID());
    }
    // If there is no view create request builder there stop here (shall not happen)
    if (viewRequestBuilders.isEmpty()) {
        return null;
    }
    // Create the view create request from first builder that we have.
    if (viewRequestBuilders.size() > 1) {
        logger.warn("More than one views to be created found for {}. Creating only the first view.", recordRefs);
    }
    final CreateViewRequest viewRequest = viewRequestBuilders.values().iterator().next().setReferencingDocumentPaths(referencingDocumentPaths).setParentViewId(parentViewId).build();
    return viewRequest;
}
Also used : TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) WindowId(de.metas.ui.web.window.datatypes.WindowId) HashMap(java.util.HashMap) Builder(lombok.Builder) CreateViewRequest(de.metas.ui.web.view.CreateViewRequest)

Example 2 with CreateViewRequest

use of de.metas.ui.web.view.CreateViewRequest in project metasfresh-webui-api by metasfresh.

the class ADProcessPostProcessService method createResultAction.

private ResultAction createResultAction(final ProcessInfo processInfo, final ProcessExecutionResult processExecutionResult) {
    final File reportTempFile = saveReportToDiskIfAny(processExecutionResult);
    final RecordsToOpen recordsToOpen = processExecutionResult.getRecordsToOpen();
    // Open report
    if (reportTempFile != null) {
        return OpenReportAction.builder().filename(processExecutionResult.getReportFilename()).contentType(processExecutionResult.getReportContentType()).tempFile(reportTempFile).build();
    } else // Open view
    if (recordsToOpen != null && recordsToOpen.getTarget() == OpenTarget.GridView) {
        final Set<DocumentPath> referencingDocumentPaths = extractReferencingDocumentPaths(processInfo);
        final String parentViewIdStr = processExecutionResult.getWebuiViewId();
        final ViewId parentViewId = parentViewIdStr != null ? ViewId.ofViewIdString(parentViewIdStr) : null;
        final CreateViewRequest viewRequest = createViewRequest(recordsToOpen, referencingDocumentPaths, parentViewId);
        final IView view = viewsRepo.createView(viewRequest);
        return OpenViewAction.builder().viewId(view.getViewId()).build();
    } else // Open included view
    if (processExecutionResult.getWebuiIncludedViewIdToOpen() != null) {
        return OpenIncludedViewAction.builder().viewId(ViewId.ofViewIdString(processExecutionResult.getWebuiIncludedViewIdToOpen())).profileId(ViewProfileId.fromJson(processExecutionResult.getWebuiViewProfileId())).build();
    } else // Open single document
    if (recordsToOpen != null && recordsToOpen.getTarget() == OpenTarget.SingleDocument) {
        final DocumentPath documentPath = extractSingleDocumentPath(recordsToOpen);
        return OpenSingleDocument.builder().documentPath(documentPath).modal(false).build();
    } else // Open single document
    if (recordsToOpen != null && recordsToOpen.getTarget() == OpenTarget.SingleDocumentModal) {
        final DocumentPath documentPath = extractSingleDocumentPath(recordsToOpen);
        return OpenSingleDocument.builder().documentPath(documentPath).modal(true).build();
    } else // 
    // No action
    {
        return null;
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) IView(de.metas.ui.web.view.IView) ViewId(de.metas.ui.web.view.ViewId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) RecordsToOpen(de.metas.process.ProcessExecutionResult.RecordsToOpen) File(java.io.File) CreateViewRequest(de.metas.ui.web.view.CreateViewRequest)

Example 3 with CreateViewRequest

use of de.metas.ui.web.view.CreateViewRequest in project metasfresh-webui-api by metasfresh.

the class HUEditorViewFactoryTemplate method createView.

@Override
public final HUEditorView createView(final CreateViewRequest request) {
    final ViewId viewId = request.getViewId();
    // 
    // Referencing documentPaths and tableName (i.e. from where are we coming, e.g. receipt schedule)
    final Set<DocumentPath> referencingDocumentPaths = request.getReferencingDocumentPaths();
    final String referencingTableName = extractReferencingTablename(referencingDocumentPaths);
    final SqlViewBinding sqlViewBinding = getSqlViewBinding();
    // 
    // HUEditorView rows repository
    final HUEditorViewRepository huEditorViewRepository;
    {
        final WindowId windowId = viewId.getWindowId();
        final boolean attributesAlwaysReadonly = rowAttributesAlwaysReadonlyByReferencingTableName.getOrDefault(referencingTableName, Boolean.TRUE);
        final SqlHUEditorViewRepositoryBuilder huEditorViewRepositoryBuilder = SqlHUEditorViewRepository.builder().windowId(windowId).rowProcessedPredicate(getRowProcessedPredicate(referencingTableName)).attributesProvider(HUEditorRowAttributesProvider.builder().readonly(attributesAlwaysReadonly).build()).sqlViewBinding(sqlViewBinding);
        customizeHUEditorViewRepository(huEditorViewRepositoryBuilder);
        huEditorViewRepository = huEditorViewRepositoryBuilder.build();
    }
    // 
    // HUEditorView
    {
        // Filters
        // as long as the deprecated getFilterOnlyIds() is around we can't ignore it
        @SuppressWarnings("deprecation") final List<DocumentFilter> stickyFilters = extractStickyFilters(request.getStickyFilters(), request.getFilterOnlyIds());
        final DocumentFilterDescriptorsProvider filterDescriptors = getViewFilterDescriptors();
        final List<DocumentFilter> filters = request.getOrUnwrapFilters(filterDescriptors);
        // Start building the HUEditorView
        final HUEditorViewBuilder huViewBuilder = HUEditorView.builder().setParentViewId(request.getParentViewId()).setParentRowId(request.getParentRowId()).setViewId(viewId).setViewType(request.getViewType()).setStickyFilters(stickyFilters).setFilters(filters).setFilterDescriptors(filterDescriptors).setReferencingDocumentPaths(referencingTableName, referencingDocumentPaths).orderBys(sqlViewBinding.getDefaultOrderBys()).setActions(request.getActions()).addAdditionalRelatedProcessDescriptors(request.getAdditionalRelatedProcessDescriptors()).setHUEditorViewRepository(huEditorViewRepository).setParameters(request.getParameters());
        // 
        // Call view customizers
        getViewCustomizers(referencingTableName).forEach(viewCustomizer -> viewCustomizer.beforeCreate(huViewBuilder));
        customizeHUEditorView(huViewBuilder);
        return huViewBuilder.build();
    }
}
Also used : ArrayKey(org.compiere.util.Util.ArrayKey) CCache(org.compiere.util.CCache) SqlViewRowFieldBinding(de.metas.ui.web.view.descriptor.SqlViewRowFieldBinding) Autowired(org.springframework.beans.factory.annotation.Autowired) Map(java.util.Map) Constants(de.metas.handlingunits.attribute.Constants) ViewLayout(de.metas.ui.web.view.descriptor.ViewLayout) PanelLayoutType(de.metas.ui.web.window.datatypes.PanelLayoutType) ConstantQueryFilter(org.adempiere.ad.dao.ConstantQueryFilter) IViewFactory(de.metas.ui.web.view.IViewFactory) OverridingMethodsMustInvokeSuper(javax.annotation.OverridingMethodsMustInvokeSuper) ImmutableMap(com.google.common.collect.ImmutableMap) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) Collection(java.util.Collection) DocumentFilterParamDescriptor(de.metas.ui.web.document.filter.DocumentFilterParamDescriptor) Set(java.util.Set) IQueryBuilder(org.adempiere.ad.dao.IQueryBuilder) SqlViewBinding(de.metas.ui.web.view.descriptor.SqlViewBinding) ISqlQueryFilter(org.adempiere.ad.dao.ISqlQueryFilter) Services(org.adempiere.util.Services) List(java.util.List) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) SqlHUEditorViewRepositoryBuilder(de.metas.ui.web.handlingunits.SqlHUEditorViewRepository.SqlHUEditorViewRepositoryBuilder) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) IMsgBL(de.metas.i18n.IMsgBL) LogManager(de.metas.logging.LogManager) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) GuavaCollectors(org.adempiere.util.GuavaCollectors) DocumentFilterDescriptorsProvider(de.metas.ui.web.document.filter.DocumentFilterDescriptorsProvider) SqlOptions(de.metas.ui.web.window.model.sql.SqlOptions) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType) PlainContextAware(org.adempiere.model.PlainContextAware) ArrayList(java.util.ArrayList) DocumentFilterDescriptor(de.metas.ui.web.document.filter.DocumentFilterDescriptor) IADWindowDAO(org.adempiere.ad.window.api.IADWindowDAO) ImmutableList(com.google.common.collect.ImmutableList) I_AD_Tab(org.compiere.model.I_AD_Tab) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) ImmutableDocumentFilterDescriptorsProvider(de.metas.ui.web.document.filter.ImmutableDocumentFilterDescriptorsProvider) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) I_M_HU(de.metas.handlingunits.model.I_M_HU) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) DocumentDescriptorFactory(de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory) InArrayQueryFilter(org.adempiere.ad.dao.impl.InArrayQueryFilter) ViewProfileId(de.metas.ui.web.view.ViewProfileId) WindowId(de.metas.ui.web.window.datatypes.WindowId) IHandlingUnitsDAO(de.metas.handlingunits.IHandlingUnitsDAO) SqlDocumentFilterConverter(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverter) Check(org.adempiere.util.Check) SqlViewFactory(de.metas.ui.web.view.SqlViewFactory) CreateViewRequest(de.metas.ui.web.view.CreateViewRequest) LayoutFactory(de.metas.ui.web.window.descriptor.factory.standard.LayoutFactory) SqlParamsCollector(de.metas.ui.web.document.filter.sql.SqlParamsCollector) ViewId(de.metas.ui.web.view.ViewId) WindowId(de.metas.ui.web.window.datatypes.WindowId) SqlViewBinding(de.metas.ui.web.view.descriptor.SqlViewBinding) ViewId(de.metas.ui.web.view.ViewId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) SqlHUEditorViewRepositoryBuilder(de.metas.ui.web.handlingunits.SqlHUEditorViewRepository.SqlHUEditorViewRepositoryBuilder) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ITranslatableString(de.metas.i18n.ITranslatableString) DocumentFilterDescriptorsProvider(de.metas.ui.web.document.filter.DocumentFilterDescriptorsProvider) ImmutableDocumentFilterDescriptorsProvider(de.metas.ui.web.document.filter.ImmutableDocumentFilterDescriptorsProvider)

Example 4 with CreateViewRequest

use of de.metas.ui.web.view.CreateViewRequest in project metasfresh-webui-api by metasfresh.

the class PackingHUsViewFactory method createPackingHUsView.

private HUEditorView createPackingHUsView(final PackingHUsViewKey key) {
    final IHUQueryBuilder huQuery = createHUQuery(key);
    final ViewId packingHUsViewId = key.getPackingHUsViewId();
    final ViewId pickingSlotsClearingViewId = key.getPickingSlotsClearingViewId();
    final CreateViewRequest request = CreateViewRequest.builder(packingHUsViewId, JSONViewDataType.includedView).setParentViewId(pickingSlotsClearingViewId).addStickyFilters(HUIdsFilterHelper.createFilter(huQuery)).addAdditionalRelatedProcessDescriptor(createProcessDescriptor(WEBUI_PackingHUsView_AddHUsToShipperTransportation.class)).addAdditionalRelatedProcessDescriptor(createProcessDescriptor(WEBUI_PackingHUsView_AddHUsToShipperTransportationShipAndInvoice.class)).setParameter(WEBUI_M_HU_Transform.PARAM_CheckExistingHUsInsideView, true).build();
    return huEditorViewFactory.createView(request);
}
Also used : IHUQueryBuilder(de.metas.handlingunits.IHUQueryBuilder) ViewId(de.metas.ui.web.view.ViewId) CreateViewRequest(de.metas.ui.web.view.CreateViewRequest) WEBUI_PackingHUsView_AddHUsToShipperTransportationShipAndInvoice(de.metas.ui.web.pickingslotsClearing.process.WEBUI_PackingHUsView_AddHUsToShipperTransportationShipAndInvoice)

Example 5 with CreateViewRequest

use of de.metas.ui.web.view.CreateViewRequest in project metasfresh-webui-api by metasfresh.

the class PickingSlotsClearingViewFactory method createView.

@Override
public PickingSlotsClearingView createView(final CreateViewRequest request) {
    request.assertNoParentViewOrRow();
    final DocumentFilterDescriptorsProvider filterDescriptors = getFilterDescriptorsProvider();
    final CreateViewRequest requestEffective = request.unwrapFiltersAndCopy(filterDescriptors);
    final ViewId viewId = ViewId.random(PickingSlotsClearingViewFactory.WINDOW_ID);
    final PickingSlotQuery query = createPickingSlotQuery(requestEffective);
    return PickingSlotsClearingView.builder().viewId(viewId).rows(() -> pickingSlotRepo.retrievePickingSlotsRows(query)).additionalRelatedProcessDescriptors(createAdditionalRelatedProcessDescriptors()).filterDescriptors(filterDescriptors).filters(requestEffective.getFilters().getFilters()).build();
}
Also used : PickingSlotQuery(de.metas.picking.api.IPickingSlotDAO.PickingSlotQuery) ViewId(de.metas.ui.web.view.ViewId) CreateViewRequest(de.metas.ui.web.view.CreateViewRequest) DocumentFilterDescriptorsProvider(de.metas.ui.web.document.filter.DocumentFilterDescriptorsProvider)

Aggregations

CreateViewRequest (de.metas.ui.web.view.CreateViewRequest)8 ViewId (de.metas.ui.web.view.ViewId)5 ImmutableList (com.google.common.collect.ImmutableList)2 DocumentFilterDescriptorsProvider (de.metas.ui.web.document.filter.DocumentFilterDescriptorsProvider)2 IView (de.metas.ui.web.view.IView)2 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 WindowId (de.metas.ui.web.window.datatypes.WindowId)2 Set (java.util.Set)2 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IHUQueryBuilder (de.metas.handlingunits.IHUQueryBuilder)1 IHandlingUnitsDAO (de.metas.handlingunits.IHandlingUnitsDAO)1 Constants (de.metas.handlingunits.attribute.Constants)1 I_M_HU (de.metas.handlingunits.model.I_M_HU)1 IMsgBL (de.metas.i18n.IMsgBL)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 LogManager (de.metas.logging.LogManager)1 PickingSlotQuery (de.metas.picking.api.IPickingSlotDAO.PickingSlotQuery)1