I am using quartz to schedule jobs. Jobs are created in a "default" group and related information is passed as payload in form of a jobdetail map when using the schedule api.
Trigger trigger = new Trigger(...);
JobDetail jobDetail = new JobDetail(...);
jobDetail.put(...);
scheduler.schedule(trigger, jobDetail);
I want an API to be able to query the triggers in the database based on the payload sent in. For instance, I have "externalId" as part of the jobDetail.
I want to do something like
scheduler.getTriggers(new Criteria("externalId", externalId));
instead of fetching all the triggers in memory and then iterating over it. I searched a bit online but wasn't able to find an API to do the same.
EDIT: As of quartz, 2.1.5, there are a few new APIs
scheduler.getTrigger(triggerKey(jobId, jobGroupName)); // which can fetch the exact trigger given the triggerKey
scheduler.getTriggerKeys(GroupMatcher.triggerGroupContains(JOB_GROUP_NAME)); //this searches all the triggers for a group.
These are not available for quartz 1.8 though. One limitation still is that trigger searches need to be exact and cannot be LIKE % in nature
you can list all you tasks in quartz and collect the required
try this code (jsp):
SchedulerFactory sf = new StdSchedulerFactory(new File(getServletContext().getRealPath("/"), "WEB-INF/quartz.properties").getAbsolutePath());
Scheduler scheduler = sf.getScheduler();
try{
List<JobExecutionContext> jobList = scheduler.getCurrentlyExecutingJobs();
out.print("<h3>Current tasks: "+jobList.size()+"</h3>");
for(JobExecutionContext jec : jobList){
out.print("<hr>");
JobDetail jobDetail = jec.getJobDetail();
Trigger trigger = jec.getTrigger();
TriggerState state = scheduler.getTriggerState(trigger.getKey());
%>
<table style="width: 400px; background-color: #ffffff;">
<tr style="height: 23px;">
<td style="width: 190px;">
class:
</td>
<td style="width: 210px;">
<b><%=jec.getJobInstance().toString()%></b>
</td>
</tr>
<tr style="height: 23px;">
<td>
descr:
</td>
<td>
<i><%=jobDetail.getDescription()%></i>
</td>
</tr>
<tr style="height: 23px;">
<td>
next fire time:
</td>
<td>
<%=new Timestamp(trigger.getFireTimeAfter(new Timestamp(System.currentTimeMillis())).getTime())%>
</td>
</tr>
<tr style="height: 23px;">
<td>
prior:
</td>
<td>
<%=state.toString()%>
</td>
</tr>
</table>
<%
}
}catch(Exception ex){
out.print(ex.getMessage());
}
out.print("<hr>");
// getting all tasks
try{
List<String> jobGroups = scheduler.getJobGroupNames();
out.print("<h3>Triggers: "+jobGroups.size()+"</h3>");
for (String jName : jobGroups){
GroupMatcher<JobKey> matcher = GroupMatcher.groupEquals(jName);
Set keys = scheduler.getJobKeys(matcher);
Iterator iter = keys.iterator();
while (iter.hasNext()){
JobKey jk = (JobKey)iter.next();
JobDetail jobDetail = scheduler.getJobDetail(jk);
// JobDataMap jobDataMap = jobDetail.getJobDataMap();
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jk);
for(Trigger t : triggers){
out.print("<hr>");
TriggerState state = scheduler.getTriggerState(t.getKey());
%>
<table style="width: 400px; background-color: #ffffff;">
<tr style="height: 23px;">
<td style="width: 190px;">
group/class:
</td>
<td style="width: 210px;">
<b><%=t.getJobKey().toString()%></b>
</td>
</tr>
<tr style="height: 23px;">
<td style="width: 190px;">
descr:
</td>
<td style="width: 210px;">
<i><%=jobDetail.getDescription()%></i>
</td>
</tr>
<tr style="height: 23px;">
<td>
curr time:
</td>
<td>
<%=new Timestamp(System.currentTimeMillis())%>
</td>
</tr>
<tr style="height: 23px;">
<td>
next fire time:
</td>
<td>
<%=new Timestamp(t.getFireTimeAfter(new Timestamp(System.currentTimeMillis())).getTime())%>
</td>
</tr>
<tr style="height: 23px;">
<td>
prior:
</td>
<td>
<%=state.toString()%>
</td>
</tr>
</table>
<%
}
}
}
out.print("<hr>");
}catch (SchedulerException ex){
out.print(ex.getMessage());
}
Quartz stores JobDetails in a serialized map (JobDataMap) format. Unless deserialization it is hard to know what are the actual contents of the map.
In your case, I think there is no direct way, You may need to find a work around something like, storing job data map values into separate table which will have Trigger id associated with it, but I am not sure how salable this solution would be.
Related
I have a form with some inputs; each input returns a list of data which is displayed in a table in another html page. Each input have a table to display it's data. My task is to do not display the data if the input is not entered by the user.
Here is my code
<!-- Country Table-->
<%for(int i = 0; i < countryList.length;i++){
if(countryList.length == 0)
break;
%>
<div class="box" align="center">
<table name="tab" align="center" class="gridtable">
<thead >
<tr>
<th style="width: 50%" scope="col">Entity Watch List Key</th>
<th style="width: 50%" scope="col">Watch List Name</th>
</tr>
</thead>
<tbody>
<tr>
<td style="width: 50%"><%out.println((String) (countryList[i].getEntityWatchListKey()));%></td>
<td style="width: 50%"><%out.println((String) (countryList[i].getEntityName()));%></td>
</tr>
</tbody>
</table>
</div>
<%}%>
I am using break to go out of the loop to do not display the table, is that true ?
You can use this condition before the for loop,
if(countryList.length != 0)
or
if(countryList.length > 0)
and then you need not use the break condition,
Furthermore the for loop you have currently defined will not work because if the length of the array is 0 then this condition i < countryList.length will become 0<0 and it will fail,so your for loop won't even be entered.So your current if condition if(countryList.length == 0) will not be accessed.
Please modify your code
<div class="box" align="center">
<table name="tab" align="center" class="gridtable">
<thead >
<tr>
<th style="width: 50%" scope="col">Entity Watch List Key</th>
<th style="width: 50%" scope="col">Watch List Name</th>
</tr>
</thead>
<tbody>
<%for(int i = 0; i < countryList.length;i++){
if(countryList.length > 0) %>
<tr>
<td style="width: 50%"><%out.println((String) (countryList[i].getEntityWatchListKey()));%></td>
<td style="width: 50%"><%out.println((String) (countryList[i].getEntityName()));%></td>
</tr>
<%}%>
</tbody>
</table>
</div>
For a good practice you have to repeat the row not the table.
I am attempting to scrape the following html:
<table>
<tr>
<td class="cellRight" style="cursor:pointer;">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="cellRight" style="border:0;color:#0066CC;"
title="View summary" width="70%">92%</td>
<td class="cellRight" style="border:0;" width="30%">
</td>
</tr>
</table>
</td>
</tr>
<tr class="listroweven">
<td class="cellLeft" nowrap><span class="categorytab" onclick=
"showAssignmentsByMPAndCourse('08/03/2015','58100:6');" title=
"Display Assignments for Art 5 with Ms. Martinho"><span style=
"text-decoration: underline">58100/6 - Art 5 with Ms.
Martinho</span></span></td>
<td class="cellLeft" nowrap>
Martinho, Suzette<br>
<b>Email:</b> <a href="mailto:smartinho#mtsd.us" style=
"text-decoration:none"><img alt="" border="0" src=
"/genesis/images/labelIcon.png" title=
"Send e-mail to teacher"></a>
</td>
<td class="cellRight" onclick=
"window.location.href = '/genesis/parents?tab1=studentdata&tab2=gradebook&tab3=coursesummary&studentid=100916&action=form&courseCode=58100&courseSection=6&mp=MP4';"
style="cursor:pointer;">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="cellCenter"><span style=
"font-style:italic;color:brown;font-size: 8pt;">No
Grades</span></td>
</tr>
</table>
</td>
</tr>
<tr class="listrowodd">
<td class="cellLeft" nowrap><span class="categorytab" onclick=
"showAssignmentsByMPAndCourse('08/03/2015','58200:10');" title=
"Display Assignments for Family and Consumer Sciences 5 with Sheerin">
<span style="text-decoration: underline">58200/10 - Family and
Consumer Sciences 5 with Sheerin</span></span></td>
<td class="cellLeft" nowrap>
Sheerin, Susan<br>
<b>Email:</b> <a href="mailto:ssheerin#mtsd.us" style=
"text-decoration:none"><img alt="" border="0" src=
"/genesis/images/labelIcon.png" title=
"Send e-mail to teacher"></a>
</td>
<td class="cellRight" style="cursor:pointer;">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="cellCenter"><span style=
"font-style:italic;color:brown;font-size: 8pt;">No
Grades</span></td>
</tr>
</table>
</td>
</tr>
</table>
I am trying to extract the values for the student's grades, and if no grades are present, the value "no grades" which will be present in the html if this is the case. However, when I do a select request such as the following:
doc.select("[class=cellRight]")
I get an output where all of the grade values are listed twice (because they are nested within two elements containing the [class=cellRight] distinguisher, and the normal amount of "no grades" listing. So my question is, how can I only select the innermost child in a document which contains the distinguisher [class=cellRight]? (I have already dealt with the issue of a blank value) All help is appreciated!!
There are many possibilities to to this.
One would be this: Test for each "cellRight" element all its parents if they also carry that class. Discard if you find it:
List<Element> keepList = new ArrayList<>();
Elements els = doc.select(".cellRight");
for (Element el : els){
boolean keep = true;
for (Element parentEl : el.parents()){
if (parentEl.hasClass("cellRight")){
//parent has class as well -> discard!
keep = false;
break;
}
}
if (keep){
keepList.add(el);
}
}
//keepList now contains inner most elements with your class
Note that this is written without compiler and out of my head. There might be spelling/syntax errors.
Other note. your use of "[class=cellRight]" works well only if there is this single class. With multiple clsses in random order (which is totally to be expected) it is better to use the dot syntax ".cellRight"
I am new to Jsoup Library. I have html like this.
<tr class="srrowns">
<td class="num"> <a name="y2015"> </a> 1 </td>
<td nowrap>CVE-2015-4004</td>
<td>119</td>
<td class="num"> <b style="color:red"> </b> </td>
<td> DoS Overflow +Info </td>
<td>2015-06-07</td>
<td>2015-06-08</td>
<td>
<div class="cvssbox" style="background-color:#ff8000">
8.5
</div></td>
<td align="center">None</td>
<td align="center">Remote</td>
<td align="center">Low</td>
<td align="center">Not required</td>
<td align="center">Partial</td>
<td align="center">None</td>
<td align="center">Complete</td>
</tr>
when I run element.select("td"), it is returning
<td class="num"> <a name="y2015"> </a> 1 </td>
<td nowrap>CVE-2015-4004</td>
<td>119</td>
<td class="num"> <b style="color:red"> </b> </td>
<td> DoS Overflow +Info </td>
<td>2015-06-07</td>
<td>2015-06-08</td>
<td>
<div class="cvssbox" style="background-color:#ff8000">
8.5
</div></td>
<td align="center">None</td>
<td align="center">Remote</td>
<td align="center">Low</td>
<td align="center">Not required</td>
<td align="center">Partial</td>
<td align="center">Complete</td>
Obivously, deleting <td align="center">None</td> before "Complete". Is there any way that I could get all items from Jsoup Selector?
My code looks something like this in Scala.
val connection = Jsoup.connect(url).get()
val treelist = connection.select("tr.srrowns:contains(CVE-2015-4001)")
val tree = tree.select("td")
I just saw that Jsoup select is implemented using LinkedHashSet. My goal is to extract text from each tags using Jsoup.text().Is there a workaround for this or do I have to write a parser just for getting all nodes(including duplicates)?
Thank you very much.
Try this CSS selector:
tr.srrowns:has(td:contains(CVE-2015-4004)) > td
DEMO
http://try.jsoup.org/~vAgiHQY6TIJ5MSUzR-m_Y1GD5_U
SAMPLE CODE
var cve = "CVE-2015-4004";
val doc = Jsoup.connect(url).get()
val tds = doc.select("tr.srrowns:has(td:contains(" + cve + ")) > td")
for( var td <- tds ){
println( td.text() );
}
I am working on a scenario, where I create a new user. Since, I will be creating tons of new users for regression, I am assigning a time-stamp to distinguish each user id. For instance, ABC_2015020615215, ABC_2015020615222, etc.
The code for creating and sending a user with the time-stamp:
public static String now = "_" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
// user
public static String user_id = PropertyLoader.loadProperty("USER_ID") + now;
Next scenario: I need to grab the last user added, and insert into a new text field, on a different page. (remaining on the same driver session).
This code creates a new user:
//enter user id in the text field and add a new user
driver.findElement(By.name(PvtConstants.ADD_USER_ID_TEXT_FIELD)).sendKeys(user_id);
This is a new text field, where I need to insert the user that was added in the previous step. I am not able to figure that out. Thanks in advance for the help!
driver.findElement(By.id(PvtConstants.READ_USER_ADVANCED_FILTER_USER_SEARCH_FIELD));
HTML:
<table class="table smallInput dataTable" id="dataTableAdvertisers" ">
<thead>
<tr role="row" style="height: 0px;">
<th class="sorting_asc" tabindex="0" "></th>
<th class="sorting" tabindex="0" "></th>
<th class="sorting" tabindex="0" "></th>
</tr>
</thead>
<tbody role="alert" aria-live="polite" aria-relevant="all">
<tr class="odd">
<td class="">
Advertiser_20150204130817</td>
<td class="">---</td>
<td class="">---</td>
<td class="">---</td>
<td class="">---</td>
</tr><tr class="even">
<td class="">
Advertiser_20150204130923</td>
<td class="">---</td>
<td class="">---</td>
<td class="">---</td><td class="">---</td>
</tr><tr class="odd">
</tbody>
</table>
I will use a Xpath and with passing the user_id as parameter.
Note: this xpath matches the any a tag with the text supplied by the user_id variable which in your case is the lastly instantiated variable with timestamp.
By byXpath = By.xpath("//a[.='" + user_id + "']");
WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(byXpath));
String newUser = myDynamicElement.getText().trim();
//send newUser this to the search field
in jsp
<table width="100%" id='table1' border="0" cellspacing="2" cellpadding="2">
<tr class="tab-highlighted-2">
<td class="tab-highlighted-2" width="10%">
<div align="left">Project ID</div>
</td>
<td class="tab-highlighted-2" width="10%">
<div align="left">Project Name</div>
</td>
<td class="tab-highlighted-2" width="20%">
<div align="left">Cost Center</div>
</td>
<td class="tab-highlighted-2" width="20%">
<div align="left">Manager</div>
</td>
</tr>
<tr class="bg-row1">
<c:forEach items="${resultList}" var="resultList">
<td class="td-highlighted-2">
<div align="left">${resultList.Projid}</div>
</td>
<td class="td-highlighted-2">
<div align="left">${resultList.Projname}</div>
</td>
<td class="td-highlighted-2">
<div align="left">${resultList.Cost}</div>
</td>
<td class="td-highlighted-2">
<div align="left">${resultList.Manager}</div>
</td>
</tr>
</table>
in dao
public final class SearchProjDAO
{
private static InitialContext context;
String CLASS_NAME="DBConnectionFactory";
public ArrayList submitProjectDetails(SearchProjVO searchprojVO)
{
ArrayList ar = new ArrayList();
String methodname="createConnection";
Connection conn = null;
PreparedStatement psmt;
try {
System.out.println("in DAO");
System.out.println("searchprojVO id=="+searchprojVO.getProjid());
conn = DBConnection.getJNDIConnection();
ResultSet rs = null;
String query="select * from CR_EMPLOYEE_DETAILS";if(searchprojVO.getProjid()!=null || searchprojVO.getProjname()!=null || searchprojVO.getManager()!=null)
query=query+" where ";
if(searchprojVO.getProjid()!=null)
query=query+" PROJ_ID="+searchprojVO.getProjid();
if(searchprojVO.getProjname()!=null)
query=query+"PROJ_NAME="+searchprojVO.getProjname();
if(searchprojVO.getCost()!=null);
query=query+"PROJ_COST="+searchprojVO.getCost();
if(searchprojVO.getManager()!=null)
query=query+"PROJ_MANAGER="+searchprojVO.getManager();
psmt= conn.prepareStatement(query);
rs=psmt.executeQuery();
while(rs.next())
{
SearchProjVO projVO = new SearchProjVO();
projVO.setProjid(rs.getString("PROJ_ID"));
projVO.setManager(rs.getString("PROJ_NAME"));
projVO.setProjname(rs.getString("PROJ_COST"));
projVO.setManager(rs.getString("PROJ_MANAGER"));
ar.add(projVO);
}
System.out.println("conn==="+conn);
} catch (Exception e) {
e.printStackTrace(System.err);
}
return ar;
}
}
I spot several mistakes:
Here,
<c:forEach items="${resultList}" var="resultList">
You're overriding the list value with the value of the list item everytime. Don't do that. Give the var an unique variable name. The entity name is the most straightforward choice.
<c:forEach items="${resultList}" var="project">
Note that I'd personally also rename the nothing-saying resultList to a more self-explaining projects.
And here,
<tr class="bg-row1">
<c:forEach items="${resultList}" var="project">
the flow is wrong. You should print a new row inside each loop. Swap them.
<c:forEach items="${resultList}" var="project">
<tr class="bg-row1">
And here,
${resultList.Projid}
${resultList.Projname}
${resultList.Cost}
${resultList.Manager}
the property names must start with lowercase (and fix the item name to be the same as in var).
${project.projid}
${project.projname}
${project.cost}
${project.manager}
Note that I'd personally also get rid of proj prefix in some property names.
And finally you're forgotten a closing </c:forEach>.
</tr>
</c:forEach>
Unrelated to the concrete problem, your JDBC code is sensitive to SQL injection attacks and is leaking resources. Fix it as well.