Search in sources :

Example 1 with LabelsLookup

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

the class GridTabVOBasedDocumentEntityDescriptorFactory method createAndAddLabelsDocumentField.

private final void createAndAddLabelsDocumentField(final DocumentEntityDescriptor.Builder entityDescriptor, final I_AD_UI_Element labelsUIElement) {
    final String labelsFieldName = getLabelsFieldName(labelsUIElement);
    final String tablename = entityDescriptor.getTableName().get();
    final LabelsLookup lookupDescriptor = createLabelsLookup(labelsUIElement, tablename);
    final SqlDocumentEntityDataBindingDescriptor.Builder entityBindings = entityDescriptor.getDataBindingBuilder(SqlDocumentEntityDataBindingDescriptor.Builder.class);
    final SqlDocumentFieldDataBindingDescriptor fieldBinding = SqlDocumentFieldDataBindingDescriptor.builder().setFieldName(labelsFieldName).setVirtualColumn(false).setMandatory(false).setWidgetType(DocumentFieldWidgetType.Labels).setValueClass(DocumentFieldWidgetType.Labels.getValueClass()).setSqlValueClass(DocumentFieldWidgetType.Labels.getValueClass()).setLookupDescriptor(lookupDescriptor).build();
    entityBindings.addField(fieldBinding);
    final IModelTranslationMap trlMap = InterfaceWrapperHelper.getModelTranslationMap(labelsUIElement);
    final DocumentFieldDescriptor.Builder fieldBuilder = DocumentFieldDescriptor.builder(labelsFieldName).setCaption(trlMap.getColumnTrl(I_AD_UI_Element.COLUMNNAME_Name, labelsUIElement.getName())).setDescription(trlMap.getColumnTrl(I_AD_UI_Element.COLUMNNAME_Description, labelsUIElement.getDescription())).setKey(false).setParentLink(false).setWidgetType(DocumentFieldWidgetType.Labels).setValueClass(fieldBinding.getValueClass()).setLookupDescriptorProvider(lookupDescriptor).setDefaultFilterInfo(createLabelsDefaultFilterInfo(labelsUIElement)).setDataBinding(fieldBinding);
    // 
    // Add Field builder to document entity
    entityDescriptor.addField(fieldBuilder);
    // 
    // Collect special field
    collectSpecialField(fieldBuilder);
}
Also used : SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) IModelTranslationMap(de.metas.i18n.IModelTranslationMap) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) LabelsLookup(de.metas.ui.web.window.model.lookup.LabelsLookup)

Example 2 with LabelsLookup

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

the class SqlDocumentsRepository method saveLabels.

private static final void saveLabels(final Document document, final IDocumentFieldView documentField) {
    final LabelsLookup lookup = LabelsLookup.cast(documentField.getDescriptor().getLookupDescriptor(LookupScope.DocumentField));
    final int linkId = document.getFieldView(lookup.getLinkColumnName()).getValueAsInt(-1);
    final Set<Object> listValuesInDatabase = lookup.retrieveExistingValues(linkId).getKeys();
    final LookupValuesList lookupValuesList = documentField.getValueAs(LookupValuesList.class);
    final Set<Object> listValuesToSave = lookupValuesList != null ? new HashSet<>(lookupValuesList.getKeys()) : new HashSet<>();
    // 
    // Delete removed labels
    {
        final Set<Object> listValuesToDelete = new HashSet<>(listValuesInDatabase);
        listValuesToDelete.removeAll(listValuesToSave);
        if (!listValuesToDelete.isEmpty()) {
            final int countDeleted = lookup.retrieveExistingValuesRecordQuery(linkId).addInArrayFilter(lookup.getLabelsValueColumnName(), listValuesToDelete).create().delete();
            if (countDeleted != listValuesToDelete.size()) {
                logger.warn("Possible issue while deleting labels for linkId={}: listValuesToDelete={}, countDeleted={}", linkId, listValuesToDelete, countDeleted);
            }
        }
    }
    // 
    // Create new labels
    {
        final Set<Object> listValuesToSaveEffective = new HashSet<>(listValuesToSave);
        listValuesToSaveEffective.removeAll(listValuesInDatabase);
        listValuesToSaveEffective.forEach(listValueToSave -> createLabelPORecord(listValueToSave, linkId, lookup));
    }
}
Also used : Password(de.metas.ui.web.window.datatypes.Password) DocumentPermissionsHelper(de.metas.ui.web.window.controller.DocumentPermissionsHelper) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) ITrx(org.adempiere.ad.trx.api.ITrx) TableModelLoader(org.adempiere.ad.persistence.TableModelLoader) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResultSet(java.sql.ResultSet) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) Map(java.util.Map) POInfo(org.compiere.model.POInfo) JSONNullValue(de.metas.ui.web.window.datatypes.json.JSONNullValue) WindowConstants(de.metas.ui.web.window.WindowConstants) DocumentValuesSupplier(de.metas.ui.web.window.model.Document.DocumentValuesSupplier) NonNull(lombok.NonNull) Timestamp(java.sql.Timestamp) Set(java.util.Set) IQueryBuilder(org.adempiere.ad.dao.IQueryBuilder) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) ITrxManager(org.adempiere.ad.trx.api.ITrxManager) UserSession(de.metas.ui.web.session.UserSession) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) DBException(org.adempiere.exceptions.DBException) Services(org.adempiere.util.Services) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) List(java.util.List) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) LookupScope(de.metas.ui.web.window.descriptor.LookupDescriptorProvider.LookupScope) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) DocumentQuery(de.metas.ui.web.window.model.DocumentQuery) Joiner(com.google.common.base.Joiner) LogManager(de.metas.logging.LogManager) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) TimeUtil(org.compiere.util.TimeUtil) OrderedDocumentsList(de.metas.ui.web.window.model.OrderedDocumentsList) Function(java.util.function.Function) PlainContextAware(org.adempiere.model.PlainContextAware) DocumentNotFoundException(de.metas.ui.web.window.exceptions.DocumentNotFoundException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SQLException(java.sql.SQLException) DB(org.compiere.util.DB) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) ImmutableList(com.google.common.collect.ImmutableList) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) DisplayType(org.compiere.util.DisplayType) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) DBMoreThenOneRecordsFoundException(org.adempiere.exceptions.DBMoreThenOneRecordsFoundException) DocumentFieldValueLoader(de.metas.ui.web.window.descriptor.sql.DocumentFieldValueLoader) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) Logger(org.slf4j.Logger) DocumentsRepository(de.metas.ui.web.window.model.DocumentsRepository) DocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDataBindingDescriptor) IQueryBL(org.adempiere.ad.dao.IQueryBL) LabelsLookup(de.metas.ui.web.window.model.lookup.LabelsLookup) AdempiereException(org.adempiere.exceptions.AdempiereException) DataTypes(de.metas.ui.web.window.datatypes.DataTypes) Check(org.adempiere.util.Check) PO(org.compiere.model.PO) JSONDate(de.metas.ui.web.window.datatypes.json.JSONDate) Document(de.metas.ui.web.window.model.Document) ResultSet(java.sql.ResultSet) Set(java.util.Set) HashSet(java.util.HashSet) LabelsLookup(de.metas.ui.web.window.model.lookup.LabelsLookup) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList)

