Search in sources :

Example 16 with DocumentEntityDescriptor

use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor in project metasfresh-webui-api by metasfresh.

the class HUEditorViewFactoryTemplate method createSqlViewBinding.

private SqlViewBinding createSqlViewBinding() {
    // Get HU's standard entity descriptor. We will needed all over.
    final DocumentEntityDescriptor huEntityDescriptor = getHUEntityDescriptor();
    // 
    // Static where clause
    final StringBuilder sqlWhereClause = new StringBuilder();
    {
        // top level
        sqlWhereClause.append(I_M_HU.COLUMNNAME_M_HU_Item_Parent_ID + " is null");
        // Consider window tab's where clause if any
        final I_AD_Tab huTab = Services.get(IADWindowDAO.class).retrieveFirstTab(WEBUI_HU_Constants.WEBUI_HU_Window_ID.toInt());
        if (!Check.isEmpty(huTab.getWhereClause(), true)) {
            sqlWhereClause.append("\n AND (").append(huTab.getWhereClause()).append(")");
        }
    }
    // 
    // Start preparing the sqlViewBinding builder
    final List<String> displayFieldNames = ImmutableList.of(I_M_HU.COLUMNNAME_M_HU_ID);
    final SqlViewBinding.Builder sqlViewBinding = SqlViewBinding.builder().tableName(I_M_HU.Table_Name).displayFieldNames(displayFieldNames).sqlWhereClause(sqlWhereClause.toString()).rowIdsConverter(HUSqlViewRowIdsConverter.instance);
    // 
    // View fields: from M_HU's entity descriptor
    {
        // NOTE: we need to add all HU's standard fields because those might be needed for some of the standard filters defined
        final SqlDocumentEntityDataBindingDescriptor huEntityBindings = SqlDocumentEntityDataBindingDescriptor.cast(huEntityDescriptor.getDataBinding());
        huEntityBindings.getFields().stream().map(huField -> SqlViewFactory.createViewFieldBindingBuilder(huField, displayFieldNames).build()).forEach(sqlViewBinding::field);
    }
    // 
    // View field: BestBeforeDate
    {
        sqlViewBinding.field(SqlViewRowFieldBinding.builder().fieldName(HUEditorRow.FIELDNAME_BestBeforeDate).widgetType(DocumentFieldWidgetType.Date).columnSql(Constants.sqlBestBeforeDate(sqlViewBinding.getTableAlias() + "." + I_M_HU.COLUMNNAME_M_HU_ID)).fieldLoader((rs, adLanguage) -> rs.getTimestamp(HUEditorRow.FIELDNAME_BestBeforeDate)).build());
    }
    // 
    // View filters and converters
    {
        sqlViewBinding.filterDescriptors(createFilterDescriptorsProvider()).filterConverter(HUBarcodeSqlDocumentFilterConverter.FILTER_ID, HUBarcodeSqlDocumentFilterConverter.instance).filterConverter(HUIdsFilterHelper.FILTER_ID, HUIdsFilterHelper.SQL_DOCUMENT_FILTER_CONVERTER);
        createFilterConvertersIndexedByFilterId().forEach(sqlViewBinding::filterConverter);
    }
    // 
    return sqlViewBinding.build();
}
Also used : ArrayKey(org.compiere.util.Util.ArrayKey) CCache(org.compiere.util.CCache) SqlViewRowFieldBinding(de.metas.ui.web.view.descriptor.SqlViewRowFieldBinding) Autowired(org.springframework.beans.factory.annotation.Autowired) Map(java.util.Map) Constants(de.metas.handlingunits.attribute.Constants) ViewLayout(de.metas.ui.web.view.descriptor.ViewLayout) PanelLayoutType(de.metas.ui.web.window.datatypes.PanelLayoutType) ConstantQueryFilter(org.adempiere.ad.dao.ConstantQueryFilter) IViewFactory(de.metas.ui.web.view.IViewFactory) OverridingMethodsMustInvokeSuper(javax.annotation.OverridingMethodsMustInvokeSuper) ImmutableMap(com.google.common.collect.ImmutableMap) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) Collection(java.util.Collection) DocumentFilterParamDescriptor(de.metas.ui.web.document.filter.DocumentFilterParamDescriptor) Set(java.util.Set) IQueryBuilder(org.adempiere.ad.dao.IQueryBuilder) SqlViewBinding(de.metas.ui.web.view.descriptor.SqlViewBinding) ISqlQueryFilter(org.adempiere.ad.dao.ISqlQueryFilter) Services(org.adempiere.util.Services) List(java.util.List) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) SqlHUEditorViewRepositoryBuilder(de.metas.ui.web.handlingunits.SqlHUEditorViewRepository.SqlHUEditorViewRepositoryBuilder) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) IMsgBL(de.metas.i18n.IMsgBL) LogManager(de.metas.logging.LogManager) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) GuavaCollectors(org.adempiere.util.GuavaCollectors) DocumentFilterDescriptorsProvider(de.metas.ui.web.document.filter.DocumentFilterDescriptorsProvider) SqlOptions(de.metas.ui.web.window.model.sql.SqlOptions) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType) PlainContextAware(org.adempiere.model.PlainContextAware) ArrayList(java.util.ArrayList) DocumentFilterDescriptor(de.metas.ui.web.document.filter.DocumentFilterDescriptor) IADWindowDAO(org.adempiere.ad.window.api.IADWindowDAO) ImmutableList(com.google.common.collect.ImmutableList) I_AD_Tab(org.compiere.model.I_AD_Tab) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) ImmutableDocumentFilterDescriptorsProvider(de.metas.ui.web.document.filter.ImmutableDocumentFilterDescriptorsProvider) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) I_M_HU(de.metas.handlingunits.model.I_M_HU) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) DocumentDescriptorFactory(de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory) InArrayQueryFilter(org.adempiere.ad.dao.impl.InArrayQueryFilter) ViewProfileId(de.metas.ui.web.view.ViewProfileId) WindowId(de.metas.ui.web.window.datatypes.WindowId) IHandlingUnitsDAO(de.metas.handlingunits.IHandlingUnitsDAO) SqlDocumentFilterConverter(de.metas.ui.web.document.filter.sql.SqlDocumentFilterConverter) Check(org.adempiere.util.Check) SqlViewFactory(de.metas.ui.web.view.SqlViewFactory) CreateViewRequest(de.metas.ui.web.view.CreateViewRequest) LayoutFactory(de.metas.ui.web.window.descriptor.factory.standard.LayoutFactory) SqlParamsCollector(de.metas.ui.web.document.filter.sql.SqlParamsCollector) ViewId(de.metas.ui.web.view.ViewId) I_AD_Tab(org.compiere.model.I_AD_Tab) SqlDocumentEntityDataBindingDescriptor(de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor) SqlViewBinding(de.metas.ui.web.view.descriptor.SqlViewBinding) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) ITranslatableString(de.metas.i18n.ITranslatableString)

