Search in sources :

Example 1 with DocumentZoomIntoInfo

use of de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo 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)

Example 2 with DocumentZoomIntoInfo

use of de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo in project metasfresh-webui-api by metasfresh.

the class DocumentCollection method getDocumentPath.

/**
 * Retrieves document path for given ZoomInto info.
 *
 * @param zoomIntoInfo
 */
public DocumentPath getDocumentPath(@NonNull final DocumentZoomIntoInfo zoomIntoInfo) {
    if (!zoomIntoInfo.isRecordIdPresent()) {
        throw new IllegalArgumentException("recordId must be set in " + zoomIntoInfo);
    }
    // 
    // Find the root window ID
    final WindowId zoomIntoWindowIdEffective = getWindowId(zoomIntoInfo);
    final DocumentEntityDescriptor rootEntityDescriptor = getDocumentEntityDescriptor(zoomIntoWindowIdEffective);
    final String zoomIntoTableName = zoomIntoInfo.getTableName();
    // (i.e. root descriptor's table is matching record's table)
    if (Objects.equals(rootEntityDescriptor.getTableName(), zoomIntoTableName)) {
        final DocumentId rootDocumentId = DocumentId.of(zoomIntoInfo.getRecordId());
        return DocumentPath.rootDocumentPath(zoomIntoWindowIdEffective, rootDocumentId);
    } else // 
    // We are dealing with an included document
    {
        // Search the root descriptor for any child entity descriptor which would match record's TableName
        final List<DocumentEntityDescriptor> childEntityDescriptors = rootEntityDescriptor.getIncludedEntities().stream().filter(includedEntityDescriptor -> Objects.equals(includedEntityDescriptor.getTableName(), zoomIntoTableName)).collect(ImmutableList.toImmutableList());
        if (childEntityDescriptors.isEmpty()) {
            throw new EntityNotFoundException("Cannot find the detail tab to zoom into").setParameter("zoomIntoInfo", zoomIntoInfo).setParameter("zoomIntoWindowId", zoomIntoWindowIdEffective).setParameter("rootEntityDescriptor", rootEntityDescriptor);
        } else if (childEntityDescriptors.size() > 1) {
            logger.warn("More then one child descriptors matched our root descriptor. Picking the fist one. \nRoot descriptor: {} \nChild descriptors: {}", rootEntityDescriptor, childEntityDescriptors);
        }
        // 
        final DocumentEntityDescriptor childEntityDescriptor = childEntityDescriptors.get(0);
        // Find the root DocumentId
        final DocumentId rowId = DocumentId.of(zoomIntoInfo.getRecordId());
        final DocumentId rootDocumentId = DocumentQuery.ofRecordId(childEntityDescriptor, rowId).retrieveParentDocumentId(rootEntityDescriptor);
        // 
        return DocumentPath.includedDocumentPath(zoomIntoWindowIdEffective, rootDocumentId, childEntityDescriptor.getDetailId(), rowId);
    }
}
Also used : DocumentPermissionsHelper(de.metas.ui.web.window.controller.DocumentPermissionsHelper) DocumentZoomIntoInfo(de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) Autowired(org.springframework.beans.factory.annotation.Autowired) OutputType(de.metas.adempiere.report.jasper.OutputType) SourceDocument(de.metas.letters.model.MADBoilerPlate.SourceDocument) Evaluatee(org.compiere.util.Evaluatee) TableModelLoader(org.adempiere.ad.persistence.TableModelLoader) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) DocumentWebsocketPublisher(de.metas.ui.web.window.events.DocumentWebsocketPublisher) CopyRecordSupport(org.adempiere.model.CopyRecordSupport) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) RecordZoomWindowFinder(org.adempiere.model.RecordZoomWindowFinder) ImmutableSet(com.google.common.collect.ImmutableSet) WindowConstants(de.metas.ui.web.window.WindowConstants) NonNull(lombok.NonNull) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DocumentDescriptor(de.metas.ui.web.window.descriptor.DocumentDescriptor) Set(java.util.Set) Objects(java.util.Objects) ITrxManager(org.adempiere.ad.trx.api.ITrxManager) UserSession(de.metas.ui.web.session.UserSession) Services(org.adempiere.util.Services) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) List(java.util.List) Builder(lombok.Builder) CopyRecordFactory(org.adempiere.model.CopyRecordFactory) CacheBuilder(com.google.common.cache.CacheBuilder) DocumentType(de.metas.ui.web.window.datatypes.DocumentType) LogManager(de.metas.logging.LogManager) ProcessInfo(de.metas.process.ProcessInfo) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) ProcessExecutionResult(de.metas.process.ProcessExecutionResult) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) InvalidDocumentPathException(de.metas.ui.web.window.exceptions.InvalidDocumentPathException) Function(java.util.function.Function) PlainContextAware(org.adempiere.model.PlainContextAware) DocumentNotFoundException(de.metas.ui.web.window.exceptions.DocumentNotFoundException) Value(lombok.Value) CopyMode(de.metas.ui.web.window.model.Document.CopyMode) ImmutableList(com.google.common.collect.ImmutableList) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) Nullable(javax.annotation.Nullable) OnVariableNotFound(org.adempiere.ad.expression.api.IExpressionEvaluator.OnVariableNotFound) MADBoilerPlate(de.metas.letters.model.MADBoilerPlate) Logger(org.slf4j.Logger) Evaluatees(org.compiere.util.Evaluatees) DocumentDescriptorFactory(de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) MoreObjects(com.google.common.base.MoreObjects) WindowId(de.metas.ui.web.window.datatypes.WindowId) IAutoCloseable(org.adempiere.util.lang.IAutoCloseable) ExecutionException(java.util.concurrent.ExecutionException) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) Component(org.springframework.stereotype.Component) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(org.adempiere.util.Check) Preconditions(com.google.common.base.Preconditions) PO(org.compiere.model.PO) Cache(com.google.common.cache.Cache) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) Immutable(javax.annotation.concurrent.Immutable) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException)

