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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations