use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class MappingTargetRepositoryImplTest method beforeMethod.
@BeforeMethod
public void beforeMethod() {
// POJOs
EntityType sourceEntityType = entityTypeFactory.create("source");
targetEntityType = entityTypeFactory.create("target");
Attribute targetAttribute = attrMetaFactory.create().setName("targetAttribute");
targetEntityType.addAttribute(targetAttribute);
entityMappings = singletonList(new EntityMapping("entityMappingID", sourceEntityType, targetEntityType, emptyList()));
mappingTargets = singletonList(new MappingTarget("mappingTargetID", targetEntityType, entityMappings));
// Entities
Entity entityMappingEntity = new DynamicEntity(entityMappingMeta);
entityMappingEntity.set(EntityMappingMetaData.IDENTIFIER, "entityMappingID");
entityMappingEntity.set(EntityMappingMetaData.SOURCE_ENTITY_TYPE, "source");
entityMappingEntity.set(EntityMappingMetaData.TARGET_ENTITY_TYPE, "target");
entityMappingEntity.set(EntityMappingMetaData.ATTRIBUTE_MAPPINGS, emptyList());
Entity mappingTargetEntity = new DynamicEntity(mappingTargetMeta);
mappingTargetEntity.set(IDENTIFIER, "mappingTargetID");
mappingTargetEntity.set(TARGET, "target");
entityMappingEntities = singletonList(entityMappingEntity);
mappingTargetEntity.set(ENTITY_MAPPINGS, entityMappingEntities);
mappingTargetEntities = singletonList(mappingTargetEntity);
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class AlgorithmServiceImplTest method testApplyConvertException.
private void testApplyConvertException(String algorithmResult, AttributeType attributeType) {
AttributeMapping attributeMapping = mock(AttributeMapping.class);
String algorithm = "algorithm";
when(attributeMapping.getAlgorithm()).thenReturn(algorithm);
Attribute targetAttribute = when(mock(Attribute.class).getDataType()).thenReturn(attributeType).getMock();
when(attributeMapping.getTargetAttribute()).thenReturn(targetAttribute);
Entity sourceEntity = mock(Entity.class);
when(jsMagmaScriptEvaluator.eval(algorithm, sourceEntity, 3)).thenReturn(algorithmResult);
algorithmServiceImpl.apply(attributeMapping, sourceEntity, null);
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class MappingServiceController method getTagsForAttribute.
private Map<String, List<OntologyTerm>> getTagsForAttribute(String target, MappingProject project) {
Map<String, List<OntologyTerm>> attributeTagMap = new HashMap<>();
for (Attribute amd : project.getMappingTarget(target).getTarget().getAtomicAttributes()) {
EntityType targetMetaData = RunAsSystemAspect.runAsSystem(() -> dataService.getEntityType(target));
attributeTagMap.put(amd.getName(), newArrayList(ontologyTagService.getTagsForAttribute(targetMetaData, amd).values()));
}
return attributeTagMap;
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class MappingServiceController method addEntityMapping.
/**
* Adds a new {@link EntityMapping} to an existing {@link MappingTarget}
*
* @param target the name of the {@link MappingTarget}'s entity to add a source entity to
* @param source the name of the source entity of the newly added {@link EntityMapping}
* @param mappingProjectId the ID of the {@link MappingTarget}'s {@link MappingProject}
* @return redirect URL for the mapping project
*/
@PostMapping("/addEntityMapping")
public String addEntityMapping(@RequestParam String mappingProjectId, String target, String source) {
EntityType sourceEntityType = dataService.getEntityType(source);
EntityType targetEntityType = dataService.getEntityType(target);
Iterable<Attribute> attributes = targetEntityType.getAtomicAttributes();
MappingProject project = mappingService.getMappingProject(mappingProjectId);
if (hasWritePermission(project)) {
EntityMapping mapping = project.getMappingTarget(target).addSource(sourceEntityType);
mappingService.updateMappingProject(project);
autoGenerateAlgorithms(mapping, sourceEntityType, targetEntityType, attributes, project);
}
return "redirect:" + getMappingServiceMenuUrl() + "/mappingproject/" + mappingProjectId;
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class MappingServiceController method attributeMappingFeedback.
@PostMapping("/attributemappingfeedback")
public String attributeMappingFeedback(@RequestParam() String mappingProjectId, @RequestParam() String target, @RequestParam() String source, @RequestParam() String targetAttribute, @RequestParam() String algorithm, Model model) {
MappingProject project = mappingService.getMappingProject(mappingProjectId);
MappingTarget mappingTarget = project.getMappingTarget(target);
EntityMapping entityMapping = mappingTarget.getMappingForSource(source);
AttributeMapping algorithmTest;
if (entityMapping.getAttributeMapping(targetAttribute) == null) {
algorithmTest = entityMapping.addAttributeMapping(targetAttribute);
algorithmTest.setAlgorithm(algorithm);
} else {
algorithmTest = entityMapping.getAttributeMapping(targetAttribute);
algorithmTest.setAlgorithm(algorithm);
}
try {
Collection<String> sourceAttributeNames = algorithmService.getSourceAttributeNames(algorithm);
if (!sourceAttributeNames.isEmpty()) {
List<Attribute> sourceAttributes = sourceAttributeNames.stream().map(attributeName -> {
EntityType sourceEntityType = entityMapping.getSourceEntityType();
return sourceEntityType.getAttribute(attributeName);
}).filter(Objects::nonNull).collect(Collectors.toList());
model.addAttribute("sourceAttributes", sourceAttributes);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
model.addAttribute("mappingProjectId", mappingProjectId);
model.addAttribute("target", target);
model.addAttribute("source", source);
model.addAttribute("targetAttribute", dataService.getEntityType(target).getAttribute(targetAttribute));
FluentIterable<Entity> sourceEntities = FluentIterable.from(() -> dataService.findAll(source).iterator()).limit(10);
ImmutableList<AlgorithmResult> algorithmResults = sourceEntities.transform(sourceEntity -> {
try {
return AlgorithmResult.createSuccess(algorithmService.apply(algorithmTest, sourceEntity, sourceEntity.getEntityType()), sourceEntity);
} catch (Exception e) {
return AlgorithmResult.createFailure(e, sourceEntity);
}
}).toList();
model.addAttribute("feedbackRows", algorithmResults);
long missing = algorithmResults.stream().filter(r -> r.isSuccess() && r.getValue() == null).count();
long success = algorithmResults.stream().filter(AlgorithmResult::isSuccess).count() - missing;
long error = algorithmResults.size() - success - missing;
model.addAttribute("success", success);
model.addAttribute("missing", missing);
model.addAttribute("error", error);
model.addAttribute("dataexplorerUri", menuReaderService.getMenu().findMenuItemPath(DataExplorerController.ID));
return VIEW_ATTRIBUTE_MAPPING_FEEDBACK;
}
Aggregations