Search in sources :

Example 26 with DocumentEntityDescriptor

use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor in project metasfresh-webui-api by metasfresh.

the class ADProcessDescriptorsFactory method retrieveProcessDescriptor.

private ProcessDescriptor retrieveProcessDescriptor(final ProcessId processId) {
    final I_AD_Process adProcess = InterfaceWrapperHelper.create(Env.getCtx(), processId.getProcessIdAsInt(), I_AD_Process.class, ITrx.TRXNAME_None);
    if (adProcess == null) {
        throw new EntityNotFoundException("@NotFound@ @AD_Process_ID@ (" + processId + ")");
    }
    final WebuiProcessClassInfo webuiProcesClassInfo = WebuiProcessClassInfo.of(adProcess.getClassname());
    final IModelTranslationMap adProcessTrlsMap = InterfaceWrapperHelper.getModelTranslationMap(adProcess);
    // 
    // Parameters document descriptor
    final DocumentEntityDescriptor parametersDescriptor;
    {
        final DocumentEntityDescriptor.Builder parametersDescriptorBuilder = DocumentEntityDescriptor.builder().setDocumentType(DocumentType.Process, processId.toDocumentId()).setCaption(adProcessTrlsMap.getColumnTrl(I_AD_Process.COLUMNNAME_Name, adProcess.getName())).setDescription(adProcessTrlsMap.getColumnTrl(I_AD_Process.COLUMNNAME_Description, adProcess.getDescription())).setDataBinding(ProcessParametersDataBindingDescriptorBuilder.instance).disableDefaultTableCallouts();
        // Get AD_Process_Para(s) and populate the entity descriptor
        adProcessDAO.retrieveProcessParameters(adProcess).stream().map(adProcessParam -> createProcessParaDescriptor(webuiProcesClassInfo, adProcessParam)).forEach(processParaDescriptor -> parametersDescriptorBuilder.addField(processParaDescriptor));
        parametersDescriptor = parametersDescriptorBuilder.build();
    }
    // 
    // Parameters layout
    final ProcessLayout.Builder layout = ProcessLayout.builder().setProcessId(processId).setLayoutType(webuiProcesClassInfo.getLayoutType()).setCaption(parametersDescriptor.getCaption()).setDescription(parametersDescriptor.getDescription()).addElements(parametersDescriptor);
    // Process descriptor
    return ProcessDescriptor.builder().setProcessId(processId).setType(extractType(adProcess)).setProcessClassname(extractClassnameOrNull(adProcess)).setParametersDescriptor(parametersDescriptor).setLayout(layout.build()).build();
}
Also used : CCache(org.compiere.util.CCache) IExpression(org.adempiere.ad.expression.api.IExpression) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) DefaultValueExpressionsFactory(de.metas.ui.web.window.descriptor.factory.standard.DefaultValueExpressionsFactory) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) IRangeAwareParams(org.adempiere.util.api.IRangeAwareParams) ProcessDescriptor(de.metas.ui.web.process.descriptor.ProcessDescriptor) IExpressionFactory(org.adempiere.ad.expression.api.IExpressionFactory) DateRangeValue(de.metas.ui.web.window.datatypes.DateRangeValue) IProcessPrecondition(de.metas.process.IProcessPrecondition) NonNull(lombok.NonNull) RelatedProcessDescriptor(de.metas.process.RelatedProcessDescriptor) ConstantLogicExpression(org.adempiere.ad.expression.api.ConstantLogicExpression) JavaProcess(de.metas.process.JavaProcess) I_AD_Form(org.compiere.model.I_AD_Form) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) Services(org.adempiere.util.Services) I_AD_Process(org.compiere.model.I_AD_Process) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) List(java.util.List) Stream(java.util.stream.Stream) ProcessId(de.metas.ui.web.process.ProcessId) DocumentEntityDataBindingDescriptorBuilder(de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor.DocumentEntityDataBindingDescriptorBuilder) Builder(lombok.Builder) IProcessPreconditionsContext(de.metas.process.IProcessPreconditionsContext) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) Optional(java.util.Optional) ProcessParams(de.metas.process.ProcessParams) DocumentType(de.metas.ui.web.window.datatypes.DocumentType) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) GuavaCollectors(org.adempiere.util.GuavaCollectors) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) I_AD_Process_Para(org.compiere.model.I_AD_Process_Para) Supplier(java.util.function.Supplier) ProcessDescriptorType(de.metas.ui.web.process.descriptor.ProcessDescriptor.ProcessDescriptorType) DescriptorsFactoryHelper(de.metas.ui.web.window.descriptor.factory.standard.DescriptorsFactoryHelper) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) ImmutableList(com.google.common.collect.ImmutableList) Characteristic(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic) ICalloutField(org.adempiere.ad.callout.api.ICalloutField) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) IADProcessDAO(de.metas.process.IADProcessDAO) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) DocumentsRepository(de.metas.ui.web.window.model.DocumentsRepository) IModelTranslationMap(de.metas.i18n.IModelTranslationMap) IUserRolePermissions(org.adempiere.ad.security.IUserRolePermissions) ProcessLayout(de.metas.ui.web.process.descriptor.ProcessLayout) WebuiRelatedProcessDescriptor(de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor) ProcessPreconditionsResolution(de.metas.process.ProcessPreconditionsResolution) DocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor) WebuiPreconditionsContext(de.metas.ui.web.process.WebuiPreconditionsContext) Check(org.adempiere.util.Check) IModelTranslationMap(de.metas.i18n.IModelTranslationMap) I_AD_Process(org.compiere.model.I_AD_Process) DocumentEntityDataBindingDescriptorBuilder(de.metas.ui.web.window.descriptor.DocumentEntityDataBindingDescriptor.DocumentEntityDataBindingDescriptorBuilder) Builder(lombok.Builder) ProcessLayout(de.metas.ui.web.process.descriptor.ProcessLayout) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 27 with DocumentEntityDescriptor

