use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class RepositoryTemplateLoaderTest method loadAndRead.
@Test
public void loadAndRead() throws IOException {
when(dataService.findOne(FREEMARKER_TEMPLATE, new QueryImpl<FreemarkerTemplate>().eq("Name", "template1"), FreemarkerTemplate.class)).thenReturn(template1);
Object source = repositoryTemplateLoader.findTemplateSource("template1");
assertNotNull(source);
Reader reader = repositoryTemplateLoader.getReader(source, null);
assertTrue(IOUtils.contentEquals(reader, new StringReader(template1.getValue())));
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class DynamicRepositoryDecoratorRegistryImplTest method testDecorate.
@Test
public void testDecorate() {
DynamicDecorator dynamicDecorator = mock(DynamicDecorator.class);
Repository decoratedRepository = mock(Repository.class);
when(decoratedRepository.getName()).thenReturn("decoratedRepositoryName");
when(decoratorConfiguration.getDecorators()).thenReturn(Arrays.asList(dynamicDecorator).stream());
when(dynamicDecorator.getId()).thenReturn("dynamicDecoratorId");
when(dynamicRepositoryDecoratorFactory.getId()).thenReturn("dynamicDecoratorId");
when(dynamicRepositoryDecoratorFactory.createDecoratedRepository(repository)).thenReturn(decoratedRepository);
Query query = new QueryImpl().eq(ENTITY_TYPE_ID, "entityTypeId");
when(dataService.findOne(DECORATOR_CONFIGURATION, query, DecoratorConfiguration.class)).thenReturn(decoratorConfiguration);
DynamicRepositoryDecoratorRegistryImpl dynamicRepositoryDecoratorRegistry = new DynamicRepositoryDecoratorRegistryImpl(dataService);
// fake the event to tell the registry that bootstrapping is done.
dynamicRepositoryDecoratorRegistry.onApplicationEvent(new BootstrappingEvent(FINISHED));
dynamicRepositoryDecoratorRegistry.addFactory(dynamicRepositoryDecoratorFactory);
assertEquals(dynamicRepositoryDecoratorRegistry.decorate(repository).getName(), "decoratedRepositoryName");
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class SavedScriptRunner method runScript.
/**
* Run a script with parameters.
*
* @param scriptName name of the script to run
* @param parameters parameters for the script
* @return ScriptResult
* @throws UnknownScriptException if scriptName is unknown
* @throws GenerateScriptException , if parameter is missing
*/
public ScriptResult runScript(String scriptName, Map<String, Object> parameters) {
Script script = dataService.findOne(SCRIPT, new QueryImpl<Script>().eq(ScriptMetaData.NAME, scriptName), Script.class);
if (script == null) {
throw new UnknownScriptException("Unknown script [" + scriptName + "]");
}
if (script.getParameters() != null) {
for (ScriptParameter param : script.getParameters()) {
if (!parameters.containsKey(param.getName())) {
throw new GenerateScriptException("Missing parameter [" + param + "]");
}
}
}
if (script.isGenerateToken()) {
String token = tokenService.generateAndStoreToken(SecurityUtils.getCurrentUsername(), "For script " + script.getName());
parameters.put("molgenisToken", token);
}
FileMeta fileMeta = null;
if (StringUtils.isNotEmpty(script.getResultFileExtension())) {
String name = generateRandomString();
File file = fileStore.getFile(name + "." + script.getResultFileExtension());
parameters.put("outputFile", file.getAbsolutePath());
fileMeta = createFileMeta(name, file);
dataService.add(FILE_META, fileMeta);
}
ScriptRunner scriptRunner = scriptRunnerFactory.getScriptRunner(script.getScriptType().getName());
String output = scriptRunner.runScript(script, parameters);
return new ScriptResult(fileMeta, output);
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class BeaconQueryServiceTest method beforeMethod.
@BeforeMethod
public void beforeMethod() {
initMocks(this);
dataset1 = mock(BeaconDataset.class, RETURNS_DEEP_STUBS);
when(dataset1.getId()).thenReturn("dataset1");
when(dataset1.getDatasetEntityType().getId()).thenReturn("dataset1");
when(dataset1.getGenomeBrowserAttributes().getChrom()).thenReturn("#CHROM");
when(dataset1.getGenomeBrowserAttributes().getPos()).thenReturn("POS");
when(dataset1.getGenomeBrowserAttributes().getRef()).thenReturn("REF");
when(dataset1.getGenomeBrowserAttributes().getAlt()).thenReturn("ALT");
dataset2 = mock(BeaconDataset.class, RETURNS_DEEP_STUBS);
when(dataset2.getId()).thenReturn("dataset2");
when(dataset2.getDatasetEntityType().getId()).thenReturn("dataset2");
when(dataset2.getGenomeBrowserAttributes().getChrom()).thenReturn("#CHROM");
when(dataset2.getGenomeBrowserAttributes().getPos()).thenReturn("POS");
when(dataset2.getGenomeBrowserAttributes().getRef()).thenReturn("REF");
when(dataset2.getGenomeBrowserAttributes().getAlt()).thenReturn("ALT");
query1 = new QueryImpl<>().eq(dataset1.getGenomeBrowserAttributes().getChrom(), "1").and().eq(dataset1.getGenomeBrowserAttributes().getPos(), 100L).and().eq(dataset1.getGenomeBrowserAttributes().getRef(), "A").and().eq(dataset1.getGenomeBrowserAttributes().getAlt(), "T");
query2 = new QueryImpl<>().eq(dataset2.getGenomeBrowserAttributes().getChrom(), "1").and().eq(dataset2.getGenomeBrowserAttributes().getPos(), 100L).and().eq(dataset2.getGenomeBrowserAttributes().getRef(), "A").and().eq(dataset2.getGenomeBrowserAttributes().getAlt(), "T");
beaconQueryService = new BeaconQueryServiceImpl(dataService);
}
use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.
the class InformationContentServiceTest method createWordIDF.
@Test
public void createWordIDF() {
String ontologyIri = "http://www.molgenis.org";
Ontology ontology = ontologyFactory.create();
ontology.setOntologyIri(ontologyIri);
when(dataService.findOne(ONTOLOGY, new QueryImpl<>().eq(OntologyMetaData.ONTOLOGY_IRI, ontologyIri))).thenReturn(ontology);
when(dataService.count(ONTOLOGY_TERM, new QueryImpl<>().eq(OntologyTermMetaData.ONTOLOGY, ontology))).thenReturn((long) 100);
QueryRule queryRule = new QueryRule(singletonList(new QueryRule(OntologyTermMetaData.ONTOLOGY_TERM_SYNONYM, Operator.FUZZY_MATCH, "hear")));
queryRule.setOperator(Operator.DIS_MAX);
QueryRule finalQuery = new QueryRule(asList(new QueryRule(OntologyTermMetaData.ONTOLOGY, Operator.EQUALS, ontology), new QueryRule(Operator.AND), queryRule));
when(dataService.count(ONTOLOGY_TERM, new QueryImpl<>(finalQuery))).thenReturn((long) 30);
QueryRule queryRule2 = new QueryRule(singletonList(new QueryRule(OntologyTermMetaData.ONTOLOGY_TERM_SYNONYM, Operator.FUZZY_MATCH, "impair")));
queryRule2.setOperator(Operator.DIS_MAX);
QueryRule finalQuery2 = new QueryRule(asList(new QueryRule(OntologyTermMetaData.ONTOLOGY, Operator.EQUALS, ontology), new QueryRule(Operator.AND), queryRule2));
when(dataService.count(ONTOLOGY_TERM, new QueryImpl<>(finalQuery2))).thenReturn((long) 10);
Map<String, Double> expectedWordIDF = informationContentService.createWordIDF("hearing impairment", ontologyIri);
Assert.assertEquals(expectedWordIDF.get("hear").intValue(), 2);
Assert.assertEquals(expectedWordIDF.get("impair").intValue(), 3);
}
Aggregations