Search in sources :

Example 11 with ApplicationEntity

use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.

the class ImportStorageRS method reimportStudy.

@POST
@Path("/studies/{study}/reimport")
public void reimportStudy(@Suspended AsyncResponse ar, @PathParam("study") String studyUID) {
    Output output = selectMediaType();
    ApplicationEntity ae = getApplicationEntity();
    try {
        ArchiveAEExtension arcAE = ae.getAEExtensionNotNull(ArchiveAEExtension.class);
        List<Location> locations = deletionService.reimportStudy(studyUID, HttpServletRequestInfo.valueOf(request), arcAE);
        Attributes coerce = new QueryAttributes(uriInfo, null).getQueryKeys();
        Date now = reasonForModification != null && !coerce.isEmpty() ? new Date() : null;
        Attributes.UpdatePolicy updatePolicy = Attributes.UpdatePolicy.valueOf(this.updatePolicy);
        for (Location location : locations) {
            if (location.getObjectType() == Location.ObjectType.METADATA)
                continue;
            Storage storage = storageFactory.getStorage(getStorageDesc(location.getStorageID()));
            final StoreSession session = service.newStoreSession(HttpServletRequestInfo.valueOf(request), ae, aet, null).withObjectStorageID(location.getStorageID());
            StoreContext ctx = service.newStoreContext(session);
            ctx.getLocations().add(location);
            importInstanceOnStorage(storage, ctx, coerce, updatePolicy, now, location.getStoragePath());
        }
        rsForward.forward(RSOperation.ReimportStudy, arcAE, null, request);
    } catch (StudyNotFoundException e) {
        throw new WebApplicationException(e.getMessage(), Response.Status.NOT_FOUND);
    } catch (StudyNotEmptyException e) {
        throw new WebApplicationException(e.getMessage(), Response.Status.FORBIDDEN);
    } catch (Exception e) {
        throw new WebApplicationException(errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR));
    }
    response.setString(Tag.RetrieveURL, VR.UR, retrieveURL());
    Response.ResponseBuilder responseBuilder = Response.status(status());
    ar.resume(responseBuilder.entity(output.entity(response, ae)).header("Warning", response.getString(Tag.ErrorComment)).build());
}
Also used : ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException) StudyNotFoundException(org.dcm4chee.arc.delete.StudyNotFoundException) AsyncResponse(javax.ws.rs.container.AsyncResponse) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) Storage(org.dcm4chee.arc.storage.Storage) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) StudyNotFoundException(org.dcm4chee.arc.delete.StudyNotFoundException) Location(org.dcm4chee.arc.entity.Location) StoreSession(org.dcm4chee.arc.store.StoreSession) StoreContext(org.dcm4chee.arc.store.StoreContext) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException)

Example 12 with ApplicationEntity

use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.

the class StorageRS method getStorageSystems.

