use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.
the class WindowRestController method getDocumentActions.
@GetMapping("/{windowId}/{documentId}/actions")
public JSONDocumentActionsList getDocumentActions(@PathVariable("windowId") final String windowIdStr, @PathVariable("documentId") final String documentId, @RequestParam(name = "selectedTabId", required = false) final String selectedTabIdStr, @RequestParam(name = "selectedRowIds", required = false) final String selectedRowIdsAsStr, @RequestParam(name = "disabled", defaultValue = "false") final boolean returnDisabled) {
final WindowId windowId = WindowId.fromJson(windowIdStr);
final DocumentPath documentPath = DocumentPath.rootDocumentPath(windowId, documentId);
final DetailId selectedTabId = DetailId.fromJson(selectedTabIdStr);
final DocumentIdsSelection selectedRowIds = DocumentIdsSelection.ofCommaSeparatedString(selectedRowIdsAsStr);
final Set<TableRecordReference> selectedIncludedRecords = selectedRowIds.stream().map(rowId -> documentPath.createChildPath(selectedTabId, rowId)).map(documentCollection::getTableRecordReference).collect(ImmutableSet.toImmutableSet());
return getDocumentActions(documentPath, selectedIncludedRecords, returnDisabled);
}
use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.
the class WindowRestController method getDocumentFieldTypeahead.
/**
* Typeahead for included document's field
*/
@GetMapping(value = "/{windowId}/{documentId}/{tabId}/{rowId}/field/{fieldName}/typeahead")
public JSONLookupValuesList getDocumentFieldTypeahead(//
@PathVariable("windowId") final String windowIdStr, //
@PathVariable("documentId") final String documentId, //
@PathVariable("tabId") final String tabId, //
@PathVariable("rowId") final String rowId, //
@PathVariable("fieldName") final String fieldName, //
@RequestParam(name = "query", required = true) final String query) {
final WindowId windowId = WindowId.fromJson(windowIdStr);
final DocumentPath documentPath = DocumentPath.includedDocumentPath(windowId, documentId, tabId, rowId);
return getDocumentFieldTypeahead(documentPath, fieldName, query);
}
use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.
the class WindowRestController method getDocumentReferences.
@GetMapping(value = "/{windowId}/{documentId}/{tabId}/{rowId}/references")
public JSONDocumentReferencesGroup getDocumentReferences(@PathVariable("windowId") final String windowIdStr, @PathVariable("documentId") final String documentIdStr, @PathVariable("tabId") final String tabIdStr, @PathVariable("rowId") final String rowIdStr) {
userSession.assertLoggedIn();
// Get document references
final WindowId windowId = WindowId.fromJson(windowIdStr);
final DocumentPath documentPath = DocumentPath.includedDocumentPath(windowId, documentIdStr, tabIdStr, rowIdStr);
final List<DocumentReference> documentReferences = documentReferencesService.getDocumentReferences(documentPath);
final JSONOptions jsonOpts = newJSONOptions().build();
return JSONDocumentReferencesGroup.builder().caption("References").references(JSONDocumentReference.ofList(documentReferences, jsonOpts)).build();
}
use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.
the class WindowRestController method getDocumentFieldZoomInto.
private JSONZoomInto getDocumentFieldZoomInto(final DocumentPath documentPath, final String fieldName) {
userSession.assertLoggedIn();
final DocumentZoomIntoInfo zoomIntoInfo = documentCollection.forDocumentReadonly(documentPath, document -> {
final IDocumentFieldView field = document.getFieldView(fieldName);
// Generic ZoomInto button
if (field.getDescriptor().getWidgetType() == DocumentFieldWidgetType.ZoomIntoButton) {
final ButtonFieldActionDescriptor buttonActionDescriptor = field.getDescriptor().getButtonActionDescriptor();
final String zoomIntoTableIdFieldName = buttonActionDescriptor.getZoomIntoTableIdFieldName();
final Integer adTableId = document.getFieldView(zoomIntoTableIdFieldName).getValueAs(Integer.class);
if (adTableId == null || adTableId <= 0) {
throw new EntityNotFoundException("Cannot fetch ZoomInto infos from a null value. No AD_Table_ID.").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName).setParameter("zoomIntoTableIdFieldName", zoomIntoTableIdFieldName);
}
final Integer recordId = field.getValueAs(Integer.class);
if (recordId == null) {
throw new EntityNotFoundException("Cannot fetch ZoomInto infos from a null value. No Record_ID.").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName).setParameter("zoomIntoTableIdFieldName", zoomIntoTableIdFieldName);
}
final String tableName = Services.get(IADTableDAO.class).retrieveTableName(adTableId);
return DocumentZoomIntoInfo.of(tableName, recordId);
} else // Key Field
if (field.isKey()) {
// Allow zooming into key column. It shall open precisely this record in a new window.
// (see https://github.com/metasfresh/metasfresh/issues/1687 to understand the use-case)
final String tableName = document.getEntityDescriptor().getTableName();
final int recordId = document.getDocumentIdAsInt();
return DocumentZoomIntoInfo.of(tableName, recordId);
} else // Regular lookup value
{
return field.getZoomIntoInfo();
}
});
final JSONDocumentPath jsonZoomIntoDocumentPath;
if (zoomIntoInfo == null) {
throw new EntityNotFoundException("ZoomInto not supported").setParameter("documentPath", documentPath).setParameter("fieldName", fieldName);
} else if (!zoomIntoInfo.isRecordIdPresent()) {
final WindowId windowId = documentCollection.getWindowId(zoomIntoInfo);
jsonZoomIntoDocumentPath = JSONDocumentPath.newWindowRecord(windowId);
} else {
final DocumentPath zoomIntoDocumentPath = documentCollection.getDocumentPath(zoomIntoInfo);
jsonZoomIntoDocumentPath = JSONDocumentPath.ofWindowDocumentPath(zoomIntoDocumentPath);
}
return JSONZoomInto.builder().documentPath(jsonZoomIntoDocumentPath).source(JSONDocumentPath.ofWindowDocumentPath(documentPath, fieldName)).build();
}
use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method invalidateDocumentByRecordId.
/**
* Invalidates all root documents identified by tableName/recordId and notifies frontend (via websocket).
*
* @param tableName
* @param recordId
*/
public void invalidateDocumentByRecordId(final String tableName, final int recordId) {
//
// Create possible documentKeys for given tableName/recordId
final DocumentId documentId = DocumentId.of(recordId);
final Set<DocumentKey> documentKeys = getCachedWindowIdsForTableName(tableName).stream().map(windowId -> DocumentKey.of(windowId, documentId)).collect(ImmutableSet.toImmutableSet());
// stop here if no document keys found
if (documentKeys.isEmpty()) {
return;
}
//
// Invalidate the root documents
rootDocuments.invalidateAll(documentKeys);
//
// Notify frontend
documentKeys.forEach(documentKey -> websocketPublisher.staleRootDocument(documentKey.getWindowId(), documentKey.getDocumentId()));
}
Aggregations