Search in sources :

Example 46 with DocumentId

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);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 47 with DocumentId

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);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) Test(org.junit.Test)

Example 48 with DocumentId

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()));
}
Also used : IPair(org.adempiere.util.lang.IPair) SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Env(org.compiere.util.Env) ArrayList(java.util.ArrayList) IStringExpression(org.adempiere.ad.expression.api.IStringExpression) Evaluatee(org.compiere.util.Evaluatee) SqlDocumentFilterConverters(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverters) ImmutableList(com.google.common.collect.ImmutableList) SqlEntityFieldBinding(de.metas.ui.web.window.descriptor.sql.SqlEntityFieldBinding) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) Map(java.util.Map) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) DocumentQueryOrderBy(de.metas.ui.web.window.model.DocumentQueryOrderBy) OnVariableNotFound(org.adempiere.ad.expression.api.IExpressionEvaluator.OnVariableNotFound) Properties(java.util.Properties) WindowConstants(de.metas.ui.web.window.WindowConstants) UserRolePermissionsKey(org.adempiere.ad.security.UserRolePermissionsKey) Evaluatees(org.compiere.util.Evaluatees) ImmutableMap(com.google.common.collect.ImmutableMap) AccessSqlStringExpression(org.adempiere.ad.security.impl.AccessSqlStringExpression) MoreObjects(com.google.common.base.MoreObjects) Objects(java.util.Objects) DocumentFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentFieldDescriptor) List(java.util.List) ImmutablePair(org.adempiere.util.lang.ImmutablePair) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(org.adempiere.util.Check) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) DocumentQuery(de.metas.ui.web.window.model.DocumentQuery) LookupValueByIdSupplier(de.metas.ui.web.window.model.lookup.LookupValueByIdSupplier) SqlParamsCollector(de.metas.ui.web.document.filter.sql.SqlParamsCollector) Collections(java.util.Collections) Document(de.metas.ui.web.window.model.Document) CompositeStringExpression(org.adempiere.ad.expression.api.impl.CompositeStringExpression) CompositeStringExpression(org.adempiere.ad.expression.api.impl.CompositeStringExpression) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Document(de.metas.ui.web.window.model.Document) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) AdempiereException(org.adempiere.exceptions.AdempiereException) IStringExpression(org.adempiere.ad.expression.api.IStringExpression) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) SqlParamsCollector(de.metas.ui.web.document.filter.sql.SqlParamsCollector)

Example 49 with DocumentId

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);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Test(org.junit.Test)

Example 50 with DocumentId

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);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Test(org.junit.Test)

Aggregations

DocumentId (de.metas.ui.web.window.datatypes.DocumentId)99 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)18 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)14 List (java.util.List)14 ImmutableList (com.google.common.collect.ImmutableList)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 AdempiereException (org.adempiere.exceptions.AdempiereException)11 JSONLookupValuesList (de.metas.ui.web.window.datatypes.json.JSONLookupValuesList)9 ArrayList (java.util.ArrayList)9 Set (java.util.Set)9 NonNull (lombok.NonNull)9 Test (org.junit.Test)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 UserSession (de.metas.ui.web.session.UserSession)8 ViewId (de.metas.ui.web.view.ViewId)8 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)8 Document (de.metas.ui.web.window.model.Document)8 IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)8 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8