Example 3 with LabelsLookup

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

the class SqlDefaultDocumentFilterConverter method buildSqlWhereClause_LabelsWidget.

private final String buildSqlWhereClause_LabelsWidget(final DocumentFilterParam filterParam, final DocumentFilterParamDescriptor paramDescriptor, final SqlParamsCollector sqlParams, final SqlOptions sqlOpts) {
    final LookupValuesList lookupValues = extractLookupValuesList(filterParam);
    if (lookupValues.isEmpty()) {
        return null;
    }
    final String tableAlias = sqlOpts.getTableNameOrAlias();
    final LabelsLookup lookup = LabelsLookup.cast(paramDescriptor.getLookupDescriptor());
    final String labelsTableName = lookup.getLabelsTableName();
    final String labelsLinkColumnName = lookup.getLabelsLinkColumnName();
    final String linkColumnName = lookup.getLinkColumnName();
    final String labelsValueColumnName = lookup.getLabelsValueColumnName();
    final StringBuilder sql = new StringBuilder();
    for (final LookupValue lookupValue : lookupValues) {
        if (sql.length() > 0) {
            sql.append(" AND ");
        }
        final Object labelValue = lookup.isLabelsValuesUseNumericKey() ? lookupValue.getIdAsInt() : lookupValue.getIdAsString();
        sql.append("EXISTS (SELECT 1 FROM " + labelsTableName + " labels " + " WHERE labels." + labelsLinkColumnName + "=" + tableAlias + "." + linkColumnName + " AND labels." + labelsValueColumnName + "=" + sqlParams.placeholder(labelValue) + ")");
    }
    return sql.toString();
}
Also used : LabelsLookup(de.metas.ui.web.window.model.lookup.LabelsLookup) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Aggregations

LabelsLookup (de.metas.ui.web.window.model.lookup.LabelsLookup)3 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)2 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)2 DocumentFieldDescriptor (de.metas.ui.web.window.descriptor.DocumentFieldDescriptor)2 SqlDocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor)2 SqlDocumentFieldDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor)2 Joiner (com.google.common.base.Joiner)1 ImmutableList (com.google.common.collect.ImmutableList)1 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)1 LogManager (de.metas.logging.LogManager)1 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)1 UserSession (de.metas.ui.web.session.UserSession)1 WindowConstants (de.metas.ui.web.window.WindowConstants)1 DocumentPermissionsHelper (de.metas.ui.web.window.controller.DocumentPermissionsHelper)1 DataTypes (de.metas.ui.web.window.datatypes.DataTypes)1 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)1 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)1 StringLookupValue (de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue)1 Password (de.metas.ui.web.window.datatypes.Password)1