Search in sources :

Example 1 with RegistryResponseType

use of oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType in project nhin-d by DirectProject.

the class DocumentRepositoryAbstract method getRepositoryProvideResponse.

/**
     * Create a RegistryResponseType object.
     * 
     * @param messageId
     *            The message ID
     * @return a RegistryResponseType object
     * @throws Exception
     */
protected RegistryResponseType getRepositoryProvideResponse(String messageId) throws Exception {
    RegistryResponseType rrt = null;
    try {
        // Call Web Service Operation
        // TODO initialize WS operation arguments here
        String status = "urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Success";
        try {
            rrt = new RegistryResponseType();
            rrt.setStatus(status);
        } catch (Exception ex) {
            LOGGER.info("not sure what this ");
            ex.printStackTrace();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return rrt;
}
Also used : RegistryResponseType(oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType)

Example 2 with RegistryResponseType

use of oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType in project nhin-d by DirectProject.

the class XDClient method forward.

private String forward(String endpoint, ProvideAndRegisterDocumentSetRequestType request) throws Exception {
    LOGGER.trace("Sending XD* request to endpoint " + endpoint);
    this.to = endpoint;
    this.messageId = UUID.randomUUID().toString();
    this.action = "urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-bResponse";
    setHeaderData();
    DocumentRepositoryPortType port;
    try {
        port = DocumentRepositoryUtils.getDocumentRepositoryPortType(endpoint);
    } catch (Exception e) {
        throw new Exception("Unable to create port.", e);
    }
    RegistryResponseType rrt = port.documentRepositoryProvideAndRegisterDocumentSetB(request);
    String response = rrt.getStatus();
    LOGGER.trace("Sending complete.");
    return response;
}
Also used : DocumentRepositoryPortType(ihe.iti.xds_b._2007.DocumentRepositoryPortType) RegistryResponseType(oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType)

Example 3 with RegistryResponseType

use of oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType in project nhin-d by DirectProject.

the class DocumentRepositoryAbstract method provideAndRegisterDocumentSet.

/**
     * Handle an incoming ProvideAndRegisterDocumentSetRequestType object and
     * transform to XDM or relay to another XDR endponit.
     * 
     * @param prdst
     *            The incoming ProvideAndRegisterDocumentSetRequestType object
     * @return a RegistryResponseType object
     * @throws Exception
     */
protected RegistryResponseType provideAndRegisterDocumentSet(ProvideAndRegisterDocumentSetRequestType prdst) throws Exception {
    RegistryResponseType resp = null;
    try {
        getHeaderData();
        @SuppressWarnings("unused") InitialContext ctx = new InitialContext();
        DirectDocuments documents = xdsDirectDocumentsTransformer.transform(prdst);
        List<String> forwards = new ArrayList<String>();
        // Get endpoints (first check direct:to header, then go to intendedRecipients)
        if (StringUtils.isNotBlank(directTo))
            forwards = Arrays.asList((new URI(directTo).getSchemeSpecificPart()));
        else {
            forwards = ParserHL7.parseRecipients(documents);
        }
        messageId = UUID.randomUUID().toString();
        // TODO patID and subsetId
        String patId = "PATID TBD";
        String subsetId = "SUBSETID";
        getAuditMessageGenerator().provideAndRegisterAudit(messageId, remoteHost, endpoint, to, thisHost, patId, subsetId, pid);
        // Send to SMTP endpoints
        if (getResolver().hasSmtpEndpoints(forwards)) {
            // Get a reply address (first check direct:from header, then go to authorPerson)
            if (StringUtils.isNotBlank(directFrom))
                replyEmail = (new URI(directFrom)).getSchemeSpecificPart();
            else {
                replyEmail = documents.getSubmissionSet().getAuthorPerson();
                replyEmail = StringUtils.splitPreserveAllTokens(replyEmail, "^")[0];
                replyEmail = StringUtils.contains(replyEmail, "@") ? replyEmail : "nhindirect@nhindirect.org";
            }
            LOGGER.info("SENDING EMAIL TO " + getResolver().getSmtpEndpoints(forwards) + " with message id " + messageId);
            // Construct message wrapper
            DirectMessage message = new DirectMessage(replyEmail, getResolver().getSmtpEndpoints(forwards));
            message.setSubject("XD* Originated Message");
            message.setBody("Please find the attached XDM file.");
            message.setDirectDocuments(documents);
            // Send mail
            MailClient mailClient = getMailClient();
            mailClient.mail(message, messageId, suffix);
        }
        // Send to XD endpoints
        for (String reqEndpoint : getResolver().getXdEndpoints(forwards)) {
            String endpointUrl = getResolver().resolve(reqEndpoint);
            String to = StringUtils.remove(endpointUrl, "?wsdl");
            Long threadId = new Long(Thread.currentThread().getId());
            LOGGER.info("THREAD ID " + threadId);
            ThreadData threadData = new ThreadData(threadId);
            threadData.setTo(to);
            List<Document> docs = prdst.getDocument();
            // Make a copy of the original documents
            List<Document> originalDocs = new ArrayList<Document>();
            for (Document d : docs) originalDocs.add(d);
            // Clear document list
            docs.clear();
            // Re-add documents
            for (Document d : originalDocs) {
                Document doc = new Document();
                doc.setId(d.getId());
                DataHandler dh = d.getValue();
                ByteArrayOutputStream buffOS = new ByteArrayOutputStream();
                dh.writeTo(buffOS);
                byte[] buff = buffOS.toByteArray();
                DataSource source = new ByteArrayDataSource(buff, documents.getDocument(d.getId()).getMetadata().getMimeType());
                DataHandler dhnew = new DataHandler(source);
                doc.setValue(dhnew);
                docs.add(doc);
            }
            LOGGER.info(" SENDING TO ENDPOINT " + to);
            DocumentRepositoryProxy proxy = new DocumentRepositoryProxy(endpointUrl, new DirectSOAPHandlerResolver());
            RegistryResponseType rrt = proxy.provideAndRegisterDocumentSetB(prdst);
            String test = rrt.getStatus();
            if (test.indexOf("Failure") >= 0) {
                String error = "";
                try {
                    error = rrt.getRegistryErrorList().getRegistryError().get(0).getCodeContext();
                } catch (Exception x) {
                }
                throw new Exception("Failure Returned from XDR forward:" + error);
            }
            getAuditMessageGenerator().provideAndRegisterAuditSource(messageId, remoteHost, endpoint, to, thisHost, patId, subsetId, pid);
        }
        resp = getRepositoryProvideResponse(messageId);
        relatesTo = messageId;
        action = "urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-bResponse";
        to = endpoint;
        setHeaderData();
    } catch (Exception e) {
        e.printStackTrace();
        throw (e);
    }
    return resp;
}
Also used : DirectMessage(org.nhindirect.xd.common.DirectMessage) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document) URI(java.net.URI) InitialContext(javax.naming.InitialContext) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource) DirectDocuments(org.nhindirect.xd.common.DirectDocuments) MailClient(org.nhind.xdm.MailClient) SmtpMailClient(org.nhind.xdm.impl.SmtpMailClient) DirectSOAPHandlerResolver(org.nhindirect.xd.soap.DirectSOAPHandlerResolver) ThreadData(org.nhindirect.xd.soap.ThreadData) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) RegistryResponseType(oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType) DocumentRepositoryProxy(org.nhindirect.xd.proxy.DocumentRepositoryProxy)

