public Attributes calculateStorageCommitmentResult(String calledAET,
Attributes actionInfo) throws DicomServiceException {
Sequence requestSeq = actionInfo.getSequence(Tag.ReferencedSOPSequence);
int size = requestSeq.size();
String[] sopIUIDs = new String[size];
Attributes eventInfo = new Attributes(6);
eventInfo.setString(Tag.RetrieveAETitle, VR.AE, calledAET);
eventInfo.setString(Tag.StorageMediaFileSetID, VR.SH, ddReader.getFileSetID());
eventInfo.setString(Tag.StorageMediaFileSetUID, VR.SH, ddReader.getFileSetUID());
eventInfo.setString(Tag.TransactionUID, VR.UI, actionInfo.getString(Tag.TransactionUID));
Sequence successSeq = eventInfo.newSequence(Tag.ReferencedSOPSequence, size);
Sequence failedSeq = eventInfo.newSequence(Tag.FailedSOPSequence, size);
LinkedHashMap<String, String> map =
new LinkedHashMap<String, String>(size * 4 / 3);
for (int i = 0; i < sopIUIDs.length; i++) {
Attributes item = requestSeq.get(i);
map.put(sopIUIDs[i] = item.getString(Tag.ReferencedSOPInstanceUID),
item.getString(Tag.ReferencedSOPClassUID));
}
DicomDirReader ddr = ddReader;
try {
Attributes patRec = ddr.findPatientRecord();
while (patRec != null) {
Attributes studyRec = ddr.findStudyRecord(patRec);
while (studyRec != null) {
Attributes seriesRec = ddr.findSeriesRecord(studyRec);
while (seriesRec != null) {
Attributes instRec = ddr.findLowerInstanceRecord(seriesRec, true, sopIUIDs);
while (instRec != null) {
String iuid = instRec.getString(Tag.ReferencedSOPInstanceUIDInFile);
String cuid = map.remove(iuid);
if (cuid.equals(instRec.getString(Tag.ReferencedSOPClassUIDInFile)))
successSeq.add(refSOP(iuid, cuid, Status.Success));
else
failedSeq.add(refSOP(iuid, cuid, Status.ClassInstanceConflict));
instRec = ddr.findNextInstanceRecord(instRec, true, sopIUIDs);
}