use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class SqlDocumentsRepository method createNewDocument.
@Override
public Document createNewDocument(final DocumentEntityDescriptor entityDescriptor, final Document parentDocument, final IDocumentChangesCollector changesCollector) {
assertThisRepository(entityDescriptor);
// TODO: check permissions if we can create a new record
final DocumentId documentId = retrieveNextDocumentId(entityDescriptor);
return Document.builder(entityDescriptor).setParentDocument(parentDocument).setChangesCollector(changesCollector).initializeAsNewDocument(documentId, VERSION_DEFAULT);
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class HUEditorRowTest method testCreateHUEditorRow.
@Test
public void testCreateHUEditorRow() {
final int huId = 10;
final int topLevelHUId = 20;
final int windowId = 123;
final HUEditorRow huEditorRow = HUEditorRow.builder(WindowId.of(windowId)).setRowId(HUEditorRowId.ofHU(huId, topLevelHUId)).setType(HUEditorRowType.TU).setTopLevel(false).build();
assertThat(huEditorRow.getM_HU_ID()).isEqualTo(huId);
final DocumentId documentId = huEditorRow.getHURowId().toDocumentId();
assertThat(documentId.isInt()).isFalse();
// expecting 10_T20
assertThat(documentId.toString()).isEqualTo(huId + "_T" + topLevelHUId);
final DocumentPath documentPath = huEditorRow.getDocumentPath();
assertThat(documentPath.getWindowId().toInt()).isEqualTo(windowId);
assertThat(documentPath.getDocumentId().toInt()).isEqualTo(huId);
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class SqlDocumentQueryBuilder method buildSqlWhereClause.
private IPair<IStringExpression, List<Object>> buildSqlWhereClause() {
final SqlParamsCollector sqlParams = SqlParamsCollector.newInstance();
final CompositeStringExpression.Builder sqlWhereClauseBuilder = IStringExpression.composer();
//
// Entity's WHERE clause
{
final IStringExpression entityWhereClauseExpression = entityBinding.getSqlWhereClause();
if (!entityWhereClauseExpression.isNullExpression()) {
sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
sqlWhereClauseBuilder.append(" /* entity where clause */ (").append(entityWhereClauseExpression).append(")");
}
}
//
// Key column
// FIXME: handle AD_Reference/AD_Ref_List(s). In that case the recordId will be AD_Ref_List.Value,
// so the SQL where clause which is currently build is AD_Ref_List_ID=<the AD_Ref_List.Value>.
// The build SQL where clause shall be something like AD_Reference_ID=<the reference, i think we shall fetch it somehow from Lookup> AND Value=<the value, which currently is the recordId>
final DocumentId recordId = getRecordId();
if (recordId != null) {
final List<SqlDocumentFieldDataBindingDescriptor> keyFields = entityBinding.getKeyFields();
if (keyFields.isEmpty()) {
throw new AdempiereException("Failed building where clause because there is no Key Column defined in " + entityBinding);
} else // Single primary key
if (keyFields.size() == 1) {
final String keyColumnName = keyFields.get(0).getColumnName();
sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
sqlWhereClauseBuilder.append(" /* key */ ").append(keyColumnName).append("=").append(sqlParams.placeholder(recordId.toInt()));
} else // Composed primary key
{
final Map<String, Object> keyColumnName2value = extractComposedKey(recordId, keyFields);
keyColumnName2value.forEach((keyColumnName, value) -> {
sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
sqlWhereClauseBuilder.append(" /* key */ ").append(keyColumnName).append("=").append(sqlParams.placeholder(value));
});
}
}
//
// Parent link where clause (if any)
final Document parentDocument = getParentDocument();
if (parentDocument != null) {
final String parentLinkColumnName = entityBinding.getParentLinkColumnName();
final String linkColumnName = entityBinding.getLinkColumnName();
if (parentLinkColumnName != null && linkColumnName != null) {
final IDocumentFieldView parentLinkField = parentDocument.getFieldView(parentLinkColumnName);
final Object parentLinkValue = parentLinkField.getValue();
final DocumentFieldWidgetType parentLinkWidgetType = parentLinkField.getWidgetType();
final Class<?> targetClass = entityBinding.getFieldByFieldName(linkColumnName).getSqlValueClass();
final Object sqlParentLinkValue = SqlDocumentsRepository.convertValueToPO(parentLinkValue, parentLinkColumnName, parentLinkWidgetType, targetClass);
sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
sqlWhereClauseBuilder.append(" /* parent link */ ").append(linkColumnName).append("=").append(sqlParams.placeholder(sqlParentLinkValue));
}
}
//
// Document filters
{
final String sqlFilters = SqlDocumentFilterConverters.createEntityBindingEffectiveConverter(entityBinding).getSql(sqlParams, getDocumentFilters(), SqlOptions.usingTableAlias(entityBinding.getTableAlias()));
if (!Check.isEmpty(sqlFilters, true)) {
sqlWhereClauseBuilder.appendIfNotEmpty("\n AND ");
sqlWhereClauseBuilder.append(" /* filters */ (\n").append(sqlFilters).append(")\n");
}
}
// Build the final SQL where clause
return ImmutablePair.of(sqlWhereClauseBuilder.build(), Collections.unmodifiableList(sqlParams.toList()));
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class PickingSlotRowIdTests method testFromDocumentId_HUStorage.
/**
* Tests the conversion between {@link DocumentId} and {@link PickingSlotRowId} in case of a picked HU storage.
*/
@Test
public void testFromDocumentId_HUStorage() {
final DocumentId documentId = PickingSlotRowId.ofPickedHU(123, 456, 789).toDocumentId();
assertThat(documentId.toJson()).isEqualTo("123-456-789");
final PickingSlotRowId rowId = PickingSlotRowId.fromDocumentId(documentId);
assertThat(rowId.toDocumentId()).isEqualTo(documentId);
assertThat(rowId.getPickingSlotId()).isEqualTo(123);
assertThat(rowId.getHuId()).isEqualTo(456);
assertThat(rowId.getHuStorageProductId()).isEqualTo(789);
assertIsPickedHURow(rowId);
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class PickingSlotRowIdTests method testFromDocumentId_PickingSlot.
/**
* Tests the conversion between {@link DocumentId} and {@link PickingSlotRowId} in case of a Picking Slot row.
*/
@Test
public void testFromDocumentId_PickingSlot() {
final DocumentId documentId = PickingSlotRowId.ofPickingSlotId(123).toDocumentId();
assertThat(documentId.toJson()).isEqualTo("123");
final PickingSlotRowId rowId = PickingSlotRowId.fromDocumentId(documentId);
assertThat(rowId.toDocumentId()).isEqualTo(documentId);
assertThat(rowId.getPickingSlotId()).isEqualTo(123);
assertThat(rowId.getHuId()).isLessThanOrEqualTo(0);
assertThat(rowId.getHuStorageProductId()).isLessThanOrEqualTo(0);
assertIsPickingSlotRow(rowId);
}
Aggregations