Example 4 with RegistryResponseType

use of oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType in project nhin-d by DirectProject.

the class DocumentRepositoryAbstract method provideAndRegisterDocumentSet.

/**
     * Handle an incoming ProvideAndRegisterDocumentSetRequestType object and
     * transform to XDM or relay to another XDR endponit.
     * 
     * @param prdst
     *            The incoming ProvideAndRegisterDocumentSetRequestType object
     * @return a RegistryResponseType object
     * @throws Exception
     */
protected RegistryResponseType provideAndRegisterDocumentSet(ProvideAndRegisterDocumentSetRequestType prdst, SafeThreadData threadData) throws Exception {
    RegistryResponseType resp = null;
    try {
        @SuppressWarnings("unused") InitialContext ctx = new InitialContext();
        DirectDocuments documents = xdsDirectDocumentsTransformer.transform(prdst);
        List<String> forwards = new ArrayList<String>();
        // Get endpoints (first check direct:to header, then go to intendedRecipients)
        if (StringUtils.isNotBlank(threadData.getDirectTo()))
            forwards = Arrays.asList((new URI(threadData.getDirectTo()).getSchemeSpecificPart()));
        else {
            forwards = ParserHL7.parseDirectRecipients(documents);
        }
        // messageId = UUID.randomUUID().toString();  remove this , its is not righ,
        //we should keep the message id of the original message for a lot of reasons vpl
        // TODO patID and subsetId  for atn
        String patId = threadData.getMessageId();
        String subsetId = threadData.getMessageId();
        getAuditMessageGenerator().provideAndRegisterAudit(threadData.getMessageId(), threadData.getRemoteHost(), threadData.getRelatesTo(), threadData.getTo(), threadData.getThisHost(), patId, subsetId, threadData.getPid());
        // Send to SMTP endpoints
        if (getResolver().hasSmtpEndpoints(forwards)) {
            String replyEmail;
            // Get a reply address (first check direct:from header, then go to authorPerson)
            if (StringUtils.isNotBlank(threadData.getDirectFrom()))
                replyEmail = (new URI(threadData.getDirectFrom())).getSchemeSpecificPart();
            else {
                // replyEmail = documents.getSubmissionSet().getAuthorPerson();
                replyEmail = documents.getSubmissionSet().getAuthorTelecommunication();
                //   replyEmail = StringUtils.splitPreserveAllTokens(replyEmail, "^")[0];
                replyEmail = ParserHL7.parseXTN(replyEmail);
                replyEmail = StringUtils.contains(replyEmail, "@") ? replyEmail : "nhindirect@nhindirect.org";
            }
            LOGGER.info("SENDING EMAIL TO " + getResolver().getSmtpEndpoints(forwards) + " with message id " + threadData.getMessageId());
            // Construct message wrapper
            DirectMessage message = new DirectMessage(replyEmail, getResolver().getSmtpEndpoints(forwards));
            message.setSubject("XD* Originated Message");
            message.setBody("Please find the attached XDM file.");
            message.setDirectDocuments(documents);
            // Send mail
            MailClient mailClient = getMailClient();
            String fileName = threadData.getMessageId().replaceAll("urn:uuid:", "");
            mailClient.mail(message, fileName, threadData.getSuffix());
            getAuditMessageGenerator().provideAndRegisterAuditSource(threadData.getMessageId(), threadData.getRemoteHost(), threadData.getRelatesTo(), threadData.getTo(), threadData.getThisHost(), patId, subsetId, threadData.getPid());
        }
        // Send to XD endpoints
        for (String reqEndpoint : getResolver().getXdEndpoints(forwards)) {
            String endpointUrl = getResolver().resolve(reqEndpoint);
            String to = StringUtils.remove(endpointUrl, "?wsdl");
            threadData.setTo(to);
            threadData.setDirectTo(to);
            threadData.save();
            List<Document> docs = prdst.getDocument();
            // Make a copy of the original documents
            List<Document> originalDocs = new ArrayList<Document>();
            for (Document d : docs) originalDocs.add(d);
            // Clear document list
            docs.clear();
            // Re-add documents
            for (Document d : originalDocs) {
                Document doc = new Document();
                doc.setId(d.getId());
                DataHandler dh = d.getValue();
                ByteArrayOutputStream buffOS = new ByteArrayOutputStream();
                dh.writeTo(buffOS);
                byte[] buff = buffOS.toByteArray();
                DataSource source = new ByteArrayDataSource(buff, documents.getDocument(d.getId()).getMetadata().getMimeType());
                DataHandler dhnew = new DataHandler(source);
                doc.setValue(dhnew);
                docs.add(doc);
            }
            LOGGER.info(" SENDING TO ENDPOINT " + to);
            DocumentRepositoryProxy proxy = new DocumentRepositoryProxy(endpointUrl, new DirectSOAPHandlerResolver());
            RegistryResponseType rrt = proxy.provideAndRegisterDocumentSetB(prdst);
            String test = rrt.getStatus();
            if (test.indexOf("Failure") >= 0) {
                String error = "";
                try {
                    error = rrt.getRegistryErrorList().getRegistryError().get(0).getCodeContext();
                } catch (Exception x) {
                }
                throw new Exception("Failure Returned from XDR forward:" + error);
            }
            getAuditMessageGenerator().provideAndRegisterAuditSource(threadData.getMessageId(), threadData.getRemoteHost(), threadData.getRelatesTo(), threadData.getTo(), threadData.getThisHost(), patId, subsetId, threadData.getPid());
        }
        resp = getRepositoryProvideResponse(threadData.getMessageId());
        String relatesTo = threadData.getRelatesTo();
        threadData.setRelatesTo(threadData.getMessageId());
        threadData.setAction("urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-bResponse");
        threadData.setTo(null);
        threadData.save();
    } catch (Exception e) {
        e.printStackTrace();
        throw (e);
    }
    return resp;
}
Also used : DirectMessage(org.nhindirect.xd.common.DirectMessage) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document) URI(java.net.URI) InitialContext(javax.naming.InitialContext) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource) DirectDocuments(org.nhindirect.xd.common.DirectDocuments) MailClient(org.nhind.xdm.MailClient) SmtpMailClient(org.nhind.xdm.impl.SmtpMailClient) DirectSOAPHandlerResolver(org.nhindirect.xd.soap.DirectSOAPHandlerResolver) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) RegistryResponseType(oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType) DocumentRepositoryProxy(org.nhindirect.xd.proxy.DocumentRepositoryProxy)

