Exemple #1
0
  protected void handleFinalMoveResponse(MoveResponse finalMoveResponse) {
    final String fn = "handleFinalMoveResponse: ";

    log.debug(fn + "Received the final move response. Move Id = " + new Integer(moveId).toString());

    log.debug(fn + "Shutting down the Check Cancel timer.");
    checkCancelTimer.cancel();

    log.debug(fn + "Updating the move database record");
    num_objects_found_cache = getNumberOfFoundStudyObjects();
    num_objects_moved_cache = finalMoveResponse.getNumberOfStudyObjectsMoved();

    PreparedStatement stmt = null;
    try {
      Connection conn = getDbConnection();
      stmt = conn.prepareStatement(CompleteStmt.SQL);
      stmt.setString(InsertStmt.PARAM_STATUS, MoveStatus.COMPLETE.toString());
      stmt.setInt(CompleteStmt.PARAM_NUM_OBJECTS_FOUND, num_objects_found_cache);
      stmt.setInt(CompleteStmt.PARAM_NUM_OBJECTS_MOVED, num_objects_moved_cache);
      stmt.setString(CompleteStmt.PARAM_MAPPING_DOC, finalMoveResponse.getUidMappingDoc());
      stmt.setString(
          CompleteStmt.PARAM_STG_CMMT_FAILURES_DOC,
          finalMoveResponse.getStorageCommitFailuresDoc());
      stmt.setBoolean(CompleteStmt.PARAM_SUCCESSFUL, finalMoveResponse.moveSuccessful());
      stmt.setString(CompleteStmt.PARAM_ERROR, finalMoveResponse.getError());
      stmt.setTimestamp(
          CompleteStmt.PARAM_MOVE_ENDED, new Timestamp(new java.util.Date().getTime()));
      stmt.setInt(CompleteStmt.CONSTRAINTS_ID, moveId);
      if (stmt.executeUpdate() != 1) {
        log.error(
            fn
                + "Failed to update move instance database record.\nStatement: "
                + stmt.toString()
                + "\nWarnings:\n"
                + stmt.getWarnings().toString());
        lastError.set("Failed to update move instance database record.");
      }
    } catch (SQLException ex) {
      log.error(
          fn + "Failed to update move instance database record. Exception:\n" + ex.getMessage());
      lastError.set(ex.getMessage());
    } finally {
      CloseUtils.safeClose(stmt);
    }
    log.debug(fn + "Move processing is complete");
  }
Exemple #2
0
  void onCStoreRQ(
      Association as,
      int pcid,
      DicomObject rq,
      PDVInputStream dataStream,
      String tsuid,
      DicomObject rsp)
      throws IOException {

    String cuid = rq.getString(Tag.AffectedSOPClassUID);
    String iuid = rq.getString(Tag.AffectedSOPInstanceUID);

    DicomObject data =
        dataStream
            .readDataset(); // You have one shot to get the data. You can't read twice with
                            // readDataset method.
    String suid = data.getString(Tag.StudyInstanceUID);

    // Calendar today = Calendar.getInstance();
    // File struturedDestination = new File(destination.getAbsolutePath() + File.separator +
    // today.get(Calendar.YEAR) + File.separator + today.get(Calendar.MONTH) + File.separator +
    // today.get(Calendar.DATE) + File.separator + suid);
    File struturedDestination =
        new File(
            destination.getAbsolutePath() + File.separator + "oviyam2" + File.separator + suid);

    String child[] = struturedDestination.list();
    if (child == null) {
      struturedDestination.mkdirs();
    }

    File file = devnull != null ? struturedDestination : new File(struturedDestination, iuid);
    // LOG.info("M-WRITE {}", file);
    try {
      DicomOutputStream dos =
          new DicomOutputStream(
              new BufferedOutputStream(new FileOutputStream(file), fileBufferSize));
      try {
        BasicDicomObject fmi = new BasicDicomObject();
        fmi.initFileMetaInformation(cuid, iuid, tsuid);
        dos.writeFileMetaInformation(fmi);
        // dataStream.copyTo(dos);
        dos.writeDataset(data, tsuid);
      } finally {
        CloseUtils.safeClose(dos);
      }
    } catch (IOException e) {
      if (devnull == null && file != null) {
        if (file.delete()) {
          LOG.info("M-DELETE {}", file);
        }
      }
      throw new DicomServiceException(rq, Status.ProcessingFailure, e.getMessage());
    }

    // Rename the file after it has been written. See DCM-279
    /*if (devnull == null && file != null) {
    File rename = new File(file.getParent(), iuid);
    LOG.info("M-RENAME {} to {}", file, rename);
    file.renameTo(rename);
    if (cache.getJournalRootDir() != null) {
    cache.record(rename);
    }
    }*/
    // NetworkQueueUpdateDelegate networkQueueUpdateDelegate = new NetworkQueueUpdateDelegate();
    // networkQueueUpdateDelegate.updateReceiveTable(file, as.getCallingAET());
  }
