How can I do multiple logical end for multiple system properties? - spring-el

I'm trying check existence of multiple system properties for EnabledIf.
When I do fo a single system property, it seems work.
#EnabledIf(expression = "#{systemProperties['some'] != null}")
But I failed for multiple system properties.
#EnabledIf(expression = "#{systemProperties['some'] != null} and " +
"#{systemProperties['other'] != null}")
How can I do that?

The and needs to be within the expression:
#EnabledIf("#{systemProperties['some'] != null and "
+ "systemProperties['other'] != null}")

Related

How to update internal table without using MODIFY?

I have created internal tables where I want to update age of employee in one internal table by calculating it from another table, I have done arithmetic calculations to get age but now how can I update it by any alternate way instead of MODIFY?
WRITE : / 'FirstName','LastName', ' Age'.
LOOP AT gt_items1 INTO gwa_items1.
READ TABLE gt_header INTO gwa_header WITH KEY empid = gwa_items1-empid.
gwa_items1-age = gv_date+0(4) - gwa_header-bdate+0(4).
MODIFY gt_items1 from gwa_items1 TRANSPORTING age WHERE empid = gwa_items1-empid.
WRITE : / gwa_items1-fname , gwa_items1-lname , gwa_items1-age .
ENDLOOP.
Use field symbols (instead of work areas) by LOOPing over internal tables:
WRITE : / 'FirstName','LastName', ' Age'.
LOOP AT gt_items1
ASSIGNING FIELD-SYMBOL(<ls_item1>).
READ TABLE gt_header
ASSIGNING FIELD-SYMBOL(<ls_header>)
WITH KEY empid = <ls_item1>-empid.
IF sy-subrc EQ 0.
<ls_item1>-age = gv_date+0(4) - <ls_header>-bdate+0(4).
WRITE : / <ls_item1>-fname , <ls_item1>-lname , <ls_item1>-age .
ENDIF.
ENDLOOP.
Field symbols have two advantages:
They modify the internal table directly, no separate MODIFY is
necessary.
They are somewhat faster, than work areas.
Besides József Szikszai's answer you could also use references:
write : / 'FirstName','LastName', ' Age'.
sort gt_header by empid. " <------------- Sort for binary search
loop at gt_items1 reference into data(r_item1).
read table gt_header reference into data(r_header)
with key empid = r_item1->empid binary search. " <------------- Faster read
check sy-subrc eq 0.
r_item1->age = gv_date+0(4) - r_header->bdate+0(4).
write : / r_item1->fname , r_item1->lname , r_item1->age .
endloop.
I added some enhacements to your code also.
For more info check this link.

Linq - Query on 2 Lists Optimization

I am having 2 Lists & I am querying on this 2 List. Both the List are populated with huge data. So the query is taking long time.
When I usually face this performance issue, I simply convert SQL queries & run them directly & get the result in a datatable. But this time I cannot do this as these 2 are not tables but Lists of Models.
How to Optimize this Query or what else should i do?
Code :-
List<TempInOut> listTempInOut = new List<TO_TempInOut>();
List<ShiftSchedule> tempShiftSch = new List<TO_TempInOut>();
var data = (from B in tempShiftSch
from C in listTempInOut
where
B.CompanyId == companyId &&
C.CompanyId == companyId &&
B.EmployeeId == C.EmployeeId &&
C.InDate >= StrOutStart &&
C.InDate <= StrOutEnd &&
B.ShiftId == item.ShiftCode &&
B.ShiftDate == tempInputDate
select new
{
C.EmployeeId,
C.InDate,
C.Time_Date1
}).ToList();
Implement an IEqualityComparer for your types, use HashSet for each collection, and use the HashSet.Intersect method to get your output.
You can simplify your query to two stepsand compare time.
I am thinking of something like that.
var listTempInOutResult = listTempInOut.Where(C => C.CompanyId == companyId
&& C.InDate >= StrOutStart
&& C.InDate <= StrOutEnd);
var employessIds = listTempInOutresult.Select(x => x.EmployeeId).ToList();
var data = tempShiftSch.Where(B => employessIds.Contains(B.EmployeeId)
&& B.CompanyId == companyId
&& B.ShiftDate == tempInputDate
&& B.ShiftId == item.ShiftCode)
.Select(C=> new
{
C.EmployeeId,
C.InDate,
C.Time_Date1
}).ToList();
if you are working with iqueryable it would be better to use joins.
see this StackOverflow question

Get the List object to compare with Date Time but am not getting greater values in the List in wpf

I want to compare the List Object with Date Time.but getting the same date values also , But I don't want same date time records. I need only maximum date values only.
List<ExpImpSurplus_Review> imprtSurplusReview = JsonConvert.DeserializeObject<List<ExpImpSurplus_Review>>(str);
TableName = "Surplus_Review";
lastImpDate = GetLatestImportedTime(TableName);
if (lastImpDate != Convert.ToDateTime("1/1/0001 12:00:00 AM"))
{
imprtSurplusReview = imprtSurplusReview.Where(p => (p.DateModified > lastImpDate && p.DateModified != null) || (p.DateCreated > lastImpDate && p.DateModified == null)).ToList();
}
Any help will be appreciated ?
I'm not entirely sure what your problem is, but I notice two things:
(p.DateModified > lastImpDate && p.DateModified != null) -- you should be checking for null first, i.e. before the first check. The && operator evaluates from the left
(p.DateCreated > lastImpDate && p.DateModified == null) -- you're checking for DateModified being populated, but you're using DateCreated in the comparison, which I assume is a bug.