Example 5 with RegistryResponseType

use of oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType in project nhin-d by DirectProject.

the class XDR method documentRepositoryProvideAndRegisterDocumentSetB.

/* 
     * (non-Javadoc)
     * 
     * @see org.nhind.xdr.DocumentRepositoryAbstract#documentRepositoryProvideAndRegisterDocumentSetB(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)
     */
public RegistryResponseType documentRepositoryProvideAndRegisterDocumentSetB(ProvideAndRegisterDocumentSetRequestType body) {
    RegistryResponseType resp = null;
    /**
       * Get thread data
       */
    Long threadID = Thread.currentThread().getId();
    SafeThreadData threadData = SafeThreadData.GetThreadInstance(threadID);
    try {
        resp = provideAndRegisterDocumentSet(body, threadData);
    } catch (Exception x) {
        threadData.setRelatesTo(threadData.getMessageId());
        threadData.setAction("urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-bResponse");
        threadData.setMessageId(UUID.randomUUID().toString());
        threadData.setTo(threadData.getEndpoint());
        threadData.save();
        resp = new RegistryResponseType();
        resp.setStatus("urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Failure");
        RegistryErrorList rel = new RegistryErrorList();
        String error = x.getMessage();
        if (error == null) {
            error = x.toString();
        }
        rel.setHighestSeverity(error);
        List<RegistryError> rl = rel.getRegistryError();
        RegistryError re = new RegistryError();
        String[] mess;
        if (error.contains(":"))
            mess = error.split(":");
        else
            mess = error.split(" ");
        String errorCode = mess[0];
        re.setErrorCode(errorCode);
        re.setSeverity("Error");
        re.setCodeContext(error);
        re.setLocation("XDR.java");
        re.setValue(error);
        rl.add(re);
        resp.setRegistryErrorList(rel);
    }
    return resp;
}
Also used : RegistryError(oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryError) SafeThreadData(org.nhindirect.xd.soap.SafeThreadData) RegistryErrorList(oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryErrorList) RegistryErrorList(oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryErrorList) List(java.util.List) RegistryResponseType(oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType)

Aggregations

RegistryResponseType (oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType)7 DocumentRepositoryProxy (org.nhindirect.xd.proxy.DocumentRepositoryProxy)3 DirectSOAPHandlerResolver (org.nhindirect.xd.soap.DirectSOAPHandlerResolver)3 Document (ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 DataHandler (javax.activation.DataHandler)2 DataSource (javax.activation.DataSource)2 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)2 InitialContext (javax.naming.InitialContext)2 MailClient (org.nhind.xdm.MailClient)2 SmtpMailClient (org.nhind.xdm.impl.SmtpMailClient)2 DirectDocuments (org.nhindirect.xd.common.DirectDocuments)2 DirectMessage (org.nhindirect.xd.common.DirectMessage)2 SafeThreadData (org.nhindirect.xd.soap.SafeThreadData)2 AuditMessageGenerator (com.gsihealth.auditclient.AuditMessageGenerator)1 DocumentRepositoryPortType (ihe.iti.xds_b._2007.DocumentRepositoryPortType)1 ProvideAndRegisterDocumentSetRequestType (ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)1 List (java.util.List)1