Search in sources :

Example 6 with DetailId

use of de.metas.ui.web.window.descriptor.DetailId in project metasfresh-webui-api by metasfresh.

the class GridTabVOBasedDocumentEntityDescriptorFactory method createDocumentEntityBuilder.

private DocumentEntityDescriptor.Builder createDocumentEntityBuilder(final GridTabVO gridTabVO, final GridTabVO parentTabVO, final boolean isSOTrx, final List<I_AD_UI_Element> labelsUIElements) {
    final String tableName = gridTabVO.getTableName();
    final DetailId detailId = parentTabVO == null ? null : DetailId.fromAD_Tab_ID(gridTabVO.getAD_Tab_ID());
    // Entity Data binding
    if (!Check.isEmpty(gridTabVO.getOrderByClause(), true)) {
        logger.warn("Ignoring SQL order by for {}. See https://github.com/metasfresh/metasfresh/issues/412.", gridTabVO);
    }
    final SqlDocumentEntityDataBindingDescriptor.Builder dataBinding = SqlDocumentEntityDataBindingDescriptor.builder().setDocumentsRepository(documentsRepository).setTableName(tableName).setTableAliasFromDetailId(detailId).setChildToParentLinkColumnNames(extractChildParentLinkColumnNames(gridTabVO, parentTabVO)).setSqlWhereClause(gridTabVO.getWhereClause());
    final ILogicExpression allowInsert = ConstantLogicExpression.of(gridTabVO.isInsertRecord());
    final ILogicExpression allowDelete = ConstantLogicExpression.of(gridTabVO.isDeleteable());
    final ILogicExpression readonlyLogic = extractTabReadonlyLogic(gridTabVO);
    final ILogicExpression allowCreateNewLogic = allowInsert.andNot(readonlyLogic);
    final ILogicExpression allowDeleteLogic = allowDelete.andNot(readonlyLogic);
    // 
    final ILogicExpression displayLogic = gridTabVO.getDisplayLogic().evaluatePartial(Evaluatees.mapBuilder().put(WebRestApiContextProvider.CTXNAME_IsWebUI, DisplayType.toBooleanString(true)).build());
    // 
    // Entity descriptor
    final DocumentEntityDescriptor.Builder entityDescriptorBuilder = DocumentEntityDescriptor.builder().setDocumentType(DocumentType.Window, gridTabVO.getAD_Window_ID()).setDetailId(detailId).setCaption(gridTabVO.getNameTrls(), gridTabVO.getName()).setDescription(gridTabVO.getDescriptionTrls(), gridTabVO.getDescription()).setReadonlyLogic(readonlyLogic).setAllowCreateNewLogic(allowCreateNewLogic).setAllowDeleteLogic(allowDeleteLogic).setDisplayLogic(displayLogic).setDataBinding(dataBinding).setHighVolume(gridTabVO.IsHighVolume).setAD_Tab_ID(// legacy
    gridTabVO.getAD_Tab_ID()).setTableName(// legacy
    tableName).setIsSOTrx(// legacy
    isSOTrx).setPrintAD_Process_ID(gridTabVO.getPrint_Process_ID());
    final Predicate<GridFieldVO> isKeyColumn;
    if (gridTabVO.getFields().stream().anyMatch(GridFieldVO::isKey)) {
        isKeyColumn = GridFieldVO::isKey;
    } else {
        isKeyColumn = GridFieldVO::isParentLink;
    }
    // 
    // Fields descriptor
    gridTabVO.getFields().stream().forEach(gridFieldVO -> createAndAddDocumentField(entityDescriptorBuilder, gridFieldVO, isKeyColumn.test(gridFieldVO)));
    // 
    // Labels field descriptors
    labelsUIElements.forEach(labelUIElement -> createAndAddLabelsDocumentField(entityDescriptorBuilder, labelUIElement));
    return entityDescriptorBuilder;
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) GridFieldVO(org.compiere.model.GridFieldVO) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 7 with DetailId

