use of org.molgenis.data.meta.model.Attribute 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.data.meta.model.Attribute in project molgenis by molgenis.
the class AttributeMappingRepositoryImpl method toAttributeMappingEntity.
private Entity toAttributeMappingEntity(AttributeMapping attributeMapping) {
Entity attributeMappingEntity = new DynamicEntity(attributeMappingMetaData);
attributeMappingEntity.set(IDENTIFIER, attributeMapping.getIdentifier());
attributeMappingEntity.set(TARGET_ATTRIBUTE, attributeMapping.getTargetAttributeName());
attributeMappingEntity.set(ALGORITHM, attributeMapping.getAlgorithm());
attributeMappingEntity.set(SOURCE_ATTRIBUTES, attributeMapping.getSourceAttributes().stream().map(Attribute::getName).collect(Collectors.joining(",")));
attributeMappingEntity.set(ALGORITHM_STATE, attributeMapping.getAlgorithmState().toString());
return attributeMappingEntity;
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class AttributeMappingRepositoryImpl method toAttributeMapping.
private AttributeMapping toAttributeMapping(Entity attributeMappingEntity, EntityType sourceEntityType, EntityType targetEntityType) {
String identifier = attributeMappingEntity.getString(IDENTIFIER);
String targetAttributeName = attributeMappingEntity.getString(TARGET_ATTRIBUTE);
Attribute targetAttribute = targetEntityType.getAttribute(targetAttributeName);
String algorithm = attributeMappingEntity.getString(ALGORITHM);
String algorithmState = attributeMappingEntity.getString(ALGORITHM_STATE);
List<Attribute> sourceAttributes = retrieveAttributesFromAlgorithm(algorithm, sourceEntityType);
return new AttributeMapping(identifier, targetAttributeName, targetAttribute, algorithm, sourceAttributes, algorithmState);
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class AttributeMappingRepositoryImpl method retrieveAttributesFromAlgorithm.
@Override
public List<Attribute> retrieveAttributesFromAlgorithm(String algorithm, EntityType sourceEntityType) {
List<Attribute> sourceAttributes = Lists.newArrayList();
Pattern pattern = Pattern.compile("\\$\\('([^']+)'\\)");
Matcher matcher = pattern.matcher(algorithm);
while (matcher.find()) {
String sourceAttribute = matcher.group(1).split("\\.")[0];
Attribute attribute = sourceEntityType.getAttribute(sourceAttribute);
if (!sourceAttributes.contains(attribute)) {
sourceAttributes.add(attribute);
}
}
return sourceAttributes;
}
use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.
the class OneToManyCategoryAlgorithmGeneratorTest method createEntityType.
private EntityType createEntityType(String entityTypeId) {
EntityType sourceRefEntityType = entityTypeFactory.create(entityTypeId);
Attribute sourceCodeAttribute = attrMetaFactory.create().setName("code").setDataType(INT);
Attribute sourceLabelAttribute = attrMetaFactory.create().setName("label");
sourceRefEntityType.addAttribute(sourceCodeAttribute, ROLE_ID);
sourceRefEntityType.addAttribute(sourceLabelAttribute, ROLE_LABEL);
return sourceRefEntityType;
}
Aggregations