private List<StorageSystem> getStorageSystems() {
    if (dicomAETitle != null) {
        ApplicationEntity ae = device.getApplicationEntity(dicomAETitle, true);
        if (ae == null || !ae.isInstalled()) {
            LOG.info("Archive AE {} not provided by Device {}", dicomAETitle, device.getDeviceName());
            return Collections.EMPTY_LIST;
        }
    }
    List<StorageSystem> storageSystems = new ArrayList<>();
    ArchiveDeviceExtension arcdev = device.getDeviceExtensionNotNull(ArchiveDeviceExtension.class);
    arcdev.getStorageDescriptors().forEach(desc -> {
        String storageID = desc.getStorageID();
        Set<String> usages = new HashSet<>();
        Set<String> aets = new HashSet<>();
        if (StringUtils.contains(arcdev.getSeriesMetadataStorageIDs(), storageID))
            usages.add("dcmSeriesMetadataStorageID");
        for (ApplicationEntity ae : device.getApplicationEntities()) {
            ArchiveAEExtension arcAE = ae.getAEExtension(ArchiveAEExtension.class);
            if (arcAE == null) {
                LOG.info("Archive AE Extension not configured for AE : {}", ae.getAETitle());
                continue;
            }
            if (StringUtils.contains(arcAE.getObjectStorageIDs(), desc.getStorageID())) {
                usages.add("dcmObjectStorageID");
                aets.add(ae.getAETitle());
            }
            if (StringUtils.contains(arcAE.getMetadataStorageIDs(), desc.getStorageID())) {
                usages.add("dcmMetadataStorageID");
                aets.add(ae.getAETitle());
            }
        }
        if ((dicomAETitle == null || aets.contains(dicomAETitle)) && (usage == null || usages.contains(usage)) && (storageClusterID == null || storageClusterID.equals(desc.getStorageClusterID())) && (uriScheme == null || desc.getStorageURI().getScheme().equals(uriScheme))) {
            try (Storage storage = storageFactory.getStorage(desc)) {
                long usableSpace = storage.getUsableSpace();
                if (usableSpaceBelow == null || usableSpace < usableSpaceBelow) {
                    long totalSpace = storage.getTotalSpace();
                    storageSystems.add(new StorageSystem(desc, usableSpace, totalSpace, usages, aets));
                }
            } catch (IOException e) {
                LOG.warn("Failed to access {}", desc, e);
            }
        }
    });
    storageSystems.sort(Comparator.comparing(storageSystem -> storageSystem.desc.getStorageID()));
    return storageSystems;
}
Also used : JsonGenerator(javax.json.stream.JsonGenerator) PrintWriter(java.io.PrintWriter) java.util(java.util) org.dcm4chee.arc.conf(org.dcm4chee.arc.conf) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) JsonWriter(org.dcm4che3.conf.json.JsonWriter) StringWriter(java.io.StringWriter) LoggerFactory(org.slf4j.LoggerFactory) StreamingOutput(javax.ws.rs.core.StreamingOutput) IOException(java.io.IOException) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) StringUtils(org.dcm4che3.util.StringUtils) Device(org.dcm4che3.net.Device) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) NoCache(org.jboss.resteasy.annotations.cache.NoCache) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) RequestScoped(javax.enterprise.context.RequestScoped) Pattern(javax.validation.constraints.Pattern) Json(javax.json.Json) StorageFactory(org.dcm4chee.arc.storage.StorageFactory) Storage(org.dcm4chee.arc.storage.Storage) IOException(java.io.IOException) Storage(org.dcm4chee.arc.storage.Storage) ApplicationEntity(org.dcm4che3.net.ApplicationEntity)

Example 13 with ApplicationEntity

use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.

the class StowRS method store.

