Nhibernate, Criteria List as search parameters - list

Basically what I am trying to do is retrieve an officer. I call this method and pass a IList of Officer Ids. what I want to do it use that Ilist which will have a number of unique ids in it. to pull the one record for each id into a IList of officers which i return and do stuff with.
My problem is that I can not for the life of me figure out how to get the restrictions correct. so say the list has 3 , 6 , 9 and 12 in it it would get all of these records.
public IList<Officer> GetOfficer(IList<int> OfficerId)
{
return session.CreateCriteria<Officer>()
.Add(Restrictions.Eq("OfficerId", OfficerId))
.SetCacheable(true)
.List<Officer>();
}
any help would be greatly appreciated thanks

Solution should be in InExpression:
public IList<Officer> GetOfficer(IList<int> OfficerId)
{
return session.CreateCriteria<Officer>()
.Add(new NHibernate.Criterion.InExpression("OfficerId"
, OfficerId.Cast<object>().ToArray()))
.SetCacheable(true)
.List<Officer>();
}

Related

Flutter; Sort List of Widgets

I currently have a list of widgets
List<LessonItem> _lessons = [];
One Widget inside this list, added by the user should look like this
LessonItem('Bio', 'Mrs Pithan', 'A1.012', HourMinute('08', '00'),
HourMinute('11', '50'), Colors.green), //lesson, teacher, room, from, to, color
Now I want to sort the list by a specific property from the widgets. How can I do that?
Thanks for any help!
I would try with the sort method in dart.
You choose a property you want to sort by, and then define how any two elements will be compared.
Here I'm comparing each element by id (smaller id would en up first after sort):
_lessons.sort((LessonItem a, LessonItem b) => a.id - b.id);
In this case I'm sorting by name (with the compareTo() method from String):
_lessons.sort((LessonItem a, LessonItem b) => a.name.compareTo(b.name));
You can find more detailed info and some examples in:
dart documentation
and
this helpful post

Camunda: query processes that do not have a specific variable

In Camunda (7.12) I can query processes by variable value:
runtimeService.createProcessInstanceQuery()
.variableValueEquals("someVar", "someValue")
.list();
I can even query processes for null-value variables:
runtimeService.createProcessInstanceQuery()
.variableValueEquals("someVar", null)
.list();
But how can I query processes that do not have variable someVar?
I am not sure why you wouldn't have figured that out, but if i am correct what i think you are looking for , then looks like its pretty simple . The ProcessInstanceQuery class has also a method called variableValueNotEquals(String name, Object value) , that allows you select the processes that do not match a variable . In the Camunda Java API Docs it is stated as :
variableValueNotEquals(String name, Object value)
Only select process instances which have a global variable with the given name, but with a different value than the passed value.
Documentation page for your reference:
https://docs.camunda.org/javadoc/camunda-bpm-platform/7.12/?org/camunda/bpm/engine/RuntimeService.html
So i believe you can simply do :
runtimeService.createProcessInstanceQuery()
.variableValueNotEquals("someVar", null)
.list();
Let me know if that helps you .
First, get list of ids of all process instances which have "someVar"
Second, get list of all process ids in camunda
Get ids, from second list, which are not contained in first list.
Here is Kotlin sample as it's shorter than Java code, but concept is the same:
val idsOfProcessesWithVar = runtimeService.createVariableInstanceQuery().variableName("someVar").list().map {
it.processInstanceId
}
val allProcessesIds = runtimeService.createProcessInstanceQuery().list().map { it.id }
allProcessesIds.minus(idsOfProcessesWithVar)

Get Taxonomy Term ID by Node in Drupal 8

I'm trying to get Taxonomy data by particular node.
How can I get Taxonomy Term Id by using Node object ?
Drupal ver. 8.3.6
You could do something like that:
$termId = $node->get('field_yourfield')->target_id;
Then you can load the term with
Term::load($termId);
Hope this helps.
If you want to get Taxonomy Term data you can use this code:
$node->get('field_yourfield')->referencedEntities();
Hope it will be useful for you.
PS: If you need just Term's id you can use this:
$node->get('field_yourfield')->getValue();
You will get something like this:
[0 => ['target_id' => 23], 1 => ['target_id'] => 25]
In example my field has 2 referenced taxonomy terms.
Thanks!
#Kevin Wenger's comment helped me. I'm totally basing this answer on his comment.
In your code, when you have access to a fully loaded \Drupal\node\Entity\Node you can access all the (deeply) nested properties.
In this example, I've got a node which has a taxonomy term field "field_site". The "field_site" term itself has a plain text field "field_site_url_base". In order to get the value of the "field_site_url_base", I can use the following:
$site_base_url = $node->get('field_site')->entity->field_site_url_base->value;
How to extract multiple term IDs easily if you know a little Laravel (specifically Collections):
Setup: composer require tightenco/collect to make Collections available in Drupal.
// see #Wau's answer for this first bit...
// remember: if you want the whole Term object, use ->referencedEntities()
$field_value = $node->get('field_yourfield')->getValue();
// then use collections to avoid loops etc.
$targets = collect($field_value)->pluck('target_id')->toArray();
// $targets = [1,2,3...]
or maybe you'd like the term IDs comma-separated? (I used this for programmatically passing contextual filter arguments to a view, which requires , (OR) or + (AND) to specify multiple values.)
$targets = collect($field_value)->implode('target_id', ',');
// $targets = "1,2,3"

