Search in sources :

Example 31 with Arrays.asList

use of java.util.Arrays.asList in project lucene-solr by apache.

the class TestReqParamsAPI method testReqParams.

private void testReqParams() throws Exception {
    CloudSolrClient cloudClient = cluster.getSolrClient();
    DocCollection coll = cloudClient.getZkStateReader().getClusterState().getCollection(COLL_NAME);
    List<String> urls = new ArrayList<>();
    for (Slice slice : coll.getSlices()) {
        for (Replica replica : slice.getReplicas()) urls.add("" + replica.get(ZkStateReader.BASE_URL_PROP) + "/" + replica.get(ZkStateReader.CORE_NAME_PROP));
    }
    RestTestHarness writeHarness = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    String payload = "{\n" + "'create-requesthandler' : { 'name' : '/dump0', 'class': 'org.apache.solr.handler.DumpRequestHandler' }\n" + "}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config?wt=json", payload);
    payload = "{\n" + "'create-requesthandler' : { 'name' : '/dump1', 'class': 'org.apache.solr.handler.DumpRequestHandler', 'useParams':'x' }\n" + "}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config?wt=json", payload);
    AbstractFullDistribZkTestBase.waitForRecoveriesToFinish(COLL_NAME, cloudClient.getZkStateReader(), false, true, 90);
    payload = " {\n" + "  'set' : {'x': {" + "                    'a':'A val',\n" + "                    'b': 'B val'}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    Map result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "x", "a"), "A val", 10);
    compareValues(result, "B val", asList("response", "params", "x", "b"));
    TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/overlay?wt=json", cloudClient, asList("overlay", "requestHandler", "/dump0", "name"), "/dump0", 10);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump0?wt=json&useParams=x", cloudClient, asList("params", "a"), "A val", 5);
    compareValues(result, "", asList("params", RequestParams.USEPARAM));
    TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump0?wt=json&useParams=x&a=fomrequest", cloudClient, asList("params", "a"), "fomrequest", 5);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/overlay?wt=json", cloudClient, asList("overlay", "requestHandler", "/dump1", "name"), "/dump1", 10);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump1?wt=json", cloudClient, asList("params", "a"), "A val", 5);
    writeHarness = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    payload = " {\n" + "  'set' : {'y':{\n" + "                'c':'CY val',\n" + "                'b': 'BY val', " + "                'i': 20, " + "                'd': ['val 1', 'val 2']}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "c"), "CY val", 10);
    compareValues(result, 20l, asList("response", "params", "y", "i"));
    compareValues(result, null, asList("response", "params", "y", "a"));
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump1?wt=json&useParams=y", cloudClient, asList("params", "c"), "CY val", 5);
    compareValues(result, "BY val", asList("params", "b"));
    compareValues(result, "A val", asList("params", "a"));
    compareValues(result, Arrays.asList("val 1", "val 2"), asList("params", "d"));
    compareValues(result, "20", asList("params", "i"));
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/requestHandler?componentName=/dump1&expandParams=true&wt=json&useParams=y&c=CC", cloudClient, asList("config", "requestHandler", "/dump1", "_useParamsExpanded_", "x", "a"), "A val", 5);
    compareValues(result, "B val", asList("config", "requestHandler", "/dump1", "_useParamsExpanded_", "x", "b"));
    compareValues(result, "CY val", asList("config", "requestHandler", "/dump1", "_useParamsExpanded_", "y", "c"));
    compareValues(result, "BY val", asList("config", "requestHandler", "/dump1", "_useParamsExpanded_", "y", "b"));
    compareValues(result, "A val", asList("config", "requestHandler", "/dump1", "_effectiveParams_", "a"));
    compareValues(result, "BY val", asList("config", "requestHandler", "/dump1", "_effectiveParams_", "b"));
    compareValues(result, "CC", asList("config", "requestHandler", "/dump1", "_effectiveParams_", "c"));
    payload = " {\n" + "  'update' : {'y': {\n" + "                'c':'CY val modified',\n" + "                'e':'EY val',\n" + "                'b': 'BY val'" + "}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "c"), "CY val modified", 10);
    compareValues(result, "EY val", asList("response", "params", "y", "e"));
    payload = " {\n" + "  'set' : {'y': {\n" + "                'p':'P val',\n" + "                'q': 'Q val'" + "}\n" + "             }\n" + "  }";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "p"), "P val", 10);
    compareValues(result, null, asList("response", "params", "y", "c"));
    compareValues(result, 2l, asList("response", "params", "y", "", "v"));
    compareValues(result, 0l, asList("response", "params", "x", "", "v"));
    payload = "{update :{x : {_appends_ :{ add : 'first' },  _invariants_ : {fixed: f }}}}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "x", "_appends_", "add"), "first", 10);
    compareValues(result, "f", asList("response", "params", "x", "_invariants_", "fixed"));
    result = TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/dump1?wt=json&fixed=changeit&add=second", cloudClient, asList("params", "fixed"), "f", 5);
    compareValues(result, new Predicate() {

        @Override
        public boolean test(Object o) {
            List l = (List) o;
            return l.contains("first") && l.contains("second");
        }
    }, asList("params", "add"));
    payload = " {'delete' : 'y'}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config/params?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(null, urls.get(random().nextInt(urls.size())), "/config/params?wt=json", cloudClient, asList("response", "params", "y", "p"), null, 10);
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Predicate(java.util.function.Predicate) Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) DocCollection(org.apache.solr.common.cloud.DocCollection) Map(java.util.Map)