private void store(AsyncResponse ar, InputStream in, final Input input, OutputType output) throws Exception {
    ApplicationEntity ae = getApplicationEntity();
    if (aet.equals(ae.getAETitle()))
        validateWebApp();
    ar.register((CompletionCallback) throwable -> purgeSpoolDirectory());
    final StoreSession session = service.newStoreSession(HttpServletRequestInfo.valueOf(request), ae, aet, null);
    new MultipartParser(boundary()).parse(new BufferedInputStream(in), (partNumber, multipartInputStream) -> {
        Map<String, List<String>> headerParams = multipartInputStream.readHeaderParams();
        LOG.info("storeInstances: Extract Part #{}{}", partNumber, headerParams);
        String contentLocation = getHeaderParamValue(headerParams, "content-location");
        String contentType = getHeaderParamValue(headerParams, "content-type");
        MediaType mediaType = normalize(MediaType.valueOf(contentType));
        try {
            if (!input.readBodyPart(StowRS.this, session, multipartInputStream, mediaType, contentLocation)) {
                LOG.info("{}: Ignore Part with Content-Type={}", session, mediaType);
                multipartInputStream.skipAll();
            }
        } catch (JsonParsingException e) {
            throw new WebApplicationException(errResponse(e.getMessage() + " at location : " + e.getLocation(), Response.Status.BAD_REQUEST));
        } catch (Exception e) {
            if (instances.size() == 1)
                throw new WebApplicationException(errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR));
            else {
                LOG.warn("Failed to process Part #" + partNumber + headerParams);
                throw new WebApplicationException(errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR));
            }
        }
    });
    int instanceNumber = 0;
    for (Attributes instance : instances) storeDicomObject(session, instance, ++instanceNumber);
    response.setString(Tag.RetrieveURL, VR.UR, retrieveURL());
    Response.ResponseBuilder responseBuilder = Response.status(status());
    ar.resume(responseBuilder.entity(output.entity(response, ae)).header("Warning", warning).build());
}
Also used : KeycloakContext(org.dcm4chee.arc.keycloak.KeycloakContext) LoggerFactory(org.slf4j.LoggerFactory) BufferedImageUtils(org.dcm4che3.image.BufferedImageUtils) MultipartInputStream(org.dcm4che3.mime.MultipartInputStream) DirectoryStream(java.nio.file.DirectoryStream) MediaType(javax.ws.rs.core.MediaType) ArchiveDeviceExtension(org.dcm4chee.arc.conf.ArchiveDeviceExtension) WebApplication(org.dcm4che3.net.WebApplication) ImageIO(javax.imageio.ImageIO) MPEG2Parser(org.dcm4che3.imageio.codec.mpeg.MPEG2Parser) StoreSession(org.dcm4chee.arc.store.StoreSession) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) MultipartParser(org.dcm4che3.mime.MultipartParser) Status(org.dcm4che3.net.Status) Suspended(javax.ws.rs.container.Suspended) StandardCharsets(java.nio.charset.StandardCharsets) ImageInputStream(javax.imageio.stream.ImageInputStream) Device(org.dcm4che3.net.Device) SeekableByteChannel(java.nio.channels.SeekableByteChannel) SAXReader(org.dcm4che3.io.SAXReader) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) CompletionCallback(javax.ws.rs.container.CompletionCallback) HttpServletRequestInfo(org.dcm4chee.arc.keycloak.HttpServletRequestInfo) Pattern(javax.validation.constraints.Pattern) JPEGParser(org.dcm4che3.imageio.codec.jpeg.JPEGParser) UriInfo(javax.ws.rs.core.UriInfo) JsonParsingException(javax.json.stream.JsonParsingException) java.util(java.util) ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) StoreService(org.dcm4chee.arc.store.StoreService) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) JSONReader(org.dcm4che3.json.JSONReader) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) InvokeValidate(org.dcm4chee.arc.validation.constraints.InvokeValidate) Json(javax.json.Json) org.dcm4che3.data(org.dcm4che3.data) StoreContext(org.dcm4chee.arc.store.StoreContext) Logger(org.slf4j.Logger) ImageReader(javax.imageio.ImageReader) Files(java.nio.file.Files) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) JPEG(org.dcm4che3.imageio.codec.jpeg.JPEG) MP4FileType(org.dcm4che3.imageio.codec.mp4.MP4FileType) MediaTypes(org.dcm4che3.ws.rs.MediaTypes) MP4Parser(org.dcm4che3.imageio.codec.mp4.MP4Parser) java.io(java.io) Paths(java.nio.file.Paths) RequestScoped(javax.enterprise.context.RequestScoped) org.dcm4che3.util(org.dcm4che3.util) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) MultipartParser(org.dcm4che3.mime.MultipartParser) JsonParsingException(javax.json.stream.JsonParsingException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) MediaType(javax.ws.rs.core.MediaType) StoreSession(org.dcm4chee.arc.store.StoreSession) JsonParsingException(javax.json.stream.JsonParsingException)

Example 14 with ApplicationEntity

use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.

the class ArchiveDeviceConfigurationTest method testPersist.

