Search in sources :

Example 46 with DocumentPath

use of de.metas.ui.web.window.datatypes.DocumentPath in project metasfresh-webui-api by metasfresh.

the class DocumentReferencesService method getDocumentReferences.

public List<DocumentReference> getDocumentReferences(final DocumentPath documentPath) {
    return documentCollection.forDocumentReadonly(documentPath, document -> {
        if (document.isNew()) {
            return ImmutableList.of();
        }
        final DocumentAsZoomSource zoomSource = new DocumentAsZoomSource(document);
        final ITranslatableString filterCaption = extractFilterCaption(document);
        return ZoomInfoFactory.get().streamZoomInfos(zoomSource).map(zoomInfo -> createDocumentReference(zoomInfo, filterCaption)).collect(ImmutableList.toImmutableList());
    });
}
Also used : IZoomSource(org.adempiere.model.ZoomInfoFactory.IZoomSource) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) Getter(lombok.Getter) ITrx(org.adempiere.ad.trx.api.ITrx) Autowired(org.springframework.beans.factory.annotation.Autowired) Evaluatee(org.compiere.util.Evaluatee) ImmutableList(com.google.common.collect.ImmutableList) Service(org.springframework.stereotype.Service) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) Nullable(javax.annotation.Nullable) Properties(java.util.Properties) WindowConstants(de.metas.ui.web.window.WindowConstants) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) MoreObjects(com.google.common.base.MoreObjects) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDataBindingDescriptor) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) ZoomInfoFactory(org.adempiere.model.ZoomInfoFactory) Services(org.adempiere.util.Services) I_AD_Column(org.compiere.model.I_AD_Column) List(java.util.List) ZoomInfo(org.adempiere.model.ZoomInfoFactory.ZoomInfo) MQueryDocumentFilterHelper(de.metas.ui.web.document.filter.MQueryDocumentFilterHelper) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) ITranslatableString(de.metas.i18n.ITranslatableString)

Example 47 with DocumentPath

use of de.metas.ui.web.window.datatypes.DocumentPath in project metasfresh-webui-api by metasfresh.

the class DocumentAttachmentsRestController method getDocumentAttachments.

private DocumentAttachments getDocumentAttachments(final String windowIdStr, final String documentId) {
    final DocumentPath documentPath = DocumentPath.rootDocumentPath(WindowId.fromJson(windowIdStr), documentId);
    final TableRecordReference recordRef = documentDescriptorFactory.getTableRecordReference(documentPath);
    return DocumentAttachments.builder().documentPath(documentPath).recordRef(recordRef).entityDescriptor(documentDescriptorFactory.getDocumentEntityDescriptor(documentPath)).websocketPublisher(websocketPublisher).build();
}
Also used : TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath)

Example 48 with DocumentPath

use of de.metas.ui.web.window.datatypes.DocumentPath in project metasfresh-webui-api by metasfresh.

the class ADProcessInstancesRepository method createProcessInfo.

