Search in sources :

Example 1 with IQueryBL

use of org.adempiere.ad.dao.IQueryBL in project metasfresh-webui-api by metasfresh.

the class BoardDescriptorRepository method createBoardDescriptor.

private BoardDescriptor createBoardDescriptor(final int boardId) {
    // 
    // Retrieve the board PO
    final IQueryBL queryBL = Services.get(IQueryBL.class);
    final I_WEBUI_Board boardPO = queryBL.createQueryBuilderOutOfTrx(I_WEBUI_Board.class).addEqualsFilter(I_WEBUI_Board.COLUMN_WEBUI_Board_ID, boardId).addOnlyActiveRecordsFilter().create().firstOnly(I_WEBUI_Board.class);
    if (boardPO == null) {
        throw new EntityNotFoundException("No board found for ID=" + boardId);
    }
    // 
    // Board document mappings
    final String tableName = Services.get(IADTableDAO.class).retrieveTableName(boardPO.getAD_Table_ID());
    final String keyColumnName = InterfaceWrapperHelper.getKeyColumnName(tableName);
    // TODO: hardcoded
    final String userIdColumnName = "UpdatedBy";
    // 
    // Board document info
    // TODO boardPO.getAD_Window_ID();
    int adWindowId = 0;
    if (adWindowId <= 0) {
        adWindowId = RecordZoomWindowFinder.findAD_Window_ID(tableName);
    }
    final WindowId documentWindowId = WindowId.of(adWindowId);
    final DocumentEntityDescriptor documentEntityDescriptor = documentDescriptors.getDocumentEntityDescriptor(documentWindowId);
    final SqlDocumentEntityDataBindingDescriptor documentBinding = documentEntityDescriptor.getDataBinding(SqlDocumentEntityDataBindingDescriptor.class);
    final String tableAlias = documentBinding.getTableAlias();
    // 
    // Board document lookup provider
    final int adValRuleId = boardPO.getAD_Val_Rule_ID();
    final LookupDescriptorProvider documentLookupDescriptorProvider = SqlLookupDescriptor.builder().setCtxTableName(null).setCtxColumnName(keyColumnName).setDisplayType(DisplayType.Search).setWidgetType(DocumentFieldWidgetType.Lookup).setAD_Val_Rule_ID(adValRuleId).buildProvider();
    // 
    // Board descriptor
    final IModelTranslationMap boardTrlMap = InterfaceWrapperHelper.getModelTranslationMap(boardPO);
    final BoardDescriptorBuilder boardDescriptor = BoardDescriptor.builder().boardId(boardPO.getWEBUI_Board_ID()).caption(boardTrlMap.getColumnTrl(I_WEBUI_Board.COLUMNNAME_Name, boardPO.getName())).documentWindowId(documentWindowId).documentLookupDescriptorProvider(documentLookupDescriptorProvider).tableName(tableName).tableAlias(tableAlias).keyColumnName(keyColumnName).userIdColumnName(userIdColumnName).websocketEndpoint(WebSocketConfig.buildBoardTopicName(boardId));
    // Source document filters: AD_Val_Rule_ID
    if (adValRuleId > 0) {
        final IValidationRule validationRule = Services.get(IValidationRuleFactory.class).create(tableName, adValRuleId, // ctx table name
        null, // ctx column name
        null);
        final String sqlWhereClause = validationRule.getPrefilterWhereClause().evaluate(Evaluatees.ofCtx(Env.getCtx()), OnVariableNotFound.Fail);
        final DocumentFilter adValRuleFilter = DocumentFilter.builder().setFilterId("AD_Val_Rule_" + adValRuleId).addParameter(DocumentFilterParam.ofSqlWhereClause(true, sqlWhereClause)).build();
        boardDescriptor.documentFilter(adValRuleFilter);
    }
    // 
    // Lanes
    {
        queryBL.createQueryBuilderOutOfTrx(I_WEBUI_Board_Lane.class).addEqualsFilter(I_WEBUI_Board_Lane.COLUMN_WEBUI_Board_ID, boardId).addOnlyActiveRecordsFilter().orderBy().addColumn(I_WEBUI_Board_Lane.COLUMN_SeqNo).addColumn(// just have a predictable order
        I_WEBUI_Board_Lane.COLUMN_WEBUI_Board_Lane_ID).endOrderBy().create().stream(I_WEBUI_Board_Lane.class).map(this::createBoardLaneDescriptor).forEach(lane -> boardDescriptor.lane(lane.getLaneId(), lane));
    }
    // 
    // Board card fields
    {
        queryBL.createQueryBuilderOutOfTrx(I_WEBUI_Board_CardField.class).addEqualsFilter(I_WEBUI_Board_CardField.COLUMN_WEBUI_Board_ID, boardId).addOnlyActiveRecordsFilter().orderBy().addColumn(I_WEBUI_Board_CardField.COLUMN_SeqNo).addColumn(I_WEBUI_Board_CardField.COLUMN_WEBUI_Board_CardField_ID).endOrderBy().create().stream(I_WEBUI_Board_CardField.class).map(cardFieldPO -> createBoardCardFieldDescriptor(cardFieldPO, documentEntityDescriptor)).forEach(cardField -> boardDescriptor.cardFieldByFieldName(cardField.getFieldName(), cardField));
    }
    // 
    return boardDescriptor.build();
}
Also used : CCache(org.compiere.util.CCache) DBUniqueConstraintException(org.adempiere.exceptions.DBUniqueConstraintException) I_WEBUI_Board_CardField(de.metas.ui.web.base.model.I_WEBUI_Board_CardField) JSONBoardChangedEventsList(de.metas.ui.web.board.json.events.JSONBoardChangedEventsList) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) Autowired(org.springframework.beans.factory.annotation.Autowired) JSONBoardChangedEventsListBuilder(de.metas.ui.web.board.json.events.JSONBoardChangedEventsList.JSONBoardChangedEventsListBuilder) BigDecimal(java.math.BigDecimal) IStringExpression(org.adempiere.ad.expression.api.IStringExpression) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) ResultSet(java.sql.ResultSet) Map(java.util.Map) ToString(lombok.ToString) Repository(org.springframework.stereotype.Repository) RecordZoomWindowFinder(org.adempiere.model.RecordZoomWindowFinder) ImmutableSet(com.google.common.collect.ImmutableSet) WindowConstants(de.metas.ui.web.window.WindowConstants) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) Collection(java.util.Collection) Set(java.util.Set) PreparedStatement(java.sql.PreparedStatement) I_WEBUI_Board_RecordAssignment(de.metas.ui.web.base.model.I_WEBUI_Board_RecordAssignment) EqualsAndHashCode(lombok.EqualsAndHashCode) ITrxManager(org.adempiere.ad.trx.api.ITrxManager) 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) DateTimeTranslatableString(de.metas.i18n.DateTimeTranslatableString) WebsocketSender(de.metas.ui.web.websocket.WebsocketSender) NumberTranslatableString(de.metas.i18n.NumberTranslatableString) LookupScope(de.metas.ui.web.window.descriptor.LookupDescriptorProvider.LookupScope) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) IMsgBL(de.metas.i18n.IMsgBL) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) Joiner(com.google.common.base.Joiner) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) LogManager(de.metas.logging.LogManager) I_WEBUI_Board_Lane(de.metas.ui.web.base.model.I_WEBUI_Board_Lane) BoardDescriptorBuilder(de.metas.ui.web.board.BoardDescriptor.BoardDescriptorBuilder) 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) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) JSONBoardLaneChangedEvent(de.metas.ui.web.board.json.events.JSONBoardLaneChangedEvent) I_WEBUI_Board(de.metas.ui.web.base.model.I_WEBUI_Board) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) DB(org.compiere.util.DB) ICurrencyDAO(de.metas.currency.ICurrencyDAO) 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) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) I_AD_User(org.compiere.model.I_AD_User) DocumentFieldValueLoader(de.metas.ui.web.window.descriptor.sql.DocumentFieldValueLoader) LinkedHashSet(java.util.LinkedHashSet) OnVariableNotFound(org.adempiere.ad.expression.api.IExpressionEvaluator.OnVariableNotFound) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) Logger(org.slf4j.Logger) BoardFieldLoader(de.metas.ui.web.board.BoardCardFieldDescriptor.BoardFieldLoader) Evaluatees(org.compiere.util.Evaluatees) DocumentDescriptorFactory(de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory) DocumentFilterParam(de.metas.ui.web.document.filter.DocumentFilterParam) IModelTranslationMap(de.metas.i18n.IModelTranslationMap) WindowId(de.metas.ui.web.window.datatypes.WindowId) IQueryBL(org.adempiere.ad.dao.IQueryBL) Amount(de.metas.currency.Amount) Consumer(java.util.function.Consumer) NumberUtils(org.adempiere.util.NumberUtils) AdempiereException(org.adempiere.exceptions.AdempiereException) ListUtils(org.adempiere.util.collections.ListUtils) IValidationRuleFactory(org.adempiere.ad.validationRule.IValidationRuleFactory) Preconditions(com.google.common.base.Preconditions) IValidationRule(org.adempiere.ad.validationRule.IValidationRule) WebSocketConfig(de.metas.ui.web.websocket.WebSocketConfig) CompositeStringExpression(org.adempiere.ad.expression.api.impl.CompositeStringExpression) IModelTranslationMap(de.metas.i18n.IModelTranslationMap) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) ToString(lombok.ToString) ITranslatableString(de.metas.i18n.ITranslatableString) DateTimeTranslatableString(de.metas.i18n.DateTimeTranslatableString) NumberTranslatableString(de.metas.i18n.NumberTranslatableString) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) IValidationRuleFactory(org.adempiere.ad.validationRule.IValidationRuleFactory) LookupDescriptorProvider(de.metas.ui.web.window.descriptor.LookupDescriptorProvider) IQueryBL(org.adempiere.ad.dao.IQueryBL) BoardDescriptorBuilder(de.metas.ui.web.board.BoardDescriptor.BoardDescriptorBuilder) WindowId(de.metas.ui.web.window.datatypes.WindowId) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) IValidationRule(org.adempiere.ad.validationRule.IValidationRule) I_WEBUI_Board(de.metas.ui.web.base.model.I_WEBUI_Board) I_WEBUI_Board_Lane(de.metas.ui.web.base.model.I_WEBUI_Board_Lane) I_WEBUI_Board_CardField(de.metas.ui.web.base.model.I_WEBUI_Board_CardField) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 2 with IQueryBL