@Test
public void testPersist() throws Exception {
    ArchiveDeviceFactory.ConfigType configType = ArchiveDeviceFactory.ConfigType.valueOf(System.getProperty("configType", ArchiveDeviceFactory.ConfigType.DEFAULT.name()));
    Device arrDevice = ArchiveDeviceFactory.createARRDevice(configType);
    Device[] otherDevices = new Device[ArchiveDeviceFactory.OTHER_DEVICES.length];
    EnumSet<DicomConfiguration.Option> register = EnumSet.of(DicomConfiguration.Option.REGISTER);
    config.persist(arrDevice, register);
    config.persist(otherDevices[0] = ArchiveDeviceFactory.createOtherDevice(0), register);
    config.persist(ArchiveDeviceFactory.createStoreSCPDevice(), register);
    config.persist(ArchiveDeviceFactory.createStowRSDevice(), register);
    if (configType == ArchiveDeviceFactory.ConfigType.SAMPLE) {
        for (int i = 1; i < ArchiveDeviceFactory.OTHER_DEVICES.length; i++) {
            config.persist(otherDevices[i] = ArchiveDeviceFactory.createOtherDevice(i), register);
        }
        config.persist(ArchiveDeviceFactory.qualifyDevice(ArchiveDeviceFactory.createHL7Device("hl7rcv", ArchiveDeviceFactory.PIX_MANAGER, "localhost", 2576, 12576), "DSS", ArchiveDeviceFactory.SITE_A, ArchiveDeviceFactory.INST_A), register);
    }
    Device arc = ArchiveDeviceFactory.createArchiveDevice("dcm4chee-arc", configType, arrDevice, otherDevices[ArchiveDeviceFactory.SCHEDULED_STATION_INDEX], otherDevices[ArchiveDeviceFactory.STORESCU_INDEX], otherDevices[ArchiveDeviceFactory.MPPSSCU_INDEX]);
    config.persist(arc, register);
    Device keycloak = ArchiveDeviceFactory.createKeycloakDevice("keycloak", arrDevice, configType);
    config.persist(keycloak, null);
    ApplicationEntity ae = config.findApplicationEntity("DCM4CHEE");
    assertNotNull(ae);
    assertDeviceEquals(arc, ae.getDevice());
}
Also used : Device(org.dcm4che3.net.Device) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) Test(org.junit.Test)

Example 15 with ApplicationEntity

use of org.dcm4che3.net.ApplicationEntity in project dcm4chee-arc-light by dcm4che.

the class QueryAETs method writeTo.

private void writeTo(ApplicationEntity ae, JsonGenerator gen) {
    ArchiveAEExtension arcAE = ae.getAEExtension(ArchiveAEExtension.class);
    JsonWriter writer = new JsonWriter(gen);
    gen.writeStartObject();
    gen.write("dicomAETitle", ae.getAETitle());
    writer.writeNotNullOrDef("dicomDescription", ae.getDescription(), null);
    writer.writeNotEmpty("dcmOtherAETitle", ae.getOtherAETitles());
    if (arcAE != null) {
        QueryRetrieveView queryRetrieveView = arcAE.getQueryRetrieveView();
        writer.writeNotDef("dcmHideNotRejectedInstances", queryRetrieveView != null && queryRetrieveView.isHideNotRejectedInstances(), false);
        writer.writeNotNullOrDef("dcmAllowDeletePatient", arcAE.allowDeletePatient(), null);
        writer.writeNotNullOrDef("dcmAllowDeleteStudyPermanently", arcAE.allowDeleteStudy(), null);
    }
    gen.writeEnd();
}
Also used : ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) QueryRetrieveView(org.dcm4chee.arc.conf.QueryRetrieveView) JsonWriter(org.dcm4che3.conf.json.JsonWriter)

Aggregations

ApplicationEntity (org.dcm4che3.net.ApplicationEntity)58 IOException (java.io.IOException)18 Attributes (org.dcm4che3.data.Attributes)18 ConfigurationException (org.dcm4che3.conf.api.ConfigurationException)15 AAssociateRQ (org.dcm4che3.net.pdu.AAssociateRQ)14 Response (javax.ws.rs.core.Response)13 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)13 ArchiveDeviceExtension (org.dcm4chee.arc.conf.ArchiveDeviceExtension)12 Query (org.dcm4chee.arc.query.Query)12 QueryContext (org.dcm4chee.arc.query.QueryContext)12 Device (org.dcm4che3.net.Device)11 StoreSession (org.dcm4chee.arc.store.StoreSession)10 ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)9 QueryAttributes (org.dcm4chee.arc.query.util.QueryAttributes)9 PresentationContext (org.dcm4che3.net.pdu.PresentationContext)7 StoreContext (org.dcm4chee.arc.store.StoreContext)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 Outcome (org.dcm4chee.arc.qmgt.Outcome)6 java.util (java.util)5