Lua - check if array exists

I'm trying to find out if a certain array exists via an if statement such as
if array{} == nil then array = {} else print("it exists") end
The above doesn't work it seems and I have no way of checking if it exists, basically I'm creating an AddOn which scans a log for a certain event and if it's true it returns the spellName. I wish to create an array with that spellName, however spellName = {} doesn't work as it seems to just create a new array (rather than updating the existing one).
local _SPD = CreateFrame("Frame");
_SPD:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
_SPD:SetScript("OnEvent", function(self, event, ...)
local timestamp, type, sourceName = select(1, ...), select(2, ...), select(5, ...)
if (event == "COMBAT_LOG_EVENT_UNFILTERED") then
if select(2,...) == "SPELL_AURA_APPLIED" then
if select(5,...) == UnitName("player") then
local spellID, spellName = select(12, ...), select(13, ...)
spellName = {
sourceName = {
}
}
table.insert(spellName["sourceName"], {id = spellID, stamp = timestamp })
for k,v in pairs ( spellName["sourceName"] ) do
print (k.. ": " ..v["id"].. " at " ..v["stamp"])
end
end
end
end
end);
Basically it's just re-creating the table every time a certain aura is applied on me (which is expected behavior)
I've banged my head but I have no idea how to check if spellName (and sourceName) exists and if so do not create them again since in this case the variable already exists because it returns the value to me so I can't check if they're nil as they won't be, I need to somehow check if a table exists on those values and if not create them.
Thanks in advance.
Your declaration for table checking is wrong. Use it like this:
if type(array) == "table" then
print("it exists")
else
array = {}
end
Try this:
local spellID, spellName = select(12, ...), select(13, ...)
spellName = spellName or {}
spellName.sourceName = spellName.sourceName or {}
table.insert(spellName.sourceName, {id = spellID, stamp = timestamp })

ASP.NET MVC 4 MvcMovie Tutorial Filter query by multiple search criteria

I was going through the MvcMovie Tutorial and I was trying to modify the SearchIndex() call in the MoviesController to search by multiple criteria. The tutorial shows you how to search by title and genre using the following code:
var movies = from m in db.Movies
select m;
if (!String.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title.Contains(searchString));
}
if (string.IsNullOrEmpty(movieGenre))
return View(movies);
else
{
return View(movies.Where(x => x.Genre == movieGenre));
}
So if I read this right they return all movies then filter on Genre. That would be fine for a dual case but when you add in a 3rd or 4th search criteria you would then increase the amount of if statement calls by a factor of 2 (to the n) - 1 cases. This would get very unruly if for say you had 10 or so columns to search by.
I tried to use something a little more straight forward like:
var movieQry = from m in db.Movies
where ((m.Title !=null && m.Title == searchString) ||
(m.Rating != null && m.Rating == movieRating) ||
(m.Genre != null && m.Genre == movieGenre))
select m;
but that would not return anything when you first visit the page and only works for a single filter (if I select the Genre - I get good results but not when I select Genre and Rating) and I get nothing returned when I enter a search term for Title.
Is there an easier way to accomplish? (At some point I will need to be able to search on dozens of filters for a project I will be writing... and I have other questions about how to search database for entries but for not this will get me moving in the right direction).
if you want to include the column in the criteria if it is not null then try following:
string Title = Request.QueryString["Title"];
string Rating= Request.QueryString["Rating"];
string Genre = Request.QueryString["Genre"];
var movieQry = from m in db.Movies
where ((string.IsNullOrEmpty(Title) ? true : m.Title == Title ) &&
(string.IsNullOrEmpty(Rating) ? true : m.Rating == Rating ) &&
(string.IsNullOrEmpty(Genre) ? true : m.Genre == Genre ))
select m;
Behnam was kind of on the right track. I modified the code as follows:
var movieQry2 = from m in db.Movies
where ((string.IsNullOrEmpty(searchString) ? true : m.Title.Contains(searchString)) &&
(string.IsNullOrEmpty(movieRating) ? true : m.Rating == movieRating) &&
(string.IsNullOrEmpty(movieGenre) ? true : m.Genre == movieGenre))
select m;
This works and gives good results. Sorry Behnam can't give you an accepted answer but I did tick it up as being useful. Thanks for pointing me in the right direction.
Try this:
var movieQry = db.Movies
.Where(x=> (Title == null || x.Title ==Title)
&& (Rating == null || x.Rating == Rating)
&& (Genre == null || x.Genre == Genre))
.ToList();
For other paging and sorting see MVC multiple field search

Resources