Skip to content

Commit

Permalink
RESTful service to get result of Compare Studies Task #1305
Browse files Browse the repository at this point in the history
  • Loading branch information
vrindanayak committed Mar 28, 2018
1 parent 511a6f1 commit bdad9e7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@

package org.dcm4chee.arc.diff.rs;

import org.dcm4che3.net.Device;
import org.dcm4che3.json.JSONWriter;
import org.dcm4che3.ws.rs.MediaTypes;
import org.dcm4chee.arc.diff.DiffService;
import org.dcm4chee.arc.entity.DiffTask;
import org.dcm4chee.arc.entity.DiffTaskAttributes;
import org.dcm4chee.arc.entity.QueueMessage;
import org.dcm4chee.arc.query.util.MatchTask;
import org.jboss.resteasy.annotations.cache.NoCache;
Expand All @@ -57,14 +58,12 @@
import javax.json.stream.JsonGenerator;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Pattern;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
Expand All @@ -78,9 +77,6 @@
public class DiffTaskRS {
private static final Logger LOG = LoggerFactory.getLogger(DiffTaskRS.class);

@Inject
private Device device;

@Inject
private DiffService diffService;

Expand Down Expand Up @@ -171,6 +167,19 @@ null, deviceName, status(), batchID, null, null, null, null),
comparefields, createdTime, updatedTime)));
}

@GET
@NoCache
@Path("/{taskPK}/studies")
@Produces("application/dicom+json,application/json")
public Response getDiffTaskResult(@PathParam("taskPK") long taskPK) {
logRequest();
DiffTask diffTask = diffService.getDiffTask(taskPK);
if (diffTask.getQueueMessage().getStatus() == QueueMessage.Status.COMPLETED)
return diffTask.getMatches() == 0 ? Response.noContent().build() : Response.ok("[]").build();

return Response.ok(entity(diffTask.getDiffTaskAttributes())).build();
}

private Output selectMediaType(String accept) {
Stream<MediaType> acceptableTypes = httpHeaders.getAcceptableMediaTypes().stream();
if (accept != null) {
Expand Down Expand Up @@ -239,6 +248,18 @@ private static boolean isCSV(MediaType type) {
abstract Object entity(final List<DiffTask> tasks);
}

private StreamingOutput entity(Collection<DiffTaskAttributes> diffTaskAttributes) {
return output -> {
try (JsonGenerator gen = Json.createGenerator(output)) {
JSONWriter writer = new JSONWriter(gen);
gen.writeStartArray();
for (DiffTaskAttributes diffTaskAttributes1 : diffTaskAttributes)
writer.write(diffTaskAttributes1.getAttributes());
gen.writeEnd();
}
};
}

private void logRequest() {
LOG.info("Process GET {} from {}@{}", request.getRequestURI(),
request.getRemoteUser(), request.getRemoteHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ public interface DiffService {
List<DiffTask> listDiffTasks(Predicate matchQueueMessage, Predicate matchDiffTask, int offset, int limit, String orderby);

long countDiffTasks(Predicate matchQueueMessage, Predicate matchDiffTask);

DiffTask getDiffTask(long taskPK);
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,8 @@ private HibernateQuery<DiffTask> createQuery(
.from(QDiffTask.diffTask)
.where(matchDiffTask, QDiffTask.diffTask.queueMessage.in(queueMsgQuery));
}

public DiffTask getDiffTask(long taskPK) {
return em.find(DiffTask.class, taskPK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ private Outcome toOutcome(DiffSCU diffSCU) {
return new Outcome(status, sb.toString());
}

@Override
public DiffTask getDiffTask(long taskPK) {
return ejb.getDiffTask(taskPK);
}

private QueueMessage.Status check(String prompt, int failures, QueueMessage.Status status, StringBuilder sb) {
if (failures == 0)
return status;
Expand All @@ -132,12 +137,11 @@ private QueueMessage.Status check(String prompt, int failures, QueueMessage.Stat

private DiffContext toDiffContext(DiffTask diffTask, HttpServletRequestInfo httpServletRequestInfo)
throws ConfigurationException {
DiffContext ctx = new DiffContext()
return new DiffContext()
.setLocalAE(device.getApplicationEntity(diffTask.getLocalAET(), true))
.setPrimaryAE(aeCache.get(diffTask.getPrimaryAET()))
.setSecondaryAE(aeCache.get(diffTask.getSecondaryAET()))
.setQueryString(diffTask.getQueryString())
.setHttpServletRequestInfo(httpServletRequestInfo);
return ctx;
}
}

0 comments on commit bdad9e7

Please sign in to comment.