List of usage examples for javax.mail.util ByteArrayDataSource getInputStream
@Override public InputStream getInputStream() throws IOException
From source file:org.apromore.service.impl.ProcessServiceImpl.java
/** * @see org.apromore.service.ProcessService#exportProcess(String, Integer, String, Version, String, String, boolean, java.util.Set) * {@inheritDoc}//w w w.j a v a 2s . co m */ @Override public ExportFormatResultType exportProcess(final String name, final Integer processId, final String branch, final Version version, final String format, final String annName, final boolean withAnn, Set<RequestParameterType<?>> canoniserProperties) throws ExportFormatException { try { // Debug tracing of the authenticated principal org.springframework.security.core.Authentication auth = org.springframework.security.core.context.SecurityContextHolder .getContext().getAuthentication(); if (auth != null) { LOGGER.info("Authentication principal=" + auth.getPrincipal() + " details=" + auth.getDetails() + " thread=" + Thread.currentThread()); } else { LOGGER.info("Authentication is null"); } ExportFormatResultType exportResult = new ExportFormatResultType(); // Work out if we are looking at the original format or native format for this model. if (isRequestForNativeFormat(processId, branch, version, format)) { exportResult.setNative(new DataHandler(new ByteArrayDataSource( nativeRepo.getNative(processId, branch, version.toString(), format).getContent(), "text/xml"))); } else if (isRequestForAnnotationsOnly(format)) { exportResult .setNative( new DataHandler(new ByteArrayDataSource( annotationRepo.getAnnotation(processId, branch, version.toString(), AnnotationHelper.getAnnotationName(annName)).getContent(), "text/xml"))); } else { CanonicalProcessType cpt = getProcessModelVersion(processId, name, branch, version, false); Process process; if (format.equals(Constants.CANONICAL)) { exportResult.setNative(new DataHandler( new ByteArrayDataSource(canoniserSrv.CPFtoString(cpt), Constants.XML_MIMETYPE))); } else { DecanonisedProcess dp; AnnotationsType anf = null; process = processRepo.findOne(processId); if (withAnn) { Annotation ann = annotationRepo.getAnnotation(processId, branch, version.toString(), annName); if (ann != null) { String annotation = ann.getContent(); if (annotation != null && !annotation.equals("")) { ByteArrayDataSource dataSource = new ByteArrayDataSource(annotation, Constants.XML_MIMETYPE); anf = ANFSchema.unmarshalAnnotationFormat(dataSource.getInputStream(), false) .getValue(); } } if (ann != null && !process.getNativeType().getNatType() .equalsIgnoreCase(ann.getNatve().getNativeType().getNatType())) { anf = annotationSrv.preProcess(ann.getNatve().getNativeType().getNatType(), format, cpt, anf); } else { anf = annotationSrv.preProcess(process.getNativeType().getNatType(), format, cpt, anf); } } else if (annName == null) { anf = annotationSrv.preProcess(null, format, cpt, null); } dp = canoniserSrv.deCanonise(format, cpt, anf, canoniserProperties); exportResult.setMessage(PluginHelper.convertFromPluginMessages(dp.getMessages())); exportResult.setNative( new DataHandler(new ByteArrayDataSource(dp.getNativeFormat(), Constants.XML_MIMETYPE))); } } return exportResult; } catch (Exception e) { LOGGER.error("Failed to export process model {} to format {}", name, format); LOGGER.error("Original exception was: ", e); throw new ExportFormatException(e); } }
From source file:org.apromore.service.impl.ProcessServiceImpl.java
/** * @see org.apromore.service.ProcessService#getBPMNRepresentation(String, Integer, String, Version) * {@inheritDoc}/*from w w w . j a v a 2s . c o m*/ */ @Override public String getBPMNRepresentation(final String name, final Integer processId, final String branch, final Version version) throws RepositoryException { String xmlBPMNProcess; String format = "BPMN 2.0"; String annName = "BPMN 2.0"; try { // Debug tracing of the authenticated principal org.springframework.security.core.Authentication auth = org.springframework.security.core.context.SecurityContextHolder .getContext().getAuthentication(); if (auth != null) { LOGGER.info("Authentication principal=" + auth.getPrincipal() + " details=" + auth.getDetails() + " thread=" + Thread.currentThread()); } else { LOGGER.info("Authentication is null"); } // Work out if we are looking at the original format or native format for this model. if (isRequestForNativeFormat(processId, branch, version, format)) { xmlBPMNProcess = nativeRepo.getNative(processId, branch, version.toString(), format).getContent(); LOGGER.info("native"); } else { LOGGER.info("notNative"); CanonicalProcessType cpt = getProcessModelVersion(processId, name, branch, version, false); Process process = processRepo.findOne(processId); DecanonisedProcess dp; AnnotationsType anf = null; Annotation ann = annotationRepo.getAnnotation(processId, branch, version.toString(), annName); if (ann != null) { String annotation = ann.getContent(); if (annotation != null && !annotation.equals("")) { ByteArrayDataSource dataSource = new ByteArrayDataSource(annotation, Constants.XML_MIMETYPE); anf = ANFSchema.unmarshalAnnotationFormat(dataSource.getInputStream(), false).getValue(); } } if (ann != null && !process.getNativeType().getNatType() .equalsIgnoreCase(ann.getNatve().getNativeType().getNatType())) { anf = annotationSrv.preProcess(ann.getNatve().getNativeType().getNatType(), format, cpt, anf); } else { anf = annotationSrv.preProcess(process.getNativeType().getNatType(), format, cpt, anf); } dp = canoniserSrv.deCanonise(format, cpt, anf, new HashSet<RequestParameterType<?>>()); xmlBPMNProcess = IOUtils.toString(dp.getNativeFormat(), "UTF-8"); } //LOGGER.info("[new method] PROCESS:\n" + xmlBPMNProcess); return xmlBPMNProcess; } catch (Exception e) { LOGGER.error("Failed to retrive the process!"); LOGGER.error("Original exception was: ", e); throw new RepositoryException(e); } }
From source file:stg.pr.engine.mailer.SmallEmailAttachment.java
/** * Constructs an attachment with the given name for the given input stream and content type. * @param name of the attachment to be associated in the email * @param is InputStream //from w w w . j a v a 2s.c o m * @param contentType * @throws IOException */ public SmallEmailAttachment(String name, InputStream is, String contentType) throws IOException { super(name, is, contentType); //this will throw exception in case the file does not exist ByteArrayDataSource datasource = new ByteArrayDataSource(is, contentType); if (datasource.getInputStream().available() > EMailAttachment.SMALL_SIZE.longValue()) { throw new IllegalArgumentException( "Small email attachments are for file size < " + EMailAttachment.SMALL_SIZE.longValue()); } this.contentType = contentType; this.bytes = IOUtils.toByteArray(is); }
From source file:stg.pr.engine.mailer.SmallEmailAttachment.java
/** * Constructs the SamllEmailAttachment using the given name and the {@link ByteArrayDataSource} * @param name The name of the attachment. * @param datasource The data source is fully read and stored in bytes array provided the length of the bytes is < {@link EMailAttachment#SMALL_SIZE}. *///from w w w. j a v a 2 s . co m public SmallEmailAttachment(String name, ByteArrayDataSource datasource) throws IOException { super(name, datasource); if (datasource.getInputStream().available() > EMailAttachment.SMALL_SIZE.longValue()) { throw new IllegalArgumentException("Small email attachments are for file size < 1MB"); } contentType = datasource.getContentType(); this.bytes = IOUtils.toByteArray(datasource.getInputStream()); }