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;
}
}
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();
}
}
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();
}
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();
}
}
Aggregations