use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor 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 28 with DocumentEntityDescriptor

use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor in project metasfresh-webui-api by metasfresh.

the class ADProcessInstancesRepository method retrieveProcessInstance.

private ADProcessInstanceController retrieveProcessInstance(final DocumentId adPInstanceId) {
    Check.assumeNotNull(adPInstanceId, "Parameter adPInstanceId is not null");
    Check.assume(adPInstanceId.toInt() > 0, "adPInstanceId > 0");
    // 
    // Load process info
    final ProcessInfo processInfo = ProcessInfo.builder().setCtx(Env.getCtx()).setCreateTemporaryCtx().setAD_PInstance_ID(adPInstanceId.toInt()).build();
    final Object processClassInstance = processInfo.newProcessClassInstanceOrNull();
    try (final IAutoCloseable c = JavaProcess.temporaryChangeCurrentInstance(processClassInstance)) {
        // 
        // Build the parameters document
        final ProcessId processId = ProcessId.ofAD_Process_ID(processInfo.getAD_Process_ID());
        final ProcessDescriptor processDescriptor = getProcessDescriptor(processId);
        // 
        // Build the parameters (as document)
        final DocumentEntityDescriptor parametersDescriptor = processDescriptor.getParametersDescriptor();
        final Document parametersDoc = parametersDescriptor.getDataBinding().getDocumentsRepository().retrieveDocumentById(parametersDescriptor, adPInstanceId, NullDocumentChangesCollector.instance);
        // TODO: handle the case when the process was already executed
        // In that case we need to load the result and provide it to ProcessInstance constructor
        // 
        // View informations
        final IRangeAwareParams processInfoParams = processInfo.getParameterAsIParams();
        final String viewIdStr = processInfoParams.getParameterAsString(ViewBasedProcessTemplate.PARAM_ViewId);
        final ViewId viewId = Strings.isNullOrEmpty(viewIdStr) ? null : ViewId.ofViewIdString(viewIdStr);
        // 
        return ADProcessInstanceController.builder().caption(processDescriptor.getCaption()).instanceId(adPInstanceId).parameters(parametersDoc).processClassInstance(processClassInstance).viewId(viewId).build();
    }
}
Also used : IRangeAwareParams(org.adempiere.util.api.IRangeAwareParams) IAutoCloseable(org.adempiere.util.lang.IAutoCloseable) ViewId(de.metas.ui.web.view.ViewId) ProcessDescriptor(de.metas.ui.web.process.descriptor.ProcessDescriptor) WebuiRelatedProcessDescriptor(de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor) ProcessInfo(de.metas.process.ProcessInfo) ProcessId(de.metas.ui.web.process.ProcessId) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) Document(de.metas.ui.web.window.model.Document)

Example 29 with DocumentEntityDescriptor

use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor in project metasfresh-webui-api by metasfresh.

the class WindowQuickInputRestController method checkSupported.

@RequestMapping(method = RequestMethod.HEAD)
public ResponseEntity<Object> checkSupported(// 
@PathVariable("windowId") final String windowIdStr, // 
@PathVariable("documentId") final String documentIdStr_NOTUSED, // 
@PathVariable("tabId") final String tabIdStr) {
    userSession.assertLoggedIn();
    final WindowId windowId = WindowId.fromJson(windowIdStr);
    final DocumentEntityDescriptor includedDocumentDescriptor = documentsCollection.getDocumentEntityDescriptor(windowId).getIncludedEntityByDetailId(DetailId.fromJson(tabIdStr));
    if (quickInputDescriptors.hasQuickInputEntityDescriptor(includedDocumentDescriptor)) {
        return new ResponseEntity<>(HttpStatus.OK);
    } else {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with DocumentEntityDescriptor

use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor 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

DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)33 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)9 WindowId (de.metas.ui.web.window.datatypes.WindowId)8 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)7 ArrayList (java.util.ArrayList)5 NonNull (lombok.NonNull)5 AdempiereException (org.adempiere.exceptions.AdempiereException)5 Services (org.adempiere.util.Services)5 ImmutableList (com.google.common.collect.ImmutableList)4 IMsgBL (de.metas.i18n.IMsgBL)4 ProcessId (de.metas.ui.web.process.ProcessId)4 QuickInputLayoutDescriptor (de.metas.ui.web.quickinput.QuickInputLayoutDescriptor)4 ViewId (de.metas.ui.web.view.ViewId)4 SqlDocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor)4 Document (de.metas.ui.web.window.model.Document)4 List (java.util.List)4 Env (org.compiere.util.Env)4 ITranslatableString (de.metas.i18n.ITranslatableString)3 SourceDocument (de.metas.letters.model.MADBoilerPlate.SourceDocument)3 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)3