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