Example 32 with Arrays.asList

use of java.util.Arrays.asList in project drools by kiegroup.

the class AccumulateTest method testAccFunctionOpaqueJoins.

private void testAccFunctionOpaqueJoins(PropertySpecificOption propertySpecificOption) throws Exception {
    String str = "package org.test; " + "import java.util.*; " + "global List list; " + "global List list2; " + "declare Tick " + "  tick : int " + "end " + "declare Data " + "  values : List " + "  bias : int = 0 " + "end " + "rule Init " + "when " + "then " + "  insert( new Data( Arrays.asList( 1, 2, 3 ), 1 ) ); " + "  insert( new Data( Arrays.asList( 4, 5, 6 ), 2 ) ); " + "  insert( new Tick( 0 ) );" + "end " + "rule Update " + "  no-loop " + "when " + "  $i : Integer() " + "  $t : Tick() " + "then " + "  System.out.println( 'Set tick to ' + $i ); " + "  modify( $t ) { " + "      setTick( $i ); " + "  } " + "end " + "rule M " + "  dialect 'mvel' " + "when " + "    Tick( $index : tick ) " + "    accumulate ( $data : Data( $bias : bias )," + "                 $tot : sum( $data.values[ $index ] + $bias ) ) " + "then " + "    System.out.println( $tot + ' for J ' + $index ); " + "    list.add( $tot ); " + "end " + "rule J " + "when " + "    Tick( $index : tick ) " + "    accumulate ( $data : Data( $bias : bias )," + "                 $tot : sum( ((Integer)$data.getValues().get( $index )) + $bias ) ) " + "then " + "    System.out.println( $tot + ' for M ' + $index ); " + "    list2.add( $tot ); " + "end ";
    KieHelper helper = new KieHelper(propertySpecificOption);
    KieSession ks = helper.addContent(str, ResourceType.DRL).build().newKieSession();
    List list = new ArrayList();
    ks.setGlobal("list", list);
    List list2 = new ArrayList();
    ks.setGlobal("list2", list2);
    // init data
    ks.fireAllRules();
    assertEquals(asList(8.0), list);
    assertEquals(asList(8.0), list2);
    ks.insert(1);
    ks.fireAllRules();
    assertEquals(asList(8.0, 10.0), list);
    assertEquals(asList(8.0, 10.0), list2);
    ks.insert(2);
    ks.fireAllRules();
    assertEquals(asList(8.0, 10.0, 12.0), list);
    assertEquals(asList(8.0, 10.0, 12.0), list2);
}
Also used : ArrayList(java.util.ArrayList) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 33 with Arrays.asList

