List of usage examples for java.time.format DateTimeFormatter ofPattern
public static DateTimeFormatter ofPattern(String pattern)
From source file:squash.booking.lambdas.core.RuleManagerTest.java
@Test public void testCreateNonrecurringRuleHappyPathReturnsCorrectBookingRules() throws Exception { // ARRANGE/*from w w w . j a v a2s. c o m*/ // Set up a rule to create that does not clash with existing rules BookingRule nonClashingRule = new BookingRule(existingThursdayNonRecurringRule); // Change day-of-week so it no longer clashes String existingDate = nonClashingRule.getBooking().getDate(); String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusDays(1) .format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); nonClashingRule.getBooking().setDate(newDate); // Wednesday Set<BookingRule> returnedBookingRules = doTestCreateRuleClashesOrNotWithExistingRule(nonClashingRule, false); Set<BookingRule> expectedBookingRules = new HashSet<>(); expectedBookingRules.addAll(existingBookingRules); expectedBookingRules.add(nonClashingRule); assertEquals("Unexpected booking rules returned by createRule", returnedBookingRules, expectedBookingRules); }
From source file:com.mycompany.trafficimportfileconverter2.Main2Controller.java
public static String toWideOrbitTitle(LocalDate ld) { return ld.format(DateTimeFormatter.ofPattern("yyMMdd")); }
From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java
@Override public HttpAccess getHttpAccess() { return (req, res, ref, copyrightAcceptedRefs) -> { if (sessionManager.getCurrentSessionUserId() == null) { log.warn("Only logged in users can access assignment downloads"); } else {//from w w w .j a v a 2s . c o m // determine the type of download to create using the reference that was requested AssignmentReferenceReckoner.AssignmentReference refReckoner = AssignmentReferenceReckoner.reckoner() .reference(ref.getReference()).reckon(); if (REFERENCE_ROOT.equals("/" + refReckoner.getType())) { // don't process any references that are not of type assignment switch (refReckoner.getSubtype()) { case REF_TYPE_CONTENT: case REF_TYPE_ASSIGNMENT: String date = DateTimeFormatter.ofPattern("yyyyMMddHHmmss") .withZone(userTimeService.getLocalTimeZone().toZoneId()) .format(ZonedDateTime.now()); String queryString = req.getQueryString(); if (StringUtils.isNotBlank(refReckoner.getId())) { // if subtype is assignment then were downloading all submissions for an assignment try { Assignment a = getAssignment(refReckoner.getId()); String filename = a.getTitle() + "_" + date; res.setContentType("application/zip"); res.setHeader("Content-Disposition", "attachment; filename = \"" + filename + ".zip\""); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { try (OutputStream out = res.getOutputStream()) { getSubmissionsZip(out, ref.getReference(), queryString); } catch (Exception e) { log.warn("Could not stream the submissions for reference: {}", ref.getReference(), e); } } }); } catch (Exception e) { log.warn("Could not find assignment for ref = {}", ref.getReference(), e); } } else { String filename = "bulk_download_" + date; // if subtype is assignment and there is no assignmentId then were downloading grades res.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); res.setHeader("Content-Disposition", "attachment; filename = \"export_grades_" + filename + ".xlsx\""); try (OutputStream out = res.getOutputStream()) { gradeSheetExporter.getGradesSpreadsheet(out, ref.getReference(), queryString); } catch (Exception e) { log.warn("Could not stream the grades for reference: {}", ref.getReference(), e); } } break; case REF_TYPE_SUBMISSION: default: log.warn("Assignments download unhandled download type for reference: {}", ref.getReference()); } } } }; }
From source file:squash.booking.lambdas.core.RuleManagerTest.java
@Test public void testCreateRuleThrowsWhenNewRuleClashesWithExistingRules_ExistingNonRecurringNewRecurringSameDayOfWeekOverlappingNoExclusion() throws Exception { // If the new rule is recurring and there are any overlapping, non-recurring // existing rules after the new rule starts, then we have a clash, unless // the new rule has a relevant exclusion. // ARRANGE/* w ww. ja v a 2s . c om*/ thrown.expect(Exception.class); thrown.expectMessage("Booking rule creation failed"); // Set up a rule to create that clashes in required way with existing rules BookingRule clashingThursdayRule = new BookingRule(existingThursdayNonRecurringRule); clashingThursdayRule.setIsRecurring(true); // Move date to same day-of-week but to some date earlier than the existing // non-recurring rule. String existingDate = clashingThursdayRule.getBooking().getDate(); String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusWeeks(1) .format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); clashingThursdayRule.getBooking().setDate(newDate); // ACT doTestCreateRuleClashesOrNotWithExistingRule(clashingThursdayRule, true); }
From source file:ru.anr.base.BaseParent.java
/** * @param date/*from w ww . jav a 2 s . c o m*/ * Date * @param locale * Locale * @return formatted date */ public static String formatDate(long date, String locale) { return DateTimeFormatter .ofPattern("ru_RU".equals(locale) ? "dd.MM.yyyy HH:mm:ss z" : "dd/MM/yyyy HH:mm:ss z") .withZone(ZoneOffset.systemDefault()) .format(LocalDateTime.ofInstant(Instant.ofEpochMilli(date), ZoneId.systemDefault())); }
From source file:org.cgiar.ccafs.marlo.action.center.summaries.ProjectSummaryAction.java
/** * Get the main information of the report * //from w w w . j a v a2 s . c om * @return */ private TypedTableModel getMasterTableModel() { // Initialization of Model final TypedTableModel model = new TypedTableModel( new String[] { "shortTitle", "currentDate", "projectSubmission", "imageUrl" }, new Class[] { String.class, String.class, String.class, String.class }); // Set short title String shortTitle = ""; if ((project.getName() != null) && !project.getName().isEmpty()) { shortTitle += project.getName() + " - "; } if ((loggedCenter.getAcronym() != null) && !loggedCenter.getAcronym().isEmpty()) { shortTitle += loggedCenter.getAcronym() + " - "; } shortTitle += "P" + Long.toString(projectID); // Set currentDate String currentDate = ""; // Get datetime final ZonedDateTime timezone = ZonedDateTime.now(); final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d 'at' HH:mm "); currentDate = timezone.format(format) + this.getTimeZone(); // Set projectSubmission final String projectSubmission = ""; // set CIAT imgage URL from repo String imageUrl = this.getBaseUrl() + "/global/images/centers/CIAT.png"; model.addRow(new Object[] { shortTitle, currentDate, projectSubmission, imageUrl }); return model; }
From source file:ru.anr.base.BaseParent.java
/** * @param pattern//w w w .j ava 2 s . c o m * patter * @param date * date * @return formatted date */ public static String formatDate(String pattern, Calendar date) { return DateTimeFormatter.ofPattern(pattern).format( LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTimeInMillis()), ZoneId.systemDefault())); }
From source file:squash.booking.lambdas.core.RuleManagerTest.java
@Test public void testCreateRuleDoesNotThrowWhenNewRuleDoesNotClashWithExistingRules_ExistingNonRecurringNewRecurringSameDayOfWeekOverlappingWithExclusion() throws Exception { // If the new rule is recurring and there are any overlapping, non-recurring // existing rules after the new rule starts, then we do not have a clash if // the new rule has a relevant exclusion. N.B. We allow exclusions at // creation time to support backup/restore. // ARRANGE//from w w w . j a v a 2 s .co m // Set up a rule to create that clashes in required way with existing rules BookingRule nonClashingThursdayRule = new BookingRule(existingThursdayNonRecurringRule); nonClashingThursdayRule.setIsRecurring(true); // Move date to same day-of-week but to some date earlier than the existing // non-recurring rule. String existingDate = nonClashingThursdayRule.getBooking().getDate(); String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusWeeks(1) .format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); nonClashingThursdayRule.getBooking().setDate(newDate); // Add exclusion to new rule - so it becomes non-clashing nonClashingThursdayRule .setDatesToExclude(new String[] { existingThursdayNonRecurringRule.getBooking().getDate() }); // ACT doTestCreateRuleClashesOrNotWithExistingRule(nonClashingThursdayRule, false); }
From source file:org.apache.nifi.atlas.reporting.ReportLineageToAtlas.java
private void initAtlasProperties(ConfigurationContext context) throws IOException { List<String> urls = new ArrayList<>(); parseAtlasUrls(context.getProperty(ATLAS_URLS), urls::add); final boolean isAtlasApiSecure = urls.stream().anyMatch(url -> url.toLowerCase().startsWith("https")); final String atlasAuthNMethod = context.getProperty(ATLAS_AUTHN_METHOD).getValue(); final String confDirStr = context.getProperty(ATLAS_CONF_DIR).evaluateAttributeExpressions().getValue(); final File confDir = confDirStr != null && !confDirStr.isEmpty() ? new File(confDirStr) : null; atlasProperties = new Properties(); final File atlasPropertiesFile = new File(confDir, ATLAS_PROPERTIES_FILENAME); final Boolean createAtlasConf = context.getProperty(ATLAS_CONF_CREATE).asBoolean(); if (!createAtlasConf) { // Load existing properties file. if (atlasPropertiesFile.isFile()) { getLogger().info("Loading {}", new Object[] { atlasPropertiesFile }); try (InputStream in = new FileInputStream(atlasPropertiesFile)) { atlasProperties.load(in); }//from www . ja v a 2 s. c o m } else { final String fileInClasspath = "/" + ATLAS_PROPERTIES_FILENAME; try (InputStream in = ReportLineageToAtlas.class.getResourceAsStream(fileInClasspath)) { getLogger().info("Loading {} from classpath", new Object[] { fileInClasspath }); if (in == null) { throw new ProcessException(String.format( "Could not find %s in classpath." + " Please add it to classpath," + " or specify %s a directory containing Atlas properties file," + " or enable %s to generate it.", fileInClasspath, ATLAS_CONF_DIR.getDisplayName(), ATLAS_CONF_CREATE.getDisplayName())); } atlasProperties.load(in); } } } // Resolve default cluster name. defaultClusterName = context.getProperty(ATLAS_DEFAULT_CLUSTER_NAME).evaluateAttributeExpressions() .getValue(); if (defaultClusterName == null || defaultClusterName.isEmpty()) { // If default cluster name is not specified by processor configuration, then load it from Atlas config. defaultClusterName = atlasProperties.getProperty(ATLAS_PROPERTY_CLUSTER_NAME); } // If default cluster name is still not defined, processor should not be able to start. if (defaultClusterName == null || defaultClusterName.isEmpty()) { throw new ProcessException("Default cluster name is not defined."); } atlasAuthN = getAtlasAuthN(atlasAuthNMethod); atlasAuthN.configure(context); // Create Atlas configuration file if necessary. if (createAtlasConf) { atlasProperties.put(ATLAS_PROPERTY_CLUSTER_NAME, defaultClusterName); atlasProperties.put(ATLAS_PROPERTY_ENABLE_TLS, String.valueOf(isAtlasApiSecure)); setKafkaConfig(atlasProperties, context); atlasAuthN.populateProperties(atlasProperties); try (FileOutputStream fos = new FileOutputStream(atlasPropertiesFile)) { String ts = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX").withZone(ZoneOffset.UTC) .format(Instant.now()); atlasProperties.store(fos, "Generated by Apache NiFi ReportLineageToAtlas ReportingTask at " + ts); } } getLogger().debug("Force reloading Atlas application properties."); ApplicationProperties.forceReload(); if (confDir != null) { // If atlasConfDir is not set, atlas-application.properties will be searched under classpath. Properties props = System.getProperties(); final String atlasConfProp = "atlas.conf"; props.setProperty(atlasConfProp, confDir.getAbsolutePath()); getLogger().debug("{} has been set to: {}", new Object[] { atlasConfProp, props.getProperty(atlasConfProp) }); } }
From source file:squash.booking.lambdas.core.RuleManagerTest.java
@Test public void testCreateRuleThrowsWhenNewRuleClashesWithExistingRules_ExistingNonRecurringNewRecurringSameDayOfWeekPartiallyOverlappingNoExclusion() throws Exception { // If the new rule is recurring and there are any overlapping, non-recurring // existing rules after the new rule starts, then we have a clash. N.B. This // tests where the court/time blocks overlap only partially. // ARRANGE/*w w w . j a v a2 s .c o m*/ thrown.expect(Exception.class); thrown.expectMessage("Booking rule creation failed"); // Set up a rule to create that clashes in required way with existing rules BookingRule clashingThursdayRule = new BookingRule(existingThursdayNonRecurringRule); clashingThursdayRule.setIsRecurring(true); // Move date to same day-of-week but to some date earlier than the existing // non-recurring rule. String existingDate = clashingThursdayRule.getBooking().getDate(); String newDate = LocalDate.parse(existingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).minusWeeks(1) .format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); clashingThursdayRule.getBooking().setDate(newDate); // Tweak court so that overlap is partial only clashingThursdayRule.getBooking().setCourt(clashingThursdayRule.getBooking().getCourt() + clashingThursdayRule.getBooking().getCourtSpan() - 1); // ACT doTestCreateRuleClashesOrNotWithExistingRule(clashingThursdayRule, true); }