List of usage examples for java.time Duration ofMinutes
public static Duration ofMinutes(long minutes)
From source file:org.opengrok.suggest.SuggesterTest.java
private SuggesterTestData initSuggester() throws IOException { Path tempIndexDir = Files.createTempDirectory("opengrok"); Directory dir = FSDirectory.open(tempIndexDir); addText(dir, "term1 term2 term3"); dir.close();//ww w . j a v a 2 s.com Path tempSuggesterDir = Files.createTempDirectory("opengrok"); Suggester s = new Suggester(tempSuggesterDir.toFile(), 10, Duration.ofMinutes(1), true, true, Collections.singleton("test"), Integer.MAX_VALUE, Runtime.getRuntime().availableProcessors()); s.init(Collections.singleton(new Suggester.NamedIndexDir("test", tempIndexDir))); await().atMost(2, TimeUnit.SECONDS).until(() -> getSuggesterProjectDataSize(s) == 1); SuggesterTestData testData = new SuggesterTestData(); testData.s = s; testData.indexDir = tempIndexDir; testData.suggesterDir = tempSuggesterDir; return testData; }
From source file:org.opengrok.suggest.SuggesterTest.java
@Test public void testIndexChangedWhileOffline() throws IOException { SuggesterTestData t = initSuggester(); t.s.close();// w w w . jav a 2s. c o m addText(t.getIndexDirectory(), "a1 a2"); t.s = new Suggester(t.suggesterDir.toFile(), 10, Duration.ofMinutes(1), false, true, Collections.singleton("test"), Integer.MAX_VALUE, Runtime.getRuntime().availableProcessors()); t.s.init(Collections.singleton(t.getNamedIndexDir())); await().atMost(2, TimeUnit.SECONDS).until(() -> getSuggesterProjectDataSize(t.s) == 1); Suggester.NamedIndexReader ir = t.getNamedIndexReader(); List<LookupResultItem> res = t.s .search(Collections.singletonList(ir), new SuggesterPrefixQuery(new Term("test", "a")), null) .getItems(); assertThat(res.stream().map(LookupResultItem::getPhrase).collect(Collectors.toList()), containsInAnyOrder("a1", "a2")); t.close(); }
From source file:org.openhab.binding.darksky.internal.config.DarkSkyChannelConfiguration.java
/** * Parses a hh:mm string and returns the minutes. *///from w w w . ja v a 2 s.c o m private long getMinutesFromTime(@Nullable String configTime) { String time = StringUtils.trimToNull(configTime); if (time != null) { try { if (!HHMM_PATTERN.matcher(time).matches()) { throw new NumberFormatException(); } else { String[] splittedConfigTime = time.split(TIME_SEPARATOR); int hour = Integer.parseInt(splittedConfigTime[0]); int minutes = Integer.parseInt(splittedConfigTime[1]); return Duration.ofMinutes(minutes).plusHours(hour).toMinutes(); } } catch (Exception ex) { logger.warn( "Cannot parse channel configuration '{}' to hour and minutes, use pattern hh:mm, ignoring!", time); } } return 0; }
From source file:org.openhab.binding.dwdunwetter.internal.data.DwdWarningsData.java
public DwdWarningsData(String cellId) { DwdWarningDataAccess dataAccess = new DwdWarningDataAccess(); this.dataAccessCached = new ExpiringCache<>(Duration.ofMinutes(MIN_REFRESH_WAIT_MINUTES), () -> dataAccess.getDataFromEndpoint(cellId)); }
From source file:org.openhab.binding.dwdunwetter.internal.data.DwdWarningsData.java
/** * Only for Tests//w ww . j a v a2s . c o m */ protected void setDataAccess(DwdWarningDataAccess dataAccess) { dataAccessCached = new ExpiringCache<String>(Duration.ofMinutes(MIN_REFRESH_WAIT_MINUTES), () -> dataAccess.getDataFromEndpoint("")); }
From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java
@Override @Transactional/*from ww w . j a v a 2s. c om*/ public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> ids, List<String> transferOptions) { Map<String, String> transversalMap = new HashMap<>(); Collection<Assignment> assignments = getAssignmentsForContext(fromContext); for (Assignment oAssignment : assignments) { String oAssignmentId = oAssignment.getId(); String nAssignmentId = null; if (ids == null || ids.isEmpty() || ids.contains(oAssignmentId)) { try { Assignment nAssignment = addAssignment(toContext); nAssignmentId = nAssignment.getId(); nAssignment.setTitle(oAssignment.getTitle()); // replace all occurrence of old context with new context inside instruction text if (StringUtils.isNotBlank(oAssignment.getInstructions())) { nAssignment .setInstructions(oAssignment.getInstructions().replaceAll(fromContext, toContext)); } nAssignment.setTypeOfGrade(oAssignment.getTypeOfGrade()); nAssignment.setTypeOfSubmission(oAssignment.getTypeOfSubmission()); // User supplied publish option takes precedence, then property, then source. if (transferOptions != null && transferOptions.contains(EntityTransferrer.PUBLISH_OPTION)) { nAssignment.setDraft(false); } else if (serverConfigurationService.getBoolean("import.importAsDraft", true)) { nAssignment.setDraft(true); } else { nAssignment.setDraft(oAssignment.getDraft()); } nAssignment.setCloseDate(oAssignment.getCloseDate()); nAssignment.setDropDeadDate(oAssignment.getDropDeadDate()); nAssignment.setDueDate(oAssignment.getDueDate()); nAssignment.setOpenDate(oAssignment.getOpenDate()); nAssignment.setHideDueDate(oAssignment.getHideDueDate()); nAssignment.setPosition(oAssignment.getPosition()); nAssignment.setAllowAttachments(oAssignment.getAllowAttachments()); nAssignment.setHonorPledge(oAssignment.getHonorPledge()); nAssignment.setIndividuallyGraded(oAssignment.getIndividuallyGraded()); nAssignment.setMaxGradePoint(oAssignment.getMaxGradePoint()); nAssignment.setScaleFactor(oAssignment.getScaleFactor()); nAssignment.setReleaseGrades(oAssignment.getReleaseGrades()); // group assignment if (oAssignment.getTypeOfAccess() == GROUP) { nAssignment.setTypeOfAccess(GROUP); Site oSite = siteService.getSite(oAssignment.getContext()); Site nSite = siteService.getSite(nAssignment.getContext()); boolean siteChanged = false; Collection<Group> nGroups = nSite.getGroups(); for (String groupId : oAssignment.getGroups()) { Group oGroup = oSite.getGroup(groupId); Optional<Group> existingGroup = nGroups.stream() .filter(g -> StringUtils.equals(g.getTitle(), oGroup.getTitle())).findAny(); Group nGroup; if (existingGroup.isPresent()) { // found a matching group nGroup = existingGroup.get(); } else { // create group nGroup = nSite.addGroup(); nGroup.setTitle(oGroup.getTitle()); nGroup.setDescription(oGroup.getDescription()); nGroup.getProperties().addProperty("group_prop_wsetup_created", Boolean.TRUE.toString()); siteChanged = true; } nAssignment.getGroups().add(nGroup.getReference()); } if (siteChanged) siteService.save(nSite); nAssignment.setIsGroup(oAssignment.getIsGroup()); } // review service nAssignment.setContentReview(oAssignment.getContentReview()); // attachments Set<String> oAttachments = oAssignment.getAttachments(); List<Reference> nAttachments = entityManager.newReferenceList(); for (String oAttachment : oAttachments) { Reference oReference = entityManager.newReference(oAttachment); String oAttachmentId = oReference.getId(); // transfer attachment, replace the context string if necessary and add new attachment String nReference = transferAttachment(fromContext, toContext, oAttachmentId); nAssignment.getAttachments().add(nReference); } // peer review nAssignment.setAllowPeerAssessment(oAssignment.getAllowPeerAssessment()); nAssignment.setPeerAssessmentAnonEval(oAssignment.getPeerAssessmentAnonEval()); nAssignment.setPeerAssessmentInstructions(oAssignment.getPeerAssessmentInstructions()); nAssignment.setPeerAssessmentNumberReviews(oAssignment.getPeerAssessmentNumberReviews()); nAssignment.setPeerAssessmentStudentReview(oAssignment.getPeerAssessmentStudentReview()); nAssignment.setPeerAssessmentPeriodDate(oAssignment.getPeerAssessmentPeriodDate()); if (nAssignment.getPeerAssessmentPeriodDate() == null && nAssignment.getCloseDate() != null) { // set the peer period time to be 10 mins after accept until date Instant tenMinutesAfterCloseDate = Instant .from(nAssignment.getCloseDate().plus(Duration.ofMinutes(10))); nAssignment.setPeerAssessmentPeriodDate(tenMinutesAfterCloseDate); } // properties Map<String, String> nProperties = nAssignment.getProperties(); nProperties.putAll(oAssignment.getProperties()); // remove the link btw assignment and announcement item. One can announce the open date afterwards nProperties.remove(ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE); nProperties.remove(AssignmentConstants.NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED); nProperties.remove(ResourceProperties.PROP_ASSIGNMENT_OPENDATE_ANNOUNCEMENT_MESSAGE_ID); // remove the link btw assignment and calendar item. One can add the due date to calendar afterwards nProperties.remove(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE); nProperties.remove(AssignmentConstants.NEW_ASSIGNMENT_DUE_DATE_SCHEDULED); nProperties.remove(ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID); if (!nAssignment.getDraft()) { Map<String, String> oProperties = oAssignment.getProperties(); String fromCalendarEventId = oProperties .get(ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID); if (fromCalendarEventId != null) { String fromCalendarId = calendarService.calendarReference(oAssignment.getContext(), SiteService.MAIN_CONTAINER); Calendar fromCalendar = calendarService.getCalendar(fromCalendarId); CalendarEvent fromEvent = fromCalendar.getEvent(fromCalendarEventId); String toCalendarId = calendarService.calendarReference(nAssignment.getContext(), SiteService.MAIN_CONTAINER); Calendar toCalendar = null; try { toCalendar = calendarService.getCalendar(toCalendarId); } catch (IdUnusedException iue) { calendarService.commitCalendar(calendarService.addCalendar(toCalendarId)); toCalendar = calendarService.getCalendar(toCalendarId); } String fromDisplayName = fromEvent.getDisplayName(); CalendarEvent toCalendarEvent = toCalendar.addEvent(fromEvent.getRange(), fromEvent.getDisplayName(), fromEvent.getDescription(), fromEvent.getType(), fromEvent.getLocation(), fromEvent.getAccess(), fromEvent.getGroups(), fromEvent.getAttachments()); nProperties.put(ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID, toCalendarEvent.getId()); nProperties.put(AssignmentConstants.NEW_ASSIGNMENT_DUE_DATE_SCHEDULED, Boolean.TRUE.toString()); nProperties.put(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE, Boolean.TRUE.toString()); } String openDateAnnounced = StringUtils.trimToNull( oProperties.get(AssignmentConstants.NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED)); String fromAnnouncementId = StringUtils.trimToNull(oProperties .get(ResourceProperties.PROP_ASSIGNMENT_OPENDATE_ANNOUNCEMENT_MESSAGE_ID)); AnnouncementChannel fromChannel = getAnnouncementChannel(oAssignment.getContext()); if (fromChannel != null && fromAnnouncementId != null) { AnnouncementMessage fromAnnouncement = fromChannel .getAnnouncementMessage(fromAnnouncementId); AnnouncementChannel toChannel = getAnnouncementChannel(nAssignment.getContext()); if (toChannel == null) { // Create the announcement channel String toChannelId = announcementService.channelReference(nAssignment.getContext(), siteService.MAIN_CONTAINER); announcementService .commitChannel(announcementService.addAnnouncementChannel(toChannelId)); toChannel = getAnnouncementChannel(nAssignment.getContext()); } AnnouncementMessage toAnnouncement = toChannel.addAnnouncementMessage( fromAnnouncement.getAnnouncementHeader().getSubject(), fromAnnouncement.getAnnouncementHeader().getDraft(), fromAnnouncement.getAnnouncementHeader().getAttachments(), fromAnnouncement.getBody()); nProperties.put(AssignmentConstants.NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED, Boolean.TRUE.toString()); nProperties.put(ResourceProperties.PROP_ASSIGNMENT_OPENDATE_ANNOUNCEMENT_MESSAGE_ID, toAnnouncement.getId()); nProperties.put(ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE, Boolean.TRUE.toString()); } } // gradebook-integration link String associatedGradebookAssignment = nProperties .get(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT); if (StringUtils.isBlank(associatedGradebookAssignment)) { // if the association property is empty then set gradebook integration to not integrated nProperties.put(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK, GRADEBOOK_INTEGRATION_NO); } else { // see if the old assignment's associated gradebook item is an internal gradebook entry or externally defined boolean isExternalAssignmentDefined = gradebookExternalAssessmentService .isExternalAssignmentDefined(oAssignment.getContext(), associatedGradebookAssignment); if (isExternalAssignmentDefined) { if (!nAssignment.getDraft()) { String gbUid = nAssignment.getContext(); if (!gradebookFrameworkService.isGradebookDefined(gbUid)) { gradebookFrameworkService.addGradebook(gbUid, gbUid); } // This assignment has been published, make sure the associated gb item is available org.sakaiproject.service.gradebook.shared.Assignment gbAssignment = gradebookService .getAssignmentByNameOrId(nAssignment.getContext(), associatedGradebookAssignment); if (gbAssignment == null) { // The associated gb item hasn't been created here yet. gbAssignment = gradebookService.getExternalAssignment(oAssignment.getContext(), associatedGradebookAssignment); Optional<Long> categoryId = createCategoryForGbAssignmentIfNecessary( gbAssignment, oAssignment.getContext(), nAssignment.getContext()); String assignmentRef = AssignmentReferenceReckoner.reckoner() .assignment(nAssignment).reckon().getReference(); gradebookExternalAssessmentService.addExternalAssessment( nAssignment.getContext(), assignmentRef, null, nAssignment.getTitle(), nAssignment.getMaxGradePoint() / (double) nAssignment.getScaleFactor(), Date.from(nAssignment.getDueDate()), this.getToolTitle(), null, false, categoryId.isPresent() ? categoryId.get() : null); nProperties.put(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT, assignmentRef); } } else { // if this is an external defined (came from assignment) // mark the link as "add to gradebook" for the new imported assignment, since the assignment is still of draft state // later when user posts the assignment, the corresponding assignment will be created in gradebook. nProperties.remove(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT); nProperties.put(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK, GRADEBOOK_INTEGRATION_ADD); } } else { // If this is an internal gradebook item then it should be associated with the assignment try { org.sakaiproject.service.gradebook.shared.Assignment gbAssignment = gradebookService .getAssignmentByNameOrId(nAssignment.getContext(), associatedGradebookAssignment); if (gbAssignment == null) { if (!nAssignment.getDraft()) { // The target gb item doesn't exist and we're in publish mode, so copy it over. gbAssignment = gradebookService.getAssignmentByNameOrId( oAssignment.getContext(), associatedGradebookAssignment); gbAssignment.setId(null); Optional<Long> categoryId = createCategoryForGbAssignmentIfNecessary( gbAssignment, oAssignment.getContext(), nAssignment.getContext()); if (categoryId.isPresent()) { gbAssignment.setCategoryId(categoryId.get()); } gradebookService.addAssignment(nAssignment.getContext(), gbAssignment); nProperties.put(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT, gbAssignment.getName()); } else { nProperties.put(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT, AssignmentReferenceReckoner.reckoner().assignment(nAssignment) .reckon().getReference()); nProperties.put(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK, GRADEBOOK_INTEGRATION_ADD); } } else { // migrate to gradebook assignment id (vs title) associatedGradebookAssignment = gbAssignment.getId().toString(); nProperties.put(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK, GRADEBOOK_INTEGRATION_ASSOCIATE); nProperties.put(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT, associatedGradebookAssignment); } } catch (AssessmentNotFoundException anfe) { log.info( "While importing assignment {} the associated gradebook item {} was missing, " + "switching assignment linkage to added by assignments", nAssignmentId, associatedGradebookAssignment); } } } updateAssignment(nAssignment); transversalMap.put("assignment/" + oAssignmentId, "assignment/" + nAssignmentId); log.info("Old assignment id: {} - new assignment id: {}", oAssignmentId, nAssignmentId); try { if (taggingManager.isTaggable()) { for (TaggingProvider provider : taggingManager.getProviders()) { provider.transferCopyTags(assignmentActivityProducer.getActivity(oAssignment), assignmentActivityProducer.getActivity(nAssignment)); } } } catch (PermissionException pe) { log.error("{} oAssignmentId={} nAssignmentId={}", pe.toString(), oAssignmentId, nAssignmentId); } // Import supplementary items if they are present in the assignment to be imported // Model Answer AssignmentModelAnswerItem oModelAnswerItem = assignmentSupplementItemService .getModelAnswer(oAssignmentId); if (oModelAnswerItem != null) { AssignmentModelAnswerItem nModelAnswerItem = assignmentSupplementItemService .newModelAnswer(); assignmentSupplementItemService.saveModelAnswer(nModelAnswerItem); nModelAnswerItem.setAssignmentId(nAssignmentId); nModelAnswerItem.setText(oModelAnswerItem.getText()); nModelAnswerItem.setShowTo(oModelAnswerItem.getShowTo()); Set<AssignmentSupplementItemAttachment> oModelAnswerItemAttachments = oModelAnswerItem .getAttachmentSet(); Set<AssignmentSupplementItemAttachment> nModelAnswerItemAttachments = new HashSet<>(); for (AssignmentSupplementItemAttachment oAttachment : oModelAnswerItemAttachments) { AssignmentSupplementItemAttachment nAttachment = assignmentSupplementItemService .newAttachment(); // New attachment creation String nAttachmentId = transferAttachment(fromContext, toContext, removeReferencePrefix(oAttachment.getAttachmentId())); if (StringUtils.isNotEmpty(nAttachmentId)) { nAttachment.setAssignmentSupplementItemWithAttachment(nModelAnswerItem); nAttachment.setAttachmentId(nAttachmentId); assignmentSupplementItemService.saveAttachment(nAttachment); nModelAnswerItemAttachments.add(nAttachment); } } nModelAnswerItem.setAttachmentSet(nModelAnswerItemAttachments); assignmentSupplementItemService.saveModelAnswer(nModelAnswerItem); } // Private Note AssignmentNoteItem oNoteItem = assignmentSupplementItemService.getNoteItem(oAssignmentId); if (oNoteItem != null) { AssignmentNoteItem nNoteItem = assignmentSupplementItemService.newNoteItem(); //assignmentSupplementItemService.saveNoteItem(nNoteItem); nNoteItem.setAssignmentId(nAssignment.getId()); nNoteItem.setNote(oNoteItem.getNote()); nNoteItem.setShareWith(oNoteItem.getShareWith()); nNoteItem.setCreatorId(userDirectoryService.getCurrentUser().getId()); assignmentSupplementItemService.saveNoteItem(nNoteItem); } // All Purpose AssignmentAllPurposeItem oAllPurposeItem = assignmentSupplementItemService .getAllPurposeItem(oAssignmentId); if (oAllPurposeItem != null) { AssignmentAllPurposeItem nAllPurposeItem = assignmentSupplementItemService .newAllPurposeItem(); assignmentSupplementItemService.saveAllPurposeItem(nAllPurposeItem); nAllPurposeItem.setAssignmentId(nAssignment.getId()); nAllPurposeItem.setTitle(oAllPurposeItem.getTitle()); nAllPurposeItem.setText(oAllPurposeItem.getText()); nAllPurposeItem.setHide(oAllPurposeItem.getHide()); nAllPurposeItem.setReleaseDate(null); nAllPurposeItem.setRetractDate(null); Set<AssignmentSupplementItemAttachment> oAllPurposeItemAttachments = oAllPurposeItem .getAttachmentSet(); Set<AssignmentSupplementItemAttachment> nAllPurposeItemAttachments = new HashSet<>(); for (AssignmentSupplementItemAttachment oAttachment : oAllPurposeItemAttachments) { AssignmentSupplementItemAttachment nAttachment = assignmentSupplementItemService .newAttachment(); // New attachment creation String nAttachId = transferAttachment(fromContext, toContext, removeReferencePrefix(oAttachment.getAttachmentId())); if (StringUtils.isNotEmpty(nAttachId)) { nAttachment.setAssignmentSupplementItemWithAttachment(nAllPurposeItem); nAttachment.setAttachmentId(nAttachId); assignmentSupplementItemService.saveAttachment(nAttachment); nAllPurposeItemAttachments.add(nAttachment); } } nAllPurposeItem.setAttachmentSet(nAllPurposeItemAttachments); assignmentSupplementItemService.cleanAllPurposeItemAccess(nAllPurposeItem); Set<AssignmentAllPurposeItemAccess> accessSet = new HashSet<>(); AssignmentAllPurposeItemAccess access = assignmentSupplementItemService .newAllPurposeItemAccess(); access.setAccess(userDirectoryService.getCurrentUser().getId()); access.setAssignmentAllPurposeItem(nAllPurposeItem); assignmentSupplementItemService.saveAllPurposeItemAccess(access); accessSet.add(access); nAllPurposeItem.setAccessSet(accessSet); assignmentSupplementItemService.saveAllPurposeItem(nAllPurposeItem); } } catch (Exception e) { log.error("{} oAssignmentId={} nAssignmentId={}", e.toString(), oAssignmentId, nAssignmentId); } } } return transversalMap; }
From source file:org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfigurationUnitTests.java
@Test // DATAREDIS-667 public void shouldConfigureAllProperties() { ClientOptions clientOptions = ClientOptions.create(); ClientResources sharedClientResources = LettuceTestClientResources.getSharedClientResources(); GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); LettucePoolingClientConfiguration configuration = LettucePoolingClientConfiguration.builder() // .useSsl() // .disablePeerVerification() // .startTls().and() // .poolConfig(poolConfig) // .clientOptions(clientOptions) // .clientResources(sharedClientResources) // .commandTimeout(Duration.ofMinutes(5)) // .shutdownTimeout(Duration.ofHours(2)) // .shutdownQuietPeriod(Duration.ofMinutes(5)) // .build();//from w ww. ja v a 2 s .c o m assertThat(configuration.getPoolConfig()).isEqualTo(poolConfig); assertThat(configuration.isUseSsl()).isTrue(); assertThat(configuration.isVerifyPeer()).isFalse(); assertThat(configuration.isStartTls()).isTrue(); assertThat(configuration.getClientOptions()).contains(clientOptions); assertThat(configuration.getClientResources()).contains(sharedClientResources); assertThat(configuration.getCommandTimeout()).isEqualTo(Duration.ofMinutes(5)); assertThat(configuration.getShutdownTimeout()).isEqualTo(Duration.ofHours(2)); assertThat(configuration.getShutdownQuietPeriod()).isEqualTo(Duration.ofMinutes(5)); }