Search in sources :

Example 1 with ProcessDescriptor

use of de.metas.ui.web.process.descriptor.ProcessDescriptor in project metasfresh-webui-api by metasfresh.

the class ADProcessDescriptorsFactory method toWebuiRelatedProcessDescriptor.

private WebuiRelatedProcessDescriptor toWebuiRelatedProcessDescriptor(@NonNull final RelatedProcessDescriptor relatedProcessDescriptor, @NonNull final IProcessPreconditionsContext preconditionsContext) {
    final ProcessId processId = ProcessId.ofAD_Process_ID(relatedProcessDescriptor.getProcessId());
    final ProcessDescriptor processDescriptor = getProcessDescriptor(processId);
    final ProcessPreconditionsResolutionSupplier preconditionsResolutionSupplier = ProcessPreconditionsResolutionSupplier.builder().preconditionsContext(preconditionsContext).processPreconditionsCheckers(relatedProcessDescriptor.getProcessPreconditionsCheckers()).processDescriptor(processDescriptor).build();
    return WebuiRelatedProcessDescriptor.builder().processId(processDescriptor.getProcessId()).processCaption(processDescriptor.getCaption()).processDescription(processDescriptor.getDescription()).debugProcessClassname(processDescriptor.getProcessClassname()).quickAction(relatedProcessDescriptor.isWebuiQuickAction()).defaultQuickAction(relatedProcessDescriptor.isWebuiDefaultQuickAction()).preconditionsResolutionSupplier(preconditionsResolutionSupplier).build();
}
Also used : ProcessDescriptor(de.metas.ui.web.process.descriptor.ProcessDescriptor) RelatedProcessDescriptor(de.metas.process.RelatedProcessDescriptor) WebuiRelatedProcessDescriptor(de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor) ProcessId(de.metas.ui.web.process.ProcessId)

Example 2 with ProcessDescriptor

use of de.metas.ui.web.process.descriptor.ProcessDescriptor in project metasfresh-webui-api by metasfresh.

the class ADProcessInstancesRepository method createNewProcessInstance0.

/**
 * @param request
 * @param shadowParentDocumentEvaluatee optional shadowParentDocumentEvaluatee which will be
 * @return
 */
private IProcessInstanceController createNewProcessInstance0(@NonNull final CreateProcessInstanceRequest request, @Nullable final IDocumentEvaluatee evalCtx) {
    // 
    // Save process info together with it's parameters and get the the newly created AD_PInstance_ID
    final ProcessInfo processInfo = createProcessInfo(request);
    Services.get(IADPInstanceDAO.class).saveProcessInfo(processInfo);
    final DocumentId adPInstanceId = DocumentId.of(processInfo.getAD_PInstance_ID());
    final Object processClassInstance = processInfo.newProcessClassInstanceOrNull();
    try (final IAutoCloseable c = JavaProcess.temporaryChangeCurrentInstance(processClassInstance)) {
        // 
        // Build the parameters document
        final ProcessDescriptor processDescriptor = getProcessDescriptor(request.getProcessId());
        final DocumentEntityDescriptor parametersDescriptor = processDescriptor.getParametersDescriptor();
        final Document parametersDoc = ADProcessParametersRepository.instance.createNewParametersDocument(parametersDescriptor, adPInstanceId, evalCtx);
        final int windowNo = parametersDoc.getWindowNo();
        // Set parameters's default values
        ProcessDefaultParametersUpdater.newInstance().addDefaultParametersProvider(processClassInstance instanceof IProcessDefaultParametersProvider ? (IProcessDefaultParametersProvider) processClassInstance : null).onDefaultValue((parameter, value) -> parametersDoc.processValueChange(parameter.getColumnName(), value, () -> "default parameter value")).updateDefaultValue(parametersDoc.getFieldViews(), field -> DocumentFieldAsProcessDefaultParameter.of(windowNo, field));
        // 
        // Create (webui) process instance and add it to our internal cache.
        final ADProcessInstanceController pinstance = ADProcessInstanceController.builder().caption(processDescriptor.getCaption()).instanceId(adPInstanceId).parameters(parametersDoc).processClassInstance(processClassInstance).contextSingleDocumentPath(request.getSingleDocumentPath()).viewId(request.getViewRowIdsSelection() != null ? request.getViewRowIdsSelection().getViewId() : null).build();
        processInstances.put(adPInstanceId, pinstance.copyReadonly());
        return pinstance;
    }
}
Also used : Env(org.compiere.util.Env) Autowired(org.springframework.beans.factory.annotation.Autowired) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) ProcessDefaultParametersUpdater(de.metas.process.ProcessDefaultParametersUpdater) IProcessInstancesRepository(de.metas.ui.web.process.IProcessInstancesRepository) IView(de.metas.ui.web.view.IView) IRangeAwareParams(org.adempiere.util.api.IRangeAwareParams) ProcessDescriptor(de.metas.ui.web.process.descriptor.ProcessDescriptor) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) ImmutableSet(com.google.common.collect.ImmutableSet) ProcessInfoBuilder(de.metas.process.ProcessInfo.ProcessInfoBuilder) NonNull(lombok.NonNull) Set(java.util.Set) JavaProcess(de.metas.process.JavaProcess) UserSession(de.metas.ui.web.session.UserSession) Services(org.adempiere.util.Services) I_AD_Process(org.compiere.model.I_AD_Process) Stream(java.util.stream.Stream) ProcessId(de.metas.ui.web.process.ProcessId) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) CacheBuilder(com.google.common.cache.CacheBuilder) IProcessInstanceController(de.metas.ui.web.process.IProcessInstanceController) IViewsRepository(de.metas.ui.web.view.IViewsRepository) ProcessInfo(de.metas.process.ProcessInfo) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) CreateProcessInstanceRequest(de.metas.ui.web.process.CreateProcessInstanceRequest) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) SqlOptions(de.metas.ui.web.window.model.sql.SqlOptions) IDocumentEvaluatee(de.metas.ui.web.window.model.IDocumentEvaluatee) Function(java.util.function.Function) NullDocumentChangesCollector(de.metas.ui.web.window.model.NullDocumentChangesCollector) Strings(com.google.common.base.Strings) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) Nullable(javax.annotation.Nullable) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) ViewRowIdsSelection(de.metas.ui.web.view.ViewRowIdsSelection) DocumentDescriptorFactory(de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory) IUserRolePermissions(org.adempiere.ad.security.IUserRolePermissions) IADPInstanceDAO(de.metas.process.IADPInstanceDAO) IAutoCloseable(org.adempiere.util.lang.IAutoCloseable) WebuiRelatedProcessDescriptor(de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Component(org.springframework.stereotype.Component) AdempiereException(org.adempiere.exceptions.AdempiereException) WebuiPreconditionsContext(de.metas.ui.web.process.WebuiPreconditionsContext) Check(de.metas.printing.esb.base.util.Check) IProcessDefaultParametersProvider(de.metas.process.IProcessDefaultParametersProvider) Cache(com.google.common.cache.Cache) Document(de.metas.ui.web.window.model.Document) ViewId(de.metas.ui.web.view.ViewId) IProcessDefaultParametersProvider(de.metas.process.IProcessDefaultParametersProvider) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) IAutoCloseable(org.adempiere.util.lang.IAutoCloseable) ProcessDescriptor(de.metas.ui.web.process.descriptor.ProcessDescriptor) WebuiRelatedProcessDescriptor(de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor) ProcessInfo(de.metas.process.ProcessInfo) IADPInstanceDAO(de.metas.process.IADPInstanceDAO) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) Document(de.metas.ui.web.window.model.Document)

