use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class CsvWriterTest method testLabels.
@Test
public void testLabels() throws IOException {
StringWriter strWriter = new StringWriter();
try (CsvWriter csvWriter = new CsvWriter(strWriter)) {
csvWriter.writeAttributes(Arrays.asList("col1", "col2"), Arrays.asList("label1", "label2"));
Entity entity = new DynamicEntity(entityType);
entity.set("col1", "val1");
entity.set("col2", "val2");
csvWriter.add(entity);
assertEquals(strWriter.toString(), "\"label1\",\"label2\"\n\"val1\",\"val2\"\n");
}
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class CsvIterator method get.
private Entity get() {
if (getNext) {
try {
String[] values = csvReader.readNext();
if (values != null && values.length == colNamesMap.size()) {
List<String> valueList = Arrays.asList(values);
for (int i = 0; i < values.length; ++i) {
// subsequent separators indicate
// null
// values instead of empty strings
String value = values[i].isEmpty() ? null : values[i];
values[i] = processCell(value, false);
}
next = new DynamicEntity(entityType);
for (String name : colNamesMap.keySet()) {
next.set(name, valueList.get(colNamesMap.get(name)));
}
} else if (values != null && (values.length > 1 || (values.length == 1 && values[0].length() > 0)) && values.length < colNamesMap.size()) {
throw new MolgenisDataException(format("Number of values (%d) doesn't match the number of headers (%d): [%s]", values.length, colNamesMap.size(), stream(values).collect(joining(","))));
} else {
next = null;
}
getNext = false;
} catch (IOException e) {
throw new MolgenisDataException(format("Exception reading line of csv file [%s]", repositoryName), e);
}
}
return next;
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class SortaController method toDownloadRow.
private Entity toDownloadRow(SortaJobExecution sortaJobExecution, Entity resultEntity, EntityType downloadEntityType) {
NumberFormat format = NumberFormat.getNumberInstance();
format.setMaximumFractionDigits(2);
Entity inputEntity = resultEntity.getEntity(MatchingTaskContentMetaData.INPUT_TERM);
Entity ontologyTermEntity = sortaService.getOntologyTermEntity(resultEntity.getString(MatchingTaskContentMetaData.MATCHED_TERM), sortaJobExecution.getOntologyIri());
Entity row = new DynamicEntity(downloadEntityType);
inputEntity.getAttributeNames().forEach(attributeName -> {
if (!attributeName.equalsIgnoreCase(SortaCsvRepository.ALLOWED_IDENTIFIER)) {
row.set(attributeName, inputEntity.get(attributeName));
}
});
if (ontologyTermEntity != null) {
row.set(OntologyTermMetaData.ONTOLOGY_TERM_NAME, ontologyTermEntity.getString(OntologyTermMetaData.ONTOLOGY_TERM_NAME));
row.set(OntologyTermMetaData.ONTOLOGY_TERM_IRI, ontologyTermEntity.getString(OntologyTermMetaData.ONTOLOGY_TERM_IRI));
}
row.set(MatchingTaskContentMetaData.VALIDATED, resultEntity.getBoolean(MatchingTaskContentMetaData.VALIDATED));
Double score = resultEntity.getDouble(MatchingTaskContentMetaData.SCORE);
if (score != null) {
row.set(MatchingTaskContentMetaData.SCORE, format.format(score));
}
return row;
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class SortaCsvRepository method iterator.
@Override
public Iterator<Entity> iterator() {
final AtomicInteger count = new AtomicInteger(0);
final Iterator<Entity> iterator = csvRepository.iterator();
return new Iterator<Entity>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public Entity next() {
Entity entity = iterator.next();
if (isEmpty(entity.getString(ALLOWED_IDENTIFIER))) {
DynamicEntity dynamicEntity = new DynamicEntity(getEntityType());
dynamicEntity.set(entity);
entity = dynamicEntity;
entity.set(ALLOWED_IDENTIFIER, String.valueOf(count.incrementAndGet()));
}
return entity;
}
};
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class OntologyTermFrequencyServiceImpl method addEntry.
private Entity addEntry(String term, PubMedTFEntity pubMedTFEntity, DataService dataService) {
if (pubMedTFEntity == null)
return null;
// FIXME remove reference to getApplicationContext
TermFrequencyMetaData termFrequencyEntityType = getApplicationContext().getBean(TermFrequencyMetaData.class);
Entity entity = new DynamicEntity(termFrequencyEntityType);
entity.set(TERM, term);
entity.set(FREQUENCY, pubMedTFEntity.getFrequency());
entity.set(OCCURRENCE, pubMedTFEntity.getOccurrence());
dataService.add(TERM_FREQUENCY, entity);
return entity;
}
Aggregations