use of de.metas.ui.web.window.descriptor.DetailId in project metasfresh-webui-api by metasfresh.

the class DocumentEvaluatee method get_ValueIfExists.

@Override
public Optional<Object> get_ValueIfExists(final String variableName, final Class<?> targetType) {
    if (variableName == null) {
        return Optional.empty();
    }
    if (isExcludedField(variableName)) {
        return Optional.empty();
    }
    if (WindowConstants.CONTEXTVAR_NextLineNo.equals(variableName)) {
        final Document parentDocument = _document.getParentDocument();
        if (parentDocument != null) {
            final DetailId detailId = _document.getEntityDescriptor().getDetailId();
            final int nextLineNo = parentDocument.getIncludedDocumentsCollection(detailId).getNextLineNo();
            return Optional.of(nextLineNo);
        }
    }
    if (IValidationContext.PARAMETER_ContextTableName.equals(variableName)) {
        return Optional.of(_document.getEntityDescriptor().getTableName());
    }
    // 
    // Check global context variable if this is an explicit global variable
    boolean globalContextChecked = false;
    if (CtxName.isExplicitGlobal(variableName)) {
        final Object value = getGlobalContext(variableName, targetType);
        globalContextChecked = true;
        if (value != null) {
            return Optional.of(value);
        }
    }
    // 
    // Document field
    final IDocumentFieldView documentField = getDocumentFieldOrNull(variableName);
    boolean inScopeField = false;
    if (documentField != null) {
        inScopeField = isFieldInScope(documentField.getFieldName());
        if (inScopeField) {
            logger.trace("Skip evaluation of {} because it's actually the field for whom we do the whole evaluation", documentField);
        } else {
            final Object documentFieldValue = documentField.getValue();
            if (documentFieldValue != null) {
                return Optional.of(documentFieldValue);
            }
        }
    }
    // Document's dynamic attribute
    if (_document.hasDynAttribute(variableName)) {
        final Object value = _document.getDynAttribute(variableName);
        if (value != null) {
            return Optional.of(value);
        }
    }
    // 
    // Check parent
    final IDocumentEvaluatee parentEvaluatee = getParentEvaluateeOrNull();
    final boolean hasParentEvaluatee = parentEvaluatee != null;
    if (hasParentEvaluatee) {
        final Optional<Object> value = parentEvaluatee.get_ValueIfExists(variableName, targetType);
        if (value.isPresent()) {
            return value;
        }
    }
    // If it's about the field in scope, try checking the global context
    if (inScopeField) {
        if (!globalContextChecked) {
            final Object value = getGlobalContext(variableName, targetType);
            globalContextChecked = true;
            if (value != null) {
                return Optional.of(value);
            }
        }
    }
    // Fallback: Check again the documentField and assume some defaults
    if (!hasParentEvaluatee) {
        if (documentField != null) {
            final Class<?> valueClass = documentField.getValueClass();
            if (StringLookupValue.class.equals(valueClass)) {
                // corner case: e.g. Field: C_Order.IncotermLocation's DisplayLogic=@Incoterm@!''
                return Optional.of("");
            }
        }
        final Optional<Object> defaultValue = getDefaultValue(variableName);
        if (defaultValue.isPresent()) {
            return defaultValue;
        }
    }
    // Value not found
    if (logger.isTraceEnabled()) {
        logger.trace("Variable '{}' not found.", variableName);
        logger.trace("Existing properties are: {}", _document.getFieldNames());
        logger.trace("Existing dyn attributes are: {}", _document.getAvailableDynAttributes());
        logger.trace("Was field in scope: {} (fieldInScope={})", inScopeField, _fieldNameInScope);
    }
    return Optional.empty();
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId)

Example 8 with DetailId

use of de.metas.ui.web.window.descriptor.DetailId in project metasfresh-webui-api by metasfresh.

