Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* 
   * Copyright (c) 2010, NHIN Direct Project
   * All rights reserved.
   *  
   * Redistribution and use in source and binary forms, with or without 
   * modification, are permitted provided that the following conditions are met:
   * 
   * 1. Redistributions of source code must retain the above copyright 
   *    notice, this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright 
  *    notice, this list of conditions and the following disclaimer in the 
  *    documentation and/or other materials provided with the distribution.  
  * 3. Neither the name of the the NHIN Direct Project (nhindirect.org)
  *    nor the names of its contributors may be used to endorse or promote products 
  *    derived from this software without specific prior written permission.
  * 
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 
  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 package org.nhindirect.xd.common;
 
 import static org.nhindirect.xd.common.DirectDocumentUtils.addSlot;
 import static org.nhindirect.xd.common.DirectDocumentUtils.makeInternationalStringType;
 import static org.nhindirect.xd.common.DirectDocumentUtils.makeSlot;
 import static org.nhindirect.xd.common.DirectDocumentUtils.slotNotEmpty;
 
 import java.util.Date;
 import java.util.List;
 
 
 
Abstract representation of a collection of documents with supporting metadata.

Author(s):
beau
 
 public class DirectDocuments {
 
     private List<DirectDocument2documents;
     private SubmissionSet submissionSet;
     private static final Log LOGGER = LogFactory.getFactory().getInstance(DirectDocuments.class);
 
     public DirectDocuments() {
         this. = new ArrayList<DirectDocument2>();
         this. = new SubmissionSet();
     }

    

Returns:
the submissionSet
 
     public SubmissionSet getSubmissionSet() {
         return ;
     }

    

Parameters:
submissionSet the submissionSet to set
 
    public void setSubmissionSet(SubmissionSet submissionSet) {
        if (this. != null && !this..equals(submissionSet)) {
            .warn("Overwriting existing SubmissionSet values");
        }
        this. = submissionSet;
    }

    

Returns:
the documents
    public List<DirectDocument2getDocuments() {
        return ;
    }

    

Parameters:
documents the documents to set
    public void setDocuments(List<DirectDocument2documents) {
        this. = documents;
    }

    
Get the metadata represented as a SubmitObjectsRequest object.
        RegistryPackageType registryPackageType = .generateRegistryPackageType();
        ClassificationType classificationType = .generateClassificationType();
        QName qname = null;
        // Generate ExtrinsicObjectType objects for each document
        List<JAXBElement<ExtrinsicObjectType>> jaxb_extrinsicObjectTypes = new ArrayList<JAXBElement<ExtrinsicObjectType>>();
        for (DirectDocument2 document : ) {
            ExtrinsicObjectType extrinsicObjectType = document.getMetadata().generateExtrinsicObjectType();
            JAXBElement<ExtrinsicObjectTypejaxb_extrinsicObjectType = new JAXBElement<ExtrinsicObjectType>(qnameExtrinsicObjectType.classextrinsicObjectType);
            jaxb_extrinsicObjectTypes.add(jaxb_extrinsicObjectType);
        }
        // Generate the RegistryPakageType (SubmissionSet) for the group of
        // documents
        JAXBElement<RegistryPackageTypejaxb_registryPackageType = new JAXBElement<RegistryPackageType>(qnameRegistryPackageType.classregistryPackageType);
        // Generate the ClassificationType object
        JAXBElement<ClassificationTypejaxb_classificationType = new JAXBElement<ClassificationType>(qnameClassificationType.classclassificationType);
        // Generate AssociationType1 objects for each document
        List<JAXBElement<AssociationType1>> jaxb_associationType1s = new ArrayList<JAXBElement<AssociationType1>>();
        for (DirectDocument2 document : ) {
            AssociationType1 associationType = .generateAssociationType(document.getMetadata().getId(), document.getMetadata().getSubmissionSetStatus());
            JAXBElement<AssociationType1jaxb_AssociationType1 = new JAXBElement<AssociationType1>(qnameAssociationType1.classassociationType);
            jaxb_associationType1s.add(jaxb_AssociationType1);
        }
        SubmitObjectsRequest submitObjectsRequest = new SubmitObjectsRequest();
        RegistryObjectListType registryObjectListType = new RegistryObjectListType();
        List<JAXBElement<? extends IdentifiableType>> elements = registryObjectListType.getIdentifiable();
        elements.addAll(jaxb_extrinsicObjectTypes);
        elements.add(jaxb_registryPackageType);
        elements.add(jaxb_classificationType);
        elements.addAll(jaxb_associationType1s);
        submitObjectsRequest.setRegistryObjectList(registryObjectListType);
        return submitObjectsRequest;
    }
    public void setValues(String submitObjectsRequestXmlthrows Exception {
        SubmitObjectsRequest sor = (SubmitObjectsRequest) XmlUtils.unmarshal(new String(submitObjectsRequestXml), oasis.names.tc.ebxml_regrep.xsd.lcm._3.ObjectFactory.class);
        setValues(sor);
    }
    public void setValues(SubmitObjectsRequest submitObjectsRequestthrows MetadataException {
        RegistryObjectListType rol = submitObjectsRequest.getRegistryObjectList();
        List<JAXBElement<? extends IdentifiableType>> elements = rol.getIdentifiable();
        for (JAXBElement<? extends IdentifiableTypeelement : elements) {
            if (element.getValue() instanceof oasis.names.tc.ebxml_regrep.xsd.rim._3.ExtrinsicObjectType) {
                ExtrinsicObjectType eot = (ExtrinsicObjectTypeelement.getValue();
                DirectDocument2 document = new DirectDocument2();
                DirectDocument2.Metadata metadata = document.getMetadata();
                metadata.setValues(eot);
                .add(document);
            } else if (element.getValue() instanceof oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) {
                RegistryPackageType rpt = (RegistryPackageTypeelement.getValue();
                SubmissionSet submissionSet = new SubmissionSet();
                submissionSet.setValues(rpt);
                this. = submissionSet;
            } else if (element.getValue() instanceof oasis.names.tc.ebxml_regrep.xsd.rim._3.ClassificationType) {
                // Empty in example
            }
        }
        for (JAXBElement<? extends IdentifiableTypeelement : elements) {
            if (element.getValue() instanceof oasis.names.tc.ebxml_regrep.xsd.rim._3.AssociationType1) {
                AssociationType1 at = (AssociationType1element.getValue();
                for (SlotType1 slot : at.getSlot()) {
                    if (..matches(slot.getName())) {
                        if (slotNotEmpty(slot)) {
                            getDocumentById(at.getTargetObject()).getMetadata().setSubmissionSetStatus(slot.getName());
                        }
                    }
                }
            }
        }
    }
    public DirectDocument2 getDocumentById(String targetObject) {
        for (DirectDocument2 document : ) {
            if (StringUtils.equalsIgnoreCase(document.getMetadata().getId(), targetObject)) {
                return document;
            }
        }
        return null;
    }
    public DirectDocument2 getDocumentByUniqueId(String uniqueId) {
        for (DirectDocument2 document : ) {
            if (StringUtils.equalsIgnoreCase(document.getMetadata().getUniqueId(), uniqueId)) {
                return document;
            }
        }
        return null;
    }
    public DirectDocument2 getDocumentByHash(String hash) {
        for (DirectDocument2 document : ) {
            if (StringUtils.equalsIgnoreCase(document.getMetadata().getHash(), hash)) {
                return document;
            }
        }
        return null;
    }
    public DirectDocument2 getDocument(String identifier) {
        DirectDocument2 document = null;
        document = getDocumentById(identifier);
        if (document != null) {
            return document;
        }
        document = getDocumentByUniqueId(identifier);
        if (document != null) {
            return document;
        }
        document = getDocumentByHash(identifier);
        if (document != null) {
            return document;
        }
        return document;
    }
        return XmlUtils.marshal(qnamegetSubmitObjectsRequest(), ihe.iti.xds_b._2007.ObjectFactory.class);
    }
        request.setSubmitObjectsRequest(this.getSubmitObjectsRequest());
        for (DirectDocument2 document : ) {
            if (document.getData() != null) {
                DataSource source = new ByteArrayDataSource(document.getData(), document.getMetadata().getMimeType());
                DataHandler dhnew = new DataHandler(source);
                Document pdoc = new Document();
                pdoc.setValue(dhnew);
                String id = document.getMetadata().getId();
                pdoc.setId(id);
                request.getDocument().add(pdoc);
            }
        }
        return request;
    }
    public XdmPackage toXdmPackage(String messageId) {
        XdmPackage xdmPackage = new XdmPackage(messageId);
        xdmPackage.setDocuments(this);
        return xdmPackage;
    }

    
Representation of a Submission Set element.

Author(s):
beau
    static public class SubmissionSet {
        private String id;
        private String name;
        private String description;
        private Date submissionTime;
        private List<StringintendedRecipient = new ArrayList<String>();
        private String authorPerson;
        private List<StringauthorInstitution = new ArrayList<String>();
        private String authorRole;
        private String authorSpecialty;
        private String authorTelecommunication;
        private String contentTypeCode;
        private String contentTypeCode_localized;
        private String uniqueId;
        private String sourceId;
        private String patientId;
        public SubmissionSet() {
            this. = "SubmissionSet01";
        }
        protected RegistryPackageType generateRegistryPackageType() {
            RegistryPackageType rpt = new RegistryPackageType();
            rpt.setId();
            List<SlotType1slots = rpt.getSlot();
            addSlot(slotsmakeSlot(. != null ? (new SimpleDateFormat("yyyyMMddHHmmss")).format() : null));
            rpt.setName(makeInternationalStringType());
            // author
            ClassificationType authorClassification = new ClassificationType();
            authorClassification.setClassifiedObject();
            authorClassification.setNodeRepresentation(""); // required empty string
            authorClassification.setId(..getClassificationId());
            List<SlotType1authorClassificationSlots = authorClassification.getSlot();
            addSlot(authorClassificationSlotsmakeSlot(.));
            addSlot(authorClassificationSlotsmakeSlot(.));
            addSlot(authorClassificationSlotsmakeSlot(.));
            addSlot(authorClassificationSlotsmakeSlot(.));
            addSlot(authorClassificationSlotsmakeSlot(.));
            rpt.getClassification().add(authorClassification);
            // contentTypeCode
            ClassificationType contentTypeCodeClassification = new ClassificationType();
            contentTypeCodeClassification.setClassifiedObject();
            contentTypeCodeClassification.setNodeRepresentation();
            contentTypeCodeClassification.setName(makeInternationalStringType());
            contentTypeCodeClassification.setId(..getClassificationId());
            contentTypeCodeClassification.setClassificationScheme(..getClassificationScheme());
            List<SlotType1contentTypeCodeClassificationSlots = contentTypeCodeClassification.getSlot();
            addSlot(contentTypeCodeClassificationSlotsmakeSlot(...getCodingScheme()));
            rpt.getClassification().add(contentTypeCodeClassification);
            // uniqueId
            ExternalIdentifierType xdsSubmissionSet_uniqueId = new ExternalIdentifierType();
            xdsSubmissionSet_uniqueId.setValue();
            xdsSubmissionSet_uniqueId.setRegistryObject();
            xdsSubmissionSet_uniqueId.setId(..getIdentificationId());
            rpt.getExternalIdentifier().add(xdsSubmissionSet_uniqueId);
            // sourceId
            ExternalIdentifierType xdsSubmissionSet_sourceId = new ExternalIdentifierType();
            xdsSubmissionSet_sourceId.setValue();
            xdsSubmissionSet_sourceId.setRegistryObject();
            xdsSubmissionSet_sourceId.setId(..getIdentificationId());
            rpt.getExternalIdentifier().add(xdsSubmissionSet_sourceId);
            // patientId
            ExternalIdentifierType xdsSubmissionSet_patientId = new ExternalIdentifierType();
            xdsSubmissionSet_patientId.setValue();
            xdsSubmissionSet_patientId.setRegistryObject();
            xdsSubmissionSet_patientId.setId(..getIdentificationId());
            rpt.getExternalIdentifier().add(xdsSubmissionSet_patientId);
            return rpt;
        }
        protected ClassificationType generateClassificationType() {
            ClassificationType ct = new ClassificationType();
            ct.setClassifiedObject();
            ct.setId(..getClassificationId());
            return ct;
        }
        protected AssociationType1 generateAssociationType(String documentIdString submissionSetStatus) {
            AssociationType1 at = new AssociationType1();
            at.setSourceObject();
            at.setTargetObject(documentId);
            List<SlotType1slots = at.getSlot();
            addSlot(slotsmakeSlot(.submissionSetStatus));
            return at;
        }
        protected void setValues(RegistryPackageType rptthrows MetadataException {
             = rpt.getId();
             = rpt.getName().getLocalizedString().get(0).getValue();
            if (rpt.getDescription() != null) {
                 = rpt.getDescription().getLocalizedString().get(0).getValue();
            }
            for (SlotType1 slot : rpt.getSlot()) {
                if (..matches(slot.getName())) {
                    if (slotNotEmpty(slot)) {
                        try {
                             = DateUtils.parseDate(slot.getValueList().getValue().get(
                                    0), new String[]{"yyyyMMddHHmmss""yyyyMMddHHmm""yyyyMMdd"});
                        } catch (ParseException e) {
                            .error("Unable to parse submissionTime"e);
                            throw new MetadataException("Unable to parse submissionTime"e);
                        }
                    }
                } else if (..matches(slot.getName())) {
                    if (slotNotEmpty(slot)) {
                        for (String value : slot.getValueList().getValue()) {
                            .add(value);
                        }
                    }
                }
            }
            for (ClassificationType ct : rpt.getClassification()) {
                if (..matchesScheme(ct.getClassificationScheme())) {
                    for (SlotType1 slot : ct.getSlot()) {
                        if (..matches(slot.getName())) {
                            if (slotNotEmpty(slot)) {
                                 = slot.getValueList().getValue().get(0);
                            }
                        } else if (..matches(slot.getName())) {
                            if (slotNotEmpty(slot)) {
                                for (String value : slot.getValueList().getValue()) {
                                    .add(value);
                                }
                            }
                        } else if (..matches(slot.getName())) {
                            if (slotNotEmpty(slot)) {
                                 = slot.getValueList().getValue().get(0);
                            }
                        } else if (..matches(slot.getName())) {
                            if (slotNotEmpty(slot)) {
                                 = slot.getValueList().getValue().get(0);
                            }
                        } else if (..matches(slot.getName())) {
                            if (slotNotEmpty(slot)) {
                                 = slot.getValueList().getValue().get(0);
                            }
                        }
                    }
                }
                    for (SlotType1 slot : ct.getSlot()) {
                        if (..matches(slot.getName())) {
                            if (slotNotEmpty(slot)) {
                                @SuppressWarnings("unused")
                                String codingScheme = slot.getValueList().getValue().get(0);
                            }
                        }
                    }
                     = ct.getNodeRepresentation();
                    if (ct.getName() != null && ct.getName().getLocalizedString() != null && !ct.getName().getLocalizedString().isEmpty()) {
                         = ct.getName().getLocalizedString().get(0).getValue();
                    }
                }
            }
            for (ExternalIdentifierType eit : rpt.getExternalIdentifier()) {
                     = eit.getValue();
                } else if (..matchesScheme(eit.getIdentificationScheme())) {
                     = eit.getValue();
                } else if (..matchesScheme(eit.getIdentificationScheme())) {
                     = eit.getValue();
                }
            }
        }
        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString() {
            return XmlUtils.marshal(qnamegenerateRegistryPackageType(), ihe.iti.xds_b._2007.ObjectFactory.class);
        }

        

Returns:
the id
        public String getId() {
            return ;
        }

        

Parameters:
id the id to set
        public void setId(String id) {
            this. = id;
        }

        

Returns:
the name
        public String getName() {
            return ;
        }

        

Parameters:
name the name to set
        public void setName(String name) {
            this. = name;
        }

        

Returns:
the description
        public String getDescription() {
            return ;
        }

        

Parameters:
description the description to set
        public void setDescription(String description) {
            this. = description;
        }

        

Returns:
the submissionTime
        public Date getSubmissionTime() {
            return ;
        }

        

Parameters:
submissionTime the submissionTime to set
        public void setSubmissionTime(Date submissionTime) {
            this. = submissionTime;
        }

        

Returns:
the intendedRecipient
        public List<StringgetIntendedRecipient() {
            return ;
        }

        

Parameters:
intendedRecipient the intendedRecipient to set
        public void setIntendedRecipient(List<StringintendedRecipient) {
            this. = intendedRecipient;
        }

        

Returns:
the authorPerson
        public String getAuthorPerson() {
            return ;
        }

        

Parameters:
authorPerson the authorPerson to set
        public void setAuthorPerson(String authorPerson) {
            this. = authorPerson;
        }

        

Returns:
the authorInstitution
        public List<StringgetAuthorInstitution() {
            return ;
        }

        

Parameters:
authorInstitution the authorInstitution to set
        public void setAuthorInstitution(List<StringauthorInstitution) {
            this. = authorInstitution;
        }

        

Returns:
the authorRole
        public String getAuthorRole() {
            return ;
        }

        

Parameters:
authorRole the authorRole to set
        public void setAuthorRole(String authorRole) {
            this. = authorRole;
        }

        

Returns:
the authorSpecialty
        public String getAuthorSpecialty() {
            return ;
        }

        

Parameters:
authorSpecialty the authorSpecialty to set
        public void setAuthorSpecialty(String authorSpecialty) {
            this. = authorSpecialty;
        }

        

Returns:
the authorTelecommunication
        public String getAuthorTelecommunication() {
            return ;
        }

        

Parameters:
authorTelecommunication the authorTelecommunication to set
        public void setAuthorTelecommunication(String authorTelecommunication) {
            this. = authorTelecommunication;
        }

        

Returns:
the contentTypeCode
        public String getContentTypeCode() {
            return ;
        }

        

Parameters:
contentTypeCode the contentTypeCode to set
        public void setContentTypeCode(String contentTypeCode) {
            setContentTypeCode(contentTypeCodefalse);
        }

        

Parameters:
contentTypeCode the contentTypeCode to set
setLocalized whether or not to set the localized field with the same value
        public void setContentTypeCode(String contentTypeCodeboolean setLocalized) {
            this. = contentTypeCode;
            if (setLocalized) {
                this. = contentTypeCode;
            }
        }

        

Returns:
the contentTypeCode_localized
        public String getContentTypeCode_localized() {
            return ;
        }

        

Parameters:
contentTypeCodeLocalized the contentTypeCode_localized to set
        public void setContentTypeCode_localized(String contentTypeCodeLocalized) {
             = contentTypeCodeLocalized;
        }

        

Returns:
the uniqueId
        public String getUniqueId() {
            return ;
        }

        

Parameters:
uniqueId the uniqueId to set
        public void setUniqueId(String uniqueId) {
            this. = uniqueId;
        }

        

Returns:
the sourceId
        public String getSourceId() {
            return ;
        }

        

Parameters:
sourceId the sourceId to set
        public void setSourceId(String sourceId) {
            this. = sourceId;
        }

        

Returns:
the patientId
        public String getPatientId() {
            return ;
        }

        

Parameters:
patientId the patientId to set
        public void setPatientId(String patientId) {
            this. = patientId;
        }
        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Object#hashCode()
         */
        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            result = prime * result + (( == null) ? 0 : .hashCode());
            return result;
        }
        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Object#equals(java.lang.Object)
         */
        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj == null) {
                return false;
            }
            if (!(obj instanceof SubmissionSet)) {
                return false;
            }
            SubmissionSet other = (SubmissionSetobj;
            if ( == null) {
                if (other.authorInstitution != null) {
                    return false;
                }
            } else if (!.equals(other.authorInstitution)) {
                return false;
            }
            if ( == null) {
                if (other.authorPerson != null) {
                    return false;
                }
            } else if (!.equals(other.authorPerson)) {
                return false;
            }
            if ( == null) {
                if (other.authorRole != null) {
                    return false;
                }
            } else if (!.equals(other.authorRole)) {
                return false;
            }
            if ( == null) {
                if (other.authorSpecialty != null) {
                    return false;
                }
            } else if (!.equals(other.authorSpecialty)) {
                return false;
            }
            if ( == null) {
                if (other.authorTelecommunication != null) {
                    return false;
                }
            } else if (!.equals(other.authorTelecommunication)) {
                return false;
            }
            if ( == null) {
                if (other.contentTypeCode != null) {
                    return false;
                }
            } else if (!.equals(other.contentTypeCode)) {
                return false;
            }
            if ( == null) {
                if (other.contentTypeCode_localized != null) {
                    return false;
                }
            } else if (!.equals(other.contentTypeCode_localized)) {
                return false;
            }
            if ( == null) {
                if (other.description != null) {
                    return false;
                }
            } else if (!.equals(other.description)) {
                return false;
            }
            if ( == null) {
                if (other.id != null) {
                    return false;
                }
            } else if (!.equals(other.id)) {
                return false;
            }
            if ( == null) {
                if (other.intendedRecipient != null) {
                    return false;
                }
            } else if (!.equals(other.intendedRecipient)) {
                return false;
            }
            if ( == null) {
                if (other.name != null) {
                    return false;
                }
            } else if (!.equals(other.name)) {
                return false;
            }
            if ( == null) {
                if (other.patientId != null) {
                    return false;
                }
            } else if (!.equals(other.patientId)) {
                return false;
            }
            if ( == null) {
                if (other.sourceId != null) {
                    return false;
                }
            } else if (!.equals(other.sourceId)) {
                return false;
            }
            if ( == null) {
                if (other.submissionTime != null) {
                    return false;
                }
            } else if (!.equals(other.submissionTime)) {
                return false;
            }
            if ( == null) {
                if (other.uniqueId != null) {
                    return false;
                }
            } else if (!.equals(other.uniqueId)) {
                return false;
            }
            return true;
        }
    }
New to GrepCode? Check out our FAQ X