Search in sources :

Example 1 with StudyNotEmptyException

use of org.dcm4chee.arc.delete.StudyNotEmptyException in project dcm4chee-arc-light by dcm4che.

the class DeletionServiceImpl method deleteStudy.

private List<Location> deleteStudy(StudyDeleteContext ctx, Study study, ArchiveAEExtension arcAE, PatientMgtContext pCtx, boolean retainObj, boolean reimport) throws Exception {
    List<Location> locations = new ArrayList<>();
    ArchiveDeviceExtension arcDev = device.getDeviceExtension(ArchiveDeviceExtension.class);
    RejectionState rejectionState = study.getRejectionState();
    if (pCtx == null) {
        if (!reimport && arcAE.allowDeleteStudy() == AllowDeleteStudyPermanently.REJECTED && (rejectionState == RejectionState.NONE || rejectionState == RejectionState.PARTIAL)) {
            ctx.setStudy(study);
            throw new StudyNotEmptyException("Deletion of Study with Rejection State: " + rejectionState + " not permitted");
        }
    }
    if (rejectionState == RejectionState.EMPTY) {
        ejb.deleteEmptyStudy(ctx);
        return locations;
    }
    List<Series> seriesWithPurgedInstances = ejb.findSeriesWithPurgedInstances(study.getPk());
    if (!seriesWithPurgedInstances.isEmpty()) {
        StoreSession session = storeService.newStoreSession(arcAE.getApplicationEntity());
        for (Series series : seriesWithPurgedInstances) {
            storeService.restoreInstances(session, study.getStudyInstanceUID(), series.getSeriesInstanceUID(), arcDev.getPurgeInstanceRecordsDelay());
        }
    }
    int limit = arcDev.getDeleteStudyChunkSize();
    int n;
    do {
        List<Location> locations1 = ejb.deleteStudy(ctx, limit, retainObj || reimport);
        n = locations1.size();
        LOG.debug("Deleted {} instances of {}", n, study);
        locations.addAll(locations1);
    } while (n == limit);
    LOG.info("Successfully delete {} from database", study);
    return locations;
}
Also used : Series(org.dcm4chee.arc.entity.Series) RejectionState(org.dcm4chee.arc.entity.RejectionState) ArchiveDeviceExtension(org.dcm4chee.arc.conf.ArchiveDeviceExtension) ArrayList(java.util.ArrayList) Location(org.dcm4chee.arc.entity.Location) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException) StoreSession(org.dcm4chee.arc.store.StoreSession)

Example 2 with StudyNotEmptyException

use of org.dcm4chee.arc.delete.StudyNotEmptyException in project dcm4chee-arc-light by dcm4che.

the class StudyMgtRS method deleteStudy.

@DELETE
@Path("/studies/{StudyUID}")
public void deleteStudy(@PathParam("StudyUID") String studyUID, @QueryParam("retainObj") @Pattern(regexp = "true|false") @DefaultValue("false") String retainObj) {
    logRequest();
    ArchiveAEExtension arcAE = getArchiveAE();
    try {
        deletionService.deleteStudy(studyUID, HttpServletRequestInfo.valueOf(request), arcAE, Boolean.parseBoolean(retainObj));
        rsForward.forward(RSOperation.DeleteStudy, arcAE, null, request);
    } catch (StudyNotFoundException e) {
        throw new WebApplicationException(errResponse(e.getMessage(), Response.Status.NOT_FOUND));
    } catch (StudyNotEmptyException e) {
        throw new WebApplicationException(errResponse(e.getMessage(), Response.Status.FORBIDDEN));
    } catch (Exception e) {
        throw new WebApplicationException(errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR));
    }
}
Also used : ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) StudyNotFoundException(org.dcm4chee.arc.delete.StudyNotFoundException) NoResultException(javax.persistence.NoResultException) StudyMissingException(org.dcm4chee.arc.study.StudyMissingException) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException) DateTimeParseException(java.time.format.DateTimeParseException) StudyNotFoundException(org.dcm4chee.arc.delete.StudyNotFoundException) JsonParsingException(javax.json.stream.JsonParsingException) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException)

Example 3 with StudyNotEmptyException

use of org.dcm4chee.arc.delete.StudyNotEmptyException 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)

Aggregations

StudyNotEmptyException (org.dcm4chee.arc.delete.StudyNotEmptyException)3 ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)2 StudyNotFoundException (org.dcm4chee.arc.delete.StudyNotFoundException)2 Location (org.dcm4chee.arc.entity.Location)2 StoreSession (org.dcm4chee.arc.store.StoreSession)2 DateTimeParseException (java.time.format.DateTimeParseException)1 ArrayList (java.util.ArrayList)1 JsonParsingException (javax.json.stream.JsonParsingException)1 NoResultException (javax.persistence.NoResultException)1 AsyncResponse (javax.ws.rs.container.AsyncResponse)1 ApplicationEntity (org.dcm4che3.net.ApplicationEntity)1 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)1 ArchiveDeviceExtension (org.dcm4chee.arc.conf.ArchiveDeviceExtension)1 RejectionState (org.dcm4chee.arc.entity.RejectionState)1 Series (org.dcm4chee.arc.entity.Series)1 QueryAttributes (org.dcm4chee.arc.query.util.QueryAttributes)1 Storage (org.dcm4chee.arc.storage.Storage)1 StoreContext (org.dcm4chee.arc.store.StoreContext)1 StudyMissingException (org.dcm4chee.arc.study.StudyMissingException)1