use of java.util.Arrays.asList in project drools by kiegroup.

the class Misc2Test method testLegacySalienceResolver.

@Test
public void testLegacySalienceResolver() {
    // DROOLS-159
    String drl = "package org.drools.test; \n" + "" + "global java.util.List list; \n " + "" + "rule X salience 10 \n" + "then\n" + " list.add( 1 ); \n" + "end\n" + "" + "rule Y salience 5 \n" + "then\n" + " list.add( 2 ); \n" + "end\n" + "";
    KnowledgeBuilder kb = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kb.add(new ByteArrayResource(drl.getBytes()), ResourceType.DRL);
    assertFalse(kb.hasErrors());
    KieBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    ((RuleBaseConfiguration) kbconf).setConflictResolver(SalienceConflictResolver.getInstance());
    InternalKnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(kbconf);
    knowledgeBase.addPackages(kb.getKnowledgePackages());
    KieSession knowledgeSession = knowledgeBase.newKieSession();
    List list = new ArrayList();
    knowledgeSession.setGlobal("list", list);
    knowledgeSession.fireAllRules();
    assertEquals(Arrays.asList(1, 2), list);
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) ByteArrayResource(org.drools.core.io.impl.ByteArrayResource) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 34 with Arrays.asList

use of java.util.Arrays.asList in project drools by kiegroup.

the class FlowTest method testCustomAccumulate.

