net.n2oapp.framework.config.util.N2oSubModelsProcessor Maven / Gradle / Ivy
The newest version!
package net.n2oapp.framework.config.util;
import net.n2oapp.criteria.api.CollectionPage;
import net.n2oapp.criteria.dataset.DataSet;
import net.n2oapp.criteria.filters.FilterType;
import net.n2oapp.framework.api.MetadataEnvironment;
import net.n2oapp.framework.api.StringUtils;
import net.n2oapp.framework.api.criteria.N2oPreparedCriteria;
import net.n2oapp.framework.api.data.DomainProcessor;
import net.n2oapp.framework.api.data.QueryProcessor;
import net.n2oapp.framework.api.exception.N2oException;
import net.n2oapp.framework.api.metadata.aware.MetadataEnvironmentAware;
import net.n2oapp.framework.api.metadata.global.dao.query.AbstractField;
import net.n2oapp.framework.api.metadata.global.dao.query.field.QuerySimpleField;
import net.n2oapp.framework.api.metadata.local.CompiledQuery;
import net.n2oapp.framework.api.metadata.local.view.widget.util.SubModelQuery;
import net.n2oapp.framework.api.util.SubModelsProcessor;
import net.n2oapp.framework.config.compile.pipeline.N2oPipelineSupport;
import net.n2oapp.framework.config.metadata.compile.context.QueryContext;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Процессор для вычисления вложенных справочных значений свойств модели.
* Использовать только для вычислений под конкретного пользователя!
*/
public class N2oSubModelsProcessor implements SubModelsProcessor, MetadataEnvironmentAware {
private QueryProcessor queryProcessor;
private MetadataEnvironment environment;
private DomainProcessor domainProcessor;
public N2oSubModelsProcessor(QueryProcessor queryProcessor, DomainProcessor domainProcessor) {
this.queryProcessor = queryProcessor;
this.domainProcessor = domainProcessor;
}
@Override
public void executeSubModels(List subQueries, DataSet dataSet) {
if (dataSet.isEmpty() || subQueries == null) return;
for (SubModelQuery subModelQuery : subQueries) {
CompiledQuery subQuery = subModelQuery.getQueryId() == null
? null
: environment.getReadCompileBindTerminalPipelineFunction()
.apply(new N2oPipelineSupport(environment))
.get(new QueryContext(subModelQuery.getQueryId()), dataSet);
executeSubModel(subModelQuery, dataSet, subQuery);
}
}
@Override
public CollectionPage getQueryResult(String queryId, DataSet params) {
CompiledQuery query = environment.getReadCompileBindTerminalPipelineFunction()
.apply(new N2oPipelineSupport(environment))
.get(new QueryContext(queryId), params);
return queryProcessor.executeOneSizeQuery(query, new N2oPreparedCriteria());
}
private void executeSubModel(SubModelQuery subModelQuery, Map dataSet, CompiledQuery subQuery) {
String valueFieldId = subModelQuery.getValueFieldId() != null ? subModelQuery.getValueFieldId() : "id";
String labelFieldId = subModelQuery.getLabelFieldId() != null ? subModelQuery.getLabelFieldId() : "name";
List