Search in sources :

Example 31 with QueryImpl

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())));
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 32 with QueryImpl

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");
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) BootstrappingEvent(org.molgenis.data.event.BootstrappingEvent) Test(org.testng.annotations.Test)

Example 33 with QueryImpl

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);
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) File(java.io.File) FileMeta(org.molgenis.data.file.model.FileMeta)

Example 34 with QueryImpl

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);
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) BeaconQueryServiceImpl(org.molgenis.beacon.service.impl.BeaconQueryServiceImpl) BeaconDataset(org.molgenis.beacon.config.BeaconDataset) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 35 with QueryImpl

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);
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) Ontology(org.molgenis.ontology.core.meta.Ontology) QueryRule(org.molgenis.data.QueryRule) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

QueryImpl (org.molgenis.data.support.QueryImpl)98 Test (org.testng.annotations.Test)70 DynamicEntity (org.molgenis.data.support.DynamicEntity)37 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)36 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)36 EntityType (org.molgenis.data.meta.model.EntityType)28 Attribute (org.molgenis.data.meta.model.Attribute)25 Entity (org.molgenis.data.Entity)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 Stream (java.util.stream.Stream)7 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)7 AggregateQueryImpl (org.molgenis.data.support.AggregateQueryImpl)7 Objects.requireNonNull (java.util.Objects.requireNonNull)6 QueryRule (org.molgenis.data.QueryRule)6 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)6 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 Instant (java.time.Instant)5 LocalDate (java.time.LocalDate)5 Operator (org.molgenis.data.QueryRule.Operator)5