List of usage examples for org.joda.time DateMidnight DateMidnight
public DateMidnight()
ISOChronology
in the default time zone. From source file:org.jasig.portal.portlets.activity.ActivityController.java
License:Apache License
private PortalActivity buildPortalActivity(PortletRequest request, int timeframe) { PortletPreferences prefs = request.getPreferences(); DateTime begin, end;//from w w w.j av a 2 s . co m final AggregationInterval interval; final List<PortalGroupActivity> groupActivities = new ArrayList<PortalGroupActivity>(); switch (timeframe) { case NOW: { end = new DateTime(); begin = end.minusHours(1); interval = AggregationInterval.FIVE_MINUTE; break; } case TODAY: { begin = new DateMidnight().toDateTime(); end = begin.plusDays(1); interval = AggregationInterval.DAY; break; } case YESTERDAY: { end = new DateMidnight().toDateTime().minusSeconds(1); begin = end.minusDays(1); interval = AggregationInterval.DAY; break; } default: { end = new DateTime(); begin = end.minusHours(1); interval = AggregationInterval.HOUR; break; } } String masterGroup = prefs.getValue(PREFERENCE_MASTER_GROUP, DEFAULT_PREFERENCE_MASTER_GROUP); List<String> displayGroups = Arrays .asList(prefs.getValues(PREFERENCE_DISPLAY_GROUPS, DEFAULT_PREFERENCE_DISPLAY_GROUPS)); boolean displayOther = Boolean .valueOf(prefs.getValue(PREFERENCE_DISPLAY_OTHER, DEFAULT_PREFERENCE_DISPLAY_OTHER)); int masterTotal = 0; int absTotal = 0; int subTotal = 0; switch (timeframe) { case NOW: for (AggregatedGroupMapping group : concurrentUserAggregationDao.getAggregatedGroupMappings()) { ConcurrentUserAggregationKey key = new ConcurrentUserAggregationKeyImpl(interval, group); final List<ConcurrentUserAggregation> aggregations = concurrentUserAggregationDao .getAggregations(begin, end, key); // NB: We only care about the most recent entry (??) if (aggregations.size() != 0) { final ConcurrentUserAggregation aggregation = aggregations.get(0); int groupTotal = aggregation.getConcurrentUsers(); absTotal += aggregation.getConcurrentUsers(); if (group.getGroupName().equalsIgnoreCase(masterGroup)) { masterTotal = groupTotal; } else { subTotal += groupTotal; } if (!group.getGroupName().equals(masterGroup)) { if (displayGroups.isEmpty() || displayGroups.contains(group.getGroupName())) { final PortalGroupActivity groupActivity = new PortalGroupActivity(group.getGroupName(), groupTotal); groupActivities.add(groupActivity); } } } } break; default: String uniqueLoginsPref = prefs.getValue(PREFERENCE_UNIQUE_LOGINS, DEFAULT_PREFERENCE_UNIQUE_LOGINS); Boolean uniqueLogins = Boolean.valueOf(uniqueLoginsPref); for (AggregatedGroupMapping group : loginAggregationDao.getAggregatedGroupMappings()) { final LoginAggregationKey key = new LoginAggregationKeyImpl(interval, group); final List<LoginAggregation> aggregations = loginAggregationDao.getAggregations(begin, end, key); // NB: We only care about the most recent entry (??) if (aggregations.size() != 0) { final LoginAggregation aggregation = aggregations.get(0); int groupTotal = getAggregationLoginCount(aggregation, uniqueLogins); absTotal += groupTotal; if (group.getGroupName().equalsIgnoreCase(masterGroup)) { masterTotal = groupTotal; } else { subTotal += groupTotal; } if (!group.getGroupName().equals(masterGroup)) { if (displayGroups.isEmpty() || displayGroups.contains(group.getGroupName())) { PortalGroupActivity groupActivity = new PortalGroupActivity(group.getGroupName(), groupTotal); groupActivities.add(groupActivity); } } } } break; } if (displayOther) { int otherTotal = masterTotal - subTotal; if (otherTotal > 0) { PortalGroupActivity otherGroup = new PortalGroupActivity("Other", otherTotal); groupActivities.add(otherGroup); } } Collections.sort(groupActivities); Collections.reverse(groupActivities); int total = masterTotal > 0 ? masterTotal : absTotal; final PortalActivity activity = new PortalActivity(total, groupActivities); return activity; }
From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.AbstractWSIT.java
License:Apache License
SessionForm buildSession() { SessionForm newForm = new SessionForm(); newForm.setAllowInSessionInvites(false); newForm.setBoundaryTime(30);// ww w .j ava2s . co m newForm.setHideParticipantNames(false); newForm.setMaxCameras(1); newForm.setMaxTalkers(1); newForm.setMustBeSupervised(false); newForm.setNewSession(true); newForm.setPermissionsOn(false); newForm.setRaiseHandOnEnter(false); newForm.setSessionName("Test session"); //start date/time newForm.setStartDate(new DateMidnight()); newForm.setStartHour(0); newForm.setStartMinute(0); newForm.setStartTime(new DateTime(new Long("1370181600000"))); //end date/time newForm.setEndDate(new DateMidnight()); newForm.setEndHour(1); newForm.setEndMinute(0); newForm.setEndTime((new DateTime(new Long("1370185200000")))); return newForm; }
From source file:org.jasig.portlet.calendar.mvc.controller.SearchContentController.java
License:Apache License
@EventMapping(SearchConstants.SEARCH_REQUEST_QNAME_STRING) public void searchContent(EventRequest request, EventResponse response) { final Event event = request.getEvent(); final SearchRequest searchQuery = (SearchRequest) event.getValue(); final String[] searchTerms = searchQuery.getSearchTerms().split(" "); List<String> errors = new ArrayList<String>(); DateMidnight start = new DateMidnight(); Interval interval = DateUtil.getInterval(start, 180); Set<CalendarDisplayEvent> events = helper.getEventList(errors, interval, request); final SearchResults searchResults = new SearchResults(); searchResults.setQueryId(searchQuery.getQueryId()); searchResults.setWindowId(request.getWindowID()); for (CalendarDisplayEvent e : events) { for (String term : searchTerms) { if (eventContainsTerm(e, term)) { final PortletUrl url = createPortletUrl(e); final SearchResult searchResult = new SearchResult(); final String summary = createSearchResultSummary(e); searchResult.setTitle(e.getSummary()); searchResult.setSummary(summary); searchResult.setPortletUrl(url); searchResult.getType().add("Calendar"); searchResults.getSearchResult().add(searchResult); }/* w w w. j av a 2 s .com*/ } } if (!searchResults.getSearchResult().isEmpty()) { response.setEvent(SearchConstants.SEARCH_RESULTS_QNAME, searchResults); } }
From source file:org.jasig.portlet.campuslife.dining.mvc.portlet.MainController.java
License:Apache License
@RenderMapping public ModelAndView showMainView(final RenderRequest request, String date) { // determine if the request represents a mobile browser and set the // view name accordingly final boolean isMobile = viewSelector.isMobile(request); final String viewName = isMobile ? "main-jQM" : "main"; final ModelAndView mav = new ModelAndView("dining/".concat(viewName)); if (logger.isDebugEnabled()) { logger.debug("Using view name " + viewName + " for main view"); }/*from w w w. ja v a 2s . c o m*/ DateMidnight d; if (date == null) { d = new DateMidnight(); } else { d = paramFormat.parseLocalDate(date).toDateMidnight(); } final List<DiningHall> halls = menuDao.getDiningHalls(d, request); if (halls != null && halls.size() == 1) { return showDiningHallView(request, halls.get(0).getKey(), paramFormat.print(d)); } else { mav.addObject("diningHalls", menuDao.getDiningHalls(d, request)); mav.addObject("displayDate", displayFormat.print(d)); mav.addObject("date", paramFormat.print(d)); mav.addObject("prev", paramFormat.print(d.minusDays(1))); mav.addObject("next", paramFormat.print(d.plusDays(1))); return mav; } }
From source file:org.key2gym.business.services.AttendancesServiceBean.java
License:Apache License
protected void doCalculatePenalties(Attendance attendance) throws SecurityViolationException, ValidationException, BusinessException { /*//from w w w .ja v a 2 s . c om * Penalties are only supported with registered clients. */ if (attendance.getClient() != null) { /* * Finds the client's current subscription. */ ItemSubscription itemSubscription; List<ItemSubscription> itemSubscriptions = getEntityManager() .createNamedQuery("ItemSubscription.findByClientOrderByDateRecordedDesc", ItemSubscription.class) //NOI18N .setParameter("client", attendance.getClient()) //NOI18N .getResultList(); if (!itemSubscriptions.isEmpty()) { itemSubscription = itemSubscriptions.get(0); List<TimeSplit> timeSplits = getEntityManager() .createNamedQuery("TimeSplit.findAll", TimeSplit.class) //NOI18N .getResultList(); /* * Calculates the quantity of penalties to apply. */ int penalties = itemSubscription.getTimeSplit().calculatePenalties(timeSplits, timeSource.getLocalTime()); /* * If there are penalties to apply, does it. */ if (penalties > 0) { Integer orderId = ordersService.findByClientIdAndDate(attendance.getClient().getId(), new DateMidnight(), true); Integer itemId = getEntityManager().find(Property.class, "time_range_mismatch_penalty_item_id") .getInteger(); OrderEntity order = getEntityManager().find(OrderEntity.class, orderId); OrderLine targetOrderLine = null; /* * Attempts to find the right order line first. */ for (OrderLine orderLine : order.getOrderLines()) { if (orderLine.getItem().getId() == itemId) { targetOrderLine = orderLine; } } Item penaltyItem = getEntityManager().find(Item.class, itemId); /* * Creates an order line, if it does not exists, and applies * the penalties. */ if (targetOrderLine == null) { targetOrderLine = new OrderLine(); targetOrderLine.setDiscount(null); targetOrderLine.setItem(penaltyItem); targetOrderLine.setOrder(order); targetOrderLine.setQuantity(penalties); getEntityManager().persist(targetOrderLine); order.getOrderLines().add(targetOrderLine); order.getClient().charge(penaltyItem, penalties, null); } else { // We only need to charge penalties that what were not yet charged int newPenalties = penalties - targetOrderLine.getQuantity(); order.getClient().charge(penaltyItem, newPenalties, null); targetOrderLine.setQuantity(penalties); } } } } }
From source file:org.key2gym.business.services.ClientsServiceBean.java
License:Apache License
@Override public ClientDTO getTemplateClient() { ClientDTO client = new ClientDTO(); client.setId(getNextId());/* ww w. j a v a 2 s. c o m*/ client.setAttendancesBalance(0); client.setExpirationDate(new DateMidnight()); client.setMoneyBalance(BigDecimal$.MODULE$.apply(0).setScale(2).underlying()); client.setRegistrationDate(new DateMidnight()); return client; }
From source file:org.key2gym.business.services.FreezesServiceBean.java
License:Apache License
@Override public void addFreeze(Integer clientId, Integer days, String note) throws ValidationException, BusinessException, SecurityViolationException { if (clientId == null) { throw new NullPointerException("The clientId is null."); //NOI18N }/*from w w w. ja va 2 s . c o m*/ if (days == null) { throw new NullPointerException("The days is null."); //NOI18N } if (note == null) { throw new NullPointerException("The note is null."); //NOI18N } if (!callerHasAnyRole(SecurityRoles.SENIOR_ADMINISTRATOR, SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Operation.Denied")); } Client client = getEntityManager().find(Client.class, clientId); if (client == null) { throw new ValidationException(getString("Invalid.Client.ID")); } if (client.getExpirationDate().compareTo(new Date()) < 0) { throw new BusinessException(getString("BusinessRule.Client.SubscriptionExpired")); } if (days < 1 || days > 10) { String message = MessageFormat.format( getString("BusinessRule.Freeze.Days.HasToBeWithinRange.withRangeBeginAndRangeEnd"), 1, 10); throw new ValidationException(message); } if (note.trim().isEmpty()) { throw new ValidationException(getString("Invalid.Freeze.Note.CanNotBeEmpty")); } DateMidnight today = new DateMidnight(); List<ClientFreeze> freezes = getEntityManager() .createNamedQuery("ClientFreeze.findByClientAndDateIssuedRange") //NOI18N .setParameter("client", client).setParameter("rangeBegin", today.minusMonths(1).toDate()) //NOI18N .setParameter("rangeEnd", today.toDate()) //NOI18N .getResultList(); if (!freezes.isEmpty()) { throw new BusinessException(getString("BusinessRule.Freeze.ClientHasAlreadyBeenFrozenLastMonth")); } // Rolls the expiration date client.setExpirationDate(new DateMidnight(client.getExpirationDate()).plusDays(days).toDate()); ClientFreeze clientFreeze = new ClientFreeze(); clientFreeze.setDateIssued(new Date()); clientFreeze.setDays(days); clientFreeze.setClient(client); clientFreeze.setAdministrator(getEntityManager().find(Administrator.class, administratorsService.getByUsername(getCallerPrincipal()).getId())); clientFreeze.setNote(note); getEntityManager().persist(clientFreeze); getEntityManager().flush(); }
From source file:org.key2gym.business.services.OrdersServiceBean.java
License:Apache License
/** * Returns a Date instance that represents the today's midnight. * * @return a Date instance/* w w w . j ava 2s .com*/ */ public Date getToday() { return new DateMidnight().toDate(); }
From source file:org.key2gym.business.services.OrdersServiceBean.java
License:Apache License
/** * Checks whether the provided date is today. * * @param date the date to check/*from w ww . ja va2 s .co m*/ * @return true, if the date's time is past the today's midnight. */ public boolean isToday(Date date) { DateMidnight today = new DateMidnight(); DateMidnight tomorrow = today.plusDays(1); return today.getMillis() <= date.getTime() && tomorrow.getMillis() > date.getTime(); }
From source file:org.key2gym.client.actions.CheckInAction.java
License:Apache License
@Override public void onActionPerformed(ActionEvent e) throws BusinessException, ValidationException, SecurityViolationException { OrdersService ordersService = ContextManager.lookup(OrdersService.class); /*// w w w .j av a2 s. c o m * Opens the CheckIn dialog. */ CheckInDialog checkInDialog = new CheckInDialog(getFrame()); checkInDialog.setVisible(true); if (checkInDialog.getResult().equals(AbstractDialog.Result.CANCEL)) { return; } /* * If requested, opens an order. */ if (checkInDialog.isOrderRequested()) { Integer orderId = null; EditOrderDialog editOrderDialog = new EditOrderDialog(getFrame()); try { if (checkInDialog.isAnonymous()) { orderId = ordersService.findForAttendanceById(checkInDialog.getAttendanceId()); } else { orderId = ordersService.findByClientIdAndDate(checkInDialog.getClientId(), new DateMidnight(), true); } } catch (ValidationException ex) { throw new RuntimeException(ex); } editOrderDialog.setOrderId(orderId); editOrderDialog.setFullPaymentForced(false); editOrderDialog.setVisible(true); } }