/** * Rest-Call for {@link TeamCalDao#getList(org.projectforge.core.BaseSearchFilter)} */ @GET @Path(RestPaths.LIST) @Produces(MediaType.APPLICATION_JSON) public Response getList(@QueryParam("fullAccess") final boolean fullAccess) { final TeamCalFilter filter = new TeamCalFilter(); if (fullAccess == true) { filter.setFullAccess(true); filter.setMinimalAccess(false); filter.setReadonlyAccess(false); } final List<TeamCalDO> list = teamCalDao.getList(filter); Integer[] teamCalBlackListIds = userXmlPreferencesDao .getDeserializedUserPreferencesByUserId(ThreadLocalUserContext.getUserId(), TeamCalDO.TEAMCALRESTBLACKLIST, Integer[].class); if(teamCalBlackListIds != null && teamCalBlackListIds.length > 0) { Arrays.stream(teamCalBlackListIds).forEach(calId -> list.remove(teamCalDao.getById(calId))); } final List<CalendarObject> result = new LinkedList<CalendarObject>(); if (list != null && list.size() > 0) { for (final TeamCalDO cal : list) { result.add(TeamCalDOConverter.getCalendarObject(cal, userRights)); } } final String json = JsonUtils.toJson(result); return Response.ok(json).build(); }
/** * @param teamEvent * @param teamCalendarId If null, then team calendar will be set to null; * @see BaseDao#getOrLoad(Integer) */ public void setCalendar(final TeamEventDO teamEvent, final Integer teamCalendarId) { final TeamCalDO teamCal = teamCalDao.getOrLoad(teamCalendarId); teamEvent.setCalendar(teamCal); }
@Override protected void afterSave(final TeamCalDO obj) { super.afterSave(obj); if (obj.isExternalSubscription() == true) { getTeamEventExternalSubscriptionCache().updateCache(obj); } }
final QueryFilter queryFilter = new QueryFilter(myFilter); queryFilter.addOrder(Order.asc("title")); final List<TeamCalDO> list = getList(queryFilter); if (myFilter.isDeleted() == true) { final TeamCalRight right = (TeamCalRight) getUserRight(); final Integer userId = user.getId(); final boolean adminAccessOnly = (myFilter.isAdmin() == true
@Override public void query(String term, final int page, final Response<TeamCalDO> response) { // add all access groups final List<TeamCalDO> fullAccessTeamCals = getTeamCalDao().getList(new TeamCalFilter()); final List<TeamCalDO> result = new ArrayList<TeamCalDO>(); term = term != null ? term.toLowerCase() : ""; final int offset = page * RESULT_PAGE_SIZE; int matched = 0; boolean hasMore = false; for (final TeamCalDO teamCal : fullAccessTeamCals) { if (result.size() == RESULT_PAGE_SIZE) { hasMore = true; break; } if (teamCal.getTitle().toLowerCase().contains(term) == true || teamCal.getOwner().getFullname().toLowerCase().contains(term) == true || teamCal.getOwner().getUsername().toLowerCase().contains(term) == true) { matched++; if (matched > offset) { result.add(teamCal); } } } response.addAll(result); response.setHasMore(hasMore); }
@Override public String getDisplayValue(final Integer object) { if (Const.TIMESHEET_CALENDAR_ID.equals(object)) { return timesheetsCalendar.getTitle(); } return teamCalDao.getById(object).getTitle(); }
/** * @see org.projectforge.web.wicket.CellItemListenerPropertyColumn#populateItem(org.apache.wicket.markup.repeater.Item, * java.lang.String, org.apache.wicket.model.IModel) */ @Override public void populateItem(final Item<ICellPopulator<TeamCalDO>> item, final String componentId, final IModel<TeamCalDO> rowModel) { final TeamCalDO teamCal = rowModel.getObject(); final TeamCalRight right = (TeamCalRight) teamCalDao.getUserRight(); String label; if (right.isOwner(getUser(), teamCal) == true) { label = getString("plugins.teamcal.owner"); } else if (right.hasFullAccess(teamCal, getUserId()) == true) { label = getString("plugins.teamcal.fullAccess"); } else if (right.hasReadonlyAccess(teamCal, getUserId()) == true) { label = getString("plugins.teamcal.readonlyAccess"); } else if (right.hasMinimalAccess(teamCal, getUserId()) == true) { label = getString("plugins.teamcal.minimalAccess"); } else if (isAdminUser == true) { label = getString("plugins.teamcal.adminAccess"); } else { label = "???"; } item.add(new Label(componentId, label)); cellItemListener.populateItem(item, componentId, rowModel); } });
/** * if has access: create drop down with teamCals else create label * * @param fieldSet */ private void initTeamCalPicker(final FieldsetPanel fieldSet) { if (access == false) { final TeamCalDO calendar = data.getCalendar(); final Label teamCalTitle = new Label(fieldSet.newChildId(), calendar != null ? new PropertyModel<String>(data.getCalendar(), "title") : ""); fieldSet.add(teamCalTitle); } else { final List<TeamCalDO> list = teamCalDao.getAllCalendarsWithFullAccess(); calendarsWithFullAccess = list.toArray(new TeamCalDO[0]); final LabelValueChoiceRenderer<TeamCalDO> calChoiceRenderer = new LabelValueChoiceRenderer<TeamCalDO>(); for (final TeamCalDO cal : list) { calChoiceRenderer.addValue(cal, cal.getTitle()); } final DropDownChoice<TeamCalDO> calDropDownChoice = new DropDownChoice<>(fieldSet.getDropDownChoiceId(), new PropertyModel<TeamCalDO>(data, "calendar"), calChoiceRenderer.getValues(), calChoiceRenderer); calDropDownChoice.setNullValid(false); calDropDownChoice.setRequired(true); fieldSet.add(calDropDownChoice); } }
/** * This method will be called by CacheHelper and is synchronized via getData(); */ @Override protected void refresh() { log.info("Initializing TeamCalCache ..."); TeamCalDao dao = ApplicationContextProvider.getApplicationContext().getBean(TeamCalDao.class); if (dao == null || teamCalRight == null) { teamCalRight = (TeamCalRight) userRights.getRight(UserRightId.PLUGIN_CALENDAR); } // This method must not be synchronized because it works with a new copy of maps. final Map<Integer, TeamCalDO> map = new HashMap<Integer, TeamCalDO>(); final List<TeamCalDO> list = dao.internalLoadAll(); for (final TeamCalDO cal : list) { TeamCalDO put = map.put(cal.getId(), cal); if (put != null) { log.info("Adding team cal with id: " + cal.getId() + " to cache."); } } this.calendarMap = map; log.info("Initializing of TeamCalCache done."); } }
public void updateCache() { log.info("Start updating TeamEventExternalSubscriptionCache."); final QueryFilter filter = new QueryFilter(); filter.add(Restrictions.eq("externalSubscription", true)); // internalGetList is valid at this point, because we are calling this method in an asyn thread final List<TeamCalDO> subscribedCalendars = teamCalDao.internalGetList(filter); for (final TeamCalDO calendar : subscribedCalendars) { updateCache(calendar); } final List<Integer> idsToRemove = new ArrayList<Integer>(); for (final Integer calendarId : subscriptions.keySet()) { // if calendar is not subscribed anymore, remove them if (calendarListContainsId(subscribedCalendars, calendarId) == false) { idsToRemove.add(calendarId); } } removeCalendarsFromCache(idsToRemove); }
teamCalDO.setExternalSubscriptionCalendarBinary(bytes); teamCalDao.internalUpdate(teamCalDO);
/** * Gets a list of all calendars with full access of the current logged-in user as well as the calendars owned by the * current logged-in user. * * @return */ public List<TeamCalDO> getAllCalendarsWithFullAccess() { final TeamCalFilter filter = new TeamCalFilter(); filter.setOwnerType(OwnerType.ALL); filter.setFullAccess(true).setReadonlyAccess(false).setMinimalAccess(false); return getList(filter); }
@Override public Collection<TeamCalDO> toChoices(final Collection<String> ids) { final List<TeamCalDO> list = new ArrayList<TeamCalDO>(); if (ids == null) { return list; } for (final String id : ids) { final Integer teamCalId = NumberHelper.parseInteger(id); if (teamCalId == null) { continue; } TeamCalDO teamCal = null; try { teamCal = getTeamCalDao().getById(teamCalId); } catch (final AccessException ex) { log.warn("User has no access to the selected calendar '" + id + "'."); } if (teamCal != null) { list.add(teamCal); } } return list; }
final List<TeamCalDO> list = teamCalDao.getAllCalendarsWithFullAccess(); final LabelValueChoiceRenderer<TeamCalDO> calChoiceRenderer = new LabelValueChoiceRenderer<TeamCalDO>(); for (final TeamCalDO cal : list) {
public TeamCalImportPage(final PageParameters parameters) { super(parameters); form = new TeamCalImportForm(this); body.add(form); final Integer calId = WicketUtils.getAsInteger(parameters, PARAM_KEY_TEAM_CAL_ID); if (calId != null) { form.calendar = teamCalDao.getById(calId); } form.init(); }
@Override protected void afterUpdate(final TeamCalDO obj, final TeamCalDO dbObj) { super.afterUpdate(obj, dbObj); if (obj != null && dbObj != null && obj.isExternalSubscription() == true && StringUtils.equals(obj.getExternalSubscriptionUrl(), dbObj.getExternalSubscriptionUrl()) == false) { // only update if the url has changed! getTeamEventExternalSubscriptionCache().updateCache(obj); } // if calendar is present in subscription cache and is not an external subscription anymore -> cleanup! if (obj != null && obj.isExternalSubscription() == false && getTeamEventExternalSubscriptionCache().isExternalSubscribedCalendar(obj.getId())) { obj.setExternalSubscriptionCalendarBinary(null); obj.setExternalSubscriptionUrl(null); obj.setExternalSubscriptionUpdateInterval(null); obj.setExternalSubscriptionHash(null); getTeamEventExternalSubscriptionCache().updateCache(obj, true); } }
private void handleDateRangeSelection(final Component caller, final WebPage returnPage, final SelectedRange range, final TeamCalDao teamCalDao, final String calendarId) { if (filter instanceof TeamCalCalendarFilter) { final TemplateEntry activeTemplateEntry = ((TeamCalCalendarFilter) filter).getActiveTemplateEntry(); if (activeTemplateEntry.getDefaultCalendarId() == null && activeTemplateEntry.getCalendars().size() > 0) { activeTemplateEntry.setDefaultCalendarId(activeTemplateEntry.getCalendars().get(0).getId()); } final TeamCalDO calendar = teamCalDao.getById(activeTemplateEntry.getDefaultCalendarId()); final TeamEventDO event = new TeamEventDO(); event.setAllDay(range.isAllDay()); event.setOwnership(true); event.setStartDate(new Timestamp(DateHelper.getDateTimeAsMillis(range.getStart()))).setEndDate( new Timestamp(DateHelper.getDateTimeAsMillis(range.getEnd()))); event.setCalendar(calendar); final TeamEventEditPage page = new TeamEventEditPage(new PageParameters(), event); page.setReturnToPage(new TeamCalCalendarPage(returnPage.getPageParameters())); caller.setResponsePage(page); } }