|
| 1 | +package com.nuix.javaenginesimple.examples; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.io.IOException; |
| 5 | +import java.io.InputStream; |
| 6 | +import java.util.HashMap; |
| 7 | +import java.util.Map; |
| 8 | +import java.util.Properties; |
| 9 | +import java.util.function.Consumer; |
| 10 | +import java.util.List; |
| 11 | + |
| 12 | +import org.apache.log4j.Logger; |
| 13 | +import org.apache.log4j.PropertyConfigurator; |
| 14 | +import org.joda.time.DateTime; |
| 15 | + |
| 16 | +import com.nuix.javaenginesimple.EngineWrapper; |
| 17 | +import com.nuix.javaenginesimple.LicenseFilter; |
| 18 | +import com.nuix.javaenginesimple.NuixDiagnostics; |
| 19 | + |
| 20 | +import nuix.Case; |
| 21 | +import nuix.Item; |
| 22 | +import nuix.ProductionSet; |
| 23 | +import nuix.ProductionSetItem; |
| 24 | +import nuix.Utilities; |
| 25 | + |
| 26 | +public class CreateProductionSetExample { |
| 27 | + // Obtain a logger instance for this class |
| 28 | + private final static Logger logger = Logger.getLogger(CreateProductionSetExample.class); |
| 29 | + |
| 30 | + public static void main(String[] args) throws Exception { |
| 31 | + String logDirectory = String.format("C:\\NuixEngineLogs\\%s",DateTime.now().toString("YYYYMMDD_HHmmss")); |
| 32 | + System.getProperties().put("nuix.logdir", logDirectory); |
| 33 | + |
| 34 | + Properties props = new Properties(); |
| 35 | + InputStream log4jSettingsStream = OpenCaseExample.class.getResourceAsStream("/log4j.properties"); |
| 36 | + props.load(log4jSettingsStream); |
| 37 | + PropertyConfigurator.configure(props); |
| 38 | + |
| 39 | + EngineWrapper wrapper = new EngineWrapper("D:\\engine-releases\\8.8.1.131"); |
| 40 | + |
| 41 | + LicenseFilter licenseFilter = wrapper.getLicenseFilter(); |
| 42 | + licenseFilter.setMinWorkers(4); |
| 43 | + licenseFilter.addRequiredFeature("CASE_CREATION"); |
| 44 | + licenseFilter.addRequiredFeature("EXPORT_ITEMS"); |
| 45 | + |
| 46 | + String licenseUserName = System.getProperty("License.UserName"); |
| 47 | + String licensePassword = System.getProperty("License.Password"); |
| 48 | + |
| 49 | + if(licenseUserName != null && !licenseUserName.trim().isEmpty()) { |
| 50 | + logger.info(String.format("License username was provided via argument -DLicense.UserName: %s",licenseUserName)); |
| 51 | + } |
| 52 | + |
| 53 | + if(licensePassword != null && !licensePassword.trim().isEmpty()) { |
| 54 | + logger.info("License password was provided via argument -DLicense.Password"); |
| 55 | + } |
| 56 | + |
| 57 | + try { |
| 58 | + wrapper.trustAllCertificates(); |
| 59 | + wrapper.withCloudLicense(licenseUserName, licensePassword, new Consumer<Utilities>() { |
| 60 | + public void accept(Utilities utilities) { |
| 61 | + File caseDirectory = new File("D:\\Cases\\MyNuixCase"); |
| 62 | + |
| 63 | + Case nuixCase = null; |
| 64 | + |
| 65 | + try { |
| 66 | + // Attempt to open the case |
| 67 | + logger.info(String.format("Opening case: %s",caseDirectory.toString())); |
| 68 | + nuixCase = utilities.getCaseFactory().open(caseDirectory); |
| 69 | + logger.info("Case opened"); |
| 70 | + |
| 71 | + // Create our production set |
| 72 | + ProductionSet productionSet = nuixCase.newProductionSet("TestProductionSet_"+System.currentTimeMillis()); |
| 73 | + |
| 74 | + // Define our numbering options |
| 75 | + Map<String,Object> numberingOptions = new HashMap<String,Object>(); |
| 76 | + numberingOptions.put("prefix", "ABC-"); |
| 77 | + |
| 78 | + Map<String,Object> docIdOptions = new HashMap<String,Object>(); |
| 79 | + docIdOptions.put("minWidth", 9); |
| 80 | + docIdOptions.put("startAt", 1); |
| 81 | + numberingOptions.put("documentId", docIdOptions); |
| 82 | + |
| 83 | + productionSet.setNumberingOptions(numberingOptions); |
| 84 | + |
| 85 | + // Obtain items that we will be adding to the production set |
| 86 | + List<Item> items = nuixCase.search("flag:audited"); |
| 87 | + |
| 88 | + // Add these items to the production set |
| 89 | + productionSet.addItems(items); |
| 90 | + |
| 91 | + // Lets report the first and last number in this production set |
| 92 | + List<ProductionSetItem> productionSetItems = productionSet.getProductionSetItems(); |
| 93 | + String firstNumber = productionSetItems.get(0).getDocumentNumber().toString(); |
| 94 | + String lastNumber = productionSetItems.get(productionSetItems.size()-1).getDocumentNumber().toString(); |
| 95 | + logger.info(String.format("Production Set Created with Nubmers %s to %s", firstNumber, lastNumber)); |
| 96 | + |
| 97 | + // Note that nuixCase is closed in finally block below |
| 98 | + } catch (IOException exc) { |
| 99 | + logger.error(String.format("Error while opening case: %s",caseDirectory.toString()),exc); |
| 100 | + } finally { |
| 101 | + // Make sure we close the case |
| 102 | + if(nuixCase != null) { |
| 103 | + logger.info(String.format("Closing case: %s",caseDirectory.toString())); |
| 104 | + nuixCase.close(); |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + }); |
| 109 | + |
| 110 | + } catch (Exception e) { |
| 111 | + logger.error("Unhandled exception",e); |
| 112 | + NuixDiagnostics.saveDiagnostics("C:\\EngineDiagnostics"); |
| 113 | + } |
| 114 | + } |
| 115 | +} |
0 commit comments