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 30aa23a commit 303e232
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
import org.dcm4che3.json.JSONWriter;
import org.dcm4che3.ws.rs.MediaTypes;
import org.dcm4chee.arc.diff.DiffService;
import org.dcm4chee.arc.entity.AttributesBlob;
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 @@ -63,7 +63,6 @@
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 Down Expand Up @@ -174,10 +173,14 @@ null, deviceName, status(), batchID, null, null, null, null),
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();
if (diffTask == null)
return Response.status(Response.Status.NOT_FOUND).build();

return Response.ok(entity(diffTask.getDiffTaskAttributes())).build();
if (diffTask.getMatches() == 0)
return Response.noContent().build();

return Response.ok(entity(diffService.getDiffTaskAttributes(diffTask, parseInt(offset), parseInt(limit))))
.build();
}

private Output selectMediaType(String accept) {
Expand Down Expand Up @@ -248,13 +251,13 @@ private static boolean isCSV(MediaType type) {
abstract Object entity(final List<DiffTask> tasks);
}

private StreamingOutput entity(Collection<DiffTaskAttributes> diffTaskAttributes) {
private StreamingOutput entity(List<byte[]> diffTaskAttributes) {
return output -> {
try (JsonGenerator gen = Json.createGenerator(output)) {
JSONWriter writer = new JSONWriter(gen);
gen.writeStartArray();
for (DiffTaskAttributes diffTaskAttributes1 : diffTaskAttributes)
writer.write(diffTaskAttributes1.getAttributes());
for (byte[] diffTaskAttributesEncoded : diffTaskAttributes)
writer.write(AttributesBlob.decodeAttributes(diffTaskAttributesEncoded, null));
gen.writeEnd();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ public interface DiffService {
long countDiffTasks(Predicate matchQueueMessage, Predicate matchDiffTask);

DiffTask getDiffTask(long taskPK);

List<byte[]> getDiffTaskAttributes(DiffTask diffTask, int offset, int limit);
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,12 @@ private HibernateQuery<DiffTask> createQuery(
public DiffTask getDiffTask(long taskPK) {
return em.find(DiffTask.class, taskPK);
}

public List<byte[]> getDiffTaskAttributes(DiffTask diffTask, int offset, int limit) {
return em.createNamedQuery(DiffTaskAttributes.FIND_BY_DIFF_TASK, byte[].class)
.setParameter(1, diffTask)
.setFirstResult(offset)
.setMaxResults(limit)
.getResultList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public DiffTask getDiffTask(long taskPK) {
return ejb.getDiffTask(taskPK);
}

@Override
public List<byte[]> getDiffTaskAttributes(DiffTask diffTask, int offset, int limit) {
return ejb.getDiffTaskAttributes(diffTask, offset, limit);
}

private QueueMessage.Status check(String prompt, int failures, QueueMessage.Status status, StringBuilder sb) {
if (failures == 0)
return status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@
*/
@Entity
@Table(name = "diff_task_attrs")
@NamedQueries({
@NamedQuery(name = DiffTaskAttributes.FIND_BY_DIFF_TASK,
query = "select o.attributesBlob from DiffTaskAttributes o " +
"where o.diffTask=?1")
})
public class DiffTaskAttributes {

public static final String FIND_BY_DIFF_TASK = "DiffTaskAttributes.findByDiffTask";

@Id
@Column(name="dicomattrs_fk")
private Long pk;
Expand Down

0 comments on commit 303e232

Please sign in to comment.