use of de.metas.ui.web.window.datatypes.json.JSONDocumentPath 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();
}
Aggregations