Search in sources :

Example 1 with ExporterDescriptor

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);
    }
}
Also used : ArchiveDeviceExtension(org.dcm4chee.arc.conf.ArchiveDeviceExtension) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) ExporterDescriptor(org.dcm4chee.arc.conf.ExporterDescriptor) RejectionNote(org.dcm4chee.arc.conf.RejectionNote)

Example 2 with ExporterDescriptor

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);
}
Also used : ExporterDescriptor(org.dcm4chee.arc.conf.ExporterDescriptor)

Example 3 with ExporterDescriptor

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);
    }
}
Also used : ArrayList(java.util.ArrayList) Response(javax.ws.rs.core.Response) ArchiveDeviceExtension(org.dcm4chee.arc.conf.ArchiveDeviceExtension) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) CSVParser(org.apache.commons.csv.CSVParser) CSVRecord(org.apache.commons.csv.CSVRecord) ExporterDescriptor(org.dcm4chee.arc.conf.ExporterDescriptor)

Example 4 with ExporterDescriptor

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);
    }
}
Also used : Query(org.dcm4chee.arc.query.Query) QueryContext(org.dcm4chee.arc.query.QueryContext) Response(javax.ws.rs.core.Response) ArchiveDeviceExtension(org.dcm4chee.arc.conf.ArchiveDeviceExtension) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) ExporterDescriptor(org.dcm4chee.arc.conf.ExporterDescriptor)

Example 5 with ExporterDescriptor

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);
    }
}
Also used : JsonGenerator(javax.json.stream.JsonGenerator) StreamingOutput(javax.ws.rs.core.StreamingOutput) ExporterDescriptor(org.dcm4chee.arc.conf.ExporterDescriptor) JsonWriter(org.dcm4che3.conf.json.JsonWriter) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Aggregations

ExporterDescriptor (org.dcm4chee.arc.conf.ExporterDescriptor)8 ArchiveDeviceExtension (org.dcm4chee.arc.conf.ArchiveDeviceExtension)5 ApplicationEntity (org.dcm4che3.net.ApplicationEntity)4 Response (javax.ws.rs.core.Response)2 ArrayList (java.util.ArrayList)1 JsonGenerator (javax.json.stream.JsonGenerator)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 CSVParser (org.apache.commons.csv.CSVParser)1 CSVRecord (org.apache.commons.csv.CSVRecord)1 ConfigurationNotFoundException (org.dcm4che3.conf.api.ConfigurationNotFoundException)1 JsonWriter (org.dcm4che3.conf.json.JsonWriter)1 Attributes (org.dcm4che3.data.Attributes)1 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)1 RejectionNote (org.dcm4chee.arc.conf.RejectionNote)1 Task (org.dcm4chee.arc.entity.Task)1 ExportContext (org.dcm4chee.arc.exporter.ExportContext)1 Exporter (org.dcm4chee.arc.exporter.Exporter)1 Outcome (org.dcm4chee.arc.qmgt.Outcome)1