SUPPORT-8811: container value loader multiple parameters support
This commit is contained in:
parent
528f1f58e0
commit
d16ee0ca0c
2 changed files with 191 additions and 8 deletions
|
|
@ -0,0 +1,126 @@
|
||||||
|
package service.loading;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import component.field.dataconvert.DataConverter;
|
||||||
|
import component.field.dataconvert.DataConverterProvider;
|
||||||
|
import component.field.loading.FieldValueByContainer;
|
||||||
|
import component.field.loading.LoadType;
|
||||||
|
import model.FieldData;
|
||||||
|
import service.loading.ContainerValueLoaderService;
|
||||||
|
|
||||||
|
import ru.cg.webbpm.modules.database.api.bean.TableRow;
|
||||||
|
import ru.cg.webbpm.modules.database.api.dao.LoadDao;
|
||||||
|
import ru.cg.webbpm.modules.database.api.dao.option.LoadOptions;
|
||||||
|
import ru.cg.webbpm.modules.database.bean.annotation.LocalGraphSource;
|
||||||
|
import ru.cg.webbpm.modules.database.bean.entity_graph.EntityColumn;
|
||||||
|
import ru.cg.webbpm.modules.database.bean.filter.EntityFilter;
|
||||||
|
import ru.cg.webbpm.modules.database.bean.filter.FilterOperation;
|
||||||
|
import ru.cg.webbpm.modules.webkit.beans.Behavior;
|
||||||
|
import ru.cg.webbpm.modules.webkit.beans.PageObjectNotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Eduard Tihomirov
|
||||||
|
*/
|
||||||
|
public class ContainerValueLoaderServiceImpl extends Behavior
|
||||||
|
implements ContainerValueLoaderService {
|
||||||
|
|
||||||
|
public LoadDao loadDao;
|
||||||
|
@LocalGraphSource(sourceFieldName = "loadDao")
|
||||||
|
public EntityColumn[] entityColumns;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<FieldData> loadOnEventData(Object[] params, List<String> guids) {
|
||||||
|
if (params.length > 1 && (entityColumns == null || params.length != entityColumns.length)) {
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"Can't support multiple params without matching entity columns");
|
||||||
|
}
|
||||||
|
return new ArrayList<>(loadValuesByParamAndColumn(params, guids));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FieldData> loadValuesByParamAndColumn(Object[] params, List<String> guids) {
|
||||||
|
Map<String, FieldValueByContainer<?>> byColumnMapping = getScriptsMapping(guids,
|
||||||
|
fieldDefaultValue -> fieldDefaultValue.loadType == LoadType.BY_COLUMN
|
||||||
|
);
|
||||||
|
if (byColumnMapping.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("No control data to load");
|
||||||
|
}
|
||||||
|
Map<String, EntityColumn> idToColumnMapping = byColumnMapping.entrySet().stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
Map.Entry::getKey,
|
||||||
|
entry -> entry.getValue().getValueColumn()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return loadData(params, idToColumnMapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FieldData> loadData(Object[] params, Map<String, EntityColumn> idToColumnMapping) {
|
||||||
|
|
||||||
|
if (loadDao == null || params == null || params.length == 0) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<EntityColumn> columns = new HashSet<>(idToColumnMapping.values());
|
||||||
|
Map<EntityColumn, Object> columnToDataMapping;
|
||||||
|
if (entityColumns == null || entityColumns.length == 0) {
|
||||||
|
columnToDataMapping = loadDao.loadByPK(
|
||||||
|
columns,
|
||||||
|
params[0].toString()
|
||||||
|
).getColumnToDataMap();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LoadOptions loadOptions = new LoadOptions();
|
||||||
|
List<EntityFilter> entityFilters = new ArrayList<>();
|
||||||
|
for(int i = 0; i < entityColumns.length; i++) {
|
||||||
|
entityFilters.add(new EntityFilter(params[i], FilterOperation.EQUAL, entityColumns[i]));
|
||||||
|
}
|
||||||
|
loadOptions.setEntityFilters(entityFilters);
|
||||||
|
List<TableRow> tableRows = loadDao.load(columns, loadOptions);
|
||||||
|
columnToDataMapping = tableRows.size() > 0
|
||||||
|
? tableRows.get(0).getColumnToDataMap()
|
||||||
|
: Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
return idToColumnMapping.entrySet().stream()
|
||||||
|
.map(entry -> {
|
||||||
|
DataConverter dataConverter = DataConverterProvider.getDataConverter(
|
||||||
|
entry.getValue().getType());
|
||||||
|
Object convertedValue = dataConverter.convertValueForLoad(
|
||||||
|
columnToDataMapping.get(entry.getValue()));
|
||||||
|
return new FieldData(entry.getKey(), convertedValue);
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, FieldValueByContainer<?>> getScriptsMapping(List<String> guids,
|
||||||
|
final Predicate<FieldValueByContainer<?>> predicate) {
|
||||||
|
return guids.stream()
|
||||||
|
.map(guid -> new HashMap.SimpleEntry<>(guid, getFieldOnEventValueScript(guid)))
|
||||||
|
.filter(entry -> entry.getValue() != null)
|
||||||
|
.filter(entry -> predicate.test(entry.getValue()))
|
||||||
|
.collect(Collectors.toMap(HashMap.SimpleEntry::getKey, HashMap.SimpleEntry::getValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
private FieldValueByContainer<?> getFieldOnEventValueScript(String guid) {
|
||||||
|
try {
|
||||||
|
return getScriptInObject(guid, FieldValueByContainer.class);
|
||||||
|
}
|
||||||
|
catch (PageObjectNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
super.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -3566,7 +3566,6 @@
|
||||||
<componentRootId>18ecb7c6-2148-4eb0-a18c-97af5e73cac7</componentRootId>
|
<componentRootId>18ecb7c6-2148-4eb0-a18c-97af5e73cac7</componentRootId>
|
||||||
<name>ГК Второй ряд</name>
|
<name>ГК Второй ряд</name>
|
||||||
<container>true</container>
|
<container>true</container>
|
||||||
<expanded>false</expanded>
|
|
||||||
<childrenReordered>false</childrenReordered>
|
<childrenReordered>false</childrenReordered>
|
||||||
<scripts id="bf098f19-480e-44e4-9084-aa42955c4d0f">
|
<scripts id="bf098f19-480e-44e4-9084-aa42955c4d0f">
|
||||||
<properties>
|
<properties>
|
||||||
|
|
@ -3680,6 +3679,24 @@
|
||||||
</complex>
|
</complex>
|
||||||
</value>
|
</value>
|
||||||
</item>
|
</item>
|
||||||
|
<item id="d86b1fd6-cef6-4bfd-ab53-59d0a8efba6c" removed="false">
|
||||||
|
<value>
|
||||||
|
<complex>
|
||||||
|
<entry>
|
||||||
|
<key>behavior</key>
|
||||||
|
<value>
|
||||||
|
<simple>{"objectId":"7085eb05-5251-41dd-8484-8d24ee839f76","packageName":"component.field","className":"ComboBox","type":"TS"}</simple>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
<entry>
|
||||||
|
<key>propertyName</key>
|
||||||
|
<value>
|
||||||
|
<simple>"valueChangeEvent"</simple>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</complex>
|
||||||
|
</value>
|
||||||
|
</item>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
|
|
@ -3706,6 +3723,37 @@
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<key>method</key>
|
<key>method</key>
|
||||||
|
<value>
|
||||||
|
<simple>"getBusinessId"</simple>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</complex>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</complex>
|
||||||
|
</value>
|
||||||
|
</item>
|
||||||
|
<item id="be7cdc26-a7e9-4cfd-a2b6-bbdd681c42a3" removed="false">
|
||||||
|
<value>
|
||||||
|
<complex>
|
||||||
|
<entry>
|
||||||
|
<key>objectValue</key>
|
||||||
|
<value>
|
||||||
|
<complex>
|
||||||
|
<entry>
|
||||||
|
<key>argument</key>
|
||||||
|
<value>
|
||||||
|
<simple>null</simple>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
<entry>
|
||||||
|
<key>behavior</key>
|
||||||
|
<value>
|
||||||
|
<simple>{"objectId":"7085eb05-5251-41dd-8484-8d24ee839f76","packageName":"component.field","className":"ComboBox","type":"TS"}</simple>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
<entry>
|
||||||
|
<key>method</key>
|
||||||
<value>
|
<value>
|
||||||
<simple>"getBusinessId"</simple>
|
<simple>"getBusinessId"</simple>
|
||||||
</value>
|
</value>
|
||||||
|
|
@ -3727,6 +3775,21 @@
|
||||||
<key>containerValueLoaderService</key>
|
<key>containerValueLoaderService</key>
|
||||||
<value>
|
<value>
|
||||||
<complex>
|
<complex>
|
||||||
|
<entry>
|
||||||
|
<key>entityColumns</key>
|
||||||
|
<value>
|
||||||
|
<item id="74a8848c-dbae-493b-ad40-23af7a5c8328" removed="false">
|
||||||
|
<value>
|
||||||
|
<simple>{"schema":"summonses_list","table":"formed_summonses","entity":"formed_summonses","name":"summonses_reason_id"}</simple>
|
||||||
|
</value>
|
||||||
|
</item>
|
||||||
|
<item id="0987c26f-e5e3-4f9f-b7da-3e22c77eca0d" removed="false">
|
||||||
|
<value>
|
||||||
|
<simple>{"schema":"metrics","table":"recruitment","entity":"recruitment","name":"idm_id"}</simple>
|
||||||
|
</value>
|
||||||
|
</item>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
<key>loadDao</key>
|
<key>loadDao</key>
|
||||||
<value>
|
<value>
|
||||||
|
|
@ -3744,15 +3807,9 @@
|
||||||
</implRef>
|
</implRef>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
|
||||||
<key>replacePkColumn</key>
|
|
||||||
<value>
|
|
||||||
<simple>{"schema":"summonses_list","table":"formed_summonses","entity":"formed_summonses","name":"summonses_reason_id"}</simple>
|
|
||||||
</value>
|
|
||||||
</entry>
|
|
||||||
</complex>
|
</complex>
|
||||||
<implRef type="JAVA">
|
<implRef type="JAVA">
|
||||||
<className>ContainerByPkValueLoaderServiceImpl</className>
|
<className>ContainerValueLoaderServiceImpl</className>
|
||||||
<packageName>service.loading</packageName>
|
<packageName>service.loading</packageName>
|
||||||
</implRef>
|
</implRef>
|
||||||
</value>
|
</value>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue