use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class MetaDataServiceIT method testUpdateEntityType.
@WithMockUser(username = USERNAME)
@Test
public void testUpdateEntityType() {
EntityType updatedEntityType = metaDataService.getEntityType(ENTITY_TYPE_ID);
updatedEntityType.getAttribute(ATTR_STRING).setDataType(ENUM).setEnumOptions(asList("string0", "string1"));
updatedEntityType.getAttribute(ATTR_BOOL).setDataType(STRING);
updatedEntityType.getAttribute(ATTR_CATEGORICAL).setDataType(LONG).setRefEntity(null);
updatedEntityType.getAttribute(ATTR_CATEGORICAL_MREF).setDataType(MREF);
updatedEntityType.getAttribute(ATTR_DATE).setDataType(DATE_TIME);
updatedEntityType.getAttribute(ATTR_DATETIME).setDataType(DATE);
updatedEntityType.getAttribute(ATTR_EMAIL).setDataType(STRING);
updatedEntityType.getAttribute(ATTR_DECIMAL).setDataType(INT);
updatedEntityType.getAttribute(ATTR_HTML).setDataType(TEXT);
updatedEntityType.getAttribute(ATTR_HYPERLINK).setDataType(STRING);
updatedEntityType.getAttribute(ATTR_LONG).setDataType(DECIMAL);
updatedEntityType.getAttribute(ATTR_INT).setDataType(LONG);
updatedEntityType.getAttribute(ATTR_SCRIPT).setDataType(TEXT);
updatedEntityType.getAttribute(ATTR_XREF).setDataType(CATEGORICAL);
updatedEntityType.getAttribute(ATTR_MREF).setDataType(CATEGORICAL_MREF);
updatedEntityType.getAttribute(ATTR_ENUM).setDataType(STRING).setEnumOptions(emptyList());
metaDataService.updateEntityType(updatedEntityType);
Entity expectedEntity = new DynamicEntity(updatedEntityType);
expectedEntity.set(ATTR_ID, "0");
expectedEntity.set(ATTR_STRING, "string1");
expectedEntity.set(ATTR_BOOL, "true");
expectedEntity.set(ATTR_CATEGORICAL, 0L);
expectedEntity.set(ATTR_CATEGORICAL_MREF, singletonList(refEntities.get(0)));
expectedEntity.set(ATTR_DATE, LocalDate.parse("2012-12-21").atStartOfDay(systemDefault()).toInstant());
expectedEntity.set(ATTR_DATETIME, MolgenisDateFormat.parseLocalDate("1985-08-12T06:12:13Z"));
expectedEntity.set(ATTR_EMAIL, "this.is@mail.address");
// before update: 0.123
expectedEntity.set(ATTR_DECIMAL, 0);
expectedEntity.set(ATTR_HTML, null);
expectedEntity.set(ATTR_HYPERLINK, "http://www.molgenis.org");
expectedEntity.set(ATTR_LONG, 0.0);
expectedEntity.set(ATTR_INT, 10L);
expectedEntity.set(ATTR_SCRIPT, "/bin/blaat/script.sh");
expectedEntity.set(ATTR_XREF, refEntities.get(0));
expectedEntity.set(ATTR_MREF, singletonList(refEntities.get(0)));
expectedEntity.set(ATTR_COMPOUND_CHILD_INT, 10);
expectedEntity.set(ATTR_ENUM, "option1");
expectedEntity = new EntityWithComputedAttributes(expectedEntity);
assertTrue(EntityUtils.equals(dataService.findOneById(ENTITY_TYPE_ID, "0"), expectedEntity));
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JobExecutionUpdaterImpl method update.
@Override
public void update(JobExecution jobExecution) {
Entity copy = new DynamicEntity(jobExecution.getEntityType());
copy.set(jobExecution);
executorService.execute(() -> updateInternal(copy));
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class SortaJobProcessor method process.
public void process() {
RunAsSystemAspect.runAsSystem(() -> {
long maxCount = dataService.count(inputRepositoryName, new QueryImpl<>());
progress.status("Matching " + maxCount + " input terms from " + inputRepositoryName + ".\nStoring results in " + resultRepositoryName);
progress.setProgressMax((int) maxCount);
// FIXME get rid of getApplicationContext reference
MatchingTaskContentMetaData matchingTaskContentMetaData = getApplicationContext().getBean(MatchingTaskContentMetaData.class);
// Match input terms with code
List<Entity> entitiesToAdd = newArrayList();
dataService.findAll(inputRepositoryName).forEach(inputRow -> {
Entity resultEntity = new DynamicEntity(matchingTaskContentMetaData) {
@Override
protected void validateValueType(String attrName, Object value) {
// FIXME enable validation by not overriding this method
}
};
resultEntity.set(MatchingTaskContentMetaData.INPUT_TERM, inputRow);
resultEntity.set(MatchingTaskContentMetaData.IDENTIFIER, idGenerator.generateId());
resultEntity.set(MatchingTaskContentMetaData.VALIDATED, false);
entitiesToAdd.add(resultEntity);
Iterable<Entity> ontologyTermEntities = sortaService.findOntologyTermEntities(ontologyIri, inputRow);
if (Iterables.size(ontologyTermEntities) > 0) {
Entity firstMatchedOntologyTerm = Iterables.getFirst(ontologyTermEntities, new DynamicEntity(matchingTaskContentMetaData));
resultEntity.set(MatchingTaskContentMetaData.MATCHED_TERM, firstMatchedOntologyTerm.get(OntologyTermMetaData.ONTOLOGY_TERM_IRI));
resultEntity.set(MatchingTaskContentMetaData.SCORE, firstMatchedOntologyTerm.get(SCORE));
} else {
resultEntity.set(MatchingTaskContentMetaData.SCORE, 0.0);
}
// Add entity in batch
if (entitiesToAdd.size() >= ADD_BATCH_SIZE) {
dataService.add(resultRepositoryName, entitiesToAdd.stream());
entitiesToAdd.clear();
}
// Increase the number of the progress
counter.incrementAndGet();
// Update the progress only when the progress proceeds the threshold
if (counter.get() % PROGRESS_UPDATE_BATCH_SIZE == 0) {
progress.progress(counter.get(), "Processed " + counter + " input terms.");
}
});
// Add the rest
if (!entitiesToAdd.isEmpty()) {
dataService.add(resultRepositoryName, entitiesToAdd.stream());
}
progress.progress(counter.get(), "Processed " + counter + " input terms.");
progress.setResultUrl(menuReaderService.getMenu().findMenuItemPath(SortaController.ID) + "/result/" + resultRepositoryName);
});
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class SortaServiceImplTest method findOntologyTermEntities.
@Test
public void findOntologyTermEntities() {
Attribute nameAttr = when(mock(Attribute.class).getName()).thenReturn("Name").getMock();
when(nameAttr.getDataType()).thenReturn(STRING);
Attribute omimAttr = when(mock(Attribute.class).getName()).thenReturn("OMIM").getMock();
when(omimAttr.getDataType()).thenReturn(STRING);
EntityType entityType = mock(EntityType.class);
when(entityType.getAtomicAttributes()).thenReturn(asList(nameAttr, omimAttr));
when(entityType.getAttribute("Name")).thenReturn(nameAttr);
when(entityType.getAttribute("OMIM")).thenReturn(omimAttr);
// Test one: match only the name of input with ontology terms
Entity firstInput = new DynamicEntity(entityType);
firstInput.set("Name", "hearing impairment");
Iterable<Entity> ontologyTerms_test1 = sortaServiceImpl.findOntologyTermEntities(ONTOLOGY_IRI, firstInput);
Iterator<Entity> iterator_test1 = ontologyTerms_test1.iterator();
assertEquals(iterator_test1.hasNext(), true);
Entity firstMatch_test1 = iterator_test1.next();
assertEquals(firstMatch_test1.getDouble(COMBINED_SCORE).intValue(), 100);
assertEquals(iterator_test1.hasNext(), true);
Entity secondMatch_test1 = iterator_test1.next();
assertEquals(secondMatch_test1.getDouble(COMBINED_SCORE).intValue(), new Double(85).intValue());
assertEquals(iterator_test1.hasNext(), false);
// Test two: match the database annotation of input with ontology terms
Entity secondInput = new DynamicEntity(entityType);
secondInput.set("Name", "input");
secondInput.set("OMIM", "123456");
Iterable<Entity> ontologyTerms_test2 = sortaServiceImpl.findOntologyTermEntities(ONTOLOGY_IRI, secondInput);
Iterator<Entity> iterator_test2 = ontologyTerms_test2.iterator();
assertEquals(iterator_test2.hasNext(), true);
Entity firstMatch_test2 = iterator_test2.next();
assertEquals(firstMatch_test2.getDouble(COMBINED_SCORE).intValue(), 100);
assertEquals(iterator_test2.hasNext(), false);
// Test three: match only the name of input with ontology terms, since the name contains multiple synonyms
// therefore add up all the scores from synonyms
Entity thirdInput = new DynamicEntity(entityType);
thirdInput.set("Name", "proptosis, protruding eye, Exophthalmos ");
Iterable<Entity> ontologyTerms_test3 = sortaServiceImpl.findOntologyTermEntities(ONTOLOGY_IRI, thirdInput);
Iterator<Entity> iterator_test3 = ontologyTerms_test3.iterator();
assertEquals(iterator_test3.hasNext(), true);
Entity firstMatch_test3 = iterator_test3.next();
assertEquals(firstMatch_test3.getDouble(COMBINED_SCORE).intValue(), 100);
assertEquals(iterator_test3.hasNext(), false);
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class OneToManyCategoryAlgorithmGeneratorTest method init.
@BeforeMethod
public void init() {
DataService dataService = Mockito.mock(DataService.class);
categoryAlgorithmGenerator = new OneToManyCategoryAlgorithmGenerator(dataService);
EntityType targetRefEntityType = entityTypeFactory.create("POTATO_REF");
Attribute targetCodeAttribute = attrMetaFactory.create().setName("code").setDataType(INT);
Attribute targetLabelAttribute = attrMetaFactory.create().setName("label");
targetRefEntityType.addAttribute(targetCodeAttribute, ROLE_ID);
targetRefEntityType.addAttribute(targetLabelAttribute, ROLE_LABEL);
targetAttribute = attrMetaFactory.create().setName("Current Consumption Frequency of Potatoes").setDataType(CATEGORICAL);
targetAttribute.setRefEntity(targetRefEntityType);
Entity targetEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Almost daily + daily"));
Entity targetEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "Several times a week"));
Entity targetEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "About once a week"));
Entity targetEntity4 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "Never + fewer than once a week"));
Entity targetEntity5 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "missing"));
Mockito.when(dataService.findAll(targetRefEntityType.getId())).thenAnswer(invocation -> Stream.of(targetEntity1, targetEntity2, targetEntity3, targetEntity4, targetEntity5));
targetEntityType = entityTypeFactory.create("target");
targetEntityType.addAttribute(targetAttribute);
EntityType sourceRefEntityType = createEntityType("LifeLines_POTATO_REF");
sourceAttribute = attrMetaFactory.create().setName("MESHED_POTATO").setDataType(CATEGORICAL);
sourceAttribute.setLabel("How often did you eat boiled or mashed potatoes (also in stew) in the past month? Baked potatoes are asked later");
sourceAttribute.setRefEntity(sourceRefEntityType);
Entity sourceEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Not this month"));
Entity sourceEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "1 day per month"));
Entity sourceEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "2-3 days per month"));
Entity sourceEntity4 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "1 day per week"));
Entity sourceEntity5 = new DynamicEntity(targetRefEntityType, of("code", 5, "label", "2-3 days per week"));
Entity sourceEntity6 = new DynamicEntity(targetRefEntityType, of("code", 6, "label", "4-5 days per week"));
Entity sourceEntity7 = new DynamicEntity(targetRefEntityType, of("code", 7, "label", "6-7 days per week"));
Mockito.when(dataService.findAll(sourceRefEntityType.getId())).thenAnswer(invocation -> Stream.of(sourceEntity1, sourceEntity2, sourceEntity3, sourceEntity4, sourceEntity5, sourceEntity6, sourceEntity7));
EntityType sourceRefEntityType1 = createEntityType("Mitchelstown_POTATO_REF");
sourceAttribute1 = attrMetaFactory.create().setName("MESHED_POTATO_1").setDataType(CATEGORICAL);
sourceAttribute1.setLabel("How often did you eat boiled or mashed potatoes (also in stew) in the past month? Baked potatoes are asked later");
sourceAttribute1.setRefEntity(sourceRefEntityType1);
Entity sourceEntity8 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "never/less than 1 per month"));
Entity sourceEntity9 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "1-3 per month"));
Entity sourceEntity10 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "once a week"));
Entity sourceEntity11 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "2-4 per week"));
Entity sourceEntity12 = new DynamicEntity(targetRefEntityType, of("code", 5, "label", "5-6 per week"));
Entity sourceEntity13 = new DynamicEntity(targetRefEntityType, of("code", 6, "label", "once a day"));
Entity sourceEntity14 = new DynamicEntity(targetRefEntityType, of("code", 7, "label", "2-3 per day"));
Entity sourceEntity15 = new DynamicEntity(targetRefEntityType, of("code", 8, "label", "4-5 per day"));
Entity sourceEntity16 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "6+ per day"));
Mockito.when(dataService.findAll(sourceRefEntityType1.getId())).thenAnswer(invocation -> Stream.of(sourceEntity8, sourceEntity9, sourceEntity10, sourceEntity11, sourceEntity12, sourceEntity13, sourceEntity14, sourceEntity15, sourceEntity16));
EntityType sourceRefEntityType2 = createEntityType("Mitchelstown_Stroke_REF");
sourceAttribute2 = attrMetaFactory.create().setName("Stroke").setDataType(CATEGORICAL);
sourceAttribute2.setLabel("History of stroke");
sourceAttribute2.setRefEntity(sourceRefEntityType2);
Entity sourceEntity17 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "yes"));
Entity sourceEntity18 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "no"));
Entity sourceEntity19 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "missing"));
Mockito.when(dataService.findAll(sourceRefEntityType2.getId())).thenAnswer(invocation -> Stream.of(sourceEntity17, sourceEntity18, sourceEntity19));
sourceEntityType = entityTypeFactory.create("source");
sourceEntityType.addAttributes(Lists.newArrayList(sourceAttribute, sourceAttribute1, sourceAttribute2));
}
Aggregations