Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mobi.chouette.dao.iev;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -47,10 +48,17 @@ public List<Job> findByReferential(String referential, Job.STATUS[] status) {
if(status.length != 0) {
statusPredicate = root.get(Job_.status).in(Arrays.asList(status));
}

Predicate referentialPredicate = builder.equal(root.get(Job_.referential),
referential);
criteria.where(builder.and( referentialPredicate, statusPredicate));
List<Predicate> predicates = new ArrayList<>();
predicates.add(statusPredicate);

if (referential != null) {
Predicate referentialPredicate = builder.equal(root.get(Job_.referential),
referential);
predicates.add(referentialPredicate);
}

criteria.where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

criteria.orderBy(builder.asc(root.get(Job_.created)));
TypedQuery<Job> query = em.createQuery(criteria);
result = query.getResultList();
Expand All @@ -71,15 +79,23 @@ public List<Job> findByReferentialAndAction(String referential, String action[],
if(status.length != 0) {
statusPredicate = root.get(Job_.status).in(Arrays.asList(status));
}
Predicate referentialPredicate = builder.equal(root.get(Job_.referential),
referential);

if(action.length != 0) {
Predicate actionPredicate = root.get(Job_.action).in(Arrays.asList(action));
criteria.where( builder.and(referentialPredicate, actionPredicate,statusPredicate ));
} else {
criteria.where( builder.and(referentialPredicate, statusPredicate ));

List<Predicate> predicates = new ArrayList<>();
predicates.add(statusPredicate);

if (action.length != 0) {
Predicate actionPredicate = root.get(Job_.action).in(Arrays.asList(action));
predicates.add(actionPredicate);
}

if (referential != null) {
Predicate referentialPredicate = builder.equal(root.get(Job_.referential),
referential);
predicates.add(referentialPredicate);
}

criteria.where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

criteria.orderBy(builder.asc(root.get(Job_.created)));
TypedQuery<Job> query = em.createQuery(criteria);
result = query.getResultList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,9 @@ public JobService getJobService(Long id) throws ServiceException {
}

public List<JobService> jobs(String referential, String action[], final Long version, Job.STATUS[] status) throws ServiceException {
validateReferential(referential);

if (referential!=null) {
validateReferential(referential);
}
List<Job> jobs = null;
if (action == null) {
jobs = jobDAO.findByReferential(referential,status);
Expand Down
13 changes: 9 additions & 4 deletions mobi.chouette.ws/src/main/java/mobi/chouette/ws/JobInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
@NoArgsConstructor
@XmlRootElement(name = "job")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "id", "referential", "action", "type", "created", "started", "updated", "status", "linkInfos",
"actionParameters" })
@XmlType(propOrder = {"id", "referential", "action", "type", "created", "started", "updated", "status", "linkInfos",
"actionParameters"})
// @XmlSeeAlso({NeptuneImportParameters.class,
// NeptuneExportParameters.class,
// GtfsImportParameters.class,
Expand Down Expand Up @@ -80,6 +80,10 @@ public class JobInfo implements ServiceConstants {
private AbstractParameter actionParameters;

public JobInfo(JobService job, boolean addLink, UriInfo uriInfo) throws ServiceException {
this(job, addLink, true, uriInfo);
}

public JobInfo(JobService job, boolean addLink, boolean addActionParameters, UriInfo uriInfo) throws ServiceException {
id = job.getId();
referential = job.getReferential();
action = job.getAction();
Expand All @@ -89,8 +93,9 @@ public JobInfo(JobService job, boolean addLink, UriInfo uriInfo) throws ServiceE
updated = job.getUpdated();
status = STATUS.valueOf(job.getStatus().name());

actionParameters = job.getActionParameter();

if (addActionParameters) {
actionParameters = job.getActionParameter();
}
if (addLink) {
linkInfos = new ArrayList<>();
for (Link link : job.getJob().getLinks()) {
Expand Down
19 changes: 15 additions & 4 deletions mobi.chouette.ws/src/main/java/mobi/chouette/ws/RestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,13 @@ public Response download(@PathParam("ref") String referential, @PathParam("id")
@Path("/{ref}/jobs")
@Produces({ MediaType.APPLICATION_JSON })
public Response jobs(@PathParam("ref") String referential,
@DefaultValue("0") @QueryParam("version") final Long version, @QueryParam("action") final String[] action, @QueryParam("status") final Job.STATUS[] status) {
@DefaultValue("0") @QueryParam("version") final Long version, @QueryParam("action") final String[] action,
@QueryParam("status") final Job.STATUS[] status, @DefaultValue("true") @QueryParam("addActionParameters") boolean addActionParameters) {

try {
log.info(Color.CYAN + "Call jobs referential = " + referential + ", action = " + StringUtils.join(action,',')+", status = " + StringUtils.join(status,',') + ", version = "
+ version + Color.NORMAL);
String refDescription = referential == null ? "all referentials" : "referential = " + referential;
log.info(Color.CYAN + "Call jobs = " + refDescription + ", action = " + StringUtils.join(action, ',') + ", status = " + StringUtils.join(status, ',') + ", version = "
+ version + Color.NORMAL);

// create jobs listing
List<JobInfo> result = new ArrayList<>();
Expand All @@ -275,7 +277,7 @@ public Response jobs(@PathParam("ref") String referential,
{
List<JobService> jobServices = jobServiceManager.jobs(referential, action, version,status);
for (JobService jobService : jobServices) {
JobInfo jobInfo = new JobInfo(jobService, true, uriInfo);
JobInfo jobInfo = new JobInfo(jobService, true,addActionParameters, uriInfo);
result.add(jobInfo);
}
jobServices.clear();
Expand All @@ -300,6 +302,15 @@ public Response jobs(@PathParam("ref") String referential,
}
}

// jobs listing for all referentials
@GET
@Path("/jobs")
@Produces({MediaType.APPLICATION_JSON})
public Response jobs(@DefaultValue("0") @QueryParam("version") final Long version, @QueryParam("action") final String[] action,
@QueryParam("status") final Job.STATUS[] status, @DefaultValue("true") @QueryParam("addActionParameters") boolean addActionParameters) {
return jobs(null, version, action, status, addActionParameters);
}

// view scheduled job
@GET
@Path("/{ref}/scheduled_jobs/{id}")
Expand Down