use of org.dcm4chee.arc.conf.ExporterDescriptor in project dcm4chee-arc-light by dcm4che.
the class RejectionServiceImpl method onExport.
public void onExport(@Observes ExportContext ctx) {
ExporterDescriptor desc = ctx.getExporter().getExporterDescriptor();
if (ctx.getException() != null || !desc.isRejectForDataRetentionExpiry() || ctx.getOutcome().getStatus() != Task.Status.COMPLETED)
return;
ApplicationEntity ae = getApplicationEntity(desc.getAETitle());
if (ae == null || !ae.isInstalled()) {
LOG.warn("No such Application Entity: {}", desc.getAETitle());
return;
}
ArchiveDeviceExtension arcDev = device.getDeviceExtension(ArchiveDeviceExtension.class);
RejectionNote rn = arcDev.getRejectionNote(RejectionNote.Type.DATA_RETENTION_POLICY_EXPIRED);
if (rn == null) {
LOG.warn("Data Retention Policy Expired Rejection Note not configured.");
return;
}
LOG.info("Export completed, invoke rejection of objects.");
try {
if (ejb.claimExpired(ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ExpirationState.REJECTED))
reject(ae, ctx.getAETitle(), ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ctx.getSopInstanceUID(), rn, ctx.getHttpServletRequestInfo());
} catch (Exception e) {
LOG.warn("Rejection of Expired Study[UID={}], Series[UID={}], SOPInstance[UID={}] failed.\n", ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ctx.getSopInstanceUID(), e);
ejb.claimExpired(ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ExpirationState.FAILED_TO_REJECT);
}
}
use of org.dcm4chee.arc.conf.ExporterDescriptor in project dcm4chee-arc-light by dcm4che.
the class StgCmtImpl method onExport.
public void onExport(@Observes ExportContext ctx) {
if (ctx.getException() != null)
return;
ExporterDescriptor descriptor = ctx.getExporter().getExporterDescriptor();
String stgCmtSCPAETitle = descriptor.getStgCmtSCPAETitle();
if (stgCmtSCPAETitle != null && ctx.getOutcome().getStatus() == Task.Status.COMPLETED)
scheduleStorageCommit(ctx, descriptor);
}
use of org.dcm4chee.arc.conf.ExporterDescriptor 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);
}
}
use of org.dcm4chee.arc.conf.ExporterDescriptor in project dcm4chee-arc-light by dcm4che.
the class ExportMatchingRS method exportMatching.
private Response exportMatching(String exporterID, String aet, String method, QueryRetrieveLevel2 qrlevel, String studyInstanceUID, String seriesInstanceUID) {
ApplicationEntity ae = device.getApplicationEntity(aet, true);
if (ae == null || !ae.isInstalled())
return errResponse(Response.Status.NOT_FOUND, "No such Application Entity: " + aet);
try {
ArchiveDeviceExtension arcDev = device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class);
ExporterDescriptor exporter = arcDev.getExporterDescriptor(exporterID);
if (exporter == null)
return errResponse(Response.Status.NOT_FOUND, "No such Exporter: " + exporterID);
QueryContext ctx = queryContext(method, qrlevel, studyInstanceUID, seriesInstanceUID, ae);
String warning;
int count;
Response.Status status = Response.Status.ACCEPTED;
try (Query query = queryService.createQuery(ctx)) {
int queryMaxNumberOfResults = ctx.getArchiveAEExtension().queryMaxNumberOfResults();
if (queryMaxNumberOfResults > 0 && !ctx.containsUniqueKey() && query.fetchCount() > queryMaxNumberOfResults)
return errResponse(Response.Status.BAD_REQUEST, "Request entity too large");
ExportMatchingObjects exportMatchingObjects = new ExportMatchingObjects(exporter, qrlevel, query, scheduledTime(), status);
runInTx.execute(exportMatchingObjects);
count = exportMatchingObjects.getCount();
status = exportMatchingObjects.getStatus();
warning = exportMatchingObjects.getWarning();
}
if (count > 0 && scheduledTime == null) {
taskScheduler.process(arcDev.getQueueDescriptorNotNull(exporter.getQueueName()), arcDev.getTaskFetchSize());
}
Response.ResponseBuilder builder = Response.status(status);
if (warning != null) {
LOG.warn("Response {} caused by {}", status, warning);
builder.header("Warning", warning);
}
return builder.entity("{\"count\":" + count + '}').build();
} catch (IllegalStateException e) {
return errResponse(Response.Status.NOT_FOUND, e.getMessage());
} catch (Exception e) {
return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.dcm4chee.arc.conf.ExporterDescriptor in project dcm4chee-arc-light by dcm4che.
the class QueryExporters method query.
@GET
@NoCache
@Produces("application/json")
public Response query() {
logRequest();
try {
return Response.ok((StreamingOutput) out -> {
JsonGenerator gen = Json.createGenerator(out);
gen.writeStartArray();
device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class).getExporterDescriptors().stream().sorted(Comparator.comparing(ExporterDescriptor::getExporterID)).forEach(exporter -> {
JsonWriter writer = new JsonWriter(gen);
gen.writeStartObject();
writer.writeNotNullOrDef("id", exporter.getExporterID(), null);
writer.writeNotNullOrDef("description", exporter.getDescription(), null);
gen.writeEnd();
});
gen.writeEnd();
gen.flush();
}).build();
} catch (IllegalStateException e) {
return errResponse(e.getMessage(), Response.Status.NOT_FOUND);
} catch (Exception e) {
return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations