public void run()

in import/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/StorageCommitmentService.java [143:213]


    public void run() {
      List<CommitmentItem> presentInstances = new ArrayList<>();
      List<CommitmentItem> absentInstances = new ArrayList<>();

      Sequence sopSequence = data.getSequence(Tag.ReferencedSOPSequence);
      for (Attributes attrsItem : sopSequence) {
        Attributes queryAttributes = new Attributes();
        CommitmentItem cmtItem = new CommitmentItem(
            attrsItem.getString(Tag.ReferencedSOPInstanceUID),
            attrsItem.getString(Tag.ReferencedSOPClassUID));
        queryAttributes
            .setString(Tag.SOPInstanceUID, VR.UI, cmtItem.getInstanceUid());
        queryAttributes.setString(Tag.QueryRetrieveLevel, VR.CS, "IMAGE");
        try {
          String qidoPath = AttributesUtil.attributesToQidoPath(queryAttributes);
          JSONArray qidoResult = dicomWebClient.qidoRs(qidoPath);
          if (qidoResult == null || qidoResult.length() == 0) {
            cmtItem.setFailureReason(Status.NoSuchObjectInstance);
            absentInstances.add(cmtItem);
          } else {
            presentInstances.add(cmtItem);
          }
        } catch (DicomServiceException | IDicomWebClient.DicomWebException e) {
          MonitoringService.addEvent(Event.COMMITMENT_QIDORS_ERROR);
          log.error("Commitment QidoPath/QidoRs error: ", e);

          cmtItem.setFailureReason(toFailureReason(e));
          absentInstances.add(cmtItem);
        }
      }

      DicomClient dicomClient;
      try {
        dicomClient = DicomClient.associatePeer(applicationEntity,
            remoteAet.getHost(), remoteAet.getPort(), makeAAssociateRQ());
      } catch (Exception e) {
        MonitoringService.addEvent(Event.COMMITMENT_ERROR);
        log.error("associatePeer exception: ", e);
        return;
      }

      Association association = dicomClient.getAssociation();
      try {
        FutureDimseRSP handler = new FutureDimseRSP(association.nextMessageID());

        int eventTypeId =
            absentInstances.size() > 0 ? EVENT_ID_FAILURES_PRESENT : EVENT_ID_ALL_SUCCESS;
        association.neventReport(UID.StorageCommitmentPushModel,
            UID.StorageCommitmentPushModelInstance,
            eventTypeId,
            makeDataset(presentInstances, absentInstances),
            transferSyntax,
            handler);

        handler.next();
        int dimseStatus = handler.getCommand().getInt(Tag.Status, /* default status */ -1);
        if (dimseStatus != Status.Success) {
          throw new IOException("Commitment Report failed with status code: " + dimseStatus);
        }
      } catch (IOException | InterruptedException e) {
        MonitoringService.addEvent(Event.COMMITMENT_ERROR);
        log.error("neventReport error: ", e);
      } finally {
        try {
          association.release();
          association.waitForSocketClose();
        } catch (Exception e) {
          log.warn("Send Commitment Report successfully, but failed to close association: ", e);
        }
      }
    }