Example 3 with DocumentZoomIntoInfo

use of de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo in project metasfresh-webui-api by metasfresh.

the class ADProcessParametersRepository method extractParameterValue.

private static Object extractParameterValue(final Map<String, ProcessInfoParameter> processInfoParameters, final DocumentFieldDescriptor parameterDescriptor) {
    final String fieldName = parameterDescriptor.getFieldName();
    final ProcessInfoParameter processInfoParameter = processInfoParameters.get(fieldName);
    if (processInfoParameter == null) {
        return null;
    }
    final Object parameterValue = processInfoParameter.getParameter();
    final String parameterDisplay = processInfoParameter.getInfo();
    final Object parameterValueConv = parameterDescriptor.convertToValueClass(parameterValue, new LookupValueByIdSupplier() {

        @Override
        public DocumentZoomIntoInfo getDocumentZoomInto(final int id) {
            throw new UnsupportedOperationException();
        }

        @Override
        public LookupValue findById(final Object id) {
            return LookupValue.fromObject(id, parameterDisplay);
        }
    });
    return parameterValueConv;
}
Also used : ProcessInfoParameter(de.metas.process.ProcessInfoParameter) DocumentZoomIntoInfo(de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo) LookupValueByIdSupplier(de.metas.ui.web.window.model.lookup.LookupValueByIdSupplier) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Aggregations

DocumentZoomIntoInfo (de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo)3 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 WindowId (de.metas.ui.web.window.datatypes.WindowId)2 MoreObjects (com.google.common.base.MoreObjects)1 Preconditions (com.google.common.base.Preconditions)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 OutputType (de.metas.adempiere.report.jasper.OutputType)1 MADBoilerPlate (de.metas.letters.model.MADBoilerPlate)1 BoilerPlateContext (de.metas.letters.model.MADBoilerPlate.BoilerPlateContext)1 SourceDocument (de.metas.letters.model.MADBoilerPlate.SourceDocument)1 LogManager (de.metas.logging.LogManager)1 ProcessExecutionResult (de.metas.process.ProcessExecutionResult)1 ProcessInfo (de.metas.process.ProcessInfo)1 ProcessInfoParameter (de.metas.process.ProcessInfoParameter)1 UserSession (de.metas.ui.web.session.UserSession)1 WindowConstants (de.metas.ui.web.window.WindowConstants)1