Example 3 with ProcessDescriptor

use of de.metas.ui.web.process.descriptor.ProcessDescriptor in project metasfresh-webui-api by metasfresh.

the class ProcessRestController method getLayout.

@RequestMapping(value = "/{processId}/layout", method = RequestMethod.GET)
public ResponseEntity<JSONProcessLayout> getLayout(@PathVariable("processId") final String adProcessIdStr, final WebRequest request) {
    userSession.assertLoggedIn();
    final ProcessId processId = ProcessId.fromJson(adProcessIdStr);
    final IProcessInstancesRepository instancesRepository = getRepository(processId);
    final ProcessDescriptor descriptor = instancesRepository.getProcessDescriptor(processId);
    return ETagResponseEntityBuilder.ofETagAware(request, descriptor).includeLanguageInETag().cacheMaxAge(userSession.getHttpCacheMaxAge()).map(ProcessDescriptor::getLayout).jsonOptions(() -> newJSONOptions()).toJson(JSONProcessLayout::of);
}
Also used : ProcessDescriptor(de.metas.ui.web.process.descriptor.ProcessDescriptor) WebuiRelatedProcessDescriptor(de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor) JSONProcessLayout(de.metas.ui.web.process.json.JSONProcessLayout) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ProcessDescriptor

use of de.metas.ui.web.process.descriptor.ProcessDescriptor 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 5 with ProcessDescriptor

use of de.metas.ui.web.process.descriptor.ProcessDescriptor 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)

Aggregations

ProcessDescriptor (de.metas.ui.web.process.descriptor.ProcessDescriptor)5 WebuiRelatedProcessDescriptor (de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor)5 ProcessId (de.metas.ui.web.process.ProcessId)4 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)3 JavaProcess (de.metas.process.JavaProcess)2 ProcessInfo (de.metas.process.ProcessInfo)2 RelatedProcessDescriptor (de.metas.process.RelatedProcessDescriptor)2 WebuiPreconditionsContext (de.metas.ui.web.process.WebuiPreconditionsContext)2 ViewId (de.metas.ui.web.view.ViewId)2 Document (de.metas.ui.web.window.model.Document)2 IRangeAwareParams (org.adempiere.util.api.IRangeAwareParams)2 Strings (com.google.common.base.Strings)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)1 Check (de.metas.printing.esb.base.util.Check)1 IADPInstanceDAO (de.metas.process.IADPInstanceDAO)1 IADProcessDAO (de.metas.process.IADProcessDAO)1