Exemple #3
0
  /**
   * Starts a new move instance for the study specified. Creates a new database record, starts the
   * move process on a separate thread, and returns the move instance id.
   *
   * @param studyUid The study to move.
   * @param xformObjectData DICOM object attributes to be added/removed/xformed during the move.
   * @return The new move id, or 0 if failed to start the move. If the move failed to start you can
   *     call getLastError to get a reason for the failure.
   */
  public int startMove(String studyUid, ObjectTransformData xformObjData) {
    final String fn = "startMove: ";

    log.info(fn + "Request to move study with uid = " + studyUid);

    dcmMover = this;
    this.studyUid = studyUid;
    xformObjectData = xformObjData;
    lastError.set("");

    // Create a database record of this move attempt and get the primary key
    log.debug(fn + "Creating move instance database record");
    PreparedStatement stmt = null;
    try {
      Connection conn = getDbConnection();
      stmt = conn.prepareStatement(InsertStmt.SQL, Statement.RETURN_GENERATED_KEYS);
      stmt.setString(InsertStmt.PARAM_STATUS, MoveStatus.IN_PROGESS.toString());
      stmt.setBoolean(InsertStmt.PARAM_SUCCESSFUL, false);
      stmt.setString(InsertStmt.PARAM_STUDY_UID, studyUid);
      stmt.setInt(InsertStmt.PARAM_NUM_OBJECTS_FOUND, 0);
      stmt.setInt(InsertStmt.PARAM_NUM_OBJECTS_MOVED, 0);
      stmt.setString(InsertStmt.PARAM_SOURCE_AE, getMoveSourceAET());
      stmt.setString(InsertStmt.PARAM_DESTINATION_AE, getMoveDestinationAET());
      stmt.setBoolean(InsertStmt.PARAM_ANONYMIZED, null != xformObjData);
      stmt.setString(
          InsertStmt.PARAM_ANONYMIZE_DATA, (xformObjData == null ? null : xformObjData.toString()));
      stmt.setTimestamp(
          InsertStmt.PARAM_MOVE_STARTED, new Timestamp(new java.util.Date().getTime()));
      if (stmt.executeUpdate() != 1) {
        log.error(
            fn
                + "Failed to create move instance database record.\nStatement: "
                + stmt.toString()
                + "\nWarnings:\n"
                + stmt.getWarnings().toString());
        lastError.set("Failed to create move instance database record.");
        return 0;
      }
      ResultSet result = stmt.getGeneratedKeys();
      if (!result.next()) {
        log.error(
            fn
                + "Created move instance database record, but failed to retrieve new move Id.\nWarnings:\n"
                + stmt.getWarnings().toString());
        lastError.set("Created move instance database record, but failed to retrieve new move Id.");
        return 0;
      }
      moveId = result.getInt(InsertStmt.RETURN_COL_ID);
    } catch (SQLException e) {
      log.error(
          fn + "Failed to create move instance database record. Exception:\n" + e.getMessage());
      lastError.set(e.getMessage());
      return 0;
    } finally {
      CloseUtils.safeClose(stmt);
    }

    // Start the move process
    log.debug(fn + "Starting the move process asyncronously. Move Id = " + moveId);
    doMoveAsync();

    // Start a timer to monitor the move process for a client cancel request
    log.debug(fn + "Starting the CHECK_CANCEL_MOVE_TIMER timer");
    checkCancelTimer = new Timer("CHECK_CANCEL_MOVE_TIMER");
    checkCancelTimer.schedule(
        new CheckCancelTimerTask(this), CANCEL_TIMER_START_DELAY, CANCEL_TIMER_PERIOD);

    log.debug(fn + "Move process started");
    return moveId;
  }