private ProcessInfo createProcessInfo(@NonNull final CreateProcessInstanceRequest request) {
    final DocumentPath singleDocumentPath = request.getSingleDocumentPath();
    final String tableName;
    final int recordId;
    final String sqlWhereClause;
    final int adWindowId;
    // View
    if (request.getViewRowIdsSelection() != null) {
        final ViewRowIdsSelection viewRowIdsSelection = request.getViewRowIdsSelection();
        final ViewId viewId = viewRowIdsSelection.getViewId();
        final IView view = viewsRepo.getView(viewId);
        final DocumentIdsSelection viewDocumentIds = viewRowIdsSelection.getRowIds();
        adWindowId = viewId.getWindowId().toIntOr(-1);
        if (viewDocumentIds.isSingleDocumentId()) {
            final DocumentId viewSingleDocumentId = viewDocumentIds.getSingleDocumentId();
            final TableRecordReference recordRef = view.getTableRecordReferenceOrNull(viewSingleDocumentId);
            if (recordRef != null) {
                tableName = recordRef.getTableName();
                recordId = recordRef.getRecord_ID();
            } else {
                tableName = view.getTableNameOrNull(viewSingleDocumentId);
                recordId = -1;
            }
        } else {
            tableName = view.getTableNameOrNull(null);
            recordId = -1;
        }
        final boolean emptyTableName = Check.isEmpty(tableName);
        if (viewDocumentIds.isEmpty() || emptyTableName) {
            // Note: in the case of material cockpit, there is no single tableName to be returned by view.getTableNameOrNull,
            // so we do have selected rows, but no table name, which is OK
            sqlWhereClause = null;
        } else {
            sqlWhereClause = view.getSqlWhereClause(viewDocumentIds, SqlOptions.usingTableName(tableName));
        }
    } else // Single document call
    if (singleDocumentPath != null) {
        final DocumentEntityDescriptor entityDescriptor = documentDescriptorFactory.getDocumentEntityDescriptor(singleDocumentPath);
        adWindowId = singleDocumentPath.getWindowId().toIntOr(-1);
        tableName = entityDescriptor.getTableNameOrNull();
        if (singleDocumentPath.isRootDocument()) {
            recordId = singleDocumentPath.getDocumentId().toInt();
        } else {
            recordId = singleDocumentPath.getSingleRowId().toInt();
        }
        sqlWhereClause = entityDescriptor.getDataBinding(SqlDocumentEntityDataBindingDescriptor.class).getSqlWhereClauseById(recordId);
    } else // 
    // From menu
    {
        tableName = null;
        recordId = -1;
        sqlWhereClause = null;
        adWindowId = -1;
    }
    // 
    final Set<TableRecordReference> selectedIncludedRecords = request.getSelectedIncludedDocumentPaths().stream().map(documentDescriptorFactory::getTableRecordReference).collect(ImmutableSet.toImmutableSet());
    final ProcessInfoBuilder processInfoBuilder = ProcessInfo.builder().setCtx(Env.getCtx()).setCreateTemporaryCtx().setAD_Process_ID(request.getProcessIdAsInt()).setAD_Window_ID(adWindowId).setRecord(tableName, recordId).setSelectedIncludedRecords(selectedIncludedRecords).setWhereClause(sqlWhereClause);
    // View related internal parameters
    if (request.getViewRowIdsSelection() != null) {
        final ViewRowIdsSelection viewRowIdsSelection = request.getViewRowIdsSelection();
        processInfoBuilder.setLoadParametersFromDB(// important: we need to load the existing parameters from database, besides the internal ones we are adding here
        true).addParameter(ViewBasedProcessTemplate.PARAM_ViewId, viewRowIdsSelection.getViewId().toJson()).addParameter(ViewBasedProcessTemplate.PARAM_ViewSelectedIds, viewRowIdsSelection.getRowIds().toCommaSeparatedString());
    }
    if (request.getParentViewRowIdsSelection() != null) {
        final ViewRowIdsSelection parentViewRowIdsSelection = request.getParentViewRowIdsSelection();
        processInfoBuilder.setLoadParametersFromDB(// important: we need to load the existing parameters from database, besides the internal ones we are adding here
        true).addParameter(ViewBasedProcessTemplate.PARAM_ParentViewId, parentViewRowIdsSelection.getViewId().toJson()).addParameter(ViewBasedProcessTemplate.PARAM_ParentViewSelectedIds, parentViewRowIdsSelection.getRowIds().toCommaSeparatedString());
    }
    if (request.getChildViewRowIdsSelection() != null) {
        final ViewRowIdsSelection childViewRowIdsSelection = request.getChildViewRowIdsSelection();
        processInfoBuilder.setLoadParametersFromDB(// important: we need to load the existing parameters from database, besides the internal ones we are adding here
        true).addParameter(ViewBasedProcessTemplate.PARAM_ChildViewId, childViewRowIdsSelection.getViewId().toJson()).addParameter(ViewBasedProcessTemplate.PARAM_ChildViewSelectedIds, childViewRowIdsSelection.getRowIds().toCommaSeparatedString());
    }
    return processInfoBuilder.build();
}
Also used : IView(de.metas.ui.web.view.IView) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ViewRowIdsSelection(de.metas.ui.web.view.ViewRowIdsSelection) ViewId(de.metas.ui.web.view.ViewId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) ProcessInfoBuilder(de.metas.process.ProcessInfo.ProcessInfoBuilder) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 49 with DocumentPath

use of de.metas.ui.web.window.datatypes.DocumentPath in project metasfresh-webui-api by metasfresh.

the class ADProcessPostProcessService method extractReferencingDocumentPaths.

