Skip to content

Commit

Permalink
correcting new field to search by job ids range
Browse files Browse the repository at this point in the history
  • Loading branch information
bnfklm committed Oct 6, 2016
1 parent 32ae3df commit 095fa0d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1092,17 +1092,33 @@ private HarvestStatusQueryBuilder buildSqlQuery(HarvestStatusQuery query, boolea
sq.addParameter(java.sql.Date.class, new java.sql.Date(cal.getTimeInMillis()));
}

Long jobIdStart = query.getJobIdStart();
if (jobIdStart != null) {
sql.append(" AND jobs.job_id >= ?");
sq.addParameter(Long.class, jobIdStart);
List<String> jobIdRangeIds = query.getPartialJobIdRangeAsList(false);
List<String> jobIdRanges = query.getPartialJobIdRangeAsList(true);
if (!jobIdRangeIds.isEmpty()) {
StringBuilder ids = new StringBuilder();
for(String id : jobIdRangeIds) {
//id
ids.append(',');
ids.append(id);
}
sql.append(" AND (jobs.job_id IN (?)");
// we remove the first comma
sq.addParameter(String.class, ids.deleteCharAt(0));
}

Long jobIdEnd = query.getJobIdEnd();
if (jobIdEnd != null) {
sql.append(" AND jobs.job_id <= ?");
sq.addParameter(Long.class, jobIdEnd);
if(!jobIdRanges.isEmpty()) {
String andOr = "AND";
if (!jobIdRangeIds.isEmpty()) {
andOr = "OR";
}
//TODO
sql.append(" AND jobs.job_id >= ?");

//sq.addParameter(Long.class, jobIdStart);
}
if (!jobIdRangeIds.isEmpty()) {
sql.append(")");
}


if (!count) {
sql.append(" ORDER BY jobs.job_id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.ServletRequest;
Expand Down Expand Up @@ -114,10 +116,9 @@ public static enum UI_FIELD {
START_DATE(""),
/** The harvest end date. No default. */
END_DATE(""),
/** The first job id. No default. */
JOB_ID_START(""),
/** The last job id. No default. */
JOB_ID_END(""),
/** The job id range : list of job ids or range separated by commas, for instance: 2,4,8-14. No default. */
JOB_ID_RANGE(""),


/**
* The number of results on each page. The default is read from the setting
Expand Down Expand Up @@ -192,10 +193,9 @@ public String getValue(ServletRequest req) {
private Date startDate;
/** The end date. */
private Date endDate;
/** The first job id. */
private Long jobIdStart;
/** The last job id. */
private Long jobIdEnd;
/** The job id range : list of job ids or range separated by commas, for instance: 2,4,8-14. No default. */
private String jobIdRange;
private List<String> jobIdRangeList;
/** The sort order. */
private SORT_ORDER sortingOrder;
/** The page-size. */
Expand All @@ -209,7 +209,7 @@ public String getValue(ServletRequest req) {
* Builds a default query that will select all jobs.
*/
public HarvestStatusQuery() {

jobIdRangeList = new ArrayList<String>();
}

/**
Expand All @@ -221,6 +221,7 @@ public HarvestStatusQuery() {
public HarvestStatusQuery(long harvestId, long harvestRunNumber) {
this.harvestId = harvestId;
this.harvestRunNumber = harvestRunNumber;
jobIdRangeList = new ArrayList<String>();
}

/**
Expand Down Expand Up @@ -284,18 +285,31 @@ public HarvestStatusQuery(ServletRequest req) {
}
}

String jobIdStartStr = UI_FIELD.JOB_ID_START.getValue(req);
try {
this.jobIdStart = Long.parseLong(jobIdStartStr);
} catch (NumberFormatException e) {
this.jobIdStart = null;
}

String jobIdEndStr = UI_FIELD.JOB_ID_END.getValue(req);
try {
this.jobIdEnd = Long.parseLong(jobIdEndStr);
} catch (NumberFormatException e) {
this.jobIdEnd = null;
jobIdRangeList = new ArrayList<String>();
String jobIdRange = UI_FIELD.JOB_ID_RANGE.getValue(req);
if(!jobIdRange.isEmpty()) {
try {
String[] splittedRange = jobIdRange.replaceAll("\\s+","").split(",");
for(String s : splittedRange) {
if(s.contains("-")) {
//if it's a range eg 11-27
String[] range = s.split("-");
if(s.length() != 2) {
throw new ArgumentNotValid("The range for job ids is incorrect!");
}
//check if it's a number
Long.parseLong(range[0]);
Long.parseLong(range[1]);
} else {
//check if it's a number
Long.parseLong(s);
}
jobIdRangeList.add(s);
}
} catch (NumberFormatException e) {
this.jobIdRange = null;
throw new ArgumentNotValid("Somes values in job ids range are not correct numbers", e);
}
}

String orderStr = UI_FIELD.JOB_ID_ORDER.getValue(req);
Expand Down Expand Up @@ -385,37 +399,29 @@ public long getEndDate() {
}

/**
* @return the first job id to search from
* @return the job ids range as String
*/
public Long getJobIdStart() {
return jobIdStart;
public String getJobIdRange() {
if(jobIdRange == null) {
return "";
}
return jobIdRange;
}

/**
* @return the last job id to search to
* return only the ids or only the range
* if isRange is true : 2,3,5-9,14-18 -> 5-9,14-18
* if isRange is false : 2,3,5-9,14-18 -> 2,3
* @return the job ids range as List, only the ids or only the ranges
*/
public Long getJobIdEnd() {
return jobIdEnd;
}

/**
* @return the first job id to search from
*/
public String getJobIdStartAsString() {
if (jobIdStart == null) {
return "";
}
return jobIdStart.toString();
}

/**
* @return the last job id to search to
*/
public String getJobIdEndAsString() {
if (jobIdEnd == null) {
return "";
}
return jobIdEnd.toString();
public List<String> getPartialJobIdRangeAsList(boolean isRange) {
List<String> list = new ArrayList<String>();
for(String s : jobIdRangeList) {
if(s.contains("-") == isRange) {
list.add(s);
}
}
return list;
}

/**
Expand Down
12 changes: 3 additions & 9 deletions harvester/history-gui/src/main/webapp/Harveststatus-alljobs.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,12 @@ setupCalendar("<%=HarvestStatusQuery.UI_FIELD.END_DATE%>", "<%=HarvestStatusQuer
</fmt:param>

<fmt:param>
<input name="<%=HarvestStatusQuery.UI_FIELD.JOB_ID_START%>"
id="<%=HarvestStatusQuery.UI_FIELD.JOB_ID_START%>"
<input name="<%=HarvestStatusQuery.UI_FIELD.JOB_ID_RANGE%>"
id="<%=HarvestStatusQuery.UI_FIELD.JOB_ID_RANGE%>"
size="10"
value="<%=query.getJobIdStartAsString()%>"/>
value="<%=query.getJobIdRange()%>"/>
</fmt:param>

<fmt:param>
<input name="<%=HarvestStatusQuery.UI_FIELD.JOB_ID_END%>"
id="<%=HarvestStatusQuery.UI_FIELD.JOB_ID_END%>"
size="10"
value="<%=query.getJobIdEndAsString()%>"/>
</fmt:param>
</fmt:message>
<br/>
<fmt:message key="status.job.filters.group2">
Expand Down

0 comments on commit 095fa0d

Please sign in to comment.