List of usage examples for java.util Locale UK
Locale UK
To view the source code for java.util Locale UK.
Click Source Link
From source file:mitm.common.security.certificate.GenerateTestCertificates.java
/** * Generates a certificate without key usage * /* w w w . ja v a2 s . c o m*/ * @throws Exception */ private void generateCertificateNoKeyUsage() throws Exception { X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder(); String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d0030818902818100b2" + "0e2afe37e1235b93919e2c30207b3c52547a7ca4b5929d3ac63984b5d951" + "244d6ee103a1cf5fd1e57f67a4becd0cb1be3c5cfe884130c412c46fdc13" + "cb175b51b3d6707130a57063e6e98c92ec5ec274cbb3c53d29be5b02383a" + "ab5f26581a84b2a32e20c84a84d182720737ccd53d7b1331b7db0d816e9c" + "b85927158c288f0203010001"; String encodedPrivateKey = "30820276020100300d06092a864886f70d0101010500048202603082025c" + "02010002818100b20e2afe37e1235b93919e2c30207b3c52547a7ca4b592" + "9d3ac63984b5d951244d6ee103a1cf5fd1e57f67a4becd0cb1be3c5cfe88" + "4130c412c46fdc13cb175b51b3d6707130a57063e6e98c92ec5ec274cbb3" + "c53d29be5b02383aab5f26581a84b2a32e20c84a84d182720737ccd53d7b" + "1331b7db0d816e9cb85927158c288f020301000102818076054e1a138ff7" + "8fcbd0c9b7206f674024923a5e440ed68fc15582eaa45ed799e879864c92" + "0492cede000502fe358c2484a41e3fd8b0dd5219de7b06b557f8b242eb9a" + "0c7650dc8a9d68b20ab32aca5fbff4a01a15a2a3e90930d4040540e695ef" + "90c21fc7383364cb111f509aa559889830a9b3846777a9b8b755152482f8" + "81024100e8dfecea5ee39b456a552eed6c51f917c191dda274edbe2ea550" + "d1360bd531aed9a5e740ab9468fde289dbdb8d8b2cf57eea3317cf0b0a7f" + "89e6b8b17e6d2b7d024100c3bca3e3b3457ac7280902a3d5ab4a2a7f6f34" + "6f37e4e9f233d4498f336aea8169c2cccd702880e58432e43bbae9301283" + "093519c9a888bf744f3c3fb191a9fb0240361eec919f91e8211ed04342bc" + "7ce49627cf7da1e6e8e5dd33606feece9b329bbf4b764e2a52288070a8b7" + "66f42357448ac565307056d18ec87ecd87baa926850240130977cf1f9274" + "5c86524a05713495a4087ce256a6d306c5ddb099eee98b4e7f83afc4877e" + "8f11ea40af4a6f5cc06d427fa81798087af1c1dd280fae0a31269d024100" + "98982a55da07b7d2ed807e3f960265180ae755edd5cb8df393c7dfdc70ec" + "db9ce973f9aa9f14834c6bf92f9e36de5163b5e27a998a0935645f2f4ec2" + "d3e685c7"; PrivateKey privateKey = decodePrivateKey(encodedPrivateKey); PublicKey publicKey = decodePublicKey(encodedPublicKey); X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder(); String email = "test@example.com"; subjectBuilder.setCommonName("No key usage"); subjectBuilder.setEmail(email); subjectBuilder.setCountryCode("NL"); subjectBuilder.setLocality("Amsterdam"); subjectBuilder.setState("NH"); AltNamesBuilder altNamesBuider = new AltNamesBuilder(); altNamesBuider.setRFC822Names(email); X500Principal subject = subjectBuilder.buildPrincipal(); GeneralNames altNames = altNamesBuider.buildAltNames(); Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>(); extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH); extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION); BigInteger serialNumber = new BigInteger("115fd0bd417e7a6f347eeacb7ff3f38", 16); Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK) .parse("21-Nov-2007 11:51:35"); certificateBuilder.setSubject(subject); certificateBuilder.setAltNames(altNames, true); certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false); certificateBuilder.setNotBefore(DateUtils.addDays(now, -20)); certificateBuilder.setNotAfter(DateUtils.addYears(now, 20)); certificateBuilder.setPublicKey(publicKey); certificateBuilder.setSerialNumber(serialNumber); certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption"); X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate); assertNotNull(certificate); certificates.add(certificate); Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate }; keyStore.setKeyEntry("NoKeyUsage", privateKey, null, chain); }
From source file:mitm.common.security.certificate.GenerateTestCertificates.java
/** * Generates a certificate without a CN/*from www. java 2s . com*/ * * @throws Exception */ private void generateCertificateNoCN() throws Exception { X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder(); String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d00308189028181008c" + "853445a83b7993183d8ed24a1eb8448bde884755c51341a20168343d2a9b" + "ab59477e643a5717e5bbea935dac51caa3a3fbff89059be9d6bf6af8d739" + "5bde8c8c45f89aeb4530805387f3402491defcd523031f2ef7085c63db71" + "bfe9e25378929f5b3c0b53e0e073e5ed7321de1ed6564e387250cef278dd" + "15a7727824620f0203010001"; String encodedPrivateKey = "30820275020100300d06092a864886f70d01010105000482025f3082025b" + "020100028181008c853445a83b7993183d8ed24a1eb8448bde884755c513" + "41a20168343d2a9bab59477e643a5717e5bbea935dac51caa3a3fbff8905" + "9be9d6bf6af8d7395bde8c8c45f89aeb4530805387f3402491defcd52303" + "1f2ef7085c63db71bfe9e25378929f5b3c0b53e0e073e5ed7321de1ed656" + "4e387250cef278dd15a7727824620f02030100010281806efedcde54d7bd" + "dd71dd560e479be263cab3d9a3b75d372bb5c334c366b95c4349ff4e17ef" + "795218168a612331f55d824b0ac7bb3d21fde0b24cd60873775cdf2db306" + "a899f7733d36c11064b76efab7c1b9ab8a897737a5d0b4f05378a033ff71" + "a150ed772f1cdbba4cbf8d41025081c960072c07c1f62d7f20a76b6d549f" + "61024100cad28338a54224d1a56c32c9f1ad7e0f721e7059dd1bb0310d2b" + "04ecc900f57b8f58d773f908a8870ba8676b4363c6087fc44f516d21c9c7" + "ea761e07ac77363f024100b15cf740a7162c3bc998fbf57c2d5335e4426d" + "5085ed295a432084c1f4311da996a8d40768d3e064e2615e0b2660faf023" + "86ed0cbce55a1b4ef0aa6583ed003102402ea29ad3828423ed24892d606b" + "b6859ecd919c29bd82694fce044f3c96b726bac36a1d182871ca364b02ec" + "cca8111feec25a0416e7edf5f486bfa40605acdf87024064abff0fec8732" + "5e51448ba7406fbdae763c9a2dbd86eb14f7cb2a6fa8ba843ab1706cc133" + "e827933bc7c6888fa5366a3dd0251738d4f9fb4c28609fb46d3ed1024007" + "49ec34b3aa1be30efcc2bc5a18b7ed51ed7b670b9a215c05725ea5dea6da" + "6a71aa14e33ab2c8c5d05f4d8e33ed09e83b1df5cdeaf73571f87e67a412" + "864bde"; PrivateKey privateKey = decodePrivateKey(encodedPrivateKey); PublicKey publicKey = decodePublicKey(encodedPublicKey); X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder(); String email = "test@example.com"; subjectBuilder.setEmail(email); subjectBuilder.setCountryCode("NL"); subjectBuilder.setLocality("Amsterdam"); subjectBuilder.setState("NH"); AltNamesBuilder altNamesBuider = new AltNamesBuilder(); altNamesBuider.setRFC822Names(email); X500Principal subject = subjectBuilder.buildPrincipal(); GeneralNames altNames = altNamesBuider.buildAltNames(); Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>(); keyUsage.add(KeyUsageType.DIGITALSIGNATURE); keyUsage.add(KeyUsageType.KEYENCIPHERMENT); keyUsage.add(KeyUsageType.NONREPUDIATION); Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>(); extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH); extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION); BigInteger serialNumber = new BigInteger("115fd0e5ee990d9426c93dea720e970", 16); Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK) .parse("21-Nov-2007 11:52:35"); certificateBuilder.setSubject(subject); certificateBuilder.setAltNames(altNames, true); certificateBuilder.setKeyUsage(keyUsage, true); certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false); certificateBuilder.setNotBefore(DateUtils.addDays(now, -20)); certificateBuilder.setNotAfter(DateUtils.addYears(now, 20)); certificateBuilder.setPublicKey(publicKey); certificateBuilder.setSerialNumber(serialNumber); certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption"); X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate); assertNotNull(certificate); certificates.add(certificate); Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate }; keyStore.setKeyEntry("NoCN", privateKey, null, chain); }
From source file:mitm.common.security.certificate.GenerateTestCertificates.java
/** * Generates a certificate with multiple email addresses * /*from w w w . j a va2s .c om*/ * @throws Exception */ private void generateCertificateMultipleEmail() throws Exception { X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder(); String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d00308189028181008e" + "1347f6e22318a40d4d8b9a97cdb06355d9a761f35f44b7d3356d4596ddf6" + "db2606fc572ed5b9c79fb2f76466f7f9bf2797de2ae1f8d9ea14d9380f2e" + "afe2040d6faab65f746d9705f7fab00956b918bc7b0c2e312895b24153b7" + "33ffede39bf6dfe0d419b8020c8772f9da1d8d1ca3d2a9da172fafdcfb7b" + "4ecff5048d46c90203010001"; String encodedPrivateKey = "30820276020100300d06092a864886f70d0101010500048202603082025c" + "020100028181008e1347f6e22318a40d4d8b9a97cdb06355d9a761f35f44" + "b7d3356d4596ddf6db2606fc572ed5b9c79fb2f76466f7f9bf2797de2ae1" + "f8d9ea14d9380f2eafe2040d6faab65f746d9705f7fab00956b918bc7b0c" + "2e312895b24153b733ffede39bf6dfe0d419b8020c8772f9da1d8d1ca3d2" + "a9da172fafdcfb7b4ecff5048d46c90203010001028180723bc28318f40b" + "1decac4af133d9685796717889e33ad86fcd5c89cd882e540b8499dd4ee4" + "13685abf67104f24138235564a5f91af3b7d4b1f144064c4af1a53e045f7" + "1678bd7af11e33f02dbd846782ff0b8a6f7fea20d6c068b0a79f0c3b136c" + "dcd201443ecc7113d8e73e9a4f8faacdd87fd314c42f54c6532ffcceeb2d" + "d9024100cd8ffedb65cdfbafc3ffe2ba0743ab4f0ebf5298bddd542be36b" + "e9393788fccb1bc8218fe0f81e85c9c2eade11d68ae30284b931cf2654bb" + "8ace741dcf67450b024100b0ef76b44180f5d729619cd855e0da81d5129c" + "b8866fee97291961f3487a3a8b5d28049cd0b7062590a963420923331ce8" + "7f76d49f7e6d02837916dd0878dffb024067979084fa5a02e381efbb4faa" + "87849653c54117ae5f12a3077a034f8d5820a52ebbfd85e786c2c3037992" + "29156e3c11c8dc200424f39931e5f2c2fb9ee0d91f02410088005906ef3e" + "b8391db6c93fc4ab246a1da4c3d0568ddd2055d80be15bb9901ca58b6818" + "3d9a21606894bb15fc3e1140cc3985d6a38e232e866e62339e1a83570240" + "10b51e80ac96ea754e7232e633daeae50efaf8f0b9f55fcd113226722197" + "d9650870c7a245348be5d4f3dd2face76ad2e82f5c6b658c67b4cdfe6d14" + "dbaf86bd"; PrivateKey privateKey = decodePrivateKey(encodedPrivateKey); PublicKey publicKey = decodePublicKey(encodedPublicKey); X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder(); String email[] = new String[] { "test@example.com", "test2@example.com", "test3@example.com", "invalid" }; subjectBuilder.setCommonName("multiple email"); subjectBuilder.setEmail(email); subjectBuilder.setCountryCode("NL"); subjectBuilder.setLocality("Amsterdam"); subjectBuilder.setState("NH"); AltNamesBuilder altNamesBuider = new AltNamesBuilder(); altNamesBuider.setRFC822Names(email); X500Principal subject = subjectBuilder.buildPrincipal(); GeneralNames altNames = altNamesBuider.buildAltNames(); Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>(); keyUsage.add(KeyUsageType.DIGITALSIGNATURE); keyUsage.add(KeyUsageType.KEYENCIPHERMENT); keyUsage.add(KeyUsageType.NONREPUDIATION); Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>(); extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH); extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION); BigInteger serialNumber = new BigInteger("115fd110a82f742d0ae14a71b651962", 16); Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK) .parse("21-Nov-2007 11:52:35"); certificateBuilder.setSubject(subject); certificateBuilder.setAltNames(altNames, true); certificateBuilder.setKeyUsage(keyUsage, true); certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false); certificateBuilder.setNotBefore(DateUtils.addDays(now, -20)); certificateBuilder.setNotAfter(DateUtils.addYears(now, 20)); certificateBuilder.setPublicKey(publicKey); certificateBuilder.setSerialNumber(serialNumber); certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption"); X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate); assertNotNull(certificate); certificates.add(certificate); Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate }; keyStore.setKeyEntry("multipleEmail", privateKey, null, chain); }
From source file:com.gtwm.pb.servlets.ServletSchemaMethods.java
public synchronized static void addCalculationToReport(SessionDataInfo sessionData, HttpServletRequest request, DatabaseInfo databaseDefn) throws DisallowedException, MissingParametersException, ObjectNotFoundException, SQLException, CantDoThatException, CodingErrorException { BaseReportInfo baseReport = ServletUtilMethods.getReportForRequest(sessionData, request, databaseDefn, ServletUtilMethods.USE_SESSION); if (!(baseReport instanceof SimpleReportInfo)) { throw new CantDoThatException("You can only add calculations to normal reports, not union reports"); }// ww w . ja va 2 s .c o m SimpleReportInfo report = (SimpleReportInfo) baseReport; String internalCalculationName = request.getParameter("internalcalculationname"); String calculationName = request.getParameter("calculationname"); String calculationDefn = request.getParameter("calculationdefn"); String dbType = request.getParameter("databasetype"); if (calculationName == null || calculationDefn == null || dbType == null) { throw new MissingParametersException( "'calculationname', 'calculationdefn' and 'databasetype' parameters needed in request to add a calculation"); } // begin updating model and persisting changes ReportCalcFieldInfo newCalculationField = null; Connection conn = null; try { HibernateUtil.startHibernateTransaction(); conn = databaseDefn.getDataSource().getConnection(); conn.setAutoCommit(false); // create the new field DatabaseFieldType databaseType = DatabaseFieldType.valueOf(dbType.toUpperCase(Locale.UK)); Map<TableInfo, Set<BaseReportInfo>> availableDataStores = databaseDefn.getViewableDataStores(request); newCalculationField = new ReportCalcFieldDefn(report, internalCalculationName, calculationName, calculationDefn, databaseType, availableDataStores); databaseDefn.addCalculationToReport(request, conn, report, newCalculationField); conn.commit(); HibernateUtil.currentSession().getTransaction().commit(); } catch (SQLException sqlex) { rollbackConnections(conn); // remove calculation from memory if (newCalculationField != null) { report.removeField(newCalculationField); } String message = sqlex.getMessage(); int bracketDifference = 0; if (message.contains("syntax error at or near \")\"")) { bracketDifference = -1; } else { bracketDifference = StringUtils.countMatches(message, "(") - StringUtils.countMatches(message, ")"); } if (bracketDifference != 0) { String word; if (Math.abs(bracketDifference) == 1) { word = "is "; } else { word = "are "; } if (bracketDifference > 0) { message = "It looks like brackets may not match - there " + word + bracketDifference + " closing bracket(s) missing"; } else { message = "It looks like brackets may not match - there " + word + bracketDifference + " more closing bracket(s) than opening brackets"; } } throw new CantDoThatException( "Calculation addition failed. " + Helpers.replaceInternalNames(message, report), sqlex); } catch (HibernateException hex) { rollbackConnections(conn); // remove calculation from memory if (newCalculationField != null) { report.removeField(newCalculationField); } throw new CantDoThatException("Calculation addition failed. " + hex.getMessage(), hex); } catch (AgileBaseException pex) { rollbackConnections(conn); // remove calculation from memory if (newCalculationField != null) { report.removeField(newCalculationField); } throw new CantDoThatException("Calculation addition failed. " + pex.getMessage(), pex); } finally { conn.close(); HibernateUtil.closeSession(); } }
From source file:mitm.common.security.certificate.GenerateTestCertificates.java
/** * Generates a certificate with MD5 Hash algorithm * /*from www . j a v a 2 s.c o m*/ * @throws Exception */ private void generateCertificateMD5Hash() throws Exception { X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder(); String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d003081890281810080" + "204142a37fe819010c9c5e021b8df7ee54083c588a04c31ffd714695ce18" + "51721b0f00a392643fa91392aa7bcf1426d2e2f724a5d996740d97b8586c" + "f59cc7bc8d865bf3957a629c8f36bb9b71017c53e8baf71821cf622ca025" + "d3c523c084700a5c1af9b624639c86c556d8038a7afc2235d2f1d0f226c4" + "48a40c2e0327dd0203010001"; String encodedPrivateKey = "30820275020100300d06092a864886f70d01010105000482025f3082025b" + "0201000281810080204142a37fe819010c9c5e021b8df7ee54083c588a04" + "c31ffd714695ce1851721b0f00a392643fa91392aa7bcf1426d2e2f724a5" + "d996740d97b8586cf59cc7bc8d865bf3957a629c8f36bb9b71017c53e8ba" + "f71821cf622ca025d3c523c084700a5c1af9b624639c86c556d8038a7afc" + "2235d2f1d0f226c448a40c2e0327dd020301000102818028427a5f2722fc" + "da468320eb453c454adf9f960ae8434e25c5fa8c4a82ae04e42ab7a7ea2a" + "7bc8765c7962ffa0f1bbc24b47b822d2de61314c481d4be3c8f59f3497f6" + "4d6d84e7d61b7858f20e88e803ff924f8d98a311a2f39398b149100a158c" + "ac03df61da458599e87da0ca48b749dee040f66c8fe3eda072f44ec4829f" + "3d024100e4361bd0489cb47e204af8905d617e1e04e7102fec2c22711b85" + "9dbade040aa41f0f2a349b88444da57c6b5a16f198ea9ac70350855eece1" + "6eafe7789a2c33730241008fba3f47889514c507b76a289d097a220f07d8" + "0dea9fd55191b6519646d11ad6399d97924906768ea19f8262cad28c7a16" + "b76d8cdc069b6c639fdce3a027836f0240678ca9b82b8a7757977d8d25ac" + "497579578e24c929e7a8c51bd0d80e17794bfec65d123086b6210ffe5be3" + "36209d055ec6563109d34a8c3f8a02e50bd320e543024033d5e4049489cf" + "d7cf94a2c0cb0223fe2c9593a251401bdb334621dea4e3bd5e0da17c8cd1" + "b17708b1d9a9589ff5979c609cfef19258ffacf3b130251819a819024018" + "81b9dae35212866780b9ce93e0c10fa40e3679773e3b067d5743bfdb8c74" + "ce8d1ed3a0d5312f220f7d0eb44c074c46898acbcfdba15c480385458d90" + "14fd7b"; PrivateKey privateKey = decodePrivateKey(encodedPrivateKey); PublicKey publicKey = decodePublicKey(encodedPublicKey); X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder(); String email[] = new String[] { "test@example.com" }; subjectBuilder.setCommonName("md5 Hash"); subjectBuilder.setEmail(email); subjectBuilder.setCountryCode("NL"); subjectBuilder.setLocality("Amsterdam"); subjectBuilder.setState("NH"); AltNamesBuilder altNamesBuider = new AltNamesBuilder(); altNamesBuider.setRFC822Names(email); X500Principal subject = subjectBuilder.buildPrincipal(); GeneralNames altNames = altNamesBuider.buildAltNames(); Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>(); keyUsage.add(KeyUsageType.DIGITALSIGNATURE); keyUsage.add(KeyUsageType.KEYENCIPHERMENT); keyUsage.add(KeyUsageType.NONREPUDIATION); Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>(); extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH); extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION); BigInteger serialNumber = new BigInteger("115fd1392a8ff07aa727558fa50b262", 16); Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK) .parse("21-Nov-2007 11:54:35"); certificateBuilder.setSubject(subject); certificateBuilder.setAltNames(altNames, true); certificateBuilder.setKeyUsage(keyUsage, true); certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false); certificateBuilder.setNotBefore(DateUtils.addDays(now, -20)); certificateBuilder.setNotAfter(DateUtils.addYears(now, 20)); certificateBuilder.setPublicKey(publicKey); certificateBuilder.setSerialNumber(serialNumber); certificateBuilder.setSignatureAlgorithm("MD5WithRSAEncryption"); X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate); assertNotNull(certificate); certificates.add(certificate); Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate }; keyStore.setKeyEntry("md5Hash", privateKey, null, chain); }
From source file:mitm.common.security.certificate.GenerateTestCertificates.java
/** * Generates a certificate with SHA256 Hash algorithm * //w w w. j a v a 2 s . c o m * @throws Exception */ private void generateCertificateSHA256Hash() throws Exception { X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder(); String encodedPublicKey = "30819f300d06092a864886f70d010101050003818d00308189028181008b" + "08d9d440857d8b6e0adf44301cecacc9e3619e25e3ecb2735a0c25a8d65c" + "005d44c92fea1e82693d676c25653d4f4a30702aefde057983ab4fd1d381" + "a18938318dcf07f635e68b32b47b5ec8246e783c912e7287c9d2e75c5f01" + "24653694c0dcf8b5983bf7659fa2558426f44978db1e5e81a4abae5ea245" + "f915d6ef663af70203010001"; String encodedPrivateKey = "30820277020100300d06092a864886f70d0101010500048202613082025d" + "020100028181008b08d9d440857d8b6e0adf44301cecacc9e3619e25e3ec" + "b2735a0c25a8d65c005d44c92fea1e82693d676c25653d4f4a30702aefde" + "057983ab4fd1d381a18938318dcf07f635e68b32b47b5ec8246e783c912e" + "7287c9d2e75c5f0124653694c0dcf8b5983bf7659fa2558426f44978db1e" + "5e81a4abae5ea245f915d6ef663af702030100010281807277ce07ef3b38" + "7ac415d56de982d6e507aeda5eff69212666cc3b760204c2685661dc9643" + "55ed1ec23c551090c2a2763d5d0c2cc289955aef7f5f0c990caad0c4be38" + "ea093a0ff82f987fb85432ff0c97acec554b9ffe6bdccec9b2c30b57e866" + "b9f964cd64d007311e2b477f88d15c4fccc57fbd06afdf815624c92ba03d" + "a9024100f508e549437f5ec1b2307b6843f692f189feed369389a598172c" + "859a768bc5b3e02765b0a8e672e54b1096f526c8df741d12910296be0c16" + "e93f7bb77fb13bd502410091419f88e027d1b0f99408eaab6dd26b2bd0a6" + "62e47f5d40f20d191dab1864a6bfea4a9c5b1b3f1aea35c4134bdf005cd0" + "25d4a0e98299e6aa2be46591607d9b024100f119f8a9f70d4bca612f8d2e" + "11b97beac8729b2c194dd62f6995f83bfd2b18b41dfa05f826a8e222b592" + "b446b20bf2bac8a46d24d3f859e2ed4cf6c99e8e60a502410085a22ee858" + "f8a934bcd7d1403c08a42e0eb83d6afbb6a50f6be05afbed7d5a940239c4" + "fc85e0d234abc65d263785e8aa7aa06336cabd696349a969cd7b6a9f0302" + "405653037277299bfd0d055bc55b5f8f9892e7254f7ddf09cb0a5a159095" + "746a3d914caa2c2a8c24d1ab57c1d065cf9c31ef4820855b2dbfa6f7a91c" + "96b152f9ef"; PrivateKey privateKey = decodePrivateKey(encodedPrivateKey); PublicKey publicKey = decodePublicKey(encodedPublicKey); X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder(); String email[] = new String[] { "test@example.com" }; subjectBuilder.setCommonName("SHA256 Hash"); subjectBuilder.setEmail(email); subjectBuilder.setCountryCode("NL"); subjectBuilder.setLocality("Amsterdam"); subjectBuilder.setState("NH"); AltNamesBuilder altNamesBuider = new AltNamesBuilder(); altNamesBuider.setRFC822Names(email); X500Principal subject = subjectBuilder.buildPrincipal(); GeneralNames altNames = altNamesBuider.buildAltNames(); Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>(); keyUsage.add(KeyUsageType.DIGITALSIGNATURE); keyUsage.add(KeyUsageType.KEYENCIPHERMENT); keyUsage.add(KeyUsageType.NONREPUDIATION); Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>(); extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH); extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION); BigInteger serialNumber = new BigInteger("115fd16008275f2616b8a235d761fff", 16); Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK) .parse("21-Nov-2007 06:38:35"); certificateBuilder.setSubject(subject); certificateBuilder.setAltNames(altNames, true); certificateBuilder.setKeyUsage(keyUsage, true); certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false); certificateBuilder.setNotBefore(DateUtils.addDays(now, -20)); certificateBuilder.setNotAfter(DateUtils.addYears(now, 20)); certificateBuilder.setPublicKey(publicKey); certificateBuilder.setSerialNumber(serialNumber); certificateBuilder.setSignatureAlgorithm("SHA256WithRSAEncryption"); X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate); assertNotNull(certificate); certificates.add(certificate); Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate }; keyStore.setKeyEntry("sha256Hash", privateKey, null, chain); }
From source file:com.gtwm.pb.servlets.ServletSchemaMethods.java
public synchronized static void updateCalculationInReport(SessionDataInfo sessionData, HttpServletRequest request, DatabaseInfo databaseDefn) throws CantDoThatException, DisallowedException, ObjectNotFoundException, MissingParametersException, SQLException, CodingErrorException { BaseReportInfo baseReport = ServletUtilMethods.getReportForRequest(sessionData, request, databaseDefn, ServletUtilMethods.USE_SESSION); if (!(baseReport instanceof SimpleReportInfo)) { throw new CantDoThatException("You can only add calculations to normal reports, not union reports"); }/*from w w w . j av a 2s . c om*/ SimpleReportInfo report = (SimpleReportInfo) baseReport; String internalCalculationName = request.getParameter("internalcalculationname"); String calculationName = request.getParameter("calculationname"); String calculationDefn = request.getParameter("calculationdefn"); String dbType = request.getParameter("databasetype"); String isReportHiddenString = request.getParameter("isreporthidden"); boolean isReportHidden = Helpers.valueRepresentsBooleanTrue(isReportHiddenString); if (internalCalculationName == null || calculationName == null || calculationDefn == null || dbType == null) { throw new MissingParametersException( "'internalcalculationname', 'calculationname', 'calculationdefn' and 'databasetype' (optionally 'isreporthidden') parameters needed in request to update a calculation"); } // begin updating model and persisting changes ReportCalcFieldInfo calculationField = (ReportCalcFieldInfo) report.getReportField(internalCalculationName); String oldCalculationName = calculationField.getBaseFieldName(); String oldCalculationDefn = calculationField.getCalculationDefinition(); boolean oldIsReportHidden = calculationField.isReportHidden(); DatabaseFieldType oldDbFieldType = calculationField.getDbType(); Connection conn = null; try { HibernateUtil.startHibernateTransaction(); conn = databaseDefn.getDataSource().getConnection(); conn.setAutoCommit(false); // update the calculation field DatabaseFieldType databaseType = DatabaseFieldType.valueOf(dbType.toUpperCase(Locale.UK)); databaseDefn.updateCalculationInReport(request, conn, report, calculationField, calculationName, calculationDefn, databaseType, isReportHidden); conn.commit(); HibernateUtil.currentSession().getTransaction().commit(); } catch (SQLException sqlex) { rollbackConnections(conn); // undo changes to calculation in memory databaseDefn.returnCalculationInReportToMemory(request, conn, report, calculationField, oldCalculationName, oldCalculationDefn, oldDbFieldType); throw new CantDoThatException("Calculation addition failed. " + sqlex.getMessage(), sqlex); } catch (HibernateException hex) { rollbackConnections(conn); // undo changes to calculation in memory databaseDefn.returnCalculationInReportToMemory(request, conn, report, calculationField, oldCalculationName, oldCalculationDefn, oldDbFieldType); throw new CantDoThatException("Calculation addition failed. " + hex.getMessage(), hex); } catch (AgileBaseException pex) { rollbackConnections(conn); // undo changes to calculation in memory databaseDefn.returnCalculationInReportToMemory(request, conn, report, calculationField, oldCalculationName, oldCalculationDefn, oldDbFieldType); throw new CantDoThatException("Calculation addition failed. " + pex.getMessage(), pex); } finally { if (conn != null) { conn.close(); } HibernateUtil.closeSession(); } }
From source file:mitm.common.security.certificate.GenerateTestCertificates.java
/** * Generates a certificate with RSA 2048 key length * /*from w w w . j a v a2s. c o m*/ * @throws Exception */ private void generateCertificateRSA2048() throws Exception { X509CertificateBuilder certificateBuilder = securityFactory.createX509CertificateBuilder(); String encodedPublicKey = "30820122300d06092a864886f70d01010105000382010f003082010a0282" + "010100804e190456423f3253d25f622b11d6601cce51b2793cb752265461" + "6e34804282b081cf0b9389a7160649ce2d62a224201027113a74351b9fda" + "7a640d96615615e934cea567b1d809180f034660ab1692d2db3a04cbc439" + "a20e947bfe5552a1a32152b7b3501c54c7255943102c5712ec0648823b44" + "be3a8c85bf550f3fda7edf8adff1505dffe1fdd8e8100f5808e57f349d5b" + "cd41d2fc8cbc3e24e29f02468ecdaa152581e55e068e3e2af0ef5c7ad106" + "01934a3e698c485971e69a8820ad7a697b1492bd695747a8dedcbfb72a6f" + "f04e4adf8c56bdcc0592cd36288cc1daee35950e9e8676c52fe0fbee02d8" + "52c09ff906c7296b12aa2bc972240af9f4720f0203010001"; String encodedPrivateKey = "308204bd020100300d06092a864886f70d0101010500048204a7308204a3" + "0201000282010100804e190456423f3253d25f622b11d6601cce51b2793c" + "b7522654616e34804282b081cf0b9389a7160649ce2d62a224201027113a" + "74351b9fda7a640d96615615e934cea567b1d809180f034660ab1692d2db" + "3a04cbc439a20e947bfe5552a1a32152b7b3501c54c7255943102c5712ec" + "0648823b44be3a8c85bf550f3fda7edf8adff1505dffe1fdd8e8100f5808" + "e57f349d5bcd41d2fc8cbc3e24e29f02468ecdaa152581e55e068e3e2af0" + "ef5c7ad10601934a3e698c485971e69a8820ad7a697b1492bd695747a8de" + "dcbfb72a6ff04e4adf8c56bdcc0592cd36288cc1daee35950e9e8676c52f" + "e0fbee02d852c09ff906c7296b12aa2bc972240af9f4720f020301000102" + "820100307fd4fb0bb42cf9543010782639aee453df358896457a326664bd" + "13906aef3941893fff6b3cbc5919f56a2743c2708f622bb25a7b34dc0557" + "ebadc86910d01ea6319cef6f3c0da29a628a655f032d1c40f237833a9729" + "05f626f09bda1acb18c3eee59bb56b902c5b14dbc1d050f5c91c32ea6f86" + "f3b5640ae6a13b8b7287446321e3c7c7543ce9bb95a2329be4e09f8ae3db" + "9eb6a886168fa91954595332091bb09580dcc83444c02e63a5915d80eaa8" + "894159bc0ec787b7cd897ce26014d537ef731d0f7d7726585fb5193b76e4" + "5d9c2baf1f8a80ed84cf15c591d0d09122c4377bdde75b7a72b0aaeec170" + "a604ffe77491038762c4125083463a11b7802902818100dcd8b76c1d0599" + "0e54a22a65fb5cdb41674f6496fa15b3d09d5b32417a5f02c477a0da482c" + "ea27fb3a5c11acf9770b83d66b43ba16d92f927ce6a3dab71ade3a918d97" + "b951d3b14ea5edeb8786df83ce46e204ece2c06ab445102ba2c74dff607a" + "84933e9f54dd987bf306079e337692df4d0d335f97f302c69106577134d9" + "030281810094ba67c454dc1b8cbaff49cde17cdc583319572d29b4f284d1" + "0b9740cb468678b0fa196626208406181717a4bc9acfaef8627ce086e0bb" + "8c95b14e911be6e8c5569a6c8198dcaa88291fc7d7ec560b19258a3d544c" + "8a6a81d09454521921c96f5b1f5c9dfc77c53d6ffe17b59fdfed04381233" + "27c1bbed740cab748324346705028181009d216097feaa2df52148644c3d" + "251b2714bf4b3d945ffe994e6c457c8af9b0b962b842b699a65c9e062edd" + "b0a9aa06ba5dc3e1e3344080f5840281d0aaf8e5e6dc0ad749d6ab7cfb0d" + "5a137b50fe15049e304ffacf76c234d2f2a76960cee1059f0656d17681e6" + "4c88dc278d220551b73c43d1419d213a98ddf8ef7f259fc94b0281805949" + "e39c31da06cc2143bc5a56c23042df429a5ca9ca5142bd81b8e794621dbe" + "fd78d8a0c3c90799e50290163d88afa07acc1dee69eb278d8a1ced6f1e92" + "2d32b400779e02589024b893b4d583b4506b63672fd499330c282d41afb1" + "ae16e3a8efcacf3ea5e07dd09998b1413fdf1e9b46d25e55c2f080e907e6" + "3347bc079dc502818021c107a9757dc38395f859e7d59ba1ef12c8719e62" + "ebbbf9d720bf29db7c48a19c2c63ab283254cd87ced3415381db08ca2714" + "0ea7cbdcf47a3bb091eeb1333caefdda0f78d41c073c166b187195fac3cd" + "54ca7ffbbc1056fe7ec2654e126ff09e2da201337f1c7733cbd28f8e2804" + "c2eb55c4224f84e28875aafab7a827a687"; PrivateKey privateKey = decodePrivateKey(encodedPrivateKey); PublicKey publicKey = decodePublicKey(encodedPublicKey); X500PrincipalBuilder subjectBuilder = new X500PrincipalBuilder(); String email[] = new String[] { "test@example.com" }; subjectBuilder.setCommonName("RSA 2048"); subjectBuilder.setEmail(email); subjectBuilder.setCountryCode("NL"); subjectBuilder.setLocality("Amsterdam"); subjectBuilder.setState("NH"); AltNamesBuilder altNamesBuider = new AltNamesBuilder(); altNamesBuider.setRFC822Names(email); X500Principal subject = subjectBuilder.buildPrincipal(); GeneralNames altNames = altNamesBuider.buildAltNames(); Set<KeyUsageType> keyUsage = new TreeSet<KeyUsageType>(); keyUsage.add(KeyUsageType.DIGITALSIGNATURE); keyUsage.add(KeyUsageType.KEYENCIPHERMENT); keyUsage.add(KeyUsageType.NONREPUDIATION); Set<ExtendedKeyUsageType> extendedKeyUsage = new TreeSet<ExtendedKeyUsageType>(); extendedKeyUsage.add(ExtendedKeyUsageType.CLIENTAUTH); extendedKeyUsage.add(ExtendedKeyUsageType.EMAILPROTECTION); BigInteger serialNumber = new BigInteger("115fd1606444bc50de5464af7d0d468", 16); Date now = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.UK) .parse("21-Nov-2007 06:38:35"); certificateBuilder.setSubject(subject); certificateBuilder.setAltNames(altNames, true); certificateBuilder.setKeyUsage(keyUsage, true); certificateBuilder.setExtendedKeyUsage(extendedKeyUsage, false); certificateBuilder.setNotBefore(DateUtils.addDays(now, -20)); certificateBuilder.setNotAfter(DateUtils.addYears(now, 20)); certificateBuilder.setPublicKey(publicKey); certificateBuilder.setSerialNumber(serialNumber); certificateBuilder.setSignatureAlgorithm("SHA1WithRSAEncryption"); X509Certificate certificate = certificateBuilder.generateCertificate(caPrivateKey, caCertificate); assertNotNull(certificate); certificates.add(certificate); Certificate[] chain = new Certificate[] { certificate, caCertificate, rootCertificate }; keyStore.setKeyEntry("rsa2048", privateKey, null, chain); }
From source file:ispyb.client.mx.results.ViewResultsAction.java
public void getResultData(ActionMapping mapping, ActionForm actForm, HttpServletRequest request, HttpServletResponse response) {/*from www. jav a 2 s . co m*/ LOG.debug("getResultData"); List<String> errors = new ArrayList<String>(); try { List<AutoProcessingInformation> autoProcList = new ArrayList<AutoProcessingInformation>(); BreadCrumbsForm bar = BreadCrumbsForm.getIt(request); boolean displayOutputParam = false; boolean displayDenzoContent = false; // booleans to fix which tab will be selected by default boolean isEDNACharacterisation = false; boolean isAutoprocessing = false; String rMerge = (String) request.getSession().getAttribute(Constants.RSYMM); String iSigma = (String) request.getSession().getAttribute(Constants.ISIGMA); double rMerge_d = DEFAULT_RMERGE; double iSigma_d = DEFAULT_ISIGMA; int nbRemoved = 0; try { if (rMerge != null && !rMerge.equals("undefined") && !rMerge.equals("")) rMerge_d = Double.parseDouble(rMerge); if (iSigma != null && !iSigma.equals("undefined") && !iSigma.equals("")) iSigma_d = Double.parseDouble(iSigma); } catch (NumberFormatException nfe) { nfe.printStackTrace(); } Integer dataCollectionId = null; List<List<AutoProcStatus3VO>> interruptedAutoProcEvents1 = new ArrayList<List<AutoProcStatus3VO>>(); DataCollection3VO dc = null; // Just one of them could be visible on the bar if (bar.getSelectedDataCollection() != null) { dataCollectionId = bar.getSelectedDataCollection().getDataCollectionId(); } if (dataCollectionId == null && request.getParameter(Constants.DATA_COLLECTION_ID) != null) dataCollectionId = new Integer(request.getParameter(Constants.DATA_COLLECTION_ID)); if (dataCollectionId == null && request.getSession().getAttribute(Constants.DATA_COLLECTION_ID) != null) dataCollectionId = new Integer( (Integer) request.getSession().getAttribute(Constants.DATA_COLLECTION_ID)); if (dataCollectionId == null) { errors.add("dataCollectionId is null"); HashMap<String, Object> data = new HashMap<String, Object>(); data.put("errors", errors); // data => Gson GSonUtils.sendToJs(response, data, "dd-MM-yyyy HH:mm:ss"); return; } dc = dataCollectionService.findByPk(dataCollectionId, false, true); // interrupted autoProc if (dc != null) { List<AutoProcIntegration3VO> autoProcIntegrationList = dc.getAutoProcIntegrationsList(); if (autoProcIntegrationList != null) { for (Iterator<AutoProcIntegration3VO> au = autoProcIntegrationList.iterator(); au.hasNext();) { AutoProcIntegration3VO autoProcIntegration = au.next(); if (autoProcIntegration.getAutoProcProgramVO() == null && autoProcIntegration.getAutoProcStatusList() != null) { List<AutoProcStatus3VO> events = autoProcIntegration.getAutoProcStatusList(); interruptedAutoProcEvents1.add(events); } } } } for (int i = 0; i < 2; i++) { boolean anomalous = (i > 0); List<AutoProc3VO> autoProcsAnomalous = apService .findByAnomalousDataCollectionIdAndOrderBySpaceGroupNumber(dataCollectionId, anomalous); if (autoProcsAnomalous != null) { nbRemoved = 0; LOG.debug("..nbAutoProc " + anomalous + " found before rMerge =" + autoProcsAnomalous.size()); for (Iterator<AutoProc3VO> a = autoProcsAnomalous.iterator(); a.hasNext();) { AutoProc3VO apv = a.next(); List<AutoProcScalingStatistics3VO> scalingStatistics = apssService .findByAutoProcId(apv.getAutoProcId(), "innerShell"); boolean existsUnderRmergeAndOverSigma = false; for (Iterator<AutoProcScalingStatistics3VO> j = scalingStatistics.iterator(); j .hasNext();) { AutoProcScalingStatistics3VO stats = j.next(); if (stats.getRmerge() != null && stats.getRmerge() < rMerge_d && stats.getMeanIoverSigI() > iSigma_d) existsUnderRmergeAndOverSigma = true; } if (!existsUnderRmergeAndOverSigma) { a.remove(); nbRemoved = nbRemoved + 1; } } LOG.debug("..nbAutoProc " + anomalous + " found=" + autoProcsAnomalous.size()); for (Iterator<AutoProc3VO> iterator = autoProcsAnomalous.iterator(); iterator.hasNext();) { AutoProc3VO o = iterator.next(); String cmdLine = ""; if (o.getAutoProcProgramVO() != null && o.getAutoProcProgramVO().getProcessingPrograms() != null) { cmdLine = o.getAutoProcProgramVO().getProcessingPrograms(); } float refinedCellA = ((float) ((int) (o.getRefinedCellA() * 10))) / 10; // round to 1 dp float refinedCellB = ((float) ((int) (o.getRefinedCellB() * 10))) / 10; // round to 1 dp float refinedCellC = ((float) ((int) (o.getRefinedCellC() * 10))) / 10; // round to 1 dp float refinedCellAlpha = ((float) ((int) (o.getRefinedCellAlpha() * 10))) / 10; // round to 1 dp float refinedCellBeta = ((float) ((int) (o.getRefinedCellBeta() * 10))) / 10; // round to 1 dp float refinedCellGamma = ((float) ((int) (o.getRefinedCellGamma() * 10))) / 10; // round to 1 dp String anoTxt = "OFF (Friedel pairs merged)"; // false if (anomalous) { anoTxt = "ON (Friedel pairs unmerged)"; // true } // String anomalousS = anomalous+"= "+anoTxt; AutoProcessingInformation info = new AutoProcessingInformation(o.getAutoProcId(), cmdLine, o.getSpaceGroup(), anoTxt, refinedCellA, refinedCellB, refinedCellC, refinedCellAlpha, refinedCellBeta, refinedCellGamma); autoProcList.add(info); } } } Integer autoProcIdSelected = (Integer) request.getSession().getAttribute("lastAutoProcIdSelected"); // check if autoProcIdSelected is in the list boolean idExists = false; if (autoProcIdSelected != null) { for (Iterator<AutoProcessingInformation> iterator = autoProcList.iterator(); iterator.hasNext();) { AutoProcessingInformation info = iterator.next(); if (info.getAutoProcId().equals(autoProcIdSelected)) { idExists = true; break; } } } if (!idExists) { autoProcIdSelected = null; } List<DataCollection3VO> listLastCollectVO = new ArrayList<DataCollection3VO>(); if (dc != null) listLastCollectVO.add(dc); AutoProcShellWrapper wrapper = ViewDataCollectionAction.getAutoProcStatistics(listLastCollectVO, rMerge_d, iSigma_d); int dcIndex = 0; // is autoproc ? List<AutoProc3VO> autoProcs = apService.findByDataCollectionId(dataCollectionId); if (autoProcs != null && autoProcs.size() > 0) isAutoprocessing = true; String beamLineName = ""; String proposal = ""; String proteinAcronym = ""; String pdbFileName = ""; String experimentType = ""; if (dc != null) { beamLineName = dc.getDataCollectionGroupVO().getSessionVO().getBeamlineName(); proposal = dc.getDataCollectionGroupVO().getSessionVO().getProposalVO().getCode() + dc.getDataCollectionGroupVO().getSessionVO().getProposalVO().getNumber(); BLSample3VO sample = dc.getDataCollectionGroupVO().getBlSampleVO(); if (sample != null && sample.getCrystalVO() != null && sample.getCrystalVO().getProteinVO() != null) proteinAcronym = sample.getCrystalVO().getProteinVO().getAcronym(); if (sample != null && sample.getCrystalVO() != null && sample.getCrystalVO().hasPdbFile()) { pdbFileName = sample.getCrystalVO().getPdbFileName(); } experimentType = dc.getDataCollectionGroupVO().getExperimentType(); } AutoProc3VO autoProc = null; AutoProcScalingStatistics3VO autoProcStatisticsOverall = null; AutoProcScalingStatistics3VO autoProcStatisticsInner = null; AutoProcScalingStatistics3VO autoProcStatisticsOuter = null; ScreeningOutputLattice3VO lattice = null; ScreeningOutput3VO screeningOutput = null; String snapshotFullPath = ""; boolean hasSnapshot = false; Screening3VO[] tabScreening = null; if (dc != null) { snapshotFullPath = dc.getXtalSnapshotFullPath1(); snapshotFullPath = PathUtils.FitPathToOS(snapshotFullPath); if (snapshotFullPath != null) hasSnapshot = (new File(snapshotFullPath)).exists(); autoProc = wrapper.getAutoProcs()[dcIndex]; autoProcStatisticsOverall = wrapper.getScalingStatsOverall()[dcIndex]; autoProcStatisticsInner = wrapper.getScalingStatsInner()[dcIndex]; autoProcStatisticsOuter = wrapper.getScalingStatsOuter()[dcIndex]; DataCollectionGroup3VO dcGroup = dataCollectionGroupService .findByPk(dc.getDataCollectionGroupVOId(), false, true); tabScreening = dcGroup.getScreeningsTab(); } if (tabScreening != null && tabScreening.length > 0) { displayOutputParam = true;// there is at least 1 screening so we display the output params Screening3VO screeningVO = tabScreening[0]; ScreeningOutput3VO[] screeningOutputTab = screeningVO.getScreeningOutputsTab(); if (screeningOutputTab != null && screeningOutputTab.length > 0) { if (screeningOutputTab[0].getScreeningOutputLatticesTab() != null && screeningOutputTab[0].getScreeningOutputLatticesTab().length > 0) { lattice = screeningOutputTab[0].getScreeningOutputLatticesTab()[0]; } screeningOutput = screeningOutputTab[0]; } } String autoprocessingStatus = ""; String autoprocessingStep = ""; if (wrapper != null && wrapper.getAutoProcs() != null && wrapper.getAutoProcs().length > dcIndex) { AutoProcIntegration3VO autoProcIntegration = wrapper.getAutoProcIntegrations()[dcIndex]; if (autoProcIntegration != null) { List<AutoProcStatus3VO> autoProcEvents = autoProcIntegration.getAutoProcStatusList(); if (autoProcEvents != null && autoProcEvents.size() > 0) { AutoProcStatus3VO st = autoProcEvents.get(autoProcEvents.size() - 1); autoprocessingStatus = st.getStatus(); autoprocessingStep = st.getStep(); } } } boolean hasAutoProcAttachment = false; if (wrapper != null && wrapper.getAutoProcs() != null) { for (int a = 0; a < autoProcs.size(); a++) { Integer autoProcProgramId = autoProcs.get(a).getAutoProcProgramVOId(); if (autoProcProgramId != null) { List<AutoProcProgramAttachment3VO> attachments = appService .findByPk(autoProcProgramId, true).getAttachmentListVOs(); if (attachments != null && attachments.size() > 0) { hasAutoProcAttachment = true; break; } } } } DataCollectionBean dataCollection = null; if (dc != null) { dataCollection = new DataCollectionBean(dc, beamLineName, proposal, proteinAcronym, pdbFileName, experimentType, hasSnapshot, autoProc, autoProcStatisticsOverall, autoProcStatisticsInner, autoProcStatisticsOuter, screeningOutput, lattice, autoprocessingStatus, autoprocessingStep, hasAutoProcAttachment); } BeamLineSetup3VO beamline = null; Session3VO session = null; Detector3VO detector = null; String fullDenzoPath = null; boolean DenzonContentPresent = false; if (dc != null) { // beamline setup beamline = dc.getDataCollectionGroupVO().getSessionVO().getBeamLineSetupVO(); // Session session = dc.getDataCollectionGroupVO().getSessionVO(); // Detector detector = dc.getDetectorVO(); // energy DecimalFormat df3 = (DecimalFormat) NumberFormat.getInstance(Locale.US); df3.applyPattern("#####0.000"); Double energy = null; if (dc.getWavelength() != null && dc.getWavelength().compareTo(new Double(0)) != 0) energy = Constants.WAVELENGTH_TO_ENERGY_CONSTANT / dc.getWavelength(); if (energy != null) dataCollection.setEnergy(new Double(df3.format(energy))); else dataCollection.setEnergy(null); // axis start label String axisStartLabel = dc.getRotationAxis() == null ? "" : dc.getRotationAxis() + " start"; dataCollection.setAxisStartLabel(axisStartLabel); // totalExposureTime if (dc.getExposureTime() != null && dc.getNumberOfImages() != null) { dataCollection.setTotalExposureTime( new Double(df3.format(dataCollection.getExposureTime() * dc.getNumberOfImages()))); } // kappa Double kappa = dc.getKappaStart(); String kappaStr = ""; if (kappa == null || kappa.equals(Constants.SILLY_NUMBER)) kappaStr = new String("0"); else kappaStr = new String(kappa.toString()); dataCollection.setKappa(kappaStr); // phi Double phi = dc.getPhiStart(); String phiStr = ""; if (phi == null || phi.equals(Constants.SILLY_NUMBER)) phiStr = new String("0"); else phiStr = new String(phi.toString()); dataCollection.setPhi(phiStr); // undulatorGaps DecimalFormat df2 = (DecimalFormat) NumberFormat.getInstance(Locale.US); // DecimalFormat df2 = new DecimalFormat("##0.##"); df2.applyPattern("##0.##"); StringBuffer buf = new StringBuffer(); // if no type then there is no meaningful value // if no undulator 1 then no 2 and no 3 if (beamline.getUndulatorType1() != null && beamline.getUndulatorType1().length() > 0) { if (dc.getUndulatorGap1() != null && !dc.getUndulatorGap1().equals(Constants.SILLY_NUMBER)) { Double gap1 = new Double(df2.format(dc.getUndulatorGap1())); buf.append(gap1.toString()).append(" mm "); } if (beamline.getUndulatorType2() != null && beamline.getUndulatorType2().length() > 0) { if (dc.getUndulatorGap2() != null && !dc.getUndulatorGap2().equals(Constants.SILLY_NUMBER)) { Double gap2 = new Double(df2.format(dc.getUndulatorGap2())); buf.append(gap2.toString()).append(" mm "); } if (beamline.getUndulatorType3() != null && beamline.getUndulatorType3().length() > 0) { if (dc.getUndulatorGap3() != null && !dc.getUndulatorGap3().equals(Constants.SILLY_NUMBER)) { Double gap3 = new Double(df2.format(dc.getUndulatorGap3())); buf.append(gap3.toString()).append(" mm "); } } } } String undulatorGaps = buf.toString(); dataCollection.setUndulatorGaps(undulatorGaps); DecimalFormat nf1 = (DecimalFormat) NumberFormat.getInstance(Locale.UK); nf1.applyPattern("#"); DecimalFormat df5 = (DecimalFormat) NumberFormat.getInstance(Locale.US); df5.applyPattern("#####0.00000"); // slitGapHorizontalMicro Integer slitGapHorizontalMicro = null; if (dc.getSlitGapHorizontal() != null) { // in DB beamsize unit is mm, display is in micrometer => conversion slitGapHorizontalMicro = new Integer( nf1.format(dc.getSlitGapHorizontal().doubleValue() * 1000)); } dataCollection.setSlitGapHorizontalMicro(slitGapHorizontalMicro); // slitGapVerticalMicro Integer slitGapVerticalMicro = null; if (dc.getSlitGapVertical() != null) { // in DB beamsize unit is mm, display is in micrometer => conversion slitGapVerticalMicro = new Integer(nf1.format(dc.getSlitGapVertical().doubleValue() * 1000)); } dataCollection.setSlitGapVerticalMicro(slitGapVerticalMicro); // detectorPixelSizeHorizontalMicro Double detectorPixelSizeHorizontalMicro = null; if (detector != null && detector.getDetectorPixelSizeHorizontal() != null) { // in DB pixel size unit is mm, detectorPixelSizeHorizontalMicro = new Double( df5.format(detector.getDetectorPixelSizeHorizontal())); } dataCollection.setDetectorPixelSizeHorizontalMicro(detectorPixelSizeHorizontalMicro); // detectorPixelSizeHorizontalMicro Double detectorPixelSizeVerticalMicro = null; if (detector != null && detector.getDetectorPixelSizeVertical() != null) { // in DB pixel size unit is mm, detectorPixelSizeVerticalMicro = new Double( df5.format(detector.getDetectorPixelSizeVertical())); } dataCollection.setDetectorPixelSizeVerticalMicro(detectorPixelSizeVerticalMicro); // beamSizeAtSampleXMicro Integer beamSizeAtSampleXMicro = null; if (dc.getBeamSizeAtSampleX() != null) { // in DB beamsize unit is mm, display is in micrometer => conversion beamSizeAtSampleXMicro = new Integer( nf1.format(dc.getBeamSizeAtSampleX().doubleValue() * 1000)); } dataCollection.setBeamSizeAtSampleXMicro(beamSizeAtSampleXMicro); // beamSizeAtSampleYMicro Integer beamSizeAtSampleYMicro = null; if (dc.getBeamSizeAtSampleY() != null) { // in DB beamsize unit is mm, display is in micrometer => conversion beamSizeAtSampleYMicro = new Integer( nf1.format(dc.getBeamSizeAtSampleY().doubleValue() * 1000)); } dataCollection.setBeamSizeAtSampleYMicro(beamSizeAtSampleYMicro); // beamDivergenceHorizontalInt Integer beamDivergenceHorizontalInt = null; if (beamline.getBeamDivergenceHorizontal() != null) { beamDivergenceHorizontalInt = new Integer(nf1.format(beamline.getBeamDivergenceHorizontal())); } dataCollection.setBeamDivergenceHorizontalInt(beamDivergenceHorizontalInt); // beamDivergenceVerticalInt Integer beamDivergenceVerticalInt = null; if (beamline.getBeamDivergenceVertical() != null) { beamDivergenceVerticalInt = new Integer(nf1.format(beamline.getBeamDivergenceVertical())); } dataCollection.setBeamDivergenceVerticalInt(beamDivergenceVerticalInt); // DNA or EDNA Content present ? String fullDNAPath = PathUtils.getFullDNAPath(dc); String fullEDNAPath = PathUtils.getFullEDNAPath(dc); boolean EDNAContentPresent = (new File(fullEDNAPath + EDNA_FILES_INDEX_FILE)).exists() || (new File(fullDNAPath + Constants.DNA_FILES_INDEX_FILE)).exists(); isEDNACharacterisation = EDNAContentPresent; // Denzo Content present ? if (Constants.DENZO_ENABLED) { fullDenzoPath = FileUtil.GetFullDenzoPath(dc); DenzonContentPresent = (new File(fullDenzoPath)).exists(); displayDenzoContent = DisplayDenzoContent(dc); if (DenzonContentPresent) // Check html file present { File denzoIndex = new File(fullDenzoPath + DENZO_HTML_INDEX); if (!denzoIndex.exists()) { errors.add("Denzo File does not exist " + denzoIndex); DenzonContentPresent = false; } } } } // HashMap<String, Object> data = new HashMap<String, Object>(); // context path data.put("contextPath", request.getContextPath()); // autoProcList data.put("autoProcList", autoProcList); // autoProcIdSelected data.put("autoProcIdSelected", autoProcIdSelected); // rMerge & iSigma data.put("rMerge", rMerge); data.put("iSigma", iSigma); data.put("nbRemoved", nbRemoved); data.put("dataCollectionId", dataCollectionId); data.put("dataCollection", dataCollection); // beamlinesetup data.put("beamline", beamline); // session data.put("session", session); // detector data.put("detector", detector); // interrupted autoProc data.put("interruptedAutoProcEvents", interruptedAutoProcEvents1); // displayOutputParam data.put("displayOutputParam", displayOutputParam); // isEDNACharacterisation data.put("isEDNACharacterisation", isEDNACharacterisation); // isAutoprocessing data.put("isAutoprocessing", isAutoprocessing); // displayDenzoContent data.put("displayDenzoContent", displayDenzoContent); // DenzonContentPresent data.put("DenzonContentPresent", DenzonContentPresent); // fullDenzoPath data.put("fullDenzoPath", fullDenzoPath); // data => Gson GSonUtils.sendToJs(response, data, "dd-MM-yyyy HH:mm:ss"); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.mifos.application.servicefacade.LoanAccountServiceFacadeWebTier.java
@Override public Errors validateCashFlowForInstallments(LoanInstallmentsDto loanInstallmentsDto, List<MonthlyCashFlowDto> monthlyCashFlows, Double repaymentCapacity, BigDecimal cashFlowTotalBalance) { Errors errors = new Errors(); if (CollectionUtils.isNotEmpty(monthlyCashFlows)) { boolean lowerBound = DateUtils.firstLessOrEqualSecond(monthlyCashFlows.get(0).getMonthDate().toDate(), loanInstallmentsDto.getFirstInstallmentDueDate()); boolean upperBound = DateUtils.firstLessOrEqualSecond(loanInstallmentsDto.getLastInstallmentDueDate(), monthlyCashFlows.get(monthlyCashFlows.size() - 1).getMonthDate().toDate()); SimpleDateFormat df = new SimpleDateFormat("MMMM yyyy", Locale.UK); if (!lowerBound) { errors.addError(AccountConstants.INSTALLMENT_BEYOND_CASHFLOW_DATE, new String[] { df.format(loanInstallmentsDto.getFirstInstallmentDueDate()) }); }/*from w ww .ja v a 2 s . com*/ if (!upperBound) { errors.addError(AccountConstants.INSTALLMENT_BEYOND_CASHFLOW_DATE, new String[] { df.format(loanInstallmentsDto.getLastInstallmentDueDate()) }); } } validateForRepaymentCapacity(loanInstallmentsDto.getTotalInstallmentAmount(), loanInstallmentsDto.getLoanAmount(), repaymentCapacity, errors, cashFlowTotalBalance); return errors; }