List of usage examples for java.time Instant isAfter
public boolean isAfter(Instant otherInstant)
From source file:nl.knaw.huygens.alexandria.dropwizard.cli.commands.AlexandriaCommand.java
private void putFileStatus(Path workDir, Path filePath, Multimap<FileStatus, String> fileStatusMap, CLIContext context, Set<String> watchedFiles) { String file = workDir.relativize(filePath).toString().replace("\\", "/"); if (watchedFiles.contains(file)) { Instant lastCommit = context.getWatchedFiles().get(file).getLastCommit(); try {/*from www . j a v a 2 s. c om*/ Instant lastModified = Files.getLastModifiedTime(filePath).toInstant(); FileStatus fileStatus = lastModified.isAfter(lastCommit) ? FileStatus.changed : FileStatus.unchanged; fileStatusMap.put(fileStatus, file); } catch (IOException e) { throw new RuntimeException(e); } watchedFiles.remove(file); } else { fileStatusMap.put(FileStatus.created, file); } }
From source file:org.fcrepo.integration.http.api.FedoraLdpIT.java
License:asdf
@Test public void testBinaryLastModified() throws Exception { final String objid = getRandomUniqueId(); final String objURI = serverAddress + objid; final String binURI = objURI + "/binary1"; final Instant lastmod1; try (final CloseableHttpResponse response = execute(putDSMethod(objid, "binary1", "some test content"))) { assertEquals(CREATED.getStatusCode(), getStatus(response)); lastmod1 = Instant.from(headerFormat.parse(response.getFirstHeader("Last-Modified").getValue())); }/* ww w .ja va2 s. c o m*/ sleep(1000); // wait a second to make sure last-modified value will be different try (final CloseableDataset dataset = getDataset(new HttpGet(binURI + "/fcr:metadata"))) { verifyModifiedMatchesCreated(dataset); } final HttpPatch patchBinary = new HttpPatch(binURI + "/fcr:metadata"); patchBinary.addHeader(CONTENT_TYPE, "application/sparql-update"); patchBinary.setEntity(new StringEntity("INSERT { <" + binURI + "> " + "<http://www.w3.org/TR/rdf-schema/label> \"this is a label\" } WHERE {}")); final Instant lastmod2; try (final CloseableHttpResponse response = execute(patchBinary)) { assertEquals(NO_CONTENT.getStatusCode(), getStatus(response)); lastmod2 = Instant.from(headerFormat.parse(response.getFirstHeader("Last-Modified").getValue())); assertTrue(lastmod2.isAfter(lastmod1)); } sleep(1000); // wait a second to make sure last-modified value will be different final Instant lastmod3; try (final CloseableHttpResponse response = execute(putDSMethod(objid, "binary1", "new test content"))) { assertEquals(NO_CONTENT.getStatusCode(), getStatus(response)); lastmod3 = Instant.from(headerFormat.parse(response.getFirstHeader("Last-Modified").getValue())); assertTrue(lastmod3.isAfter(lastmod2)); } }
From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java
@Override @Transactional//from w w w. ja v a2s . co m public void updateSubmission(AssignmentSubmission submission) throws PermissionException { Assert.notNull(submission, "Submission cannot be null"); Assert.notNull(submission.getId(), "Submission doesn't appear to have been persisted yet"); String reference = AssignmentReferenceReckoner.reckoner().submission(submission).reckon().getReference(); if (!allowUpdateSubmission(reference)) { throw new PermissionException(sessionManager.getCurrentSessionUserId(), SECURE_UPDATE_ASSIGNMENT_SUBMISSION, null); } eventTrackingService.post(eventTrackingService .newEvent(AssignmentConstants.EVENT_UPDATE_ASSIGNMENT_SUBMISSION, reference, true)); assignmentRepository.updateSubmission(submission); // Assignment Submission Notifications Instant dateReturned = submission.getDateReturned(); Instant dateSubmitted = submission.getDateSubmitted(); if (!submission.getSubmitted()) { // if the submission is not submitted then saving a submission event eventTrackingService.post(eventTrackingService .newEvent(AssignmentConstants.EVENT_SAVE_ASSIGNMENT_SUBMISSION, reference, true)); } else if (dateReturned == null && !submission.getReturned() && (dateSubmitted == null || submission.getDateModified().toEpochMilli() - dateSubmitted.toEpochMilli() > 1000 * 60)) { // make sure the last modified time is at least one minute after the submit time if (!(StringUtils.trimToNull(submission.getSubmittedText()) == null && submission.getAttachments().isEmpty() && StringUtils.trimToNull(submission.getGrade()) == null && StringUtils.trimToNull(submission.getFeedbackText()) == null && StringUtils.trimToNull(submission.getFeedbackComment()) == null && submission.getFeedbackAttachments().isEmpty())) { if (submission.getGraded()) { //TODO: This should use an LRS_Group when that exists rather than firing off individual events for each LRS_Actor KNL-1560 for (AssignmentSubmissionSubmitter submitter : submission.getSubmitters()) { try { User user = userDirectoryService.getUser(submitter.getSubmitter()); LRS_Statement statement = getStatementForAssignmentGraded(reference, submission.getAssignment(), submission, user); // graded and saved before releasing it Event event = eventTrackingService.newEvent( AssignmentConstants.EVENT_GRADE_ASSIGNMENT_SUBMISSION, reference, null, true, NotificationService.NOTI_OPTIONAL, statement); eventTrackingService.post(event); } catch (UserNotDefinedException e) { log.warn("Assignments could not find user ({}) while registering Event for LRSS", submitter.getSubmitter()); } } } } } else if (dateReturned != null && submission.getGraded() && (dateSubmitted == null || dateReturned.isAfter(dateSubmitted) || dateSubmitted.isAfter(dateReturned) && submission.getDateModified().isAfter(dateSubmitted))) { if (submission.getGraded()) { //TODO: This should use an LRS_Group when that exists rather than firing off individual events for each LRS_Actor KNL-1560 for (AssignmentSubmissionSubmitter submitter : submission.getSubmitters()) { try { User user = userDirectoryService.getUser(submitter.getSubmitter()); LRS_Statement statement = getStatementForAssignmentGraded(reference, submission.getAssignment(), submission, user); // releasing a submitted assignment or releasing grade to an unsubmitted assignment Event event = eventTrackingService.newEvent( AssignmentConstants.EVENT_GRADE_ASSIGNMENT_SUBMISSION, reference, null, true, NotificationService.NOTI_OPTIONAL, statement); eventTrackingService.post(event); } catch (UserNotDefinedException e) { log.warn("Assignments could not find user ({}) while registering Event for LRSS", submitter.getSubmitter()); } } } // if this is releasing grade, depending on the release grade notification setting, send email notification to student sendGradeReleaseNotification(submission); } else if (dateSubmitted == null) { //TODO: This should use an LRS_Group when that exists rather than firing off individual events for each LRS_Actor KNL-1560 for (AssignmentSubmissionSubmitter submitter : submission.getSubmitters()) { try { User user = userDirectoryService.getUser(submitter.getSubmitter()); LRS_Statement statement = getStatementForUnsubmittedAssignmentGraded(reference, submission.getAssignment(), submission, user); // releasing a submitted assignment or releasing grade to an unsubmitted assignment Event event = eventTrackingService.newEvent( AssignmentConstants.EVENT_GRADE_ASSIGNMENT_SUBMISSION, reference, null, true, NotificationService.NOTI_OPTIONAL, statement); eventTrackingService.post(event); } catch (UserNotDefinedException e) { log.warn("Assignments could not find user ({}) while registering Event for LRSS", submitter.getSubmitter()); } } } else { // submitting a submission Assignment a = submission.getAssignment(); LRS_Statement statement = getStatementForSubmitAssignment(a.getId(), serverConfigurationService.getAccessUrl(), a.getTitle()); eventTrackingService .post(eventTrackingService.newEvent(AssignmentConstants.EVENT_SUBMIT_ASSIGNMENT_SUBMISSION, reference, null, true, NotificationService.NOTI_OPTIONAL, statement)); // only doing the notification for real online submissions if (submission.getAssignment() .getTypeOfSubmission() != Assignment.SubmissionType.NON_ELECTRONIC_ASSIGNMENT_SUBMISSION) { // instructor notification notificationToInstructors(submission, submission.getAssignment()); // student notification, whether the student gets email notification once he submits an assignment notificationToStudent(submission); } } }
From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java
@Override public String getSubmissionStatus(String submissionId) { String status = ""; AssignmentSubmission submission;//from ww w . j av a 2s.c o m try { submission = getSubmission(submissionId); } catch (PermissionException e) { log.warn("Could not get submission with id {}, {}", submissionId, e.getMessage()); return status; } Assignment assignment = submission.getAssignment(); String assignmentReference = AssignmentReferenceReckoner.reckoner().assignment(assignment).reckon() .getReference(); boolean allowGrade = assignment != null && allowGradeSubmission(assignmentReference); Instant submitTime = submission.getDateSubmitted(); Instant returnTime = submission.getDateReturned(); Instant lastModTime = submission.getDateModified(); if (submission.getSubmitted() || (!submission.getSubmitted() && allowGrade)) { if (submitTime != null) { if (submission.getReturned()) { if (returnTime != null && returnTime.isBefore(submitTime)) { if (!submission.getGraded()) { status = resourceLoader.getString("gen.resub") + " " + getUsersLocalDateTimeString(submitTime); if (submitTime.isAfter(assignment.getDueDate())) { status = status + resourceLoader.getString("gen.late2"); } } else status = resourceLoader.getString("gen.returned"); } else status = resourceLoader.getString("gen.returned"); } else if (submission.getGraded() && allowGrade) { status = StringUtils.isNotBlank(submission.getGrade()) ? resourceLoader.getString("grad3") : resourceLoader.getString("gen.commented"); } else { if (allowGrade) { // ungraded submission status = resourceLoader.getString("ungra"); } else { status = resourceLoader.getString("gen.subm4") + " " + getUsersLocalDateTimeString(submitTime); } } } else { if (submission.getReturned()) { // instructor can return grading to non-submitted user status = resourceLoader.getString("gen.returned"); } else if (submission.getGraded() && allowGrade) { // instructor can grade non-submitted ones status = StringUtils.isNotBlank(submission.getGrade()) ? resourceLoader.getString("grad3") : resourceLoader.getString("gen.commented"); } else { if (allowGrade) { // show "no submission" to graders status = resourceLoader.getString("listsub.nosub"); } else { if (assignment.getHonorPledge() && submission.getHonorPledge()) { status = resourceLoader.getString("gen.hpsta"); } else { // show "not started" to students status = resourceLoader.getString("gen.notsta"); } } } } } else { if (submission.getGraded()) { if (submission.getReturned()) { // modified time is after returned time + 10 seconds if (lastModTime != null && returnTime != null && lastModTime.isAfter(returnTime.plusSeconds(10)) && !allowGrade) { // working on a returned submission now status = resourceLoader.getString("gen.dra2") + " " + resourceLoader.getString("gen.inpro"); } else { // not submitted submmission has been graded and returned status = resourceLoader.getString("gen.returned"); } } else if (allowGrade) { // grade saved but not release yet, show this to graders status = StringUtils.isNotBlank(submission.getGrade()) ? resourceLoader.getString("grad3") : resourceLoader.getString("gen.commented"); } else { // submission saved, not submitted. status = resourceLoader.getString("gen.dra2") + " " + resourceLoader.getString("gen.inpro"); } } else { if (allowGrade) status = resourceLoader.getString("ungra"); else { // TODO add a submission state of draft so we can eliminate the date check here if (assignment.getHonorPledge() && submission.getHonorPledge() && submission.getDateCreated().equals(submission.getDateModified())) { status = resourceLoader.getString("gen.hpsta"); } else { // submission saved, not submitted, status = resourceLoader.getString("gen.dra2") + " " + resourceLoader.getString("gen.inpro"); } } } } return status; }
From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java
@Override public boolean canSubmit(Assignment a, String userId) { if (a == null) return false; // submissions are never allowed to non-electronic assignments if (a.getTypeOfSubmission() == Assignment.SubmissionType.NON_ELECTRONIC_ASSIGNMENT_SUBMISSION) { return false; }//www .j av a2 s . co m // return false only if the user is not allowed to submit and not allowed to add to the assignment if (!allowAddSubmissionCheckGroups(a) && !allowAddAssignment(a.getContext())) return false; //If userId is not defined look it up if (userId == null) { userId = sessionManager.getCurrentSessionUserId(); } try { // if user the user can access this assignment checkAssignmentAccessibleForUser(a, userId); // get user User u = userDirectoryService.getUser(userId); Instant currentTime = Instant.now(); // return false if the assignment is draft or is not open yet Instant openTime = a.getOpenDate(); if (a.getDraft() || openTime.isAfter(currentTime)) { return false; } // whether the current time is after the assignment close date inclusive boolean isBeforeAssignmentCloseDate = !currentTime.isAfter(a.getCloseDate()); // get user's submission AssignmentSubmission submission = getSubmission( AssignmentReferenceReckoner.reckoner().assignment(a).reckon().getId(), u); if (submission != null) { // check for allow resubmission or not first // return true if resubmission is allowed and current time is before resubmission close time // get the resubmit settings from submission object first String allowResubmitNumString = submission.getProperties() .get(AssignmentConstants.ALLOW_RESUBMIT_NUMBER); if (NumberUtils.isParsable(allowResubmitNumString) && submission.getSubmitted() && submission.getDateSubmitted() != null) { String allowResubmitCloseTime = submission.getProperties() .get(AssignmentConstants.ALLOW_RESUBMIT_CLOSETIME); try { int allowResubmitNumber = Integer.parseInt(allowResubmitNumString); Instant resubmitCloseTime; if (NumberUtils.isParsable(allowResubmitCloseTime)) { // see if a resubmission close time is set on submission level resubmitCloseTime = Instant.ofEpochMilli(Long.parseLong(allowResubmitCloseTime)); } else { // otherwise, use assignment close time as the resubmission close time resubmitCloseTime = a.getCloseDate(); } return (allowResubmitNumber > 0 || allowResubmitNumber == -1) && !currentTime.isAfter(resubmitCloseTime); } catch (NumberFormatException e) { log.warn("allowResubmitNumString = {}, allowResubmitCloseTime = {}", allowResubmitNumString, allowResubmitCloseTime, e); } } if (isBeforeAssignmentCloseDate && (submission.getDateSubmitted() == null || !submission.getSubmitted())) { // before the assignment close date // and if no date then a submission was never never submitted // or if there is a submitted date and its a not submitted then it is considered a draft return true; } } else { // there is no submission yet so only check if before assignment close date return isBeforeAssignmentCloseDate; } } catch (UserNotDefinedException e) { log.warn("The user {} could not be found while checking if they can submit to assignment {}, {}", userId, a.getId(), e.getMessage()); } catch (PermissionException e) { log.warn("The user {} cannot submit to assignment {}, {}", userId, a.getId(), e.getMessage()); } return false; }
From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java
@Override public boolean isPeerAssessmentOpen(Assignment assignment) { if (assignment.getAllowPeerAssessment()) { Instant now = Instant.now(); return now.isBefore(assignment.getPeerAssessmentPeriodDate()) && now.isAfter(assignment.getCloseDate()); }/*from www .j a v a 2 s. c om*/ return false; }
From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java
private String whenSubmissionMade(AssignmentSubmission s) { Instant dueTime = s.getAssignment().getDueDate(); Instant submittedTime = s.getDateSubmitted(); String latenessStatus;//w w w. j av a 2s . c o m if (submittedTime == null) { latenessStatus = resourceLoader.getString("grades.lateness.unknown"); } else if (dueTime != null && submittedTime.isAfter(dueTime)) { latenessStatus = resourceLoader.getString("grades.lateness.late"); } else { latenessStatus = resourceLoader.getString("grades.lateness.ontime"); } return latenessStatus; }
From source file:org.trellisldp.http.impl.SimpleEventTest.java
@Test public void testSimpleEvent() { final IRI resource = rdf.createIRI(identifier); final Instant time = now(); final Event event = new SimpleEvent(identifier, agent, asList(PROV.Activity, AS.Create), asList(LDP.RDFSource, SKOS.Concept)); assertFalse(time.isAfter(event.getCreated()), "Non-sequential events!"); assertTrue(event.getIdentifier().getIRIString().startsWith("urn:uuid:"), "Incorrect ID prefix for event!"); assertEquals(of(resource), event.getTarget(), "Incorrect target resource!"); assertEquals(1L, event.getAgents().size(), "Incorrect agent count!"); assertTrue(event.getAgents().contains(agent), "Incorrect agent value!"); final Collection<IRI> targetTypes = event.getTargetTypes(); assertEquals(2L, targetTypes.size(), "Incorrect target type size!"); assertTrue(targetTypes.contains(LDP.RDFSource), "Missing ldp:RDFSource type!"); assertTrue(targetTypes.contains(SKOS.Concept), "Missing skos:Concept type!"); final Collection<IRI> eventTypes = event.getTypes(); assertEquals(2L, eventTypes.size(), "Incorrect event type size!"); assertTrue(eventTypes.contains(AS.Create), "Missing as:Create from event type!"); assertTrue(eventTypes.contains(PROV.Activity), "Missing prov:Activity from event type!"); assertFalse(event.getInbox().isPresent()); }
From source file:org.trellisldp.test.TestUtils.java
/** * Check that it is now really later than the provided instant. * @param time an instant/* www . j av a2s. c o m*/ * @return true if it is now later than the provided instant; false otherwise */ public static boolean isReallyLaterThan(final Instant time) { final Instant t = now(); return t.isAfter(time) && t.getEpochSecond() > time.getEpochSecond(); }
From source file:org.trellisldp.triplestore.TriplestoreResourceServiceTest.java
private static boolean isReallyLaterThan(final Instant time) { final Instant t = now(); return t.isAfter(time) && (t.toEpochMilli() > time.toEpochMilli() || t.getNano() > time.getNano()); }