Example 17 with DocumentEntityDescriptor

use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor in project metasfresh-webui-api by metasfresh.

the class HUReportProcessInstancesRepository method toWebuiHUProcessDescriptor.

private WebuiHUProcessDescriptor toWebuiHUProcessDescriptor(final HUProcessDescriptor huProcessDescriptor) {
    final int reportADProcessId = huProcessDescriptor.getProcessId();
    final ProcessId processId = ProcessId.of(PROCESS_HANDLER_TYPE, reportADProcessId);
    final I_AD_Process adProcess = Services.get(IADProcessDAO.class).retrieveProcessById(reportADProcessId);
    final IModelTranslationMap adProcessTrl = InterfaceWrapperHelper.getModelTranslationMap(adProcess);
    final ITranslatableString caption = adProcessTrl.getColumnTrl(I_AD_Process.COLUMNNAME_Name, adProcess.getName());
    final ITranslatableString description = adProcessTrl.getColumnTrl(I_AD_Process.COLUMNNAME_Description, adProcess.getDescription());
    final DocumentEntityDescriptor parametersDescriptor = DocumentEntityDescriptor.builder().setDocumentType(DocumentType.Process, processId.toDocumentId()).setCaption(caption).setDescription(description).disableDefaultTableCallouts().addField(DocumentFieldDescriptor.builder(HUReportProcessInstance.PARAM_Copies).setCaption(Services.get(IMsgBL.class).translatable(HUReportProcessInstance.PARAM_Copies)).setWidgetType(DocumentFieldWidgetType.Integer)).build();
    return WebuiHUProcessDescriptor.builder().huProcessDescriptor(huProcessDescriptor).processDescriptor(ProcessDescriptor.builder().setProcessId(processId).setType(ProcessDescriptorType.Report).setParametersDescriptor(parametersDescriptor).setLayout(ProcessLayout.builder().setProcessId(processId).setCaption(caption).setDescription(description).addElements(parametersDescriptor).build()).build()).build();
}
Also used : IModelTranslationMap(de.metas.i18n.IModelTranslationMap) I_AD_Process(org.compiere.model.I_AD_Process) IMsgBL(de.metas.i18n.IMsgBL) ITranslatableString(de.metas.i18n.ITranslatableString) ProcessId(de.metas.ui.web.process.ProcessId) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) IADProcessDAO(de.metas.process.IADProcessDAO)

Example 18 with DocumentEntityDescriptor

use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor in project metasfresh-webui-api by metasfresh.

the class HUEditorViewFactoryTemplate method createFilterDescriptorsProvider.

@OverridingMethodsMustInvokeSuper
protected DocumentFilterDescriptorsProvider createFilterDescriptorsProvider() {
    final DocumentEntityDescriptor huEntityDescriptor = getHUEntityDescriptor();
    final Collection<DocumentFilterDescriptor> huStandardFilters = huEntityDescriptor.getFilterDescriptors().getAll();
    return ImmutableDocumentFilterDescriptorsProvider.builder().addDescriptors(huStandardFilters).addDescriptor(HUBarcodeSqlDocumentFilterConverter.createDocumentFilterDescriptor()).build();
}
Also used : DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) DocumentFilterDescriptor(de.metas.ui.web.document.filter.DocumentFilterDescriptor) OverridingMethodsMustInvokeSuper(javax.annotation.OverridingMethodsMustInvokeSuper)

Example 19 with DocumentEntityDescriptor

use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor in project metasfresh-webui-api by metasfresh.

the class SqlDocumentsRepository method retriveDocuments.

public OrderedDocumentsList retriveDocuments(final DocumentQuery query, final int limit, final IDocumentChangesCollector changesCollector) {
    logger.debug("Retrieving records: query={}, limit={}", query, limit);
    final DocumentEntityDescriptor entityDescriptor = query.getEntityDescriptor();
    assertThisRepository(entityDescriptor);
    final Document parentDocument = query.getParentDocument();
    final Function<DocumentId, Document> existingDocumentsSupplier = query.getExistingDocumentsSupplier();
    final List<Object> sqlParams = new ArrayList<>();
    final SqlDocumentQueryBuilder sqlBuilder = SqlDocumentQueryBuilder.of(query);
    final String sql = sqlBuilder.getSql(sqlParams);
    final String adLanguage = sqlBuilder.getAD_Language();
    logger.debug("Retrieving records: SQL={} -- {}", sql, sqlParams);
    final int loadLimitWarn = this.loadLimitWarn;
    final int loadLimitMax = this.loadLimitMax;
    int maxRowsToFetch = limit;
    if (maxRowsToFetch <= 0) {
        maxRowsToFetch = loadLimitMax;
    }
    final OrderedDocumentsList documentsCollector = OrderedDocumentsList.newEmpty(query.getOrderBys());
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, ITrx.TRXNAME_ThreadInherited);
        if (maxRowsToFetch > 0) {
            pstmt.setMaxRows(maxRowsToFetch);
        }
        DB.setParameters(pstmt, sqlParams);
        rs = pstmt.executeQuery();
        boolean loadLimitWarnReported = false;
        while (rs.next()) {
            final ResultSetDocumentValuesSupplier documentValuesSupplier = new ResultSetDocumentValuesSupplier(entityDescriptor, adLanguage, rs);
            Document document = null;
            if (existingDocumentsSupplier != null) {
                final DocumentId documentId = documentValuesSupplier.getDocumentId();
                document = existingDocumentsSupplier.apply(documentId);
            }
            if (document == null) {
                document = Document.builder(entityDescriptor).setParentDocument(parentDocument).setChangesCollector(changesCollector).initializeAsExistingRecord(documentValuesSupplier);
            }
            documentsCollector.addDocument(document);
            final int loadCount = documentsCollector.size();
            // Stop if we reached the limit
            if (limit > 0 && loadCount >= limit) {
                break;
            }
            // Stop if we reached the MAXIMUM limit
            if (loadLimitMax > 0 && loadCount >= loadLimitMax) {
                logger.warn("Reached load count MAXIMUM level. Stop loading. \n SQL: {} \n SQL Params: {} \n loadCount: {}", sql, sqlParams, loadCount);
                break;
            }
            // WARN if we reached the Warning limit
            if (!loadLimitWarnReported && loadLimitWarn > 0 && loadCount >= loadLimitWarn) {
                logger.warn("Reached load count Warning level. Continue loading. \n SQL: {} \n SQL Params: {} \n loadCount: {}", sql, sqlParams, loadCount);
                loadLimitWarnReported = true;
            }
        }
    } catch (final SQLException e) {
        throw new DBException(e, sql, sqlParams);
    } finally {
        DB.close(rs, pstmt);
    }
    logger.debug("Retrieved {} records.", documentsCollector.size());
    return documentsCollector;
}
Also used : DBException(org.adempiere.exceptions.DBException) SQLException(java.sql.SQLException) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) OrderedDocumentsList(de.metas.ui.web.window.model.OrderedDocumentsList) Document(de.metas.ui.web.window.model.Document) ResultSet(java.sql.ResultSet) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 20 with DocumentEntityDescriptor

