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));
}
}
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);
}
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;
}
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);
}
}
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();
}
Aggregations