private static final Set<DocumentPath> extractReferencingDocumentPaths(final ProcessInfo processInfo) {
    final String tableName = processInfo.getTableNameOrNull();
    if (tableName == null) {
        return ImmutableSet.of();
    }
    final TableRecordReference sourceRecordRef = processInfo.getRecordRefOrNull();
    final IQueryFilter<Object> selectionQueryFilter = processInfo.getQueryFilterOrElse(null);
    if (selectionQueryFilter != null) {
        final List<Integer> recordIds = Services.get(IQueryBL.class).createQueryBuilder(tableName, PlainContextAware.newWithThreadInheritedTrx()).filter(selectionQueryFilter).setLimit(MAX_REFERENCED_DOCUMENTPATHS_ALLOWED + 1).create().listIds();
        if (recordIds.isEmpty()) {
            return ImmutableSet.of();
        } else if (recordIds.size() > MAX_REFERENCED_DOCUMENTPATHS_ALLOWED) {
            throw new AdempiereException("Selecting more than " + MAX_REFERENCED_DOCUMENTPATHS_ALLOWED + " records is not allowed");
        }
        final TableRecordReference firstRecordRef = TableRecordReference.of(tableName, recordIds.get(0));
        // assume all records are from same window
        final WindowId windowId = WindowId.of(RecordZoomWindowFinder.findAD_Window_ID(firstRecordRef));
        return recordIds.stream().map(recordId -> DocumentPath.rootDocumentPath(windowId, recordId)).collect(ImmutableSet.toImmutableSet());
    } else if (sourceRecordRef != null) {
        final WindowId windowId = WindowId.of(RecordZoomWindowFinder.findAD_Window_ID(sourceRecordRef));
        final DocumentPath documentPath = DocumentPath.rootDocumentPath(windowId, sourceRecordRef.getRecord_ID());
        return ImmutableSet.of(documentPath);
    } else {
        return ImmutableSet.of();
    }
}
Also used : MimeType(org.compiere.util.MimeType) LogManager(de.metas.logging.LogManager) ProcessInfo(de.metas.process.ProcessInfo) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) OpenViewAction(de.metas.ui.web.process.ProcessInstanceResult.OpenViewAction) ProcessExecutionResult(de.metas.process.ProcessExecutionResult) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HashMap(java.util.HashMap) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) OpenReportAction(de.metas.ui.web.process.ProcessInstanceResult.OpenReportAction) Supplier(java.util.function.Supplier) IQueryFilter(org.adempiere.ad.dao.IQueryFilter) PlainContextAware(org.adempiere.model.PlainContextAware) OpenIncludedViewAction(de.metas.ui.web.process.ProcessInstanceResult.OpenIncludedViewAction) IView(de.metas.ui.web.view.IView) RecordsToOpen(de.metas.process.ProcessExecutionResult.RecordsToOpen) Map(java.util.Map) ResultAction(de.metas.ui.web.process.ProcessInstanceResult.ResultAction) Suppliers(com.google.common.base.Suppliers) ProcessInstanceResult(de.metas.ui.web.process.ProcessInstanceResult) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) Util(org.compiere.util.Util) RecordZoomWindowFinder(org.adempiere.model.RecordZoomWindowFinder) Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) OpenTarget(de.metas.process.ProcessExecutionResult.RecordsToOpen.OpenTarget) OpenSingleDocument(de.metas.ui.web.process.ProcessInstanceResult.OpenSingleDocument) NonNull(lombok.NonNull) ViewProfileId(de.metas.ui.web.view.ViewProfileId) Set(java.util.Set) IOException(java.io.IOException) JavaProcess(de.metas.process.JavaProcess) WindowId(de.metas.ui.web.window.datatypes.WindowId) IQueryBL(org.adempiere.ad.dao.IQueryBL) File(java.io.File) Services(org.adempiere.util.Services) List(java.util.List) Builder(lombok.Builder) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(de.metas.printing.esb.base.util.Check) CreateViewRequest(de.metas.ui.web.view.CreateViewRequest) IViewsRepository(de.metas.ui.web.view.IViewsRepository) ViewId(de.metas.ui.web.view.ViewId) IQueryBL(org.adempiere.ad.dao.IQueryBL) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) WindowId(de.metas.ui.web.window.datatypes.WindowId) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath)

Example 50 with DocumentPath

use of de.metas.ui.web.window.datatypes.DocumentPath in project metasfresh-webui-api by metasfresh.

the class WindowQuickInputRestController method create.

@PostMapping
public JSONDocument create(// 
@PathVariable("windowId") final String windowIdStr, // 
@PathVariable("documentId") final String documentIdStr, // 
@PathVariable("tabId") final String tabIdStr) {
    userSession.assertLoggedIn();
    final WindowId windowId = WindowId.fromJson(windowIdStr);
    final DocumentPath rootDocumentPath = DocumentPath.rootDocumentPath(windowId, documentIdStr);
    final DetailId detailId = DetailId.fromJson(tabIdStr);
    return Execution.callInNewExecution("quickInput.create", () -> {
        final QuickInput quickInput = documentsCollection.forRootDocumentReadonly(rootDocumentPath, rootDocument -> {
            // Make sure we can edit our root document. Fail fast.
            DocumentPermissionsHelper.assertCanEdit(rootDocument, userSession.getUserRolePermissions());
            final DocumentEntityDescriptor includedDocumentDescriptor = rootDocument.getEntityDescriptor().getIncludedEntityByDetailId(detailId);
            final QuickInputDescriptor quickInputDescriptor = quickInputDescriptors.getQuickInputEntityDescriptor(includedDocumentDescriptor);
            try {
                return QuickInput.builder().setQuickInputDescriptor(quickInputDescriptor).setRootDocumentPath(rootDocument.getDocumentPath()).build().bindRootDocument(rootDocument).assertTargetWritable();
            } catch (Exception ex) {
                // see https://github.com/metasfresh/metasfresh-webui-frontend/issues/487
                throw EntityNotFoundException.wrapIfNeeded(ex);
            }
        });
        commit(quickInput);
        return JSONDocument.ofDocument(quickInput.getQuickInputDocument(), newJSONOptions());
    });
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)51 WindowId (de.metas.ui.web.window.datatypes.WindowId)22 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)17 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)17 List (java.util.List)10 Set (java.util.Set)9 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)9 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 DetailId (de.metas.ui.web.window.descriptor.DetailId)7 AdempiereException (org.adempiere.exceptions.AdempiereException)7 GetMapping (org.springframework.web.bind.annotation.GetMapping)7 ViewId (de.metas.ui.web.view.ViewId)6 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)6 NonNull (lombok.NonNull)6 Services (org.adempiere.util.Services)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)6 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)5 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)5 DocumentCollection (de.metas.ui.web.window.model.DocumentCollection)5