List of usage examples for javax.activation DataHandler DataHandler
public DataHandler(URL url)
DataHandler
instance referencing a URL. From source file:edu.xtec.colex.client.beans.ColexIndexBean.java
/** * Calls the web service operation <I>importCollection(User,Collection,FILE) * : void</I>/*from w w w .j a va 2 s .co m*/ * * @param importName the String name of the Collection to import * @param fiImport the FileItem Zip of the Collection to import * @throws java.lang.Exception when an Exception error occurs */ private void importCollection(String importName, FileItem fiImport) throws Exception { User uRequest = new User(getUserId()); Collection cRequest = new Collection(importName); File fTemp = null; try { smRequest = mf.createMessage(); SOAPBody sbRequest = smRequest.getSOAPBody(); Name n = sf.createName("importCollection"); SOAPBodyElement sbeRequest = sbRequest.addBodyElement(n); sbeRequest.addChildElement(uRequest.toXml()); sbeRequest.addChildElement(cRequest.toXml()); String sNomFitxer = Utils.getFileName(fiImport.getName()); fTemp = File.createTempFile("attach", null); fiImport.write(fTemp); URL urlFile = new URL("file://" + fTemp.getPath()); AttachmentPart ap = smRequest.createAttachmentPart(new DataHandler(urlFile)); smRequest.addAttachmentPart(ap); smRequest.saveChanges(); SOAPMessage smResponse = sendMessage(smRequest, this.getJspProperties().getProperty("url.servlet.collection")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "import"); } else { } } catch (Exception e) { throw e; } finally { if (fTemp != null) { fTemp.delete(); } } }
From source file:com.docdoku.client.actions.MainController.java
public void saveFile(Component pParent, DocumentIteration pDocument, File pLocalFile) throws Exception { if (!NamingConvention.correct(pLocalFile.getName())) { throw new NotAllowedException(Locale.getDefault(), "NotAllowedException9"); }//from w w w. java2 s. com MainModel model = MainModel.getInstance(); String message = I18N.BUNDLE.getString("UploadMsg_part1") + " " + pLocalFile.getName() + " (" + (int) (pLocalFile.length() / 1024) + I18N.BUNDLE.getString("UploadMsg_part2"); DataHandler data = new DataHandler(new ProgressMonitorFileDataSource(pParent, pLocalFile, message)); try { Map<String, Object> ctxt = ((BindingProvider) mFileService).getRequestContext(); try { if (ctxt.containsKey(Config.HTTP_CLIENT_STREAMING_CHUNK_SIZE)) { mFileService.uploadToDocument(model.getWorkspace().getId(), pDocument.getDocumentMasterId(), pDocument.getDocumentMasterVersion(), pDocument.getIteration(), pLocalFile.getName(), data); } else { //workaround mode uploadFileWithServlet(pParent, pLocalFile, getServletURL(pDocument, pLocalFile)); } } catch (Exception ex) { Throwable currentEx = ex; while (currentEx != null) { if (currentEx instanceof InterruptedIOException) throw ex; if (currentEx instanceof ApplicationException) throw ex; currentEx = currentEx.getCause(); } //error encountered, try again, workaround mode if (ctxt.containsKey(Config.HTTP_CLIENT_STREAMING_CHUNK_SIZE)) { System.out.println("Disabling chunked mode"); ctxt.remove(Config.HTTP_CLIENT_STREAMING_CHUNK_SIZE); uploadFileWithServlet(pParent, pLocalFile, getServletURL(pDocument, pLocalFile)); } else { //we were already not using the chunked mode //there's not much to do... throw ex; } } } catch (WebServiceException pWSEx) { Throwable t = pWSEx.getCause(); if (t instanceof Exception) { throw (Exception) t; } else { throw pWSEx; } } }
From source file:gov.nih.nci.cacis.nav.AbstractSendMail.java
/** * Creates MimeMessage with supplied values * /*from w w w . ja va 2 s . c om*/ * @param to - to email address * @param docType - String value for the attached document type * @param subject - Subject for the email * @param instructions - email body * @param content - content to be sent as attachment * @return MimeMessage instance */ public MimeMessage createMessage(String to, String docType, String subject, String instructions, String content, String metadataXMl, String title, String indexBodyToken, String readmeToken) { final MimeMessage msg = mailSender.createMimeMessage(); UUID uniqueID = UUID.randomUUID(); tempZipFolder = new File(secEmailTempZipLocation + "/" + uniqueID); try { msg.setFrom(new InternetAddress(getFrom())); msg.setSubject(subject); msg.setSentDate(new Date()); msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); // The readable part final MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(instructions); mbp1.setHeader("Content-Type", "text/plain"); // The notification final MimeBodyPart mbp2 = new MimeBodyPart(); final String contentType = "application/xml; charset=UTF-8"; String extension; // HL7 messages should be a txt file, otherwise xml if (StringUtils.contains(instructions, "HL7_V2_CLINICAL_NOTE")) { extension = TXT_EXT; } else { extension = XML_EXT; } final String fileName = docType + UUID.randomUUID() + extension; // final DataSource ds = new AttachmentDS(fileName, content, contentType); // mbp2.setDataHandler(new DataHandler(ds)); /******** START NHIN COMPLIANCE CHANGES *****/ boolean isTempZipFolderCreated = tempZipFolder.mkdirs(); if (!isTempZipFolderCreated) { LOG.error("Error creating temp folder for NHIN zip file: " + tempZipFolder.getAbsolutePath()); throw new ApplicationRuntimeException( "Error creating temp folder for NHIN zip file: " + tempZipFolder.getAbsolutePath()); } String indexFileString = FileUtils.readFileToString(new File(secEmailTempZipLocation + "/INDEX.HTM")); String readmeFileString = FileUtils.readFileToString(new File(secEmailTempZipLocation + "/README.TXT")); indexFileString = StringUtils.replace(indexFileString, "@document_title@", title); indexFileString = StringUtils.replace(indexFileString, "@indexBodyToken@", indexBodyToken); FileUtils.writeStringToFile(new File(tempZipFolder + "/INDEX.HTM"), indexFileString); readmeFileString = StringUtils.replace(readmeFileString, "@readmeToken@", readmeToken); FileUtils.writeStringToFile(new File(tempZipFolder + "/README.TXT"), readmeFileString); // move template files & replace tokens // FileUtils.copyFileToDirectory(new File(secEmailTempZipLocation + "/INDEX.HTM"), tempZipFolder, false); // FileUtils.copyFileToDirectory(new File(secEmailTempZipLocation + "/README.TXT"), tempZipFolder, false); // create sub-directories String nhinSubDirectoryPath = tempZipFolder + "/IHE_XDM/SUBSET01"; File nhinSubDirectory = new File(nhinSubDirectoryPath); boolean isNhinSubDirectoryCreated = nhinSubDirectory.mkdirs(); if (!isNhinSubDirectoryCreated) { LOG.error("Error creating NHIN sub-directory: " + nhinSubDirectory.getAbsolutePath()); throw new ApplicationRuntimeException( "Error creating NHIN sub-directory: " + nhinSubDirectory.getAbsolutePath()); } FileOutputStream metadataStream = new FileOutputStream( new File(nhinSubDirectoryPath + "/METADATA.XML")); metadataStream.write(metadataXMl.getBytes()); metadataStream.flush(); metadataStream.close(); FileOutputStream documentStream = new FileOutputStream( new File(nhinSubDirectoryPath + "/DOCUMENT" + extension)); documentStream.write(content.getBytes()); documentStream.flush(); documentStream.close(); String zipFile = secEmailTempZipLocation + "/" + tempZipFolder.getName() + ".ZIP"; byte[] buffer = new byte[1024]; // FileOutputStream fos = new FileOutputStream(zipFile); // ZipOutputStream zos = new ZipOutputStream(fos); List<String> fileList = generateFileList(tempZipFolder); ByteArrayOutputStream bout = new ByteArrayOutputStream(fileList.size()); ZipOutputStream zos = new ZipOutputStream(bout); // LOG.info("File List size: "+fileList.size()); for (String file : fileList) { ZipEntry ze = new ZipEntry(file); zos.putNextEntry(ze); FileInputStream in = new FileInputStream(tempZipFolder + File.separator + file); int len; while ((len = in.read(buffer)) > 0) { zos.write(buffer, 0, len); } in.close(); } zos.closeEntry(); // remember close it zos.close(); DataSource source = new ByteArrayDataSource(bout.toByteArray(), "application/zip"); mbp2.setDataHandler(new DataHandler(source)); mbp2.setFileName(docType + ".ZIP"); /******** END NHIN COMPLIANCE CHANGES *****/ // mbp2.setFileName(fileName); // mbp2.setHeader("Content-Type", contentType); final Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); msg.setContent(mp); msg.setSentDate(new Date()); // FileUtils.deleteDirectory(tempZipFolder); } catch (AddressException e) { LOG.error("Error creating email message!"); throw new ApplicationRuntimeException("Error creating message!", e); } catch (MessagingException e) { LOG.error("Error creating email message!"); throw new ApplicationRuntimeException("Error creating message!", e); } catch (IOException e) { LOG.error(e.getMessage()); throw new ApplicationRuntimeException(e.getMessage()); } finally { //reset filelist contents fileList = new ArrayList<String>(); } return msg; }
From source file:com.cloud.bridge.service.controller.s3.S3ObjectAction.java
private void executePutObject(HttpServletRequest request, HttpServletResponse response) throws IOException { String continueHeader = request.getHeader("Expect"); if (continueHeader != null && continueHeader.equalsIgnoreCase("100-continue")) { S3RestServlet.writeResponse(response, "HTTP/1.1 100 Continue\r\n"); }/*from w ww .java2s . c om*/ String contentType = request.getHeader("Content-Type"); long contentLength = Converter.toLong(request.getHeader("Content-Length"), 0); String bucket = (String) request.getAttribute(S3Constants.BUCKET_ATTR_KEY); String key = (String) request.getAttribute(S3Constants.OBJECT_ATTR_KEY); S3PutObjectInlineRequest engineRequest = new S3PutObjectInlineRequest(); engineRequest.setBucketName(bucket); engineRequest.setKey(key); engineRequest.setContentLength(contentLength); engineRequest.setMetaEntries(extractMetaData(request)); engineRequest.setCannedAccess(request.getHeader("x-amz-acl")); DataHandler dataHandler = new DataHandler(new ServletRequestDataSource(request)); engineRequest.setData(dataHandler); S3PutObjectInlineResponse engineResponse = ServiceProvider.getInstance().getS3Engine() .handleRequest(engineRequest); response.setHeader("ETag", engineResponse.getETag()); String version = engineResponse.getVersion(); if (null != version) response.addHeader("x-amz-version-id", version); }
From source file:it.eng.spagobi.tools.scheduler.dispatcher.MailDocumentDispatchChannel.java
public boolean dispatch(BIObject document, byte[] executionOutput) { Map parametersMap;/*from w w w .java2 s. c o m*/ String contentType; String fileExtension; IDataStore emailDispatchDataStore; String nameSuffix; String descriptionSuffix; String containedFileName; String zipFileName; boolean reportNameInSubject; logger.debug("IN"); try { parametersMap = dispatchContext.getParametersMap(); contentType = dispatchContext.getContentType(); fileExtension = dispatchContext.getFileExtension(); emailDispatchDataStore = dispatchContext.getEmailDispatchDataStore(); nameSuffix = dispatchContext.getNameSuffix(); descriptionSuffix = dispatchContext.getDescriptionSuffix(); containedFileName = dispatchContext.getContainedFileName() != null && !dispatchContext.getContainedFileName().equals("") ? dispatchContext.getContainedFileName() : document.getName(); zipFileName = dispatchContext.getZipMailName() != null && !dispatchContext.getZipMailName().equals("") ? dispatchContext.getZipMailName() : document.getName(); reportNameInSubject = dispatchContext.isReportNameInSubject(); String smtphost = SingletonConfig.getInstance().getConfigValue("MAIL.PROFILES.scheduler.smtphost"); String smtpport = SingletonConfig.getInstance().getConfigValue("MAIL.PROFILES.scheduler.smtpport"); String smtpssl = SingletonConfig.getInstance().getConfigValue("MAIL.PROFILES.scheduler.useSSL"); logger.debug(smtphost + " " + smtpport + " use SSL: " + smtpssl); //Custom Trusted Store Certificate Options String trustedStorePath = SingletonConfig.getInstance() .getConfigValue("MAIL.PROFILES.trustedStore.file"); String trustedStorePassword = SingletonConfig.getInstance() .getConfigValue("MAIL.PROFILES.trustedStore.password"); int smptPort = 25; if ((smtphost == null) || smtphost.trim().equals("")) throw new Exception("Smtp host not configured"); if ((smtpport == null) || smtpport.trim().equals("")) { throw new Exception("Smtp host not configured"); } else { smptPort = Integer.parseInt(smtpport); } String from = SingletonConfig.getInstance().getConfigValue("MAIL.PROFILES.scheduler.from"); if ((from == null) || from.trim().equals("")) from = "spagobi.scheduler@eng.it"; String user = SingletonConfig.getInstance().getConfigValue("MAIL.PROFILES.scheduler.user"); if ((user == null) || user.trim().equals("")) { logger.debug("Smtp user not configured"); user = null; } // throw new Exception("Smtp user not configured"); String pass = SingletonConfig.getInstance().getConfigValue("MAIL.PROFILES.scheduler.password"); if ((pass == null) || pass.trim().equals("")) { logger.debug("Smtp password not configured"); } // throw new Exception("Smtp password not configured"); String mailSubj = dispatchContext.getMailSubj(); mailSubj = StringUtilities.substituteParametersInString(mailSubj, parametersMap, null, false); String mailTxt = dispatchContext.getMailTxt(); String[] recipients = findRecipients(dispatchContext, document, emailDispatchDataStore); if (recipients == null || recipients.length == 0) { logger.error("No recipients found for email sending!!!"); return false; } //Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.host", smtphost); props.put("mail.smtp.port", Integer.toString(smptPort)); // open session Session session = null; // create autheticator object Authenticator auth = null; if (user != null) { auth = new SMTPAuthenticator(user, pass); props.put("mail.smtp.auth", "true"); //SSL Connection if (smtpssl.equals("true")) { Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); //props.put("mail.smtp.debug", "true"); props.put("mail.smtps.auth", "true"); props.put("mail.smtps.socketFactory.port", Integer.toString(smptPort)); if ((!StringUtilities.isEmpty(trustedStorePath))) { /* Dynamic configuration of trustedstore for CA * Using Custom SSLSocketFactory to inject certificates directly from specified files */ //System.setProperty("java.security.debug","certpath"); //System.setProperty("javax.net.debug","ssl "); props.put("mail.smtps.socketFactory.class", CUSTOM_SSL_FACTORY); } else { //System.setProperty("java.security.debug","certpath"); //System.setProperty("javax.net.debug","ssl "); props.put("mail.smtps.socketFactory.class", DEFAULT_SSL_FACTORY); } props.put("mail.smtp.socketFactory.fallback", "false"); } //session = Session.getDefaultInstance(props, auth); session = Session.getInstance(props, auth); //session.setDebug(true); //session.setDebugOut(null); logger.info("Session.getInstance(props, auth)"); } else { //session = Session.getDefaultInstance(props); session = Session.getInstance(props); logger.info("Session.getInstance(props)"); } // create a message Message msg = new MimeMessage(session); // set the from and to address InternetAddress addressFrom = new InternetAddress(from); msg.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0; i < recipients.length; i++) { addressTo[i] = new InternetAddress(recipients[i]); } msg.setRecipients(Message.RecipientType.TO, addressTo); // Setting the Subject and Content Type String subject = mailSubj; if (reportNameInSubject) { subject += " " + document.getName() + nameSuffix; } msg.setSubject(subject); // create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(mailTxt + "\n" + descriptionSuffix); // create the second message part MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message SchedulerDataSource sds = null; //if zip requested if (dispatchContext.isZipMailDocument()) { mbp2 = zipAttachment(executionOutput, containedFileName, zipFileName, nameSuffix, fileExtension); } //else else { sds = new SchedulerDataSource(executionOutput, contentType, containedFileName + nameSuffix + fileExtension); mbp2.setDataHandler(new DataHandler(sds)); mbp2.setFileName(sds.getName()); } // create the Multipart and add its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); // send message if ((smtpssl.equals("true")) && (!StringUtilities.isEmpty(user)) && (!StringUtilities.isEmpty(pass))) { //USE SSL Transport comunication with SMTPS Transport transport = session.getTransport("smtps"); transport.connect(smtphost, smptPort, user, pass); transport.sendMessage(msg, msg.getAllRecipients()); transport.close(); } else { //Use normal SMTP Transport.send(msg); } } catch (Exception e) { logger.error("Error while sending schedule result mail", e); return false; } finally { logger.debug("OUT"); } return true; }
From source file:gmailclientfx.core.GmailClient.java
public static void sendMessage(String to, String subject, String body, List<String> attachments) throws Exception { // authenticate with gmail smtp server SMTPTransport smtpTransport = connectToSmtp("smtp.gmail.com", 587, EMAIL, ACCESS_TOKEN, true); // kreiraj MimeMessage objekt MimeMessage msg = new MimeMessage(OAuth2Authenticator.getSession()); // dodaj headere msg.addHeader("Content-type", "text/HTML; charset=UTF-8"); msg.addHeader("format", "flowed"); msg.addHeader("Content-Transfer-Encoding", "8bit"); msg.setFrom(new InternetAddress(EMAIL)); msg.setRecipients(javax.mail.Message.RecipientType.CC, InternetAddress.parse(to)); msg.setSubject(subject, "UTF-8"); msg.setReplyTo(InternetAddress.parse(EMAIL, false)); // tijelo poruke BodyPart msgBodyPart = new MimeBodyPart(); msgBodyPart.setText(body);// w ww . j a v a 2s . com Multipart multipart = new MimeMultipart(); multipart.addBodyPart(msgBodyPart); msg.setContent(multipart); // dodaj privitke if (attachments.size() > 0) { for (String attachment : attachments) { msgBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(attachment); msgBodyPart.setDataHandler(new DataHandler(source)); msgBodyPart.setFileName(source.getName()); multipart.addBodyPart(msgBodyPart); } msg.setContent(multipart); } smtpTransport.sendMessage(msg, InternetAddress.parse(to)); Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle("Poruka poslana!"); alert.setHeaderText(null); alert.setContentText("Email uspjeno poslan!"); alert.showAndWait(); }
From source file:de.extra.client.core.plugin.dummies.DummyQueryDataResponceOutputPlugin.java
/** * @return Dummy Body Response/*w w w.ja v a2 s.co m*/ * @throws MalformedURLException */ private ResponsePackageBody createDummyBodyResponse(final String queryArgument) throws MalformedURLException { final ResponsePackageBody packageBody = new ResponsePackageBody(); final DataType value = new DataType(); final String stringValue = "DUMMY Response for Query Argument:" + queryArgument; // final byte[] decodeBase64Value = Base64.encodeBase64(stringValue // .getBytes()); final Base64CharSequenceType base64CharSequenceType = new Base64CharSequenceType(); final DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(stringValue.getBytes(), "*/*")); base64CharSequenceType.setValue(dataHandler); value.setBase64CharSequence(base64CharSequenceType); packageBody.setData(value); return packageBody; }
From source file:immf.ImodeForwardMail.java
private void attacheFile() throws EmailException { try {//from w ww .j a va2s.c o m List<AttachedFile> files = this.imm.getAttachFileList(); for (AttachedFile f : files) { BodyPart part = createBodyPart(); part.setDataHandler(new DataHandler(new ByteArrayDataSource(f.getData(), f.getContentType()))); Util.setFileName(part, f.getFilename(), this.charset, null); part.setDisposition(BodyPart.ATTACHMENT); getContainer().addBodyPart(part); } } catch (Exception e) { throw new EmailException(e); } }
From source file:cz.zcu.kiv.eegdatabase.webservices.datadownload.UserDataImpl.java
public DataHandler downloadDataFile(int dataFileId) throws UserDataServiceException { List<DataFile> files = experimentDao.getDataFilesWhereId(dataFileId); DataFile file = files.get(0);/*from ww w. j av a 2 s . c o m*/ DataSource rawData; final InputStream in; try { in = new ByteArrayInputStream(file.getFileContent().getBytes(1, (int) file.getFileContent().length())); } catch (SQLException ex) { throw new RuntimeException(ex); } rawData = new DataSource() { public String getContentType() { return "application/octet-stream"; } public InputStream getInputStream() throws IOException { return in; } public String getName() { return "application/octet-stream"; } public OutputStream getOutputStream() throws IOException { return null; } }; log.debug("User " + personDao.getLoggedPerson().getEmail() + " retrieved file " + dataFileId); return new DataHandler(rawData); }
From source file:org.jembi.rhea.transformers.XDSRepositoryProvideAndRegisterDocument.java
protected ProvideAndRegisterDocumentSetRequestType buildRegisterRequest(String oru_r01_request, EncounterInfo enc, XDSAffinityDomain domain) { ProvideAndRegisterDocumentSetRequestType xdsRequest = new ProvideAndRegisterDocumentSetRequestType(); SubmitObjectsRequest submissionRequest = new SubmitObjectsRequest(); RegistryObjectListType registryObjects = new RegistryObjectListType(); submissionRequest.setRegistryObjectList(registryObjects); xdsRequest.setSubmitObjectsRequest(submissionRequest); Date now = new Date(); // For each document ExtrinsicObjectType document = XDSUtil.createExtrinsicObject("text/xml", "Physical", XdsGuidType.XDSDocumentEntry); // To add slots document.getSlot().add(XDSUtil.createSlot("creationTime", formatter_yyyyMMdd.format(now))); document.getSlot().add(XDSUtil.createSlot("languageCode", "en-us")); document.getSlot().add(XDSUtil.createSlot("serviceStartTime", enc.getEncounterDateTime())); document.getSlot().add(XDSUtil.createSlot("serviceStopTime", enc.getEncounterDateTime())); document.getSlot().add(XDSUtil.createSlot("sourcePatientId", enc.getPID())); document.getSlot()/*from www. jav a 2 s . c om*/ .add(XDSUtil.createSlot("sourcePatientInfo", "PID-3|" + enc.getPID(), "PID-5|" + enc.getName())); //if (domain.getRepositoryUniqueId()!=null) // document.getSlot().add(XDSUtil.createSlot("repositoryUniqueId", domain.getRepositoryUniqueId())); //if (domain.getHomeCommunityId()!=null) // document.getSlot().add(XDSUtil.createSlot("homeCommunityId", domain.getHomeCommunityId())); // To add classifications SlotType1[] authorSlots = new SlotType1[] { XDSUtil.createSlot("authorPerson", enc.getAttendingDoctor()), XDSUtil.createSlot("authorInstitution", enc.getLocation()), }; document.getClassification().add( XDSUtil.createClassification(document, XdsGuidType.XDSDocumentEntry_Author, "", null, authorSlots)); SlotType1[] classCodeSlots = new SlotType1[] { XDSUtil.createSlot("codingScheme", domain.getClassCode().getCodingScheme()) }; document.getClassification() .add(XDSUtil.createClassification(document, XdsGuidType.XDSDocumentEntry_ClassCode, domain.getClassCode().getCode(), domain.getClassCode().getDisplay(), classCodeSlots)); SlotType1[] confidentialitySlots = new SlotType1[] { XDSUtil.createSlot("codingScheme", domain.getConfidentialityCode().getCodingScheme()) }; document.getClassification() .add(XDSUtil.createClassification(document, XdsGuidType.XDSDocumentEntry_ConfidentialityCode, domain.getConfidentialityCode().getCode(), domain.getConfidentialityCode().getDisplay(), confidentialitySlots)); // To add external ids document.getExternalIdentifier().add( XDSUtil.createExternalIdentifier(document, XdsGuidType.XDSDocumentEntry_PatientId, enc.getPID())); String docUniqueId = String.format("%s.%s.%s", systemSourceID, "1", new SimpleDateFormat("yyyy.MM.dd.ss.SSS").format(now)); document.getExternalIdentifier().add( XDSUtil.createExternalIdentifier(document, XdsGuidType.XDSDocumentEntry_UniqueId, docUniqueId)); // Add to list of objects registryObjects.getIdentifiable() .add(new JAXBElement<ExtrinsicObjectType>( new QName("urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0", "ExtrinsicObject"), ExtrinsicObjectType.class, document)); //TODO eventCodeList // Create submission set RegistryPackageType pkg = XDSUtil.createRegistryPackage(); pkg.getSlot().add(XDSUtil.createSlot("submissionTime", formatter_yyyyMMdd.format(now))); // To add classifications SlotType1[] contentTypeSlots = new SlotType1[] { XDSUtil.createSlot("codingScheme", domain.getContentTypeCode().getCodingScheme()) }; pkg.getClassification().add(XDSUtil.createClassification(pkg, XdsGuidType.XDSSubmissionSet_ContentType, domain.getContentTypeCode().getCode(), domain.getContentTypeCode().getDisplay(), contentTypeSlots)); SlotType1[] formatSlots = new SlotType1[] { XDSUtil.createSlot("codingScheme", domain.getFormatCode().getCodingScheme()) }; document.getClassification() .add(XDSUtil.createClassification(document, XdsGuidType.XDSDocumentEntry_FormatCode, domain.getFormatCode().getCode(), domain.getFormatCode().getDisplay(), formatSlots)); SlotType1[] healthcareFacilityTypeSlots = new SlotType1[] { XDSUtil.createSlot("codingScheme", domain.getHealthcareFacilityTypeCode().getCodingScheme()) }; document.getClassification() .add(XDSUtil.createClassification(document, XdsGuidType.XDSDocumentEntry_HealthcareFacilityCode, domain.getHealthcareFacilityTypeCode().getCode(), domain.getHealthcareFacilityTypeCode().getDisplay(), healthcareFacilityTypeSlots)); SlotType1[] practiceSettingSlots = new SlotType1[] { XDSUtil.createSlot("codingScheme", domain.getPracticeSettingCode().getCodingScheme()) }; document.getClassification() .add(XDSUtil.createClassification(document, XdsGuidType.XDSDocumentEntry_PracticeSettingCode, domain.getPracticeSettingCode().getCode(), domain.getPracticeSettingCode().getDisplay(), practiceSettingSlots)); SlotType1[] typeSlots = new SlotType1[] { XDSUtil.createSlot("codingScheme", domain.getTypeCode().getCodingScheme()) }; document.getClassification() .add(XDSUtil.createClassification(document, XdsGuidType.XDSDocumentEntry_TypeCode, domain.getTypeCode().getCode(), domain.getTypeCode().getDisplay(), typeSlots)); // To add external ids pkg.getExternalIdentifier().add( XDSUtil.createExternalIdentifier(document, XdsGuidType.XDSSubmissionSet_PatientId, enc.getPID())); _uniqueId = String.format("%s.%s.%s", systemSourceID, "2", new SimpleDateFormat("yyyy.MM.dd.ss.SSS").format(now)); pkg.getExternalIdentifier() .add(XDSUtil.createExternalIdentifier(document, XdsGuidType.XDSSubmissionSet_UniqueId, _uniqueId)); pkg.getExternalIdentifier().add( XDSUtil.createExternalIdentifier(document, XdsGuidType.XDSSubmissionSet_SourceId, systemSourceID)); // Add package to submission registryObjects.getIdentifiable() .add(new JAXBElement<RegistryPackageType>( new QName("urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0", "RegistryPackage"), RegistryPackageType.class, pkg)); // Add classification for state registryObjects.getIdentifiable().add(new JAXBElement<ClassificationType>( new QName("urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0", "Classification"), ClassificationType.class, XDSUtil.createNodeClassification(pkg, XdsGuidType.XDSSubmissionSet))); // Add association registryObjects.getIdentifiable() .add(new JAXBElement<AssociationType1>( new QName("urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0", "Association"), AssociationType1.class, XDSUtil.createAssociation(pkg, document, "Original", "urn:oasis:names:tc:ebxml-regrep:AssociationType:HasMember"))); // Add document Document content = new Document(); content.setId(document.getId()); content.setValue( new DataHandler(new ByteArrayDataSource(oru_r01_request.getBytes(), "application/octet-stream"))); xdsRequest.getDocument().add(content); return xdsRequest; }