@Test
public void testCustomAccumulate() {
    final Variable<Customer> var_$customer = declarationOf(Customer.class, "$customer");
    final Variable<String> var_$code = declarationOf(String.class, "$code");
    final Variable<TargetPolicy> var_$target = declarationOf(TargetPolicy.class, "$target");
    final Variable<java.util.List> var_$pattern_List$1$ = declarationOf(java.util.List.class, "$pattern_List$1$");
    final Variable<TargetPolicy> var_$tp = declarationOf(TargetPolicy.class, "$tp");
    final org.drools.model.BitMask mask_$target = org.drools.model.BitMask.getPatternMask(TargetPolicy.class, "coefficient");
    org.drools.model.Rule rule = rule("Customer can only have one Target Policy for Product p1 with coefficient 1").build(bind(var_$code).as(var_$customer, (_this) -> _this.getCode()).reactOn("code"), expr("$expr$2$", var_$target, var_$code, (_this, $code) -> org.drools.modelcompiler.util.EvaluationUtil.areNullSafeEquals(_this.getCustomerCode(), $code)).indexedBy(String.class, org.drools.model.Index.ConstraintType.EQUAL, 0, _this -> _this.getCustomerCode(), $code -> $code).reactOn("customerCode"), expr("$expr$3$", var_$target, (_this) -> org.drools.modelcompiler.util.EvaluationUtil.areNullSafeEquals(_this.getProductCode(), "p1")).indexedBy(String.class, org.drools.model.Index.ConstraintType.EQUAL, 1, _this -> _this.getProductCode(), "p1").reactOn("productCode"), expr("$expr$4$", var_$target, (_this) -> _this.getCoefficient() == 1).indexedBy(int.class, org.drools.model.Index.ConstraintType.EQUAL, 2, _this -> _this.getCoefficient(), 1).reactOn("coefficient"), expr("$expr$5$", var_$pattern_List$1$, (_this) -> _this.size() > 1).indexedBy(int.class, org.drools.model.Index.ConstraintType.GREATER_THAN, 0, _this -> _this.size(), 1).reactOn("size"), accumulate(and(expr("$expr$2$", var_$tp, var_$code, (_this, $code) -> org.drools.modelcompiler.util.EvaluationUtil.areNullSafeEquals(_this.getCustomerCode(), $code)).indexedBy(String.class, org.drools.model.Index.ConstraintType.EQUAL, 0, _this -> _this.getCustomerCode(), $code -> $code).reactOn("customerCode"), expr("$expr$3$", var_$tp, (_this) -> org.drools.modelcompiler.util.EvaluationUtil.areNullSafeEquals(_this.getProductCode(), "p1")).indexedBy(String.class, org.drools.model.Index.ConstraintType.EQUAL, 1, _this -> _this.getProductCode(), "p1").reactOn("productCode"), expr("$expr$4$", var_$tp, (_this) -> _this.getCoefficient() == 1).indexedBy(int.class, org.drools.model.Index.ConstraintType.EQUAL, 2, _this -> _this.getCoefficient(), 1).reactOn("coefficient")), accFunction(MyAccumulateFunction.class, var_$tp).as(var_$pattern_List$1$)), on(var_$target).execute((drools, $target) -> {
        $target.setCoefficient(0);
        drools.update($target, mask_$target);
    }));
    Model model = new ModelImpl().addRule(rule);
    KieBase kieBase = KieBaseBuilder.createKieBaseFromModel(model);
    KieSession ksession = kieBase.newKieSession();
    Customer customer = new Customer();
    customer.setCode("code1");
    TargetPolicy target1 = new TargetPolicy();
    target1.setCustomerCode("code1");
    target1.setProductCode("p1");
    target1.setCoefficient(1);
    TargetPolicy target2 = new TargetPolicy();
    target2.setCustomerCode("code1");
    target2.setProductCode("p1");
    target2.setCoefficient(1);
    TargetPolicy target3 = new TargetPolicy();
    target3.setCustomerCode("code1");
    target3.setProductCode("p1");
    target3.setCoefficient(1);
    ksession.insert(customer);
    ksession.insert(target1);
    ksession.insert(target2);
    ksession.insert(target3);
    ksession.fireAllRules();
    List<TargetPolicy> targetPolicyList = Arrays.asList(target1, target2, target3);
    long filtered = targetPolicyList.stream().filter(c -> c.getCoefficient() == 1).count();
    assertEquals(1, filtered);
}
Also used : Arrays(java.util.Arrays) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) FlowDSL.eval(org.drools.model.FlowDSL.eval) ObjectOutput(java.io.ObjectOutput) Man(org.drools.modelcompiler.domain.Man) Global(org.drools.model.Global) FlowDSL.not(org.drools.model.FlowDSL.not) Toy(org.drools.modelcompiler.domain.Toy) FlowDSL.and(org.drools.model.FlowDSL.and) FlowDSL.accFunction(org.drools.model.FlowDSL.accFunction) Relationship(org.drools.modelcompiler.domain.Relationship) BaseModelTest.getObjectsIntoList(org.drools.modelcompiler.BaseModelTest.getObjectsIntoList) Assert.assertThat(org.junit.Assert.assertThat) Query2Def(org.drools.model.Query2Def) Child(org.drools.modelcompiler.domain.Child) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) FlowDSL.from(org.drools.model.FlowDSL.from) QueryResults(org.kie.api.runtime.rule.QueryResults) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) FlowDSL.reactiveFrom(org.drools.model.FlowDSL.reactiveFrom) Assertions(org.assertj.core.api.Assertions) KieSession(org.kie.api.runtime.KieSession) FlowDSL.declarationOf(org.drools.model.FlowDSL.declarationOf) TargetPolicy(org.drools.modelcompiler.domain.TargetPolicy) FlowDSL.or(org.drools.model.FlowDSL.or) EventProcessingOption(org.kie.api.conf.EventProcessingOption) Collection(java.util.Collection) FlowDSL.on(org.drools.model.FlowDSL.on) Customer(org.drools.modelcompiler.domain.Customer) Serializable(java.io.Serializable) ConstraintType(org.drools.model.Index.ConstraintType) List(java.util.List) Query(org.drools.model.Query) FlowDSL.executeScript(org.drools.model.FlowDSL.executeScript) InternationalAddress(org.drools.modelcompiler.oopathdtables.InternationalAddress) Assert.assertFalse(org.junit.Assert.assertFalse) KnowledgeBaseFactory(org.drools.core.impl.KnowledgeBaseFactory) FlowDSL.bind(org.drools.model.FlowDSL.bind) FlowDSL.valueOf(org.drools.model.FlowDSL.valueOf) Person(org.drools.modelcompiler.domain.Person) ObjectInput(java.io.ObjectInput) InOperator(org.drools.model.operators.InOperator) FlowDSL.when(org.drools.model.FlowDSL.when) ModelImpl(org.drools.model.impl.ModelImpl) FlowDSL.globalOf(org.drools.model.FlowDSL.globalOf) StockTick(org.drools.modelcompiler.domain.StockTick) Employee.createEmployee(org.drools.modelcompiler.domain.Employee.createEmployee) ClockType(org.drools.core.ClockType) FlowDSL.accumulate(org.drools.model.FlowDSL.accumulate) ArrayList(java.util.ArrayList) Result(org.drools.modelcompiler.domain.Result) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) Adult(org.drools.modelcompiler.domain.Adult) Employee(org.drools.modelcompiler.domain.Employee) FlowDSL.execute(org.drools.model.FlowDSL.execute) Woman(org.drools.modelcompiler.domain.Woman) KieBase(org.kie.api.KieBase) Model(org.drools.model.Model) FlowDSL.rule(org.drools.model.FlowDSL.rule) FlowDSL.expr(org.drools.model.FlowDSL.expr) Variable(org.drools.model.Variable) FlowDSL.query(org.drools.model.FlowDSL.query) Address(org.drools.modelcompiler.domain.Address) FlowDSL.window(org.drools.model.FlowDSL.window) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) FlowDSL.input(org.drools.model.FlowDSL.input) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) FactHandle(org.kie.api.runtime.rule.FactHandle) TimeUnit(java.util.concurrent.TimeUnit) KieBaseBuilder(org.drools.modelcompiler.builder.KieBaseBuilder) ClockTypeOption(org.kie.api.runtime.conf.ClockTypeOption) Assert.assertNull(org.junit.Assert.assertNull) FlowDSL.forall(org.drools.model.FlowDSL.forall) Rule(org.drools.model.Rule) Query1Def(org.drools.model.Query1Def) Assert.assertEquals(org.junit.Assert.assertEquals) Customer(org.drools.modelcompiler.domain.Customer) TargetPolicy(org.drools.modelcompiler.domain.TargetPolicy) KieBase(org.kie.api.KieBase) Rule(org.drools.model.Rule) Model(org.drools.model.Model) BaseModelTest.getObjectsIntoList(org.drools.modelcompiler.BaseModelTest.getObjectsIntoList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ModelImpl(org.drools.model.impl.ModelImpl) Test(org.junit.Test)

Example 35 with Arrays.asList

use of java.util.Arrays.asList in project molgenis by molgenis.

the class SortaController method retrieveSortaJobResults.

@PostMapping("/match/retrieve")
@ResponseBody
public EntityCollectionResponse retrieveSortaJobResults(@RequestBody SortaServiceRequest sortaServiceRequest) {
    List<Map<String, Object>> entityMaps = new ArrayList<>();
    String sortaJobExecutionId = sortaServiceRequest.getSortaJobExecutionId();
    String filterQuery = sortaServiceRequest.getFilterQuery();
    String ontologyIri = sortaServiceRequest.getOntologyIri();
    EntityPager entityPager = sortaServiceRequest.getEntityPager();
    SortaJobExecution sortaJobExecution = findSortaJobExecution(sortaJobExecutionId);
    String resultEntityName = sortaJobExecution.getResultEntityName();
    double threshold = sortaJobExecution.getThreshold();
    boolean isMatched = sortaServiceRequest.isMatched();
    QueryRule queryRuleInputEntities = new QueryRule(Arrays.asList(new QueryRule(VALIDATED, EQUALS, isMatched), new QueryRule(isMatched ? OR : AND), new QueryRule(SCORE, isMatched ? GREATER_EQUAL : LESS, threshold)));
    List<QueryRule> queryRuleInputEntitiesInOneMatchingTask = singletonList(queryRuleInputEntities);
    // Add filter to the query if query string is not empty
    if (isNotEmpty(filterQuery)) {
        Iterable<String> filteredInputTermIds = dataService.findAll(sortaJobExecution.getSourceEntityName(), new QueryImpl<>().search(filterQuery)).map(inputEntity -> inputEntity.getString(SortaServiceImpl.DEFAULT_MATCHING_IDENTIFIER)).collect(Collectors.toList());
        QueryRule previousQueryRule = new QueryRule(queryRuleInputEntitiesInOneMatchingTask);
        QueryRule queryRuleFilterInput = new QueryRule(MatchingTaskContentMetaData.INPUT_TERM, Operator.IN, filteredInputTermIds);
        queryRuleInputEntitiesInOneMatchingTask = Arrays.asList(previousQueryRule, new QueryRule(Operator.AND), queryRuleFilterInput);
    }
    Query<Entity> query = new QueryImpl<>(queryRuleInputEntitiesInOneMatchingTask);
    long count = dataService.count(resultEntityName, query);
    int start = entityPager.getStart();
    int num = entityPager.getNum();
    Stream<Entity> findAll = dataService.findAll(sortaJobExecution.getResultEntityName(), query.offset(start).pageSize(num).sort(new Sort().on(VALIDATED, DESC).on(SCORE, DESC)));
    findAll.forEach(mappingEntity -> {
        Map<String, Object> outputEntity = new HashMap<>();
        outputEntity.put("inputTerm", getEntityAsMap(mappingEntity.getEntity(INPUT_TERM)));
        outputEntity.put("matchedTerm", getEntityAsMap(mappingEntity));
        Object matchedTerm = mappingEntity.get(MATCHED_TERM);
        if (matchedTerm != null) {
            outputEntity.put("ontologyTerm", SortaServiceUtil.getEntityAsMap(sortaService.getOntologyTermEntity(matchedTerm.toString(), ontologyIri)));
        }
        entityMaps.add(outputEntity);
    });
    EntityPager pager = new EntityPager(start, num, count, null);
    return new EntityCollectionResponse(pager, entityMaps, "/match/retrieve", ontologyTermMetaData, permissionService, dataService);
}
Also used : PluginController(org.molgenis.web.PluginController) DEEP_COPY_ATTRS(org.molgenis.data.meta.model.EntityType.AttributeCopyMode.DEEP_COPY_ATTRS) MenuReaderService(org.molgenis.core.ui.menu.MenuReaderService) IdGenerator(org.molgenis.data.populate.IdGenerator) Operator(org.molgenis.data.QueryRule.Operator) LoggerFactory(org.slf4j.LoggerFactory) PermissionSystemService(org.molgenis.data.security.permission.PermissionSystemService) StringUtils(org.apache.commons.lang3.StringUtils) Attribute(org.molgenis.data.meta.model.Attribute) FileStore(org.molgenis.data.file.FileStore) Collections.singletonList(java.util.Collections.singletonList) JobExecutionMetaData(org.molgenis.jobs.model.JobExecutionMetaData) User(org.molgenis.data.security.auth.User) Model(org.springframework.ui.Model) ByteArrayInputStream(java.io.ByteArrayInputStream) SORTA_JOB_EXECUTION(org.molgenis.ontology.sorta.meta.SortaJobExecutionMetaData.SORTA_JOB_EXECUTION) Arrays.asList(java.util.Arrays.asList) RunAsSystemAspect(org.molgenis.security.core.runas.RunAsSystemAspect) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) EntityCollectionResponse(org.molgenis.data.rest.EntityCollectionResponse) AttributeFactory(org.molgenis.data.meta.model.AttributeFactory) org.molgenis.data(org.molgenis.data) ImmutableMap(com.google.common.collect.ImmutableMap) XREF(org.molgenis.data.meta.AttributeType.XREF) UserAccountService(org.molgenis.security.user.UserAccountService) EntityType(org.molgenis.data.meta.model.EntityType) Collectors(java.util.stream.Collectors) Stream(java.util.stream.Stream) UserPermissionEvaluator(org.molgenis.security.core.UserPermissionEvaluator) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) URI(org.molgenis.ontology.sorta.controller.SortaController.URI) CsvWriter(org.molgenis.data.csv.CsvWriter) SortaJobExecutionMetaData(org.molgenis.ontology.sorta.meta.SortaJobExecutionMetaData) SortaService(org.molgenis.ontology.sorta.service.SortaService) EntityPager(org.molgenis.data.rest.EntityPager) java.util(java.util) SortaServiceImpl(org.molgenis.ontology.sorta.service.impl.SortaServiceImpl) SimpleDateFormat(java.text.SimpleDateFormat) QueryImpl(org.molgenis.data.support.QueryImpl) SortaCsvRepository(org.molgenis.ontology.sorta.repo.SortaCsvRepository) Controller(org.springframework.stereotype.Controller) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) OntologyTermMetaData(org.molgenis.ontology.core.meta.OntologyTermMetaData) NumberFormat(java.text.NumberFormat) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) HttpServletRequest(javax.servlet.http.HttpServletRequest) DynamicEntity(org.molgenis.data.support.DynamicEntity) SortaJobImpl(org.molgenis.ontology.sorta.job.SortaJobImpl) SortaServiceRequest(org.molgenis.ontology.sorta.request.SortaServiceRequest) Objects.requireNonNull(java.util.Objects.requireNonNull) EntityTypeFactory(org.molgenis.data.meta.model.EntityTypeFactory) StreamSupport(java.util.stream.StreamSupport) MatchingTaskContentMetaData(org.molgenis.ontology.sorta.meta.MatchingTaskContentMetaData) OntologyService(org.molgenis.ontology.core.service.OntologyService) ExecutorService(java.util.concurrent.ExecutorService) AttributeType(org.molgenis.data.meta.AttributeType) Logger(org.slf4j.Logger) SortaJobFactory(org.molgenis.ontology.sorta.job.SortaJobFactory) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) SortaServiceUtil(org.molgenis.ontology.utils.SortaServiceUtil) File(java.io.File) SortaServiceResponse(org.molgenis.ontology.sorta.request.SortaServiceResponse) HttpStatus(org.springframework.http.HttpStatus) DESC(org.molgenis.data.Sort.Direction.DESC) SortaServiceUtil.getEntityAsMap(org.molgenis.ontology.utils.SortaServiceUtil.getEntityAsMap) SortaJobExecution(org.molgenis.ontology.sorta.job.SortaJobExecution) MultipartFile(org.springframework.web.multipart.MultipartFile) SortaJobExecutionFactory(org.molgenis.ontology.sorta.job.SortaJobExecutionFactory) InputStream(java.io.InputStream) DynamicEntity(org.molgenis.data.support.DynamicEntity) EntityCollectionResponse(org.molgenis.data.rest.EntityCollectionResponse) SortaJobExecution(org.molgenis.ontology.sorta.job.SortaJobExecution) EntityPager(org.molgenis.data.rest.EntityPager) QueryImpl(org.molgenis.data.support.QueryImpl) ImmutableMap(com.google.common.collect.ImmutableMap) SortaServiceUtil.getEntityAsMap(org.molgenis.ontology.utils.SortaServiceUtil.getEntityAsMap)

Aggregations

Arrays.asList (java.util.Arrays.asList)73 List (java.util.List)66 ArrayList (java.util.ArrayList)49 Test (org.junit.Test)37 Arrays (java.util.Arrays)22 Collections.singletonList (java.util.Collections.singletonList)20 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)18 Test (org.junit.jupiter.api.Test)15 HashMap (java.util.HashMap)14 Before (org.junit.Before)13 Collection (java.util.Collection)12 Stream (java.util.stream.Stream)10 Method (java.lang.reflect.Method)9 Optional (java.util.Optional)9 Collections (java.util.Collections)8 Collections.emptyList (java.util.Collections.emptyList)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 Employee (com.artezio.arttime.datamodel.Employee)6 HourType (com.artezio.arttime.datamodel.HourType)6