List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:com.mycompany.projecta.CommonTasks.java
@Override public String FileToDirectory(String sourceFile, String targetDirectory, String fileExtension) throws Exception { try {/*from w w w . j a v a 2 s. co m*/ File Source = new File(sourceFile); File[] listOfFiles = Source.listFiles(); File Target = new File(targetDirectory); for (File file : listOfFiles) { if (file.isFile() && file.getName().contains(fileExtension)) { FileUtils.copyFileToDirectory(file, Target); } } } catch (Exception ex) { ex.printStackTrace(System.out); return ex.toString(); } return "passed"; }
From source file:com.asakusafw.testdriver.LegacyJobflowExecutor.java
private void deployApplication(JobflowInfo info) throws IOException { LOG.debug("Deploying application library: {}", info.getPackageFile()); //$NON-NLS-1$ File jobflowDest = context.getJobflowPackageLocation(info.getJobflow().getBatchId()); FileUtils.copyFileToDirectory(info.getPackageFile(), jobflowDest); File dependenciesDest = context.getLibrariesPackageLocation(info.getJobflow().getBatchId()); if (dependenciesDest.exists()) { LOG.debug("Cleaning up dependency libraries: {}", dependenciesDest); //$NON-NLS-1$ FileUtils.deleteDirectory(dependenciesDest); }// w w w . j ava 2s . co m File dependencies = context.getLibrariesPath(); if (dependencies.exists()) { LOG.debug("Deplogying dependency libraries: {} -> {}", dependencies, dependenciesDest); //$NON-NLS-1$ if (dependenciesDest.mkdirs() == false && dependenciesDest.isDirectory() == false) { LOG.warn(MessageFormat.format(Messages.getString("JobflowExecutor.warnFailedToCreateDirectory"), //$NON-NLS-1$ dependenciesDest.getAbsolutePath())); } for (File file : dependencies.listFiles()) { if (file.isFile() == false) { continue; } LOG.debug("Copying a library: {} -> {}", file, dependenciesDest); //$NON-NLS-1$ FileUtils.copyFileToDirectory(file, dependenciesDest); } } }
From source file:com.email.SendEmail.java
/** * Sends a single email and uses account based off of the section that the * email comes from after email is sent the attachments are gathered * together and collated into a single PDF file and a history entry is * created based off of that entry//from ww w . j av a 2s. c o m * * @param eml EmailOutModel */ public static void sendEmails(EmailOutModel eml) { SystemEmailModel account = null; String section = eml.getSection(); if (eml.getSection().equalsIgnoreCase("Hearings") && (eml.getCaseType().equalsIgnoreCase("MED") || eml.getCaseType().equalsIgnoreCase("REP") || eml.getCaseType().equalsIgnoreCase("ULP"))) { section = eml.getCaseType(); } //Get Account for (SystemEmailModel acc : Global.getSystemEmailParams()) { if (acc.getSection().equals(section)) { account = acc; break; } } //Account Exists? if (account != null) { //Case Location String casePath = (eml.getCaseType().equals("CSC") || eml.getCaseType().equals("ORG")) ? FileService.getCaseFolderORGCSCLocation(eml) : FileService.getCaseFolderLocation(eml); //Attachment List boolean allFilesExists = true; List<EmailOutAttachmentModel> attachmentList = EmailOutAttachment.getAttachmentsByEmail(eml.getId()); for (EmailOutAttachmentModel attach : attachmentList) { File attachment = new File(casePath + attach.getFileName()); boolean exists = attachment.exists(); if (exists == false) { allFilesExists = false; SECExceptionsModel item = new SECExceptionsModel(); item.setClassName("SendEmail"); item.setMethodName("sendEmails"); item.setExceptionType("FileMissing"); item.setExceptionDescription("Can't Send Email, File Missing for EmailID: " + eml.getId() + System.lineSeparator() + "EmailSubject: " + eml.getSubject() + System.lineSeparator() + "File: " + attachment); ExceptionHandler.HandleNoException(item); break; } else { if ("docx".equalsIgnoreCase(FilenameUtils.getExtension(attach.getFileName())) || "doc".equalsIgnoreCase(FilenameUtils.getExtension(attach.getFileName()))) { if (!attachment.renameTo(attachment)) { allFilesExists = false; SECExceptionsModel item = new SECExceptionsModel(); item.setClassName("SendEmail"); item.setMethodName("sendEmails"); item.setExceptionType("File In Use"); item.setExceptionDescription("Can't Send Email, File In Use for EmailID: " + eml.getId() + System.lineSeparator() + "EmailSubject: " + eml.getSubject() + System.lineSeparator() + "File: " + attachment); ExceptionHandler.HandleNoException(item); break; } } } } if (allFilesExists) { //Set up Initial Merge Utility PDFMergerUtility ut = new PDFMergerUtility(); //List ConversionPDFs To Delete Later List<String> tempPDFList = new ArrayList<>(); //create email message body Date emailSentTime = new Date(); String emailPDFname = EmailBodyToPDF.createEmailOutBody(eml, attachmentList, emailSentTime); //Add Email Body To PDF Merge try { ut.addSource(casePath + emailPDFname); tempPDFList.add(casePath + emailPDFname); } catch (FileNotFoundException ex) { ExceptionHandler.Handle(ex); } //Get parts String FromAddress = account.getEmailAddress(); String[] TOAddressess = ((eml.getTo() == null) ? "".split(";") : eml.getTo().split(";")); String[] CCAddressess = ((eml.getCc() == null) ? "".split(";") : eml.getCc().split(";")); String[] BCCAddressess = ((eml.getBcc() == null) ? "".split(";") : eml.getBcc().split(";")); String emailSubject = eml.getSubject(); String emailBody = eml.getBody(); //Set Email Parts Authenticator auth = EmailAuthenticator.setEmailAuthenticator(account); Properties properties = EmailProperties.setEmailOutProperties(account); Session session = Session.getInstance(properties, auth); MimeMessage smessage = new MimeMessage(session); Multipart multipart = new MimeMultipart(); //Add Parts to Email Message try { smessage.addFrom(new InternetAddress[] { new InternetAddress(FromAddress) }); for (String To : TOAddressess) { if (EmailValidator.getInstance().isValid(To)) { smessage.addRecipient(Message.RecipientType.TO, new InternetAddress(To)); } } for (String CC : CCAddressess) { if (EmailValidator.getInstance().isValid(CC)) { smessage.addRecipient(Message.RecipientType.CC, new InternetAddress(CC)); } } for (String BCC : BCCAddressess) { if (EmailValidator.getInstance().isValid(BCC)) { smessage.addRecipient(Message.RecipientType.BCC, new InternetAddress(BCC)); } } smessage.setSubject(emailSubject); MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setContent(emailBody, "text/plain"); multipart.addBodyPart(messageBodyPart); //get attachments for (EmailOutAttachmentModel attachment : attachmentList) { String fileName = attachment.getFileName(); String extension = FilenameUtils.getExtension(fileName); //Convert attachments to PDF //If Image if (FileService.isImageFormat(fileName)) { fileName = ImageToPDF.createPDFFromImageNoDelete(casePath, fileName); //Add Attachment To PDF Merge try { ut.addSource(casePath + fileName); tempPDFList.add(casePath + fileName); } catch (FileNotFoundException ex) { ExceptionHandler.Handle(ex); } //If Word Doc } else if (extension.equals("docx") || extension.equals("doc")) { fileName = WordToPDF.createPDFNoDelete(casePath, fileName); //Add Attachment To PDF Merge try { ut.addSource(casePath + fileName); tempPDFList.add(casePath + fileName); } catch (FileNotFoundException ex) { ExceptionHandler.Handle(ex); } //If Text File } else if ("txt".equals(extension)) { fileName = TXTtoPDF.createPDFNoDelete(casePath, fileName); //Add Attachment To PDF Merge try { ut.addSource(casePath + fileName); tempPDFList.add(casePath + fileName); } catch (FileNotFoundException ex) { ExceptionHandler.Handle(ex); } //If PDF } else if (FilenameUtils.getExtension(fileName).equals("pdf")) { //Add Attachment To PDF Merge try { ut.addSource(casePath + fileName); } catch (FileNotFoundException ex) { ExceptionHandler.Handle(ex); } } DataSource source = new FileDataSource(casePath + fileName); messageBodyPart = new MimeBodyPart(); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(fileName); multipart.addBodyPart(messageBodyPart); } smessage.setContent(multipart); //Send Message if (Global.isOkToSendEmail()) { Transport.send(smessage); } else { Audit.addAuditEntry("Email Not Actually Sent: " + eml.getId() + " - " + emailSubject); } //DocumentFileName String savedDoc = (String.valueOf(new Date().getTime()) + "_" + eml.getSubject()) .replaceAll("[:\\\\/*?|<>]", "_") + ".pdf"; //Set Merge File Destination ut.setDestinationFileName(casePath + savedDoc); //Try to Merge try { ut.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly()); } catch (IOException ex) { ExceptionHandler.Handle(ex); } //Add emailBody Activity addEmailActivity(eml, savedDoc, emailSentTime); //Copy to related case folders if (section.equals("MED")) { List<RelatedCaseModel> relatedMedList = RelatedCase.getRelatedCases(eml); if (relatedMedList.size() > 0) { for (RelatedCaseModel related : relatedMedList) { //Copy finalized document to proper folder File srcFile = new File(casePath + savedDoc); File destPath = new File((section.equals("CSC") || section.equals("ORG")) ? FileService.getCaseFolderORGCSCLocation(related) : FileService.getCaseFolderLocationRelatedCase(related)); destPath.mkdirs(); try { FileUtils.copyFileToDirectory(srcFile, destPath); } catch (IOException ex) { Logger.getLogger(SendEmail.class.getName()).log(Level.SEVERE, null, ex); } //Add Related Case Activity Entry addEmailActivityRelatedCase(eml, related, savedDoc, emailSentTime); } } } else { //This is blanket and should grab all related cases. (UNTESTED outside of CMDS) List<EmailOutRelatedCaseModel> relatedList = EmailOutRelatedCase.getRelatedCases(eml); if (relatedList.size() > 0) { for (EmailOutRelatedCaseModel related : relatedList) { //Copy finalized document to proper folder File srcFile = new File(casePath + savedDoc); File destPath = new File((section.equals("CSC") || section.equals("ORG")) ? FileService.getCaseFolderORGCSCLocation(related) : FileService.getCaseFolderLocationEmailOutRelatedCase(related)); destPath.mkdirs(); try { FileUtils.copyFileToDirectory(srcFile, destPath); } catch (IOException ex) { Logger.getLogger(SendEmail.class.getName()).log(Level.SEVERE, null, ex); } //Add Related Case Activity Entry addEmailOutActivityRelatedCase(eml, related, savedDoc, emailSentTime); } } } //Clean SQL entries EmailOut.deleteEmailEntry(eml.getId()); EmailOutAttachment.deleteAttachmentsForEmail(eml.getId()); EmailOutRelatedCase.deleteEmailOutRelatedForEmail(eml.getId()); //Clean up temp PDFs for (String tempPDF : tempPDFList) { new File(tempPDF).delete(); } } catch (AddressException ex) { ExceptionHandler.Handle(ex); } catch (MessagingException ex) { ExceptionHandler.Handle(ex); } } } }
From source file:com.piketec.jenkins.plugins.tpt.publisher.TrendGraph.java
/** * Generates the json file with the historyData. * /* ww w. j a v a2 s . c om*/ * @throws IOException * if files could not be created * @throws InterruptedException * if the job is cancelled */ private void generateJson() throws IOException, InterruptedException { File oldIndexHTML = new File(Utils.getTptPluginRootDir(), "TrendGraph" + File.separator + "index.html"); File utilsJs = new File(Utils.getTptPluginRootDir(), "TrendGraph" + File.separator + "utils.js"); File buildDir = actualBuild.getRootDir(); File trendGraph = new File(buildDir.getAbsolutePath() + File.separator + "TrendGraph"); if (!trendGraph.isDirectory() && !trendGraph.mkdirs()) { throw new IOException("Could not create directory \"" + trendGraph.getAbsolutePath() + "\""); } if (utilsJs.exists()) { FileUtils.copyFileToDirectory(utilsJs, trendGraph); FileUtils.copyFileToDirectory(oldIndexHTML, trendGraph); } // replace the place holder "toReplace" by actual json script String jsonScript = getResultArray(historyData); String newIndexHTMLWithJson = FileUtils.readFileToString(oldIndexHTML); newIndexHTMLWithJson = newIndexHTMLWithJson.replace("toReplace", jsonScript); File newIndexHTML = new File( buildDir.getAbsolutePath() + File.separator + "TrendGraph" + File.separator + "index.html"); FileUtils.writeStringToFile(newIndexHTML, newIndexHTMLWithJson); }
From source file:com.litt.core.security.license.gui.CustomerPanel.java
public CustomerPanel() { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 0, 0, 0, 0 }; gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE }; gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; setLayout(gridBagLayout);/*from w w w . j a v a 2 s . c om*/ JLabel lblProduct = new JLabel("\u4EA7\u54C1\uFF1A"); GridBagConstraints gbc_lblProduct = new GridBagConstraints(); gbc_lblProduct.insets = new Insets(0, 0, 5, 5); gbc_lblProduct.anchor = GridBagConstraints.EAST; gbc_lblProduct.gridx = 0; gbc_lblProduct.gridy = 0; add(lblProduct, gbc_lblProduct); comboBoxProduct = new JComboBox(); GridBagConstraints gbc_comboBoxProduct = new GridBagConstraints(); gbc_comboBoxProduct.insets = new Insets(0, 0, 5, 5); gbc_comboBoxProduct.fill = GridBagConstraints.HORIZONTAL; gbc_comboBoxProduct.gridx = 1; gbc_comboBoxProduct.gridy = 0; add(comboBoxProduct, gbc_comboBoxProduct); JButton btnRefresh = new JButton(""); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { initProduct(); } }); btnRefresh.setIcon(new ImageIcon(CustomerPanel.class.getResource("/images/icon_refresh.png"))); GridBagConstraints gbc_btnRefresh = new GridBagConstraints(); gbc_btnRefresh.insets = new Insets(0, 0, 5, 0); gbc_btnRefresh.gridx = 2; gbc_btnRefresh.gridy = 0; add(btnRefresh, gbc_btnRefresh); JLabel lblProductVersion = new JLabel("\u4EA7\u54C1\u7248\u672C\uFF1A"); GridBagConstraints gbc_lblProductVersion = new GridBagConstraints(); gbc_lblProductVersion.anchor = GridBagConstraints.EAST; gbc_lblProductVersion.insets = new Insets(0, 0, 5, 5); gbc_lblProductVersion.gridx = 0; gbc_lblProductVersion.gridy = 1; add(lblProductVersion, gbc_lblProductVersion); textFieldProductVersion = new VersionTextField(); textFieldProductVersion.setColumns(10); GridBagConstraints gbc_textFieldProductVersion = new GridBagConstraints(); gbc_textFieldProductVersion.anchor = GridBagConstraints.WEST; gbc_textFieldProductVersion.insets = new Insets(0, 0, 5, 5); gbc_textFieldProductVersion.gridx = 1; gbc_textFieldProductVersion.gridy = 1; add(textFieldProductVersion, gbc_textFieldProductVersion); JLabel lblCompanyName = new JLabel("\u516C\u53F8\u540D\u79F0\uFF1A"); GridBagConstraints gbc_lblCompanyName = new GridBagConstraints(); gbc_lblCompanyName.anchor = GridBagConstraints.EAST; gbc_lblCompanyName.insets = new Insets(0, 0, 5, 5); gbc_lblCompanyName.gridx = 0; gbc_lblCompanyName.gridy = 2; add(lblCompanyName, gbc_lblCompanyName); textFieldCompanyName = new JTextField(); GridBagConstraints gbc_textFieldCompanyName = new GridBagConstraints(); gbc_textFieldCompanyName.insets = new Insets(0, 0, 5, 5); gbc_textFieldCompanyName.fill = GridBagConstraints.HORIZONTAL; gbc_textFieldCompanyName.gridx = 1; gbc_textFieldCompanyName.gridy = 2; add(textFieldCompanyName, gbc_textFieldCompanyName); textFieldCompanyName.setColumns(10); JLabel lblCustomerCode = new JLabel("\u5BA2\u6237\u7F16\u53F7\uFF1A"); GridBagConstraints gbc_lblCustomerCode = new GridBagConstraints(); gbc_lblCustomerCode.anchor = GridBagConstraints.EAST; gbc_lblCustomerCode.insets = new Insets(0, 0, 5, 5); gbc_lblCustomerCode.gridx = 0; gbc_lblCustomerCode.gridy = 3; add(lblCustomerCode, gbc_lblCustomerCode); textFieldCustomerCode = new JTextField(); GridBagConstraints gbc_textFieldCustomerCode = new GridBagConstraints(); gbc_textFieldCustomerCode.insets = new Insets(0, 0, 5, 5); gbc_textFieldCustomerCode.fill = GridBagConstraints.HORIZONTAL; gbc_textFieldCustomerCode.gridx = 1; gbc_textFieldCustomerCode.gridy = 3; add(textFieldCustomerCode, gbc_textFieldCustomerCode); textFieldCustomerCode.setColumns(10); JLabel lblCustomerName = new JLabel("\u5BA2\u6237\u540D\u79F0\uFF1A"); GridBagConstraints gbc_lblCustomerName = new GridBagConstraints(); gbc_lblCustomerName.anchor = GridBagConstraints.EAST; gbc_lblCustomerName.insets = new Insets(0, 0, 5, 5); gbc_lblCustomerName.gridx = 0; gbc_lblCustomerName.gridy = 4; add(lblCustomerName, gbc_lblCustomerName); textFieldCustomerName = new JTextField(); GridBagConstraints gbc_textFieldCustomerName = new GridBagConstraints(); gbc_textFieldCustomerName.insets = new Insets(0, 0, 5, 5); gbc_textFieldCustomerName.fill = GridBagConstraints.HORIZONTAL; gbc_textFieldCustomerName.gridx = 1; gbc_textFieldCustomerName.gridy = 4; add(textFieldCustomerName, gbc_textFieldCustomerName); textFieldCustomerName.setColumns(10); JLabel lblLicenseType = new JLabel("\u8BC1\u4E66\u7C7B\u578B\uFF1A"); GridBagConstraints gbc_lblLicenseType = new GridBagConstraints(); gbc_lblLicenseType.anchor = GridBagConstraints.EAST; gbc_lblLicenseType.insets = new Insets(0, 0, 5, 5); gbc_lblLicenseType.gridx = 0; gbc_lblLicenseType.gridy = 5; add(lblLicenseType, gbc_lblLicenseType); comboBoxLicenseType = new JComboBox(); GridBagConstraints gbc_comboBoxLicenseType = new GridBagConstraints(); gbc_comboBoxLicenseType.insets = new Insets(0, 0, 5, 5); gbc_comboBoxLicenseType.fill = GridBagConstraints.HORIZONTAL; gbc_comboBoxLicenseType.gridx = 1; gbc_comboBoxLicenseType.gridy = 5; add(comboBoxLicenseType, gbc_comboBoxLicenseType); JLabel lblExpiredDate = new JLabel("\u8FC7\u671F\u65F6\u95F4\uFF1A"); GridBagConstraints gbc_lblExpiredDate = new GridBagConstraints(); gbc_lblExpiredDate.insets = new Insets(0, 0, 5, 5); gbc_lblExpiredDate.gridx = 0; gbc_lblExpiredDate.gridy = 6; add(lblExpiredDate, gbc_lblExpiredDate); datePickerExpiredDate = new DatePicker(new Date(), "yyyy-MM-dd", null, null); GridBagConstraints gbc_datePicker = new GridBagConstraints(); gbc_datePicker.anchor = GridBagConstraints.WEST; gbc_datePicker.insets = new Insets(0, 0, 5, 5); gbc_datePicker.gridx = 1; gbc_datePicker.gridy = 6; add(datePickerExpiredDate, gbc_datePicker); JButton btnSave = new JButton("\u4FDD\u5B58"); btnSave.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { //???????? if (comboBoxProduct.getSelectedIndex() <= 0) { JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "??"); return; } String[] array = StringUtils.split(comboBoxProduct.getSelectedItem().toString(), '-'); String productCode = array[0]; String productName = array[1]; String customerCode = textFieldCustomerCode.getText(); //?? File configFile = ResourceUtils.getFile(Gui.HOME_PATH + File.separator + "config.xml"); Document document = XmlUtils.readXml(configFile); Element customerNode = (Element) document.selectSingleNode( "//product[@code='" + productCode + "']/customer[@code='" + customerCode + "']"); if (customerNode != null) { JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "???"); return; } String licenseId = new RandomGUID().toString(); String licenseType = Utility.splitStringAll(comboBoxLicenseType.getSelectedItem().toString(), " - ")[0]; String companyName = textFieldCompanyName.getText(); String customerName = textFieldCustomerName.getText(); String version = textFieldProductVersion.getText(); Date expiredDate = Utility.parseDate(datePickerExpiredDate.getText()); License license = new License(); license.setLicenseId(licenseId); license.setLicenseType(licenseType); license.setProductName(productName); license.setCompanyName(companyName); license.setCustomerName(customerName); license.setVersion(Version.parseVersion(version)); license.setCreateDate(new Date()); license.setExpiredDate(expiredDate); LicenseService service = new LicenseService(); String productPath = Gui.HOME_PATH + File.separator + productCode; File licenseDir = new File(productPath, customerCode); if (!licenseDir.exists()) { licenseDir.mkdir(); //? FileUtils.copyFileToDirectory(new File(productPath, "license.key"), licenseDir); } File priKeyFile = new File(Gui.HOME_PATH + File.separator + productCode, "private.key"); File licenseFile = new File(licenseDir, "license.xml"); service.save(Gui.HOME_PATH, productCode, customerCode, license, priKeyFile, licenseFile); //??zip? File customerPath = licenseFile.getParentFile(); //???license????? File licensePath = new File(customerPath.getParent(), "license"); if (!licensePath.exists() && !licensePath.isDirectory()) { licensePath.mkdir(); } else { FileUtils.cleanDirectory(licensePath); } //? FileUtils.copyDirectory(customerPath, licensePath); String currentTime = FormatDateTime.formatDateTimeNum(new Date()); ZipUtils.zip(licensePath, new File(licensePath.getParentFile(), customerCode + "-" + currentTime + ".zip")); //license FileUtils.deleteDirectory(licensePath); JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "??"); } catch (Exception e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), e1.getMessage()); } } }); GridBagConstraints gbc_btnSave = new GridBagConstraints(); gbc_btnSave.insets = new Insets(0, 0, 5, 5); gbc_btnSave.gridx = 1; gbc_btnSave.gridy = 7; add(btnSave, gbc_btnSave); //?? initData(); }
From source file:ddf.security.pdp.xacml.processor.BalanaPdpTest.java
@Test public void testBalanaPdp_policies_directory_policy_added() throws Exception { LOGGER.debug("\n\n\n##### testBalanaPdp_policies_directory_policy_added"); File policyDir = folder.newFolder("tempDir"); // Perform Test BalanaPdp pdp = new BalanaPdp(policyDir); File srcFile = new File( PROJECT_HOME + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE); FileUtils.copyFileToDirectory(srcFile, policyDir); // By setting the polling interval to a second // the policy will be loaded pdp.setPollingInterval(1);/*from w ww. jav a 2 s . c o m*/ RequestType xacmlRequestType = new RequestType(); xacmlRequestType.setCombinedDecision(false); xacmlRequestType.setReturnPolicyIdList(false); AttributesType actionAttributes = new AttributesType(); actionAttributes.setCategory(ACTION_CATEGORY); AttributeType actionAttribute = new AttributeType(); actionAttribute.setAttributeId(ACTION_ID); actionAttribute.setIncludeInResult(false); AttributeValueType actionValue = new AttributeValueType(); actionValue.setDataType(STRING_DATA_TYPE); actionValue.getContent().add(QUERY_ACTION); actionAttribute.getAttributeValue().add(actionValue); actionAttributes.getAttribute().add(actionAttribute); AttributesType subjectAttributes = new AttributesType(); subjectAttributes.setCategory(SUBJECT_CATEGORY); AttributeType subjectAttribute = new AttributeType(); subjectAttribute.setAttributeId(SUBJECT_ID); subjectAttribute.setIncludeInResult(false); AttributeValueType subjectValue = new AttributeValueType(); subjectValue.setDataType(STRING_DATA_TYPE); subjectValue.getContent().add(TEST_USER_1); subjectAttribute.getAttributeValue().add(subjectValue); subjectAttributes.getAttribute().add(subjectAttribute); AttributeType roleAttribute = new AttributeType(); roleAttribute.setAttributeId(ROLE_CLAIM); roleAttribute.setIncludeInResult(false); AttributeValueType roleValue = new AttributeValueType(); roleValue.setDataType(STRING_DATA_TYPE); roleValue.getContent().add(ROLE); roleAttribute.getAttributeValue().add(roleValue); subjectAttributes.getAttribute().add(roleAttribute); AttributesType categoryAttributes = new AttributesType(); categoryAttributes.setCategory(PERMISSIONS_CATEGORY); AttributeType citizenshipAttribute = new AttributeType(); citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE); citizenshipAttribute.setIncludeInResult(false); AttributeValueType citizenshipValue = new AttributeValueType(); citizenshipValue.setDataType(STRING_DATA_TYPE); citizenshipValue.getContent().add(US_COUNTRY); citizenshipAttribute.getAttributeValue().add(citizenshipValue); categoryAttributes.getAttribute().add(citizenshipAttribute); xacmlRequestType.getAttributes().add(actionAttributes); xacmlRequestType.getAttributes().add(subjectAttributes); xacmlRequestType.getAttributes().add(categoryAttributes); // Perform Test ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType); // Verify - The policy was loaded to allow a permit decision JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class); Marshaller marshaller = jaxbContext.createMarshaller(); ObjectFactory objectFactory = new ObjectFactory(); Writer writer = new StringWriter(); marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer); LOGGER.debug("\nXACML 3.0 Response:\n" + writer.toString()); assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT); FileUtils.deleteDirectory(policyDir); }
From source file:com.atlassian.jira.functest.framework.AdministrationImpl.java
private void copyFileToJiraImportDirectory(File file) { String filename = file.getName(); if (!copiedFiles.contains(filename)) { File jiraImportDirectory = new File(getJiraHomeDirectory(), IMPORT_DIR); try {/*from w w w. j av a2 s . co m*/ FileUtils.copyFileToDirectory(file, jiraImportDirectory); copiedFiles.add(filename); } catch (IOException e) { throw new RuntimeException("Could not copy file " + file.getAbsolutePath() + " to the import directory in jira home " + jiraImportDirectory, e); } } }
From source file:de.sulaco.bittorrent.service.downloader.TtorrentDownloaderTest.java
@Test public void testDownloadResume() throws IOException, NoSuchAlgorithmException { // Start seeder and tracker Tracker tracker = startTracker();/*from w w w . j a v a 2 s.c o m*/ Client client = startSeeder(); // Copy partly available file to download directory FileUtils.copyFileToDirectory(new File(CONTENT_FILE_PART), new File(TEMPORARY_DIRECTORY)); File partFile = new File(CONTENT_FILE_PART); File sourceFile = new File(CONTENT_DIRECTORY + File.separator + CONTENT_NAME); assertThat(FileUtils.contentEquals(partFile, sourceFile)).isFalse(); // Download file DownloadListener downloadListener = Mockito.mock(DownloadListener.class); TtorrentDownloader ttorrentDownloader = new TtorrentDownloader(); ttorrentDownloader.setDownloadListener(downloadListener); ttorrentDownloader.setTimeout(60 * 1000); ttorrentDownloader.download(TORRENT_FILE, TEMPORARY_DIRECTORY); // Verification Mockito.verify(downloadListener, Mockito.times(1)).onDownloadEnd(TORRENT_FILE, DownloadState.COMPLETED); Mockito.verify(downloadListener, Mockito.times(1)).onDownloadStart(TORRENT_FILE); Mockito.verify(downloadListener, Mockito.times(1)).onDownloadProgress(TORRENT_FILE, 100); File downloadFile = new File(TEMPORARY_DIRECTORY + File.separator + CONTENT_NAME); assertThat(downloadFile.exists()).isTrue(); assertThat(FileUtils.contentEquals(sourceFile, downloadFile)).isTrue(); // Tear down seeder and tracker client.stop(); tracker.stop(); }
From source file:ddf.security.pdp.realm.xacml.processor.XacmlClientTest.java
@Test public void testWrapperpoliciesdirectorypolicyadded() throws Exception { LOGGER.debug("\n\n\n##### testXACMLWrapper_policies_directory_policy_added"); File policyDir = folder.newFolder("tempDir"); XacmlClient.defaultPollingIntervalInSeconds = 1; // Perform Test XacmlClient pdp = new XacmlClient(policyDir.getCanonicalPath(), new XmlParser()); File srcFile = new File( projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE); FileUtils.copyFileToDirectory(srcFile, policyDir); Thread.sleep(2000);//w ww.j a va 2 s. c om RequestType xacmlRequestType = new RequestType(); xacmlRequestType.setCombinedDecision(false); xacmlRequestType.setReturnPolicyIdList(false); AttributesType actionAttributes = new AttributesType(); actionAttributes.setCategory(ACTION_CATEGORY); AttributeType actionAttribute = new AttributeType(); actionAttribute.setAttributeId(ACTION_ID); actionAttribute.setIncludeInResult(false); AttributeValueType actionValue = new AttributeValueType(); actionValue.setDataType(STRING_DATA_TYPE); actionValue.getContent().add(QUERY_ACTION); actionAttribute.getAttributeValue().add(actionValue); actionAttributes.getAttribute().add(actionAttribute); AttributesType subjectAttributes = new AttributesType(); subjectAttributes.setCategory(SUBJECT_CATEGORY); AttributeType subjectAttribute = new AttributeType(); subjectAttribute.setAttributeId(SUBJECT_ID); subjectAttribute.setIncludeInResult(false); AttributeValueType subjectValue = new AttributeValueType(); subjectValue.setDataType(STRING_DATA_TYPE); subjectValue.getContent().add(TEST_USER_1); subjectAttribute.getAttributeValue().add(subjectValue); subjectAttributes.getAttribute().add(subjectAttribute); AttributeType roleAttribute = new AttributeType(); roleAttribute.setAttributeId(ROLE_CLAIM); roleAttribute.setIncludeInResult(false); AttributeValueType roleValue = new AttributeValueType(); roleValue.setDataType(STRING_DATA_TYPE); roleValue.getContent().add(ROLE); roleAttribute.getAttributeValue().add(roleValue); subjectAttributes.getAttribute().add(roleAttribute); AttributesType categoryAttributes = new AttributesType(); categoryAttributes.setCategory(PERMISSIONS_CATEGORY); AttributeType citizenshipAttribute = new AttributeType(); citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE); citizenshipAttribute.setIncludeInResult(false); AttributeValueType citizenshipValue = new AttributeValueType(); citizenshipValue.setDataType(STRING_DATA_TYPE); citizenshipValue.getContent().add(US_COUNTRY); citizenshipAttribute.getAttributeValue().add(citizenshipValue); categoryAttributes.getAttribute().add(citizenshipAttribute); xacmlRequestType.getAttributes().add(actionAttributes); xacmlRequestType.getAttributes().add(subjectAttributes); xacmlRequestType.getAttributes().add(categoryAttributes); // Perform Test ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType); // Verify - The policy was loaded to allow a permit decision JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class); Marshaller marshaller = jaxbContext.createMarshaller(); ObjectFactory objectFactory = new ObjectFactory(); Writer writer = new StringWriter(); marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer); LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString()); assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT); FileUtils.deleteDirectory(policyDir); }
From source file:es.bsc.servicess.ide.PackagingUtils.java
/** Copy the runtime files required for the Core Elements. * @param runtimePath Path to the programming model runtime * @param jarFolder Folder to store the jars *///from w w w. ja v a 2 s. c om private static void copyCoreRuntimeFiles(String runtimePath, IFolder jarFolder) { File d = new File(runtimePath + "/../worker/"); File it_jar = new File(runtimePath + File.separator + "lib" + File.separator + "IT.jar"); File jar_folder_file = jarFolder.getLocation().toFile(); File jar_lib_folder = jarFolder.getLocation().append("lib").toFile(); try { FileUtils.copyFileToDirectory(it_jar, jar_lib_folder); } catch (IOException e) { log.error("File " + it_jar.getAbsolutePath() + "could not be copied to " + jar_lib_folder.getAbsolutePath()); } if (d.isDirectory()) { Iterator<File> fi = FileUtils.iterateFiles(d, new String[] { "sh" }, false); while (fi.hasNext()) { File f = fi.next(); if (!isFileInDiscardList(f)) { try { // System.out.println("Trying to copy File "+ // f.getAbsolutePath()); FileUtils.copyFileToDirectory(f, jar_folder_file); File fc = new File(jar_folder_file.getAbsolutePath() + File.separator + f.getName()); fc.setExecutable(true); log.debug(" File copied " + f.getAbsolutePath()); } catch (IOException e) { log.error("File " + f.getAbsolutePath() + "could not be copied to " + jar_folder_file.getAbsolutePath()); } } } } else log.error("File " + d.getAbsolutePath() + "is not a directory"); }