use of org.adempiere.ad.dao.IQueryBL in project metasfresh-webui-api by metasfresh.

the class MaterialCockpitRowRepository method retrieveAllProducts.

private List<I_M_Product> retrieveAllProducts(final int adOrgId) {
    final IQueryBL queryBL = Services.get(IQueryBL.class);
    final // 
    ICompositeQueryFilter<I_M_Product> relevantProductFilter = queryBL.createCompositeQueryFilter(I_M_Product.class).setJoinOr().addEqualsFilter(I_M_Product.COLUMN_IsSold, true).addEqualsFilter(I_M_Product.COLUMN_IsPurchased, true).addEqualsFilter(I_M_Product.COLUMN_IsStocked, true);
    final // 
    List<I_M_Product> products = queryBL.createQueryBuilder(I_M_Product.class).addOnlyActiveRecordsFilter().addInArrayFilter(I_M_Product.COLUMN_AD_Org_ID, adOrgId, 0).filter(relevantProductFilter).create().list();
    return products;
}
Also used : IQueryBL(org.adempiere.ad.dao.IQueryBL) I_M_Product(org.compiere.model.I_M_Product)

Example 3 with IQueryBL

use of org.adempiere.ad.dao.IQueryBL in project metasfresh-webui-api by metasfresh.

