use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.
the class StgCmtImpl method scheduleStorageCommit.
@Override
public void scheduleStorageCommit(ExportContext ctx, ExporterDescriptor descriptor) {
String stgCmtSCPAETitle = descriptor.getStgCmtSCPAETitle();
if (stgCmtSCPAETitle != null) {
ApplicationEntity ae = device.getApplicationEntity(ctx.getAETitle(), true);
Attributes actionInfo = createActionInfo(ctx, ae);
scheduleNAction(ae.getCallingAETitle(stgCmtSCPAETitle), stgCmtSCPAETitle, actionInfo, ctx, descriptor.getExporterID(), new Date());
}
}
use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.
the class IANSCURS method ian.
private Response ian(String studyUID, String seriesUID, String sopUID, String externalAET) {
logRequest();
ApplicationEntity ae = device.getApplicationEntity(aet, true);
if (ae == null || !ae.isInstalled())
return errResponse("No such Application Entity: " + aet, Response.Status.NOT_FOUND);
Response.Status rspStatus = Response.Status.BAD_GATEWAY;
try {
ApplicationEntity remoteAE = aeCache.findApplicationEntity(externalAET);
Attributes ian = queryService.createIAN(ae, studyUID, new String[] { seriesUID }, sopUID, null, null, null);
if (ian == null)
return errResponse("No matching instances", Response.Status.NOT_FOUND);
DimseRSP dimseRSP = ianSCU.sendIANRQ(ae, remoteAE, UIDUtils.createUID(), ian);
dimseRSP.next();
if (dimseRSP.getCommand().getInt(Tag.Status, -1) == Status.Success)
rspStatus = Response.Status.OK;
return Response.status(rspStatus).entity(entity(ian, dimseRSP)).build();
} catch (ConfigurationException e) {
return errResponse(e.getMessage(), Response.Status.NOT_FOUND);
} catch (IOException e) {
return errResponse(e.getMessage(), rspStatus);
} catch (Exception e) {
return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.
the class IANScheduler method scheduleIAN.
public void scheduleIAN(ExportContext ctx, ExporterDescriptor descriptor) {
ApplicationEntity ae = device.getApplicationEntity(ctx.getAETitle(), true);
Attributes ian = queryService.createIAN(ae, ctx.getStudyInstanceUID(), null, null, descriptor.getRetrieveAETitles(), descriptor.getRetrieveLocationUID(), descriptor.getInstanceAvailability());
if (ian != null)
for (String remoteAET : descriptor.getIanDestinations()) ejb.scheduleMessage(ctx.getAETitle(), ian, remoteAET, new Date(), null);
}
use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.
the class IANScheduler method execute.
@Override
protected void execute() {
ArchiveDeviceExtension arcDev = device.getDeviceExtension(ArchiveDeviceExtension.class);
int fetchSize = arcDev.getIanTaskFetchSize();
long ianTaskPk = 0;
List<IanTask> ianTasks;
Attributes ian;
do {
ianTasks = ejb.fetchIANTasksForMPPS(device.getDeviceName(), ianTaskPk, fetchSize);
for (IanTask ianTask : ianTasks) {
if (getPollingInterval() == null)
return;
try {
ianTaskPk = ianTask.getPk();
ApplicationEntity ae = device.getApplicationEntity(ianTask.getCallingAET(), true);
LOG.info("Check availability of {}", ianTask.getMpps());
ian = createIANForMPPS(ae, ianTask.getMpps(), true);
if (ian != null) {
LOG.info("Schedule {}", ianTask);
ejb.scheduleIANTask(ianTask, ian);
}
} catch (Exception e) {
LOG.warn("Failed to process {}", ianTask, e);
}
}
} while (ianTasks.size() == fetchSize);
do {
ianTasks = ejb.fetchIANTasksForStudy(device.getDeviceName(), fetchSize);
for (IanTask ianTask : ianTasks) {
if (getPollingInterval() == null)
return;
try {
ApplicationEntity ae = device.getApplicationEntity(ianTask.getCallingAET(), true);
if (ianTask.getMpps() == null) {
ian = queryService.createIAN(ae, ianTask.getStudyInstanceUID(), null, null, null, null, null);
if (ian != null) {
LOG.info("Schedule {}", ianTask);
ejb.scheduleIANTask(ianTask, ian);
} else {
LOG.info("Ignore {} without referenced objects", ianTask);
ejb.removeIANTask(ianTask);
}
} else {
if (ae.getAEExtension(ArchiveAEExtension.class).ianOnTimeout() && (ian = createIANForMPPS(ae, ianTask.getMpps(), false)) != null) {
LOG.warn("Timeout for {} exceeded - schedule IAN for available instances", ianTask);
ejb.scheduleIANTask(ianTask, ian);
} else {
LOG.warn("Timeout for {} exceeded - no IAN", ianTask);
ejb.removeIANTask(ianTask);
}
}
} catch (Exception e) {
LOG.warn("Failed to process {}", ianTask, e);
}
}
} while (ianTasks.size() == fetchSize);
}
use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.
the class ExportCSVRS method exportFromCSV.
Response exportFromCSV(String aet, String exporterID, int studyUIDField, Integer seriesUIDField, InputStream in) {
logRequest();
Response.Status status = Response.Status.BAD_REQUEST;
try {
if (studyUIDField < 1)
return errResponse(status, "CSV field for Study Instance UID should be greater than or equal to 1");
if (seriesUIDField != null) {
if (studyUIDField == seriesUIDField)
return errResponse(status, "CSV fields for Study and Series Instance UIDs should be different");
if (seriesUIDField < 1)
return errResponse(status, "CSV field for Series Instance UID should be greater than or equal to 1");
}
ApplicationEntity ae = device.getApplicationEntity(aet, true);
if (ae == null || !ae.isInstalled())
return errResponse(Response.Status.NOT_FOUND, "No such Application Entity: " + aet);
ArchiveDeviceExtension arcDev = device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class);
ExporterDescriptor exporter = arcDev.getExporterDescriptor(exporterID);
if (exporter == null)
return errResponse(Response.Status.NOT_FOUND, "No such Exporter: " + exporterID);
int count = 0;
String warning = null;
int csvUploadChunkSize = arcDev.getCSVUploadChunkSize();
List<StudySeriesInfo> studySeries = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in));
CSVParser parser = new CSVParser(reader, CSVFormat.DEFAULT.builder().setDelimiter(csvDelimiter()).build())) {
boolean header = true;
for (CSVRecord csvRecord : parser) {
if (csvRecord.size() == 0 || csvRecord.get(0).isEmpty())
continue;
String studyUID = csvRecord.get(studyUIDField - 1).replaceAll("\"", "");
if (header && studyUID.chars().allMatch(Character::isLetter)) {
header = false;
continue;
}
if (!arcDev.isValidateUID() || validateUID(studyUID)) {
StudySeriesInfo studySeriesInfo = new StudySeriesInfo(studyUID);
addSeriesUID(studySeriesInfo, csvRecord, seriesUIDField, arcDev);
studySeries.add(studySeriesInfo);
}
if (studySeries.size() == csvUploadChunkSize) {
count += scheduleExportTasks(exporter, studySeries, scheduledTime());
studySeries.clear();
}
}
if (!studySeries.isEmpty())
count += scheduleExportTasks(exporter, studySeries, scheduledTime());
if (count == 0) {
warning = "Empty file or Incorrect field position or Not a CSV file or Invalid UIDs.";
status = Response.Status.NO_CONTENT;
}
} catch (Exception e) {
warning = e.getMessage();
status = Response.Status.INTERNAL_SERVER_ERROR;
}
if (warning == null && count > 0)
return Response.accepted(count(count)).build();
LOG.info("Response {} caused by {}", status, warning);
Response.ResponseBuilder builder = Response.status(status).header("Warning", warning);
if (count > 0)
builder.entity(count(count));
return builder.build();
} catch (Exception e) {
return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations