Skip to content
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
Expand Up @@ -259,8 +259,9 @@ protected static int handleGet(HttpServletRequest httpRequest, HttpServletRespon
annotationCount = false;
//ml added for project download
boolean includeAims = "true".equalsIgnoreCase(httpRequest.getParameter("includeAims"));
boolean includeFiles = "true".equalsIgnoreCase(httpRequest.getParameter("includeFiles"));
if (returnStream(httpRequest)) {
DownloadUtil.streamProject(httpResponse, projectReference, username, sessionID, searchFilter, subjectUIDs, includeAims);
DownloadUtil.streamProject(httpResponse, projectReference, username, sessionID, searchFilter, subjectUIDs, includeAims, includeFiles);
// DownloadUtil.downloadProject(true, httpResponse, projectReference, username, sessionID, searchFilter, subjectUIDs, includeAims);
}else if (returnConnected(httpRequest)) { //ml connected data for deletion
//need to get all subjects within and return their connected projects
Expand Down Expand Up @@ -353,6 +354,7 @@ else if (projectReference.projectID.equalsIgnoreCase(EPADConfig.getParamValue("U
} else if (HandlerUtil.matchesTemplate(ProjectsRouteTemplates.SUBJECT, pathInfo)) {
SubjectReference subjectReference = SubjectReference.extract(ProjectsRouteTemplates.SUBJECT, pathInfo);
boolean includeAims = "true".equalsIgnoreCase(httpRequest.getParameter("includeAims"));
boolean includeFiles = "true".equalsIgnoreCase(httpRequest.getParameter("includeFiles"));
boolean includeAnnotationStatus = "true".equalsIgnoreCase(httpRequest.getParameter("includeAnnotationStatus"));
//ml multiple subjects
if (subjectReference.subjectID.contains(",") && returnStream(httpRequest) ) {
Expand All @@ -371,7 +373,7 @@ else if (projectReference.projectID.equalsIgnoreCase(EPADConfig.getParamValue("U
}else if (returnFile(httpRequest)) {
DownloadUtil.downloadSubject(false, httpResponse, subjectReference, username, sessionID, searchFilter, studyUIDs, includeAims);
} else if (returnStream(httpRequest)) {
DownloadUtil.streamSubject(httpResponse, subjectReference, username, sessionID, searchFilter, studyUIDs, includeAims);
DownloadUtil.streamSubject(httpResponse, subjectReference, username, sessionID, searchFilter, studyUIDs, includeAims, includeFiles);
// DownloadUtil.downloadSubject(true, httpResponse, subjectReference, username, sessionID, searchFilter, studyUIDs, includeAims);
} else {
EPADSubject subject = epadOperations.getSubjectDescription(subjectReference, username, sessionID, includeAnnotationStatus);
Expand Down Expand Up @@ -399,6 +401,7 @@ else if (projectReference.projectID.equalsIgnoreCase(EPADConfig.getParamValue("U
} else if (HandlerUtil.matchesTemplate(ProjectsRouteTemplates.STUDY, pathInfo)) {
StudyReference studyReference = StudyReference.extract(ProjectsRouteTemplates.STUDY, pathInfo);
boolean includeAims = "true".equalsIgnoreCase(httpRequest.getParameter("includeAims"));
boolean includeFiles = "true".equalsIgnoreCase(httpRequest.getParameter("includeFiles"));
boolean includeAnnotationStatus = "true".equalsIgnoreCase(httpRequest.getParameter("includeAnnotationStatus"));
if (returnConnected(httpRequest)) { //ml connected data for deletion
log.info("get projects for study " + studyReference.studyUID );
Expand All @@ -418,7 +421,7 @@ else if (projectReference.projectID.equalsIgnoreCase(EPADConfig.getParamValue("U
if (studyReference.studyUID.contains(","))
DownloadUtil.downloadStudies(true, httpResponse, studyReference.studyUID, username, sessionID, includeAims, studyReference.projectID);
else
DownloadUtil.streamStudy(httpResponse, studyReference, username, sessionID, searchFilter, studyUIDs, includeAims);
DownloadUtil.streamStudy(httpResponse, studyReference, username, sessionID, searchFilter, studyUIDs, includeAims, includeFiles);

// DownloadUtil.downloadStudy(true, httpResponse, studyReference, username, sessionID, searchFilter, seriesUIDs, includeAims);
} else {
Expand Down Expand Up @@ -460,6 +463,7 @@ else if (projectReference.projectID.equalsIgnoreCase(EPADConfig.getParamValue("U
} else if (HandlerUtil.matchesTemplate(ProjectsRouteTemplates.SERIES, pathInfo)) {
SeriesReference seriesReference = SeriesReference.extract(ProjectsRouteTemplates.SERIES, pathInfo);
boolean includeAims = "true".equalsIgnoreCase(httpRequest.getParameter("includeAims"));
boolean includeFiles = "true".equalsIgnoreCase(httpRequest.getParameter("includeFiles"));
boolean includeAnnotationStatus = "true".equalsIgnoreCase(httpRequest.getParameter("includeAnnotationStatus"));
if (returnConnected(httpRequest)) { //ml connected data for deletion
log.info("get projects for study " + seriesReference.studyUID );
Expand All @@ -479,7 +483,7 @@ else if (projectReference.projectID.equalsIgnoreCase(EPADConfig.getParamValue("U
if (seriesReference.seriesUID.contains(","))
DownloadUtil.downloadSeries(true, httpResponse, seriesReference.seriesUID, username, sessionID, includeAims);
else
DownloadUtil.streamSeries(httpResponse, seriesReference, username, sessionID, includeAims);
DownloadUtil.streamSeries(httpResponse, seriesReference, username, sessionID, includeAims, includeFiles);
// DownloadUtil.downloadSeries(true, httpResponse, seriesReference, username, sessionID, includeAims);
} else {
EPADSeries series = epadOperations.getSeriesDescription(seriesReference, username, sessionID, includeAnnotationStatus);
Expand Down Expand Up @@ -1834,8 +1838,9 @@ else if (returnJson(httpRequest))
statusCode = HttpServletResponse.SC_OK;

} else if (HandlerUtil.matchesTemplate(ProjectsRouteTemplates.PROJECT_FILE_LIST, pathInfo)) {
boolean allLevels = "false".equalsIgnoreCase(httpRequest.getParameter("topLevel"));
ProjectReference projectReference = ProjectReference.extract(ProjectsRouteTemplates.PROJECT_FILE_LIST, pathInfo);
EPADFileList files = epadOperations.getFileDescriptions(projectReference, username, sessionID, searchFilter, true);
EPADFileList files = epadOperations.getFileDescriptions(projectReference, username, sessionID, searchFilter, allLevels);
responseStream.append(files.toJSON());
statusCode = HttpServletResponse.SC_OK;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
import edu.stanford.epad.dtos.EPADAIM;
import edu.stanford.epad.dtos.EPADAIMList;
import edu.stanford.epad.dtos.EPADFile;
import edu.stanford.epad.dtos.EPADFileList;
import edu.stanford.epad.dtos.EPADImage;
import edu.stanford.epad.dtos.EPADImageList;
import edu.stanford.epad.dtos.EPADSeries;
Expand Down Expand Up @@ -1617,7 +1618,7 @@ private static String formatDate(Date date)
/***** Stream codes from Dev ***********/

public static Set<String> streamProject(HttpServletResponse httpResponse, ProjectReference projectReference, String username, String sessionID,
EPADSearchFilter searchFilter, String subjectUIDs, boolean includeAIMs) throws Exception
EPADSearchFilter searchFilter, String subjectUIDs, boolean includeAIMs, boolean includeFiles) throws Exception
{
log.info("Streaming project:" + projectReference.projectID + " includeAIMs:" + includeAIMs);
String downloadDirPath = EPADConfig.getEPADWebServerResourcesDir() + downloadDirName + "temp" + Long.toString(System.currentTimeMillis());
Expand Down Expand Up @@ -1810,6 +1811,45 @@ public static Set<String> streamProject(HttpServletResponse httpResponse, Projec
}
}
}
if (includeFiles)
{
List<EpadFile> files = projectOperations.getSeriesFiles(seriesReference.projectID, seriesReference.subjectID, seriesReference.studyUID, seriesReference.seriesUID);
for (EpadFile file: files) {
String name = file.getName();
File epadFile = new File(EPADConfig.getEPADWebServerResourcesDir() + getEpadFilePath(file));
if (!epadFile.exists()) continue;
String fileZipPath = seriesZipPath + "/" + name;
log.debug("Streaming file: " + fileZipPath);
try
{
zipout.putNextEntry(new ZipEntry(fileZipPath));
}
catch (Exception e)
{
log.warning("Error adding to zip file", e);
throw e;
}
BufferedInputStream fr;
try
{
fr = new BufferedInputStream(new FileInputStream(epadFile));

byte buffer[] = new byte[0xffff];
int b;
while ((b = fr.read(buffer)) != -1)
zipout.write(buffer, 0, b);

fr.close();
zipout.closeEntry();

}
catch (Exception e)
{
log.warning("Error closing zip file", e);
throw e;
}
}
}
}
}
}
Expand All @@ -1829,7 +1869,7 @@ public static Set<String> streamProject(HttpServletResponse httpResponse, Projec
}

public static void streamSubject(HttpServletResponse httpResponse, SubjectReference subjectReference, String username, String sessionID,
EPADSearchFilter searchFilter, String studyUIDs, boolean includeAIMs) throws Exception
EPADSearchFilter searchFilter, String studyUIDs, boolean includeAIMs, boolean includeFiles) throws Exception
{
log.info("Streaming projectID:" + subjectReference.projectID + " subject:" + subjectReference.subjectID);
String downloadDirPath = EPADConfig.getEPADWebServerResourcesDir() + downloadDirName + "temp" + Long.toString(System.currentTimeMillis());
Expand Down Expand Up @@ -2023,6 +2063,45 @@ public static void streamSubject(HttpServletResponse httpResponse, SubjectRefere
}
}
}
if (includeFiles)
{
List<EpadFile> files = projectOperations.getSeriesFiles(seriesReference.projectID, seriesReference.subjectID, seriesReference.studyUID, seriesReference.seriesUID);
for (EpadFile file: files) {
String name = file.getName();
File epadFile = new File(EPADConfig.getEPADWebServerResourcesDir() + getEpadFilePath(file));
if (!epadFile.exists()) continue;
String fileZipPath = seriesZipPath + "/" + name;
log.debug("Streaming file: " + fileZipPath);
try
{
zipout.putNextEntry(new ZipEntry(fileZipPath));
}
catch (Exception e)
{
log.warning("Error adding to zip file", e);
throw e;
}
BufferedInputStream fr;
try
{
fr = new BufferedInputStream(new FileInputStream(epadFile));

byte buffer[] = new byte[0xffff];
int b;
while ((b = fr.read(buffer)) != -1)
zipout.write(buffer, 0, b);

fr.close();
zipout.closeEntry();

}
catch (Exception e)
{
log.warning("Error closing zip file", e);
throw e;
}
}
}
}
}

Expand All @@ -2038,7 +2117,7 @@ public static void streamSubject(HttpServletResponse httpResponse, SubjectRefere
}
EPADFileUtils.deleteDirectoryAndContents(downloadDir);
}
public static void streamStudy(HttpServletResponse httpResponse, StudyReference studyReference, String username, String sessionID, EPADSearchFilter searchFilter, String seriesUIDs, boolean includeAIMs) throws Exception
public static void streamStudy(HttpServletResponse httpResponse, StudyReference studyReference, String username, String sessionID, EPADSearchFilter searchFilter, String seriesUIDs, boolean includeAIMs, boolean includeFiles) throws Exception
{
log.info("Streaming projectID:" + studyReference.projectID + " subject:" + studyReference.subjectID + " study:" + studyReference.studyUID);
String downloadDirPath = EPADConfig.getEPADWebServerResourcesDir() + downloadDirName + "temp" + Long.toString(System.currentTimeMillis());
Expand Down Expand Up @@ -2214,6 +2293,45 @@ public static void streamStudy(HttpServletResponse httpResponse, StudyReference
}
}
}
if (includeFiles)
{
List<EpadFile> files = projectOperations.getSeriesFiles(seriesReference.projectID, seriesReference.subjectID, seriesReference.studyUID, seriesReference.seriesUID);
for (EpadFile file: files) {
String name = file.getName();
File epadFile = new File(EPADConfig.getEPADWebServerResourcesDir() + getEpadFilePath(file));
if (!epadFile.exists()) continue;
String fileZipPath = seriesZipPath + "/" + name;
log.debug("Streaming file: " + fileZipPath);
try
{
zipout.putNextEntry(new ZipEntry(fileZipPath));
}
catch (Exception e)
{
log.warning("Error adding to zip file", e);
throw e;
}
BufferedInputStream fr;
try
{
fr = new BufferedInputStream(new FileInputStream(epadFile));

byte buffer[] = new byte[0xffff];
int b;
while ((b = fr.read(buffer)) != -1)
zipout.write(buffer, 0, b);

fr.close();
zipout.closeEntry();

}
catch (Exception e)
{
log.warning("Error closing zip file", e);
throw e;
}
}
}
}

try
Expand All @@ -2229,7 +2347,7 @@ public static void streamStudy(HttpServletResponse httpResponse, StudyReference
EPADFileUtils.deleteDirectoryAndContents(downloadDir);
}

public static void streamSeries(HttpServletResponse httpResponse, SeriesReference seriesReference, String username, String sessionID, boolean includeAIMs) throws Exception
public static void streamSeries(HttpServletResponse httpResponse, SeriesReference seriesReference, String username, String sessionID, boolean includeAIMs, boolean includeFiles) throws Exception
{
log.info("Streaming series:" + seriesReference.seriesUID);
String downloadDirPath = EPADConfig.getEPADWebServerResourcesDir() + downloadDirName + "temp" + Long.toString(System.currentTimeMillis());
Expand Down Expand Up @@ -2384,6 +2502,46 @@ public static void streamSeries(HttpServletResponse httpResponse, SeriesReferenc
}
}
}
if (includeFiles)
{
List<EpadFile> files = projectOperations.getSeriesFiles(seriesReference.projectID, seriesReference.subjectID, seriesReference.studyUID, seriesReference.seriesUID);
for (EpadFile file: files) {
String name = file.getName();
File epadFile = new File(EPADConfig.getEPADWebServerResourcesDir() + getEpadFilePath(file));
if (!epadFile.exists()) continue;
String fileZipPath = seriesZipPath + "/" + name;
log.debug("Streaming file: " + fileZipPath);
try
{
zipout.putNextEntry(new ZipEntry(fileZipPath));
}
catch (Exception e)
{
log.warning("Error adding to zip file", e);
throw e;
}
BufferedInputStream fr;
try
{
fr = new BufferedInputStream(new FileInputStream(epadFile));

byte buffer[] = new byte[0xffff];
int b;
while ((b = fr.read(buffer)) != -1)
zipout.write(buffer, 0, b);

fr.close();
zipout.closeEntry();

}
catch (Exception e)
{
log.warning("Error closing zip file", e);
throw e;
}
}
}


try
{
Expand Down