the class ProductFilterUtil method createProductQueryOrNull.

public static IQuery<I_M_Product> createProductQueryOrNull(final ProductFilterVO productFilterVO) {
    if (productFilterVO == null) {
        return null;
    }
    final IQueryBL queryBL = Services.get(IQueryBL.class);
    final IQueryBuilder<I_M_Product> productQuery = queryBL.createQueryBuilder(I_M_Product.class).addOnlyActiveRecordsFilter();
    boolean anyRestrictionAdded = false;
    final String productName = productFilterVO.getProductName();
    if (!Check.isEmpty(productName, true)) {
        final boolean ignoreCase = true;
        productQuery.addStringLikeFilter(I_M_Product.COLUMN_Name, productName, ignoreCase);
        anyRestrictionAdded = true;
    }
    final String productValue = productFilterVO.getProductValue();
    if (!Check.isEmpty(productValue, true)) {
        final boolean ignoreCase = true;
        productQuery.addStringLikeFilter(I_M_Product.COLUMN_Value, productValue, ignoreCase);
        anyRestrictionAdded = true;
    }
    final int productCategoryId = productFilterVO.getProductCategoryId();
    if (productCategoryId > 0) {
        productQuery.addEqualsFilter(I_M_Product.COLUMN_M_Product_Category_ID, productCategoryId);
        anyRestrictionAdded = true;
    }
    final Boolean isPurchased = productFilterVO.getIsPurchased();
    if (isPurchased != null) {
        productQuery.addEqualsFilter(I_M_Product.COLUMN_IsPurchased, isPurchased);
        anyRestrictionAdded = true;
    }
    final Boolean isSold = productFilterVO.getIsSold();
    if (isSold != null) {
        productQuery.addEqualsFilter(I_M_Product.COLUMN_IsSold, isSold);
        anyRestrictionAdded = true;
    }
    // 
    if (!anyRestrictionAdded) {
        return null;
    }
    return productQuery.create();
}
Also used : IQueryBL(org.adempiere.ad.dao.IQueryBL) I_M_Product(org.compiere.model.I_M_Product)

Example 4 with IQueryBL

use of org.adempiere.ad.dao.IQueryBL in project metasfresh-webui-api by metasfresh.

the class SqlDocumentsRepository method toQueryBuilder.

private static final IQueryBuilder<Object> toQueryBuilder(final SqlDocumentEntityDataBindingDescriptor dataBinding, final DocumentId documentId) {
    final String tableName = dataBinding.getTableName();
    final List<SqlDocumentFieldDataBindingDescriptor> keyFields = dataBinding.getKeyFields();
    final int keyFieldsCount = keyFields.size();
    if (keyFieldsCount == 0) {
        throw new AdempiereException("No primary key defined for " + tableName);
    }
    final List<Object> keyParts = documentId.toComposedKeyParts();
    if (keyFieldsCount != keyParts.size()) {
        throw new AdempiereException("Invalid documentId '" + documentId + "'. It shall have " + keyFieldsCount + " parts but it has " + keyParts.size());
    }
    final IQueryBL queryBL = Services.get(IQueryBL.class);
    final IQueryBuilder<Object> queryBuilder = queryBL.createQueryBuilder(tableName, PlainContextAware.newWithThreadInheritedTrx());
    for (int i = 0; i < keyFieldsCount; i++) {
        final SqlDocumentFieldDataBindingDescriptor keyField = keyFields.get(i);
        final String keyColumnName = keyField.getColumnName();
        final Object keyValue = convertValueToPO(keyParts.get(i), keyColumnName, keyField.getWidgetType(), keyField.getSqlValueClass());
        queryBuilder.addEqualsFilter(keyColumnName, keyValue);
    }
    return queryBuilder;
}
Also used : SqlDocumentFieldDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor) IQueryBL(org.adempiere.ad.dao.IQueryBL) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 5 with IQueryBL

use of org.adempiere.ad.dao.IQueryBL in project metasfresh-webui-api by metasfresh.

the class StockFilters method createStockQueryFor.

public static IQuery<I_MD_Stock> createStockQueryFor(@NonNull final List<DocumentFilter> filters) {
    final IQueryBL queryBL = Services.get(IQueryBL.class);
    final IQueryBuilder<I_MD_Stock> queryBuilder = queryBL.createQueryBuilder(I_MD_Stock.class).addOnlyActiveRecordsFilter();
    boolean anyRestrictionAdded = false;
    if (augmentQueryBuilder(queryBuilder, ProductFilterUtil.extractProductFilterVO(filters))) {
        anyRestrictionAdded = true;
    }
    if (anyRestrictionAdded) {
        return queryBuilder.create();
    } else {
        // avoid memory problems in case the filters are accidentally empty
        return queryBuilder.filter(ConstantQueryFilter.of(false)).create();
    }
}
Also used : IQueryBL(org.adempiere.ad.dao.IQueryBL) I_MD_Stock(de.metas.material.cockpit.model.I_MD_Stock)

Aggregations

IQueryBL (org.adempiere.ad.dao.IQueryBL)7 SqlDocumentFieldDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentFieldDataBindingDescriptor)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 I_M_Product (org.compiere.model.I_M_Product)2 Joiner (com.google.common.base.Joiner)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Amount (de.metas.currency.Amount)1 ICurrencyDAO (de.metas.currency.ICurrencyDAO)1 I_M_HU (de.metas.handlingunits.model.I_M_HU)1 I_M_Picking_Candidate (de.metas.handlingunits.model.I_M_Picking_Candidate)1 IHUPickingSlotDAO (de.metas.handlingunits.picking.IHUPickingSlotDAO)1 DateTimeTranslatableString (de.metas.i18n.DateTimeTranslatableString)1 IModelTranslationMap (de.metas.i18n.IModelTranslationMap)1 IMsgBL (de.metas.i18n.IMsgBL)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 ImmutableTranslatableString (de.metas.i18n.ImmutableTranslatableString)1 NumberTranslatableString (de.metas.i18n.NumberTranslatableString)1 LogManager (de.metas.logging.LogManager)1