the class WindowRestController method getLayout.

@GetMapping("/{windowId}/{tabId}/layout")
public ResponseEntity<JSONDocumentLayout> getLayout(@PathVariable("windowId") final String windowIdStr, @PathVariable("tabId") final String tabIdStr, @RequestParam(name = PARAM_Advanced, required = false, defaultValue = PARAM_Advanced_DefaultValue) final boolean advanced, final WebRequest request) {
    userSession.assertLoggedIn();
    final WindowId windowId = WindowId.fromJson(windowIdStr);
    final DetailId detailId = DetailId.fromJson(tabIdStr);
    final DocumentDescriptor descriptor = documentCollection.getDocumentDescriptorFactory().getDocumentDescriptor(windowId);
    DocumentPermissionsHelper.checkWindowAccess(descriptor.getEntityDescriptor(), userSession.getUserRolePermissions());
    return ETagResponseEntityBuilder.ofETagAware(request, descriptor).includeLanguageInETag().cacheMaxAge(userSession.getHttpCacheMaxAge()).map(desc -> desc.getLayout().getDetail(detailId)).jsonOptions(() -> newJSONOptions().setShowAdvancedFields(advanced).build()).toJson(JSONDocumentLayout::ofDetailTab);
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) WindowId(de.metas.ui.web.window.datatypes.WindowId) JSONDocumentLayout(de.metas.ui.web.window.datatypes.json.JSONDocumentLayout) DocumentDescriptor(de.metas.ui.web.window.descriptor.DocumentDescriptor) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 9 with DetailId

use of de.metas.ui.web.window.descriptor.DetailId in project metasfresh-webui-api by metasfresh.

the class DocumentChangesCollector method isStaleDocumentChanges.

private boolean isStaleDocumentChanges(final DocumentChanges documentChanges) {
    final DocumentPath documentPath = documentChanges.getDocumentPath();
    if (!documentPath.isSingleIncludedDocument()) {
        return false;
    }
    final DocumentPath rootDocumentPath = documentPath.getRootDocumentPath();
    final DetailId detailId = documentPath.getDetailId();
    return documentChangesIfExists(rootDocumentPath).flatMap(rootDocumentChanges -> rootDocumentChanges.includedDetailInfoIfExists(detailId)).map(IncludedDetailInfo::isStale).orElse(false);
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath)

Example 10 with DetailId

use of de.metas.ui.web.window.descriptor.DetailId in project metasfresh-webui-api by metasfresh.

the class QuickInputDescriptorFactoryService method getQuickInputEntityDescriptor.

public QuickInputDescriptor getQuickInputEntityDescriptor(final DocumentEntityDescriptor includedDocumentDescriptor) {
    final DocumentType documentType = includedDocumentDescriptor.getDocumentType();
    final DocumentId documentTypeId = includedDocumentDescriptor.getDocumentTypeId();
    final String tableName = includedDocumentDescriptor.getTableNameOrNull();
    final DetailId detailId = includedDocumentDescriptor.getDetailId();
    final Optional<Boolean> soTrx = includedDocumentDescriptor.getIsSOTrx();
    return getQuickInputEntityDescriptor(documentType, documentTypeId, tableName, detailId, soTrx);
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) DocumentType(de.metas.ui.web.window.datatypes.DocumentType)

Aggregations

DetailId (de.metas.ui.web.window.descriptor.DetailId)11 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)6 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)5 WindowId (de.metas.ui.web.window.datatypes.WindowId)5 JsonAutoDetect (com.fasterxml.jackson.annotation.JsonAutoDetect)2 Visibility (com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)2 DocumentType (de.metas.ui.web.window.datatypes.DocumentType)2 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)2 List (java.util.List)2 Set (java.util.Set)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 MoreObjects (com.google.common.base.MoreObjects)1 Preconditions (com.google.common.base.Preconditions)1