Search in sources :

Example 1 with JSONDocumentPath

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();
}
Also used : ButtonFieldActionDescriptor(de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor) DocumentZoomIntoInfo(de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo) WindowId(de.metas.ui.web.window.datatypes.WindowId) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath)

Aggregations

EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)1 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 WindowId (de.metas.ui.web.window.datatypes.WindowId)1 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)1 ButtonFieldActionDescriptor (de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor)1 IDocumentFieldView (de.metas.ui.web.window.model.IDocumentFieldView)1 DocumentZoomIntoInfo (de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo)1 IADTableDAO (org.adempiere.ad.table.api.IADTableDAO)1