use of org.hisp.dhis.node.NodeTransformer in project dhis2-core by dhis2.
the class DefaultFieldFilterService method init.
@PostConstruct
public void init() {
ImmutableMap.Builder<String, Preset> presetBuilder = ImmutableMap.builder();
for (Preset preset : Preset.values()) {
presetBuilder.put(preset.getName(), preset);
}
presets = presetBuilder.build();
ImmutableMap.Builder<String, NodeTransformer> transformerBuilder = ImmutableMap.builder();
for (NodeTransformer transformer : nodeTransformers) {
transformerBuilder.put(transformer.name(), transformer);
}
transformers = transformerBuilder.build();
baseIdentifiableIdProperty = schemaService.getDynamicSchema(BaseIdentifiableObject.class).getProperty("id");
}
use of org.hisp.dhis.node.NodeTransformer in project dhis2-core by dhis2.
the class DefaultFieldFilterService method updateFields.
private void updateFields(FieldMap fieldMap, Class<?> klass, boolean expandOnly) {
if (fieldMap.isEmpty()) {
return;
}
Schema schema = schemaService.getDynamicSchema(klass);
List<String> cleanupFields = Lists.newArrayList();
for (String fieldKey : Sets.newHashSet(fieldMap.keySet())) {
Collection<Property> properties = schema.getReadableProperties().values();
if ("*".equals(fieldKey)) {
properties.stream().filter(property -> !fieldMap.containsKey(property.key())).forEach(property -> fieldMap.put(property.key(), new FieldMap()));
cleanupFields.add(fieldKey);
} else if (":persisted".equals(fieldKey)) {
properties.stream().filter(property -> !fieldMap.containsKey(property.key()) && property.isPersisted()).forEach(property -> fieldMap.put(property.key(), new FieldMap()));
cleanupFields.add(fieldKey);
} else if (":owner".equals(fieldKey)) {
properties.stream().filter(property -> !fieldMap.containsKey(property.key()) && property.isPersisted() && property.isOwner()).forEach(property -> fieldMap.put(property.key(), new FieldMap()));
cleanupFields.add(fieldKey);
} else if (fieldKey.startsWith(":")) {
Preset preset = presets.get(fieldKey.substring(1));
if (preset == null) {
continue;
}
List<String> fields = preset.getFields();
fields.stream().filter(field -> !fieldMap.containsKey(field)).forEach(field -> fieldMap.put(field, new FieldMap()));
cleanupFields.add(fieldKey);
} else if (fieldKey.startsWith("!") && !expandOnly) {
cleanupFields.add(fieldKey);
} else if (fieldKey.contains("::") || fieldKey.contains("|") || fieldKey.contains("~")) {
Matcher matcher = FIELD_PATTERN.matcher(fieldKey);
if (!matcher.find()) {
continue;
}
String fieldName = matcher.group("field");
FieldMap value = new FieldMap();
value.putAll(fieldMap.get(fieldKey));
matcher = TRANSFORMER_PATTERN.matcher(fieldKey);
while (matcher.find()) {
String nameMatch = matcher.group("name");
String argsMatch = matcher.group("args");
if (transformers.containsKey(nameMatch)) {
NodeTransformer transformer = transformers.get(nameMatch);
List<String> args = argsMatch == null ? new ArrayList<>() : Lists.newArrayList(argsMatch.split(";"));
value.getPipeline().addTransformer(transformer, args);
}
}
fieldMap.put(fieldName, value);
cleanupFields.add(fieldKey);
}
}
for (String field : cleanupFields) {
fieldMap.remove(field);
if (!expandOnly) {
fieldMap.remove(field.substring(1));
}
}
}
use of org.hisp.dhis.node.NodeTransformer in project dhis2-core by dhis2.
the class DefaultFieldFilterServiceTest method setUp.
@BeforeEach
public void setUp() {
final Set<NodeTransformer> nodeTransformers = new HashSet<>();
nodeTransformers.add(new PluckNodeTransformer());
final SchemaService schemaService = new DefaultSchemaService(new DefaultPropertyIntrospectorService(new JacksonPropertyIntrospector()), sessionFactory);
CacheProvider cacheProvider = mock(CacheProvider.class);
when(cacheProvider.createPropertyTransformerCache()).thenReturn(new NoOpCache<>());
service = new DefaultFieldFilterService(new DefaultFieldParser(), schemaService, aclService, currentUserService, attributeService, cacheProvider, userGroupService, userService, nodeTransformers);
service.init();
}
Aggregations