Search in sources :

Example 16 with LookupValuesList

use of de.metas.ui.web.window.datatypes.LookupValuesList 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 17 with LookupValuesList

use of de.metas.ui.web.window.datatypes.LookupValuesList in project metasfresh-webui-api by metasfresh.

the class FullyCachedLookupDataSource method findEntities.

@Override
public LookupValuesList findEntities(final Evaluatee ctx, final String filter, final int firstRow, final int pageLength) {
    final LookupValuesList partition = getLookupValuesList(ctx);
    if (partition.isEmpty()) {
        return partition;
    }
    final Predicate<LookupValue> filterPredicate = LookupValueFilterPredicates.of(filter);
    if (filterPredicate == LookupValueFilterPredicates.MATCH_ALL) {
        return partition.offsetAndLimit(firstRow, pageLength);
    }
    return partition.filter(filterPredicate, firstRow, pageLength);
}
Also used : LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 18 with LookupValuesList

use of de.metas.ui.web.window.datatypes.LookupValuesList in project metasfresh-webui-api by metasfresh.

the class DocumentField method getLookupValuesForQuery.

@Override
public LookupValuesList getLookupValuesForQuery(final String query) {
    final LookupDataSource lookupDataSource = getLookupDataSource();
    final Evaluatee ctx = getDocument().asEvaluatee();
    final LookupValuesList values = lookupDataSource.findEntities(ctx, query);
    lookupValuesStaled = false;
    return values;
}
Also used : LookupDataSource(de.metas.ui.web.window.model.lookup.LookupDataSource) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) Evaluatee(org.compiere.util.Evaluatee)

Example 19 with LookupValuesList

use of de.metas.ui.web.window.datatypes.LookupValuesList in project metasfresh-webui-api by metasfresh.

the class WebuiProcessClassInfo method retriveLookupValues.

private static final LookupValuesList retriveLookupValues(final Method method, final List<Function<LookupDataSourceContext, Object>> parameterValueProviders, final LookupDataSourceContext evalCtx) {
    Check.assumeNotNull(method, "Parameter method is not null");
    final JavaProcess processClassInstance = JavaProcess.currentInstance();
    final Object[] methodParams = parameterValueProviders.stream().map(paramValueProvider -> paramValueProvider.apply(evalCtx)).toArray();
    try {
        if (!method.isAccessible()) {
            method.setAccessible(true);
        }
        final LookupValuesList lookupValues = (LookupValuesList) method.invoke(processClassInstance, methodParams);
        return lookupValues;
    } catch (IllegalAccessException | InvocationTargetException e) {
        final Throwable cause = AdempiereException.extractCause(e);
        throw new AdempiereException("Failed invoking " + method + " using " + methodParams, cause);
    } catch (final Exception e) {
        throw AdempiereException.wrapIfNeeded(e);
    }
}
Also used : LogManager(de.metas.logging.LogManager) LoadingCache(com.google.common.cache.LoadingCache) GuavaCollectors(org.adempiere.util.GuavaCollectors) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) Function(java.util.function.Function) ProcessClassInfo(de.metas.process.ProcessClassInfo) ListLookupDescriptor(de.metas.ui.web.window.descriptor.ListLookupDescriptor) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) PanelLayoutType(de.metas.ui.web.window.datatypes.PanelLayoutType) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) LookupDataSourceContext(de.metas.ui.web.window.model.lookup.LookupDataSourceContext) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) MoreObjects(com.google.common.base.MoreObjects) JavaProcess(de.metas.process.JavaProcess) InvocationTargetException(java.lang.reflect.InvocationTargetException) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) Stream(java.util.stream.Stream) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(org.adempiere.util.Check) ProcessParamLookupValuesProvider(de.metas.ui.web.process.descriptor.ProcessParamLookupValuesProvider) ReflectionUtils(org.reflections.ReflectionUtils) CacheBuilder(com.google.common.cache.CacheBuilder) AdempiereException(org.adempiere.exceptions.AdempiereException) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) AdempiereException(org.adempiere.exceptions.AdempiereException) JavaProcess(de.metas.process.JavaProcess)

Example 20 with LookupValuesList

use of de.metas.ui.web.window.datatypes.LookupValuesList 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

LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)20 IntegerLookupValue (de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue)8 LookupDescriptor (de.metas.ui.web.window.descriptor.LookupDescriptor)8 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)7 LookupDataSource (de.metas.ui.web.window.model.lookup.LookupDataSource)7 List (java.util.List)7 NonNull (lombok.NonNull)7 SqlLookupDescriptor (de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor)6 ImmutableList (com.google.common.collect.ImmutableList)5 LogManager (de.metas.logging.LogManager)4 ActionType (de.metas.ui.web.handlingunits.process.WebuiHUTransformCommand.ActionType)4 LookupDataSourceContext (de.metas.ui.web.window.model.lookup.LookupDataSourceContext)4 Set (java.util.Set)4 Services (org.adempiere.util.Services)4 DisplayType (org.compiere.util.DisplayType)4 I_M_HU (de.metas.handlingunits.model.I_M_HU)3 Check (de.metas.printing.esb.base.util.Check)3 IProcessDefaultParametersProvider (de.metas.process.IProcessDefaultParametersProvider)3 StringLookupValue (de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue)3 LookupDataSourceFactory (de.metas.ui.web.window.model.lookup.LookupDataSourceFactory)3