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