class RetrieveImagingDocumentSetRequestValidator implements Validator<EbXMLRetrieveImagingDocumentSetRequest, ValidationProfile> {

    @Override
    public void validate(EbXMLRetrieveImagingDocumentSetRequest request, ValidationProfile profile) {
        notNull(request, "request cannot be null");
        
        for (RetrieveStudy retrieveStudy : request.getRetrieveStudies()) {
            String studyInstanceUID = retrieveStudy.getStudyInstanceUID();
            metaDataAssert(studyInstanceUID != null && !studyInstanceUID.isEmpty(), STUDY_INSTANCE_UID_MUST_BE_SPECIFIED);

            for (RetrieveSeries retrieveSeries : retrieveStudy.getRetrieveSerieses()) {
                String seriesInstanceUID = retrieveSeries.getSeriesInstanceUID();
                metaDataAssert(seriesInstanceUID != null && !seriesInstanceUID.isEmpty(), SERIES_INSTANCE_UID_MUST_BE_SPECIFIED);

                for (RetrieveDocument document : retrieveSeries.getDocuments()) {
                    //todo: Eliminate this duplicate code from DocumentRequest?
                    String repoId = document.getRepositoryUniqueId();
                    metaDataAssert(repoId != null && !repoId.isEmpty(), REPO_ID_MUST_BE_SPECIFIED);

                    String docId = document.getDocumentUniqueId();
                    metaDataAssert(docId != null && !docId.isEmpty(), DOC_ID_MUST_BE_SPECIFIED);

                    if (profile.getProfile() == ValidationProfile.InteractionProfile.XCA) {
                        hcValidator.validate(document.getHomeCommunityId());
                    }
                }
            }
        }
    }

}