Search in sources :

Example 1 with ProcessInfo

use of de.metas.process.ProcessInfo 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 2 with ProcessInfo

use of de.metas.process.ProcessInfo 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 3 with ProcessInfo

use of de.metas.process.ProcessInfo in project metasfresh-webui-api by metasfresh.

the class ADProcessPostProcessService method postProcess.

public ProcessInstanceResult postProcess(@NonNull final ADProcessPostProcessRequest request) {
    final ProcessInfo processInfo = request.getProcessInfo();
    final ProcessExecutionResult processExecutionResult = request.getProcessExecutionResult();
    invalidateDocumentsAndViews(request.getViewId(), processExecutionResult);
    return ProcessInstanceResult.builder(extractInstanceId(request)).summary(extractSummary(processExecutionResult)).error(processExecutionResult.isError()).action(createResultAction(processInfo, processExecutionResult)).build();
}
Also used : ProcessInfo(de.metas.process.ProcessInfo) ProcessExecutionResult(de.metas.process.ProcessExecutionResult)

Example 4 with ProcessInfo

use of de.metas.process.ProcessInfo 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)

Aggregations

ProcessInfo (de.metas.process.ProcessInfo)4 ViewId (de.metas.ui.web.view.ViewId)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Check (de.metas.printing.esb.base.util.Check)2 JavaProcess (de.metas.process.JavaProcess)2 ProcessExecutionResult (de.metas.process.ProcessExecutionResult)2 ProcessId (de.metas.ui.web.process.ProcessId)2 ProcessDescriptor (de.metas.ui.web.process.descriptor.ProcessDescriptor)2 WebuiRelatedProcessDescriptor (de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor)2 IView (de.metas.ui.web.view.IView)2 IViewsRepository (de.metas.ui.web.view.IViewsRepository)2 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)2 Document (de.metas.ui.web.window.model.Document)2 DocumentCollection (de.metas.ui.web.window.model.DocumentCollection)2 Set (java.util.Set)2 Strings (com.google.common.base.Strings)1 Suppliers (com.google.common.base.Suppliers)1 Cache (com.google.common.cache.Cache)1