compare two dictionary, one with list of float value per key, the other one a value per key (python)

I have a query sequence that I blasted online using NCBIWWW.qblast. In my xml blast file result I obtained for a query sequence a list of hit (i.e: gi|). Each hit or gi| have multiple hsp. I made a dictionary my_dict1 where I placed gi| as key and I appended the bit score as value. So multiple values for each key.
my_dict1 = {
gi|1002819492|: [437.702, 384.47, 380.86, 380.86, 362.83],
gi|675820360| : [2617.97, 2614.37, 122.112],
gi|953764029| : [414.258, 318.66, 122.112, 86.158],
gi|675820410| : [450.653, 388.08, 386.27] }
Then I looked for max value in each key using:
for key, value in my_dict1.items():
max_value = max(value)
And made a second dictionary my_dict2:
my_dict2 = {
gi|1002819492|: 437.702,
gi|675820360| : 2617.97,
gi|953764029| : 414.258,
gi|675820410| : 450.653 }
I want to compare both dictionary. So I can extract the hsp with the highest score bits. I am also including other parameters like query coverage and identity percentage (Not shown here). The finality is to get the best gi| with the highest bit scores, coverage and identity percentage.
I tried many things to compare both dictionary like this :
First code :
matches[]
if my_dict1.keys() not in my_dict2.keys():
matches[hit_id] = bit_score
else:
matches = matches[hit_id], bit_score
Second code:
if hit_id not in matches.keys():
matches[hit_id]= bit_score
else:
matches = matches[hit_id], bit_score
Third code:
intersection = set(set(my_dict1.items()) & set(my_dict2.items()))
Howerver I always end up with 2 types of errors:
1 ) TypeError: list indices must be integers, not unicode
2 ) ... float not iterable...
Please I need some help and guidance. Thank you very much in advance for your time. Best regards.
It's not clear what you're trying to do. What is hit_id? What is bit_score? It looks like your second dict is always going to have the same keys as your first if you're creating it by pulling the max value for each key of the first dict.
You say you're trying to compare them, but don't really state what you're actually trying to do. Find those with values under a certain max? Find those with the highest max?
Your first code doesn't work because I'm assuming you're trying to use a dict key value as an index to matches, which you define as a list. That's probably where your first error is coming from, though you haven't given the lines where the error is actually occurring.
See in-code comments below:
# First off, this needs to be a dict.
matches{}
# This will never happen if you've created these dicts as you stated.
if my_dict1.keys() not in my_dict2.keys():
matches[hit_id] = bit_score # Not clear what bit_score is?
else:
# Also not sure what you're trying to do here. This will assign a tuple
# to matches with whatever the value of matches[hit_id] is and bit_score.
matches = matches[hit_id], bit_score
Regardless, we really need more information and the full code to figure out your actual goal and what's going wrong.

Apex - Salesforce - Maps

Hello Folks
I have a small query regarding Maps in Apex. I have a map map <String, list <Account>>. I am trying to do the following -
What needs to be done: I am passing a key to string variable and then passing that string to a Map.get() method to get the values for that key. Here, it does not give me the right answer. Even when I print out the Map using System.Debug() it prints out the map very differently!
String Id = 'Some Id that is the key in the map';
List <Account> testList = Map.get(Id);
This does not give me the corresponding value and I do not know why!
BUT
when I type the below code, the values are printed out perfectly.
for(String s : Map.keySet()){
List <Account> TestList = Map.get(s);
System.Debug('TestList' + TestList);
}
The Test list actually prints out what it is supposed to print out i.e. for each key it prints out the values where as when I print the map it does not print out as expected.
What is expected: I want to pass a key to the Map.get() method to retrieve the results but its clearly not happening in my case.
Any kinds of help is really appreciated!
The only two things I can think of here are:
It's a case issue. To verify, convert your keys to uppercase:
theMap.put(stringKey.toUpperCase(), theAccountList);
By using Id as a variable name (itself a type), you are getting strange results
As others have already mentioned here, please post the actual code segment so we can help further or close this issue.
Thanks