use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class RetrieveServiceImpl method openLocationInputStream.
@Override
public LocationInputStream openLocationInputStream(RetrieveContext ctx, InstanceLocations inst) throws IOException {
String studyInstanceUID = inst.getAttributes().getString(Tag.StudyInstanceUID);
ArchiveDeviceExtension arcdev = getArchiveDeviceExtension();
Map<Availability, List<Location>> locationsByAvailability = inst.getLocations().stream().filter(Location::isDicomFile).collect(Collectors.groupingBy(l -> arcdev.getStorageDescriptor(l.getStorageID()).getInstanceAvailability()));
List<Location> locations = locationsByAvailability.get(Availability.ONLINE);
if (locations == null)
locations = locationsByAvailability.get(Availability.NEARLINE);
else if (locationsByAvailability.containsKey(Availability.NEARLINE))
locations.addAll(locationsByAvailability.get(Availability.NEARLINE));
if (locations == null || locations.isEmpty()) {
throw new IOException("Failed to find location of " + inst);
}
IOException ex = null;
for (Location location : locations) {
try {
LOG.debug("Read {} from {}", inst, location);
return openLocationInputStream(getStorage(location.getStorageID(), ctx), location, studyInstanceUID);
} catch (IOException e) {
ex = e;
Location.Status errStatus = toStatus(e);
if (errStatus == Location.Status.MISSING_OBJECT && !exists(location)) {
LOG.warn("{} of {} no longer exists", location, inst);
ctx.incrementMissing();
} else {
LOG.warn("Failed to read {} from {}:\n", inst, location, e);
ctx.getUpdateLocations().add(new UpdateLocation(inst, location, errStatus, null));
}
}
}
throw ex;
}
use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class ImageDocumentSource method imagingDocumentSourceRetrieveRenderedImagingDocumentSet.
@Override
public RetrieveRenderedImagingDocumentSetResponseType imagingDocumentSourceRetrieveRenderedImagingDocumentSet(RetrieveRenderedImagingDocumentSetRequestType req) {
log(req);
RetrieveRenderedImagingDocumentSetResponseType rsp = new RetrieveRenderedImagingDocumentSetResponseType();
RegistryResponseType regRsp = new RegistryResponseType();
rsp.setRegistryResponse(regRsp);
MultivaluedHashMap<String, RenderedDocumentRequest> map = new MultivaluedHashMap<>();
RetrieveContext ctx = newRetrieveContextXDSI(req, map);
if (calculateMatches(ctx, regRsp, map)) {
retrieveStart.fire(ctx);
RenderedImageDataHandler dh = null;
ImageReader imageReader = getDicomImageReader();
ImageWriter imageWriter = getImageWriter(MediaTypes.IMAGE_JPEG_TYPE);
for (InstanceLocations match : ctx.getMatches()) {
if (!ctx.copyToRetrieveCache(match)) {
for (RenderedDocumentRequest docReq : map.get(match.getSopInstanceUID())) {
dh = new RenderedImageDataHandler(ctx, match, docReq, imageReader, imageWriter);
rsp.getRenderedDocumentResponse().add(createRenderedDocumentResponse(docReq, dh));
}
}
}
ctx.copyToRetrieveCache(null);
InstanceLocations match;
while ((match = ctx.copiedToRetrieveCache()) != null) {
for (RenderedDocumentRequest docReq : map.get(match.getSopInstanceUID())) {
dh = new RenderedImageDataHandler(ctx, match, docReq, imageReader, imageWriter);
rsp.getRenderedDocumentResponse().add(createRenderedDocumentResponse(docReq, dh));
}
}
if (dh != null)
dh.setRetrieveEnd(retrieveEnd);
}
regRsp.setStatus(regRsp.getRegistryErrorList() == null ? XDS_STATUS_SUCCESS : rsp.getRenderedDocumentResponse().isEmpty() ? XDS_STATUS_FAILURE : XDS_STATUS_PARTIAL_SUCCESS);
log(rsp);
return rsp;
}
use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class CompressionScheduler method process.
private void process(ApplicationEntity ae, Series.Compression compr) {
ArchiveAEExtension arcAE = ae.getAEExtensionNotNull(ArchiveAEExtension.class);
if (compr.instancePurgeState == Series.InstancePurgeState.PURGED) {
try (StoreSession session = storeService.newStoreSession(ae)) {
storeService.restoreInstances(session, compr.studyInstanceUID, compr.seriesInstanceUID, arcAE.getPurgeInstanceRecordsDelay());
} catch (Exception e) {
LOG.warn("Failed to restore Instance records for compression of Series[iuid={}] of Study[iuid={}]:\n", compr.seriesInstanceUID, compr.studyInstanceUID, e);
return;
}
}
try (RetrieveContext retrCtx = retrieveService.newRetrieveContext(ae.getAETitle(), compr.studyInstanceUID, compr.seriesInstanceUID, null);
StoreSession session = storeService.newStoreSession(ae)) {
retrieveService.calculateMatches(retrCtx);
LOG.info("Start compression of {} Instances of Series[iuid={}] of Study[iuid={}]", retrCtx.getNumberOfMatches(), compr.seriesInstanceUID, compr.studyInstanceUID);
int failures = 0;
int completed = 0;
int skipped = 0;
ArchiveCompressionRule compressionRule = new ArchiveCompressionRule();
compressionRule.setTransferSyntax(compr.transferSyntaxUID);
compressionRule.setImageWriteParams(compr.imageWriteParams());
for (InstanceLocations inst : retrCtx.getMatches()) {
if (alreadyCompressed(inst.getLocations(), compr.transferSyntaxUID)) {
LOG.info("{} of Series[iuid={}] of Study[iuid={}] already compressed with {} - skipped", inst, compr.seriesInstanceUID, compr.studyInstanceUID, UID.nameOf(compr.transferSyntaxUID));
skipped++;
continue;
}
try (LocationInputStream lis = retrieveService.openLocationInputStream(retrCtx, inst)) {
StoreContext ctx = storeService.newStoreContext(session);
ctx.setCompressionRule(compressionRule);
storeService.compress(ctx, inst, lis.stream);
completed++;
} catch (Exception e) {
LOG.info("Failed to compress {} of Series[iuid={}] of Study[iuid={}]:\n", inst, compr.seriesInstanceUID, compr.studyInstanceUID, e);
failures++;
}
}
ejb.updateDB(compr, completed, failures);
LOG.info("Finished compression of {} Instances of Series[iuid={}] of Study[iuid={}] - {} failures, {} skipped", completed, compr.seriesInstanceUID, compr.studyInstanceUID, failures, skipped);
retrieveService.updateLocations(retrCtx);
} catch (IOException e) {
LOG.warn("Failed to calculate Instances for compression of Series[iuid={}] of Study[iuid={}]:\n", compr.seriesInstanceUID, compr.studyInstanceUID, e);
}
}
use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class Curve2PRExporter method export.
@Override
public Outcome export(ExportContext ctx) throws Exception {
ApplicationEntity ae;
List<Attributes> results = new ArrayList<>();
try (RetrieveContext retrieveContext = retrieveService.newRetrieveContext(ctx.getAETitle(), ctx.getStudyInstanceUID(), ctx.getSeriesInstanceUID(), ctx.getSopInstanceUID())) {
ae = retrieveContext.getLocalApplicationEntity();
retrieveContext.setHttpServletRequestInfo(ctx.getHttpServletRequestInfo());
if (!retrieveService.calculateMatches(retrieveContext))
return new Outcome(Task.Status.WARNING, noMatches(ctx));
for (InstanceLocations instanceLocations : retrieveContext.getMatches()) {
if (isImage(instanceLocations))
curve2pr(retrieveContext, instanceLocations, results);
}
}
if (results.isEmpty())
return new Outcome(Task.Status.COMPLETED, noPresentationStateCreated(ctx));
int totInstanceRefs = 0;
int instanceRefs;
try (StoreSession session = storeService.newStoreSession(ctx.getHttpServletRequestInfo(), ae, ctx.getAETitle(), properties.get("SourceAET"))) {
for (Attributes pr : results) {
totInstanceRefs += instanceRefs = countInstanceRefs(pr);
trimSoftcopyVOILUT(pr, instanceRefs);
trimDisplayAreaSelection(pr);
StoreContext storeCtx = storeService.newStoreContext(session);
storeCtx.setReceiveTransferSyntax(UID.ExplicitVRLittleEndian);
storeService.store(storeCtx, pr);
}
}
return new Outcome(Task.Status.COMPLETED, toMessage(ctx, results.size(), totInstanceRefs));
}
use of org.dcm4chee.arc.store.InstanceLocations in project dcm4chee-arc-light by dcm4che.
the class ImageDocumentSource method imagingDocumentSourceRetrieveImagingDocumentSet.
@Override
public RetrieveDocumentSetResponseType imagingDocumentSourceRetrieveImagingDocumentSet(RetrieveImagingDocumentSetRequestType req) {
log(req);
RetrieveDocumentSetResponseType rsp = new RetrieveDocumentSetResponseType();
RegistryResponseType regRsp = new RegistryResponseType();
rsp.setRegistryResponse(regRsp);
MultivaluedHashMap<String, DocumentRequest> map = new MultivaluedHashMap<>();
RetrieveContext ctx = newRetrieveContextXDSI(req, map);
List<String> tsuids = req.getTransferSyntaxUIDList().getTransferSyntaxUID();
if (calculateMatches(ctx, regRsp, map.keySet(), tsuids)) {
retrieveStart.fire(ctx);
DicomDataHandler dh = null;
for (InstanceLocations match : ctx.getMatches()) {
if (!ctx.copyToRetrieveCache(match)) {
dh = new DicomDataHandler(ctx, match, tsuids);
for (DocumentRequest docReq : map.get(match.getSopInstanceUID())) {
rsp.getDocumentResponse().add(createDocumentResponse(docReq, dh));
}
}
}
ctx.copyToRetrieveCache(null);
InstanceLocations match;
while ((match = ctx.copiedToRetrieveCache()) != null) {
dh = new DicomDataHandler(ctx, match, tsuids);
for (DocumentRequest docReq : map.get(match.getSopInstanceUID())) {
rsp.getDocumentResponse().add(createDocumentResponse(docReq, dh));
}
}
if (dh != null)
dh.setRetrieveEnd(retrieveEnd);
}
regRsp.setStatus(regRsp.getRegistryErrorList() == null ? XDS_STATUS_SUCCESS : rsp.getDocumentResponse().isEmpty() ? XDS_STATUS_FAILURE : XDS_STATUS_PARTIAL_SUCCESS);
log(rsp);
return rsp;
}
Aggregations