use of org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState in project molgenis by molgenis.
the class MappingServiceController method getFirstAttributeMappingInfo.
/**
* Find the firstattributeMapping skip the the algorithmStates that are given in the {@link AttributeMapping} to an
* {@link EntityMapping}.
*
* @param mappingProjectId ID of the mapping project
* @param target name of the target entity
* @param skipAlgorithmStates the mapping algorithm states that should skip
*/
@PostMapping("/firstattributemapping")
@ResponseBody
public FirstAttributeMappingInfo getFirstAttributeMappingInfo(@RequestParam() String mappingProjectId, @RequestParam() String target, @RequestParam(value = "skipAlgorithmStates[]") List<AlgorithmState> skipAlgorithmStates, Model model) {
MappingProject mappingProject = mappingService.getMappingProject(mappingProjectId);
if (hasWritePermission(mappingProject)) {
MappingTarget mappingTarget = mappingProject.getMappingTarget(target);
List<String> sourceNames = mappingTarget.getEntityMappings().stream().map(i -> i.getSourceEntityType().getId()).collect(Collectors.toList());
EntityType targetEntityMeta = mappingTarget.getTarget();
for (Attribute attribute : targetEntityMeta.getAtomicAttributes()) {
if (attribute.equals(targetEntityMeta.getIdAttribute())) {
continue;
}
for (String source : sourceNames) {
EntityMapping entityMapping = mappingTarget.getMappingForSource(source);
AttributeMapping attributeMapping = entityMapping.getAttributeMapping(attribute.getName());
if (null != attributeMapping) {
AlgorithmState algorithmState = attributeMapping.getAlgorithmState();
if (null != skipAlgorithmStates) {
if (skipAlgorithmStates.contains(algorithmState)) {
continue;
}
}
}
return FirstAttributeMappingInfo.create(mappingProjectId, target, source, attribute.getName());
}
}
}
return null;
}
use of org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState in project molgenis by molgenis.
the class AlgorithmGeneratorServiceImpl method generate.
@Override
public GeneratedAlgorithm generate(Attribute targetAttribute, Map<Attribute, ExplainedAttribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) {
String algorithm = StringUtils.EMPTY;
AlgorithmState algorithmState = null;
Set<Attribute> mappedSourceAttributes = null;
if (sourceAttributes.size() > 0) {
AlgorithmTemplate algorithmTemplate = algorithmTemplateService.find(sourceAttributes).findFirst().orElse(null);
if (algorithmTemplate != null) {
algorithm = algorithmTemplate.render();
mappedSourceAttributes = AlgorithmGeneratorHelper.extractSourceAttributesFromAlgorithm(algorithm, sourceEntityType);
algorithm = convertUnitForTemplateAlgorithm(algorithm, targetAttribute, targetEntityType, mappedSourceAttributes, sourceEntityType);
algorithmState = GENERATED_HIGH;
} else {
Entry<Attribute, ExplainedAttribute> firstEntry = sourceAttributes.entrySet().stream().findFirst().get();
Attribute sourceAttribute = firstEntry.getKey();
algorithm = generate(targetAttribute, Arrays.asList(sourceAttribute), targetEntityType, sourceEntityType);
mappedSourceAttributes = AlgorithmGeneratorHelper.extractSourceAttributesFromAlgorithm(algorithm, sourceEntityType);
algorithmState = firstEntry.getValue().isHighQuality() ? GENERATED_HIGH : GENERATED_LOW;
}
}
return GeneratedAlgorithm.create(algorithm, mappedSourceAttributes, algorithmState);
}
Aggregations