use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor in project metasfresh-webui-api by metasfresh.

the class SqlDocumentsRepository method retrieveLastLineNo.

@Override
public int retrieveLastLineNo(final DocumentQuery query) {
    logger.debug("Retrieving last LineNo: query={}", query);
    final DocumentEntityDescriptor entityDescriptor = query.getEntityDescriptor();
    assertThisRepository(entityDescriptor);
    final List<Object> sqlParams = new ArrayList<>();
    final SqlDocumentQueryBuilder sqlBuilder = SqlDocumentQueryBuilder.of(query);
    final String sql = sqlBuilder.getSqlMaxLineNo(sqlParams);
    return DB.getSQLValueEx(ITrx.TRXNAME_ThreadInherited, sql, sqlParams);
}
Also used : ArrayList(java.util.ArrayList) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Aggregations

DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)33 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)9 WindowId (de.metas.ui.web.window.datatypes.WindowId)8 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)7 ArrayList (java.util.ArrayList)5 NonNull (lombok.NonNull)5 AdempiereException (org.adempiere.exceptions.AdempiereException)5 Services (org.adempiere.util.Services)5 ImmutableList (com.google.common.collect.ImmutableList)4 IMsgBL (de.metas.i18n.IMsgBL)4 ProcessId (de.metas.ui.web.process.ProcessId)4 QuickInputLayoutDescriptor (de.metas.ui.web.quickinput.QuickInputLayoutDescriptor)4 ViewId (de.metas.ui.web.view.ViewId)4 SqlDocumentEntityDataBindingDescriptor (de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor)4 Document (de.metas.ui.web.window.model.Document)4 List (java.util.List)4 Env (org.compiere.util.Env)4 ITranslatableString (de.metas.i18n.ITranslatableString)3 SourceDocument (de.metas.letters.model.MADBoilerPlate.SourceDocument)3 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)3