List of usage examples for java.util TimeZone getID
public String getID()
From source file:com.nubits.nubot.notifications.jhipchat.HipChat.java
public User updateUser(UserId id, String email, String name, String title, boolean isGroupAdmin, String password, TimeZone timeZone) { String query = String.format(HipChatConstants.USERS_CREATE_QUERY_FORMAT, HipChatConstants.JSON_FORMAT, authToken);//from ww w .jav a 2 s .c o m StringBuilder params = new StringBuilder(); if (id == null) { throw new IllegalArgumentException("updateUser: id cannot be null"); } else { params.append("user_id="); params.append(id.getId()); } if (email != null) { params.append("&email="); params.append(email); } if (name != null) { if (!name.contains(" ")) { throw new IllegalArgumentException( "updateUser: name must contain a space separating first and last name"); } else { params.append("&name="); params.append(name); } } if (title != null) { params.append("&title="); params.append(title); } if (isGroupAdmin) { params.append("&is_group_admin=1"); } else { params.append("&is_group_admin=0"); } if (password != null) { params.append("&password="); params.append(password); } if (timeZone != null) { String tz = timeZone.getID(); params.append("&timezone="); params.append(tz); } final String paramsToSend = params.toString(); OutputStream output = null; InputStream input = null; HttpURLConnection connection = null; User result = null; try { URL requestUrl = new URL(HipChatConstants.API_BASE + HipChatConstants.USERS_UPDATE + query); connection = (HttpURLConnection) requestUrl.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", Integer.toString(paramsToSend.getBytes().length)); connection.setRequestProperty("Content-Language", "en-US"); output = new BufferedOutputStream(connection.getOutputStream()); IOUtils.write(paramsToSend, output); IOUtils.closeQuietly(output); input = connection.getInputStream(); result = UserParser.parseUser(this, input); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(input); connection.disconnect(); } return result; }
From source file:com.leanplum.Leanplum.java
private static void startHelper(String userId, final Map<String, ?> attributes, final boolean isBackground) { LeanplumPushService.onStart();/*ww w .ja va 2s.c o m*/ Boolean limitAdTracking = null; String deviceId = Request.deviceId(); if (deviceId == null) { if (!userSpecifiedDeviceId && Constants.defaultDeviceId != null) { deviceId = Constants.defaultDeviceId; } else if (customDeviceId != null) { deviceId = customDeviceId; } else { DeviceIdInfo deviceIdInfo = Util.getDeviceId(deviceIdMode); deviceId = deviceIdInfo.id; limitAdTracking = deviceIdInfo.limitAdTracking; } Request.setDeviceId(deviceId); } if (userId == null) { userId = Request.userId(); if (userId == null) { userId = Request.deviceId(); } } Request.setUserId(userId); // Setup parameters. String versionName = Util.getVersionName(); if (versionName == null) { versionName = ""; } TimeZone localTimeZone = TimeZone.getDefault(); Date now = new Date(); int timezoneOffsetSeconds = localTimeZone.getOffset(now.getTime()) / 1000; HashMap<String, Object> params = new HashMap<>(); params.put(Constants.Params.INCLUDE_DEFAULTS, Boolean.toString(false)); if (isBackground) { params.put(Constants.Params.BACKGROUND, Boolean.toString(true)); } params.put(Constants.Params.VERSION_NAME, versionName); params.put(Constants.Params.DEVICE_NAME, Util.getDeviceName()); params.put(Constants.Params.DEVICE_MODEL, Util.getDeviceModel()); params.put(Constants.Params.DEVICE_SYSTEM_NAME, Util.getSystemName()); params.put(Constants.Params.DEVICE_SYSTEM_VERSION, Util.getSystemVersion()); params.put(Constants.Keys.TIMEZONE, localTimeZone.getID()); params.put(Constants.Keys.TIMEZONE_OFFSET_SECONDS, Integer.toString(timezoneOffsetSeconds)); params.put(Constants.Keys.LOCALE, Util.getLocale()); params.put(Constants.Keys.COUNTRY, Constants.Values.DETECT); params.put(Constants.Keys.REGION, Constants.Values.DETECT); params.put(Constants.Keys.CITY, Constants.Values.DETECT); params.put(Constants.Keys.LOCATION, Constants.Values.DETECT); if (Boolean.TRUE.equals(limitAdTracking)) { params.put(Constants.Params.LIMIT_TRACKING, limitAdTracking.toString()); } if (attributes != null) { params.put(Constants.Params.USER_ATTRIBUTES, JsonConverter.toJson(attributes)); } if (Constants.isDevelopmentModeEnabled) { params.put(Constants.Params.DEV_MODE, Boolean.TRUE.toString()); } // Get the current inbox messages on the device. params.put(Constants.Params.INBOX_MESSAGES, LeanplumInbox.getInstance().messagesIds()); Util.initializePreLeanplumInstall(params); // Issue start API call. Request req = Request.post(Constants.Methods.START, params); req.onApiResponse(new Request.ApiResponseCallback() { @Override public void response(List<Map<String, Object>> requests, JSONObject response) { Leanplum.handleApiResponse(response, requests); } }); if (isBackground) { req.sendEventually(); } else { req.sendIfConnected(); } LeanplumInternal.triggerStartIssued(); }
From source file:com.layer8apps.CalendarHandler.java
/************ * PURPOSE: Adds the parsed out events to the calendar * ARGUMENTS: NULL//from w ww .j ava2 s.c o m * RETURNS: VOID * AUTHOR: Devin Collins <agent14709@gmail.com>, Bobby Ore <bob1987@gmail.com> *************/ private int addDays() { ArrayList<Shift> shifts = buildShifts(); try { // deleteOldEvents(); Preferences pf = new Preferences(this); // Get our stored notification time int notification = pf.getNotification(); // Convert the stored time into minutes switch (notification) { case 0: { notification = 0; break; } case 1: { notification = 5; break; } case 2: { notification = 15; break; } case 3: { notification = 30; break; } case 4: { notification = 60; break; } case 5: { notification = 120; break; } case 6: { notification = 180; break; } } shifts = checkForDuplicates(shifts); if (shifts.size() == 0) { return 0; } TimeZone zone = TimeZone.getDefault(); for (Shift shift : shifts) { /************ * ContentResolver and ContentValues are what we use to add * our calendar events to the device *************/ ContentResolver cr = this.getContentResolver(); ContentValues cv = new ContentValues(); /************ * Here we create our calendar event based on the version code *************/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { cv.put(CalendarContract.Events.CALENDAR_ID, calID); cv.put(CalendarContract.Events.DESCRIPTION, shift.getDepartment()); cv.put(CalendarContract.Events.DTEND, shift.getEndDate().getTimeInMillis()); cv.put(CalendarContract.Events.DTSTART, shift.getStartDate().getTimeInMillis()); cv.put(CalendarContract.Events.EVENT_LOCATION, shift.getAddress()); cv.put(CalendarContract.Events.EVENT_TIMEZONE, zone.getID()); cv.put(CalendarContract.Events.HAS_ALARM, (notification == 0) ? 0 : 1); cv.put(CalendarContract.Events.TITLE, shift.getTitle()); } else { cv.put("calendar_id", calID); cv.put("description", shift.getDepartment()); cv.put("dtend", shift.getEndDate().getTimeInMillis()); cv.put("dtstart", shift.getStartDate().getTimeInMillis()); cv.put("eventLocation", shift.getAddress()); cv.put("eventTimezone", zone.getID()); cv.put("title", shift.getTitle()); cv.put("hasAlarm", (notification <= 0) ? 0 : 1); } /************ * Add our events to the calendar based on the Uri we get *************/ Uri uri = cr.insert(getEventsUri(), cv); if (uri == null) { continue; } // Get the ID of the calendar event long eventID = Long.parseLong(uri.getLastPathSegment()); pf.saveShift(String.valueOf(eventID)); /************ * If we retrieved a Uri for the event, try to add the reminder *************/ if (notification > 0) { /************ * Build our reminder based on version code *************/ ContentValues reminders = new ContentValues(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { reminders.put(CalendarContract.Reminders.EVENT_ID, eventID); reminders.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT); reminders.put(CalendarContract.Reminders.MINUTES, notification); } else { reminders.put("event_id", eventID); reminders.put("method", 1); reminders.put("minutes", notification); } // Add the reminder to the system cr.insert(getRemindersUri(), reminders); } } } catch (Exception e) { showError( "Could not create calendar events on calendar, please make sure you have a calendar application on your device"); return -1; } return shifts.size(); }
From source file:com.github.hipchat.api.HipChat.java
public User createUser(String email, String name, String title, boolean isGroupAdmin, String password, TimeZone timeZone) { String query = String.format(HipChatConstants.USERS_CREATE_QUERY_FORMAT, HipChatConstants.JSON_FORMAT, authToken);//from www . j a va 2 s .co m StringBuilder params = new StringBuilder(); if (email == null || "".equals(email)) { throw new IllegalArgumentException("createUser: email cannot be null or empty"); } else { params.append("email="); params.append(email); } if (name == null || "".equals(name)) { throw new IllegalArgumentException("createUser: name cannot be null or empty"); } else if (!name.contains(" ")) { throw new IllegalArgumentException( "createUser: name must contain a space separating first and last name"); } else { params.append("&name="); params.append(name); } if (title == null || "".equals(title)) { throw new IllegalArgumentException("createUser: title cannot be null or empty"); } else { params.append("&title="); params.append(title); } if (isGroupAdmin) { params.append("&is_group_admin=1"); } else { params.append("&is_group_admin=0"); } if (password != null && !"".equals(password)) { params.append("&password="); params.append(password); } if (timeZone != null) { String tz = timeZone.getID(); params.append("&timezone="); params.append(tz); } final String paramsToSend = params.toString(); OutputStream output = null; InputStream input = null; HttpURLConnection connection = null; User result = null; try { URL requestUrl = getRequestUrl(HipChatConstants.API_BASE, HipChatConstants.USERS_CREATE, query); connection = getPostConnection(requestUrl, paramsToSend); output = new BufferedOutputStream(connection.getOutputStream()); IOUtils.write(paramsToSend, output); IOUtils.closeQuietly(output); input = connection.getInputStream(); result = UserParser.parseUser(this, input); } catch (IOException e) { LogMF.error(logger, "IO Exception: {0}", new Object[] { e.getMessage() }); } finally { IOUtils.closeQuietly(input); connection.disconnect(); } return result; }
From source file:com.nubits.nubot.notifications.jhipchat.HipChat.java
public User createUser(String email, String name, String title, boolean isGroupAdmin, String password, TimeZone timeZone) { String query = String.format(HipChatConstants.USERS_CREATE_QUERY_FORMAT, HipChatConstants.JSON_FORMAT, authToken);//from w w w .j a v a2 s . c om StringBuilder params = new StringBuilder(); if (email == null || "".equals(email)) { throw new IllegalArgumentException("createUser: email cannot be null or empty"); } else { params.append("email="); params.append(email); } if (name == null || "".equals(name)) { throw new IllegalArgumentException("createUser: name cannot be null or empty"); } else if (!name.contains(" ")) { throw new IllegalArgumentException( "createUser: name must contain a space separating first and last name"); } else { params.append("&name="); params.append(name); } if (title == null || "".equals(title)) { throw new IllegalArgumentException("createUser: title cannot be null or empty"); } else { params.append("&title="); params.append(title); } if (isGroupAdmin) { params.append("&is_group_admin=1"); } else { params.append("&is_group_admin=0"); } if (password != null && !"".equals(password)) { params.append("&password="); params.append(password); } if (timeZone != null) { String tz = timeZone.getID(); params.append("&timezone="); params.append(tz); } final String paramsToSend = params.toString(); OutputStream output = null; InputStream input = null; HttpURLConnection connection = null; User result = null; try { URL requestUrl = new URL(HipChatConstants.API_BASE + HipChatConstants.USERS_CREATE + query); connection = (HttpURLConnection) requestUrl.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", Integer.toString(paramsToSend.getBytes().length)); connection.setRequestProperty("Content-Language", "en-US"); output = new BufferedOutputStream(connection.getOutputStream()); IOUtils.write(paramsToSend, output); IOUtils.closeQuietly(output); input = connection.getInputStream(); result = UserParser.parseUser(this, input); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(input); connection.disconnect(); } return result; }
From source file:org.unitedinternet.cosmo.service.account.OutOfTheBoxHelper.java
private NoteItem makeWelcomeItem(OutOfTheBoxContext context) { NoteItem item = entityFactory.createNote(); TimeZone tz = context.getTimezone(); Locale locale = context.getLocale(); User user = context.getUser();//w ww . ja v a2s.c o m String name = "Welcome to Chandler Server"; String body = "1. Get a tour of Chandler @ chandlerproject.org/getstarted\n\n2. Consult our FAQ @ chandlerproject.org/faq\n\n3. Read about any known issues with the Preview release @ chandlerproject.org/knownissues\n\n4. Ask questions and give us feedback by joining the Chandler-Users mailing list @ chandlerproject.org/mailinglists. Find out how to get involved @ chandlerproject.org/getinvolved\n\n5. Learn more about the project and access a wide range of design, planning and developer documentation @ chandlerproject.org/wikihome"; String from = "OSAF"; String sentBy = "OSAF"; String to = ""; item.setUid(contentDao.generateUid()); item.setDisplayName(name); item.setOwner(user); item.setClientCreationDate(Calendar.getInstance(tz, locale).getTime()); item.setClientModifiedDate(item.getClientCreationDate()); TriageStatus triage = entityFactory.createTriageStatus(); TriageStatusUtil.initialize(triage); item.setTriageStatus(triage); item.setLastModifiedBy(user.getUsername()); item.setLastModification(ContentItem.Action.CREATED); item.setSent(Boolean.FALSE); item.setNeedsReply(Boolean.FALSE); item.setIcalUid(item.getUid()); item.setBody(body); Calendar start = Calendar.getInstance(tz, locale); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); DateTime startDate = (DateTime) Dates.getInstance(start.getTime(), Value.DATE_TIME); startDate.setTimeZone(vtz(tz.getID())); EventStamp es = entityFactory.createEventStamp(item); item.addStamp(es); es.createCalendar(); es.setStartDate(startDate); es.setDuration(new Dur(0, 1, 0, 0)); TaskStamp ts = entityFactory.createTaskStamp(); item.addStamp(ts); MessageStamp ms = entityFactory.createMessageStamp(); item.addStamp(ms); ms.setFrom(from); ms.setTo(to); ms.setOriginators(sentBy); ms.setDateSent(DateUtil.formatDate(MessageStamp.FORMAT_DATE_SENT, item.getClientCreationDate())); return item; }
From source file:com.cttapp.bby.mytlc.layer8apps.CalendarHandler.java
/************ * PURPOSE: Adds the parsed out events to the calendar * ARGUMENTS: NULL//from www . j a v a2 s . c o m * RETURNS: VOID * AUTHOR: Devin Collins <agent14709@gmail.com>, Bobby Ore <bob1987@gmail.com> *************/ private int addDays() { ArrayList<Shift> shifts = buildShifts(); try { // deleteOldEvents(); Preferences pf = new Preferences(this); // Get our stored notification time int notification = pf.getNotification(); // Convert the stored time into minutes switch (notification) { case 0: { notification = 0; break; } case 1: { notification = 5; break; } case 2: { notification = 15; break; } case 3: { notification = 30; break; } case 4: { notification = 60; break; } case 5: { notification = 120; break; } case 6: { notification = 180; break; } } createJSONArray(shifts); shifts = checkForDuplicates(shifts); if (shifts.size() == 0) { return 0; } TimeZone zone = TimeZone.getDefault(); for (Shift shift : shifts) { /************ * ContentResolver and ContentValues are what we use to add * our calendar events to the device *************/ ContentResolver cr = this.getContentResolver(); ContentValues cv = new ContentValues(); /************ * Here we create our calendar event based on the version code *************/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { cv.put(CalendarContract.Events.CALENDAR_ID, calID); cv.put(CalendarContract.Events.DESCRIPTION, shift.getDepartment()); cv.put(CalendarContract.Events.DTEND, shift.getEndDate().getTimeInMillis()); cv.put(CalendarContract.Events.DTSTART, shift.getStartDate().getTimeInMillis()); cv.put(CalendarContract.Events.EVENT_LOCATION, shift.getAddress()); cv.put(CalendarContract.Events.EVENT_TIMEZONE, zone.getID()); cv.put(CalendarContract.Events.HAS_ALARM, (notification == 0) ? 0 : 1); cv.put(CalendarContract.Events.TITLE, shift.getTitle()); } else { cv.put("calendar_id", calID); cv.put("description", shift.getDepartment()); cv.put("dtend", shift.getEndDate().getTimeInMillis()); cv.put("dtstart", shift.getStartDate().getTimeInMillis()); cv.put("eventLocation", shift.getAddress()); cv.put("eventTimezone", zone.getID()); cv.put("title", shift.getTitle()); cv.put("hasAlarm", (notification <= 0) ? 0 : 1); } /************ * Add our events to the calendar based on the Uri we get *************/ Uri uri = cr.insert(getEventsUri(), cv); if (uri == null) { continue; } // Get the ID of the calendar event long eventID = Long.parseLong(uri.getLastPathSegment()); pf.saveShift(String.valueOf(eventID)); /************ * If we retrieved a Uri for the event, try to add the reminder *************/ if (notification > 0) { /************ * Build our reminder based on version code *************/ ContentValues reminders = new ContentValues(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { reminders.put(CalendarContract.Reminders.EVENT_ID, eventID); reminders.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT); reminders.put(CalendarContract.Reminders.MINUTES, notification); } else { reminders.put("event_id", eventID); reminders.put("method", 1); reminders.put("minutes", notification); } // Add the reminder to the system cr.insert(getRemindersUri(), reminders); } } } catch (Exception e) { showError( "Could not create calendar events on calendar, please make sure you have a calendar application on your device"); return -1; } return shifts.size(); }
From source file:com.sonicle.webtop.core.Service.java
public void processLookupTimezones(HttpServletRequest request, HttpServletResponse response, PrintWriter out) { ArrayList<JsSimple> items = new ArrayList<>(); try {/*from ww w . j ava 2 s . c o m*/ int off; for (TimeZone tz : WT.getTimezones()) { final String normId = StringUtils.replace(tz.getID(), "_", " "); off = tz.getRawOffset() / 3600000; items.add(new JsSimple(tz.getID(), MessageFormat.format("{0} (GMT{1}{2})", normId, (off < 0) ? "-" : "+", Math.abs(off)))); } new JsonResult("timezones", items, items.size()).printTo(out); } catch (Exception ex) { logger.error("Error in LookupTimezones", ex); new JsonResult(false, "Unable to lookup timezones").printTo(out); } }
From source file:org.sakaiproject.portal.charon.SkinnableCharonPortal.java
public void includeBottom(PortalRenderContext rcontext) { if (rcontext.uses(INCLUDE_BOTTOM)) { String thisUser = SessionManager.getCurrentSessionUserId(); //Get user preferences PreferencesService preferencesService = (PreferencesService) ComponentManager .get(PreferencesService.class); Preferences prefs = preferencesService.getPreferences(thisUser); boolean showServerTime = ServerConfigurationService.getBoolean("portal.show.time", true); if (showServerTime) { rcontext.put("showServerTime", "true"); Calendar now = Calendar.getInstance(); Date nowDate = new Date(now.getTimeInMillis()); //first set server date and time TimeZone serverTz = TimeZone.getDefault(); now.setTimeZone(serverTz);//from w w w . ja va 2s . c o m rcontext.put("serverTzDisplay", serverTz.getDisplayName(serverTz.inDaylightTime(nowDate), TimeZone.SHORT)); rcontext.put("serverTzGMTOffset", String.valueOf( now.getTimeInMillis() + now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET))); //provide the user's preferred timezone information if it is different //Get the Properties object that holds user's TimeZone preferences ResourceProperties tzprops = prefs.getProperties(TimeService.APPLICATION_ID); //Get the ID of the timezone using the timezone key. //Default to 'localTimeZone' (server timezone?) String preferredTzId = (String) tzprops.get(TimeService.TIMEZONE_KEY); if (preferredTzId != null && !preferredTzId.equals(serverTz.getID())) { TimeZone preferredTz = TimeZone.getTimeZone(preferredTzId); now.setTimeZone(preferredTz); rcontext.put("showPreferredTzTime", "true"); //now set up the portal information rcontext.put("preferredTzDisplay", preferredTz.getDisplayName(preferredTz.inDaylightTime(nowDate), TimeZone.SHORT)); rcontext.put("preferredTzGMTOffset", String.valueOf( now.getTimeInMillis() + now.get(Calendar.ZONE_OFFSET) + now.get(Calendar.DST_OFFSET))); } else { rcontext.put("showPreferredTzTime", "false"); } } rcontext.put("pagepopup", false); String copyright = ServerConfigurationService.getString("bottom.copyrighttext"); /** * Replace keyword in copyright message from sakai.properties * with the server's current year to auto-update of Copyright end date */ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy"); String currentServerYear = simpleDateFormat.format(new Date()); copyright = copyright.replaceAll(SERVER_COPYRIGHT_CURRENT_YEAR_KEYWORD, currentServerYear); String service = ServerConfigurationService.getString("ui.service", "Sakai"); String serviceVersion = ServerConfigurationService.getString("version.service", "?"); String sakaiVersion = ServerConfigurationService.getString("version.sakai", "?"); String server = ServerConfigurationService.getServerId(); String[] bottomNav = ServerConfigurationService.getStrings("bottomnav"); String[] poweredByUrl = ServerConfigurationService.getStrings("powered.url"); String[] poweredByImage = ServerConfigurationService.getStrings("powered.img"); String[] poweredByAltText = ServerConfigurationService.getStrings("powered.alt"); { List<Object> l = new ArrayList<Object>(); if ((bottomNav != null) && (bottomNav.length > 0)) { for (int i = 0; i < bottomNav.length; i++) { l.add(bottomNav[i]); } } rcontext.put("bottomNav", l); } boolean neoChatAvailable = ServerConfigurationService.getBoolean("portal.neochat", true) && chatHelper.checkChatPermitted(thisUser); rcontext.put("neoChat", neoChatAvailable); rcontext.put("portalChatPollInterval", ServerConfigurationService.getInt("portal.chat.pollInterval", 5000)); rcontext.put("neoAvatar", ServerConfigurationService.getBoolean("portal.neoavatar", true)); rcontext.put("neoChatVideo", ServerConfigurationService.getBoolean("portal.chat.video", true)); rcontext.put("portalVideoChatTimeout", ServerConfigurationService.getInt("portal.chat.video.timeout", 25)); if (sakaiTutorialEnabled && thisUser != null) { if (!("1".equals(prefs.getProperties().getProperty("sakaiTutorialFlag")))) { rcontext.put("tutorial", true); //now save this in the user's prefefences so we don't show it again PreferencesEdit preferences = null; SecurityAdvisor secAdv = null; try { secAdv = new SecurityAdvisor() { @Override public SecurityAdvice isAllowed(String userId, String function, String reference) { if ("prefs.add".equals(function) || "prefs.upd".equals(function)) { return SecurityAdvice.ALLOWED; } return null; } }; securityService.pushAdvisor(secAdv); try { preferences = preferencesService.edit(thisUser); } catch (IdUnusedException ex1) { try { preferences = preferencesService.add(thisUser); } catch (IdUsedException ex2) { M_log.error(ex2); } catch (PermissionException ex3) { M_log.error(ex3); } } if (preferences != null) { ResourcePropertiesEdit props = preferences.getPropertiesEdit(); props.addProperty("sakaiTutorialFlag", "1"); preferencesService.commit(preferences); } } catch (Exception e1) { M_log.error(e1); } finally { if (secAdv != null) { securityService.popAdvisor(secAdv); } } } } // rcontext.put("bottomNavSitNewWindow", // Web.escapeHtml(rb.getString("site_newwindow"))); if ((poweredByUrl != null) && (poweredByImage != null) && (poweredByAltText != null) && (poweredByUrl.length == poweredByImage.length) && (poweredByUrl.length == poweredByAltText.length)) { { List<Object> l = new ArrayList<Object>(); for (int i = 0; i < poweredByUrl.length; i++) { Map<String, Object> m = new HashMap<String, Object>(); m.put("poweredByUrl", poweredByUrl[i]); m.put("poweredByImage", poweredByImage[i]); m.put("poweredByAltText", poweredByAltText[i]); l.add(m); } rcontext.put("bottomNavPoweredBy", l); } } else { List<Object> l = new ArrayList<Object>(); Map<String, Object> m = new HashMap<String, Object>(); m.put("poweredByUrl", "http://sakaiproject.org"); m.put("poweredByImage", "/library/image/sakai_powered.gif"); m.put("poweredByAltText", "Powered by Sakai"); l.add(m); rcontext.put("bottomNavPoweredBy", l); } rcontext.put("bottomNavService", service); rcontext.put("bottomNavCopyright", copyright); rcontext.put("bottomNavServiceVersion", serviceVersion); rcontext.put("bottomNavSakaiVersion", sakaiVersion); rcontext.put("bottomNavServer", server); // SAK-25931 - Do not remove this from session here - removal is done by /direct Session s = SessionManager.getCurrentSession(); String userWarning = (String) s.getAttribute("userWarning"); rcontext.put("userWarning", new Boolean(StringUtils.isNotEmpty(userWarning))); if (ServerConfigurationService.getBoolean("pasystem.enabled", false)) { PASystem paSystem = (PASystem) ComponentManager.get(PASystem.class); rcontext.put("paSystemEnabled", true); rcontext.put("paSystem", paSystem); } } }
From source file:org.exoplatform.calendar.ws.CalendarRestApi.java
/** * Returns occurrences of a recurring event with specified id when : * the calendar of the event is public//w w w . j a v a2 s .c o m * the authenticated user is the owner of the calendar of the event * the authenticated user belongs to the group of the calendar of the event * the authenticated user is a participant of the event * the calendar of the event has been shared with the authenticated user or with a group of the authenticated user * * @param id * identity of recurrence event, if event not exists, return 404 http status code * * @param start * date follow ISO8601 (YYYY-MM-DDThh:mm:ssTZD). Search for events *from* this date. * Default: current server time. * * @param end * date follow ISO8601 (YYYY-MM-DDThh:mm:ssTZD). Search for events *to* this date * Default: current server time + 1 week. * * @param offset * The starting point when paging through a list of entities. Defaults to *0*. * * @param limit * The maximum number of results when paging through a list of entities, if not specify or exceed * the *query_limit* configuration of calendar rest service, it will use the *query_limit* * (see more on {@link #CalendarRestApi(OrganizationService, InitParams)} java doc) * * @param resturnSize * tell the service if it must return the total size of the returned collection result, and the *link* http headers. * It can be true or false, by default, it's *false* * * @param fields * This is a list of comma separated property's names of response json object, * if not specified, it return the json will all available properties. * * @param jsonp * The name of a JavaScript function to be used as the JSONP callback, if not specified, only * json object is returned. * * @param expand * used to ask for a full representation of a subresource, instead of only its link. * This is a list of comma-separated property's names. For example: expand=calendar,categories. In case of collections, * you can put offset (default: 0), limit (default: *query_limit* of the rest service) value into param, for example: expand=categories(1,5). * Instead of: * { * id: "...", * calendar: "http://localhost:8080/portal/rest/v1/calendar/calendars/demo-defaultCalendarId" * .... * } * It returns: * { * id: "...", * calendar: { * id: "...", * name:"demo-defaultId", * .... * } * .... * } * * @request GET: http://localhost:8080/portal/rest/v1/calendar/events/Event123/occurences?offset=1&limit=5 * * @format JSON * * @response * [ * { * id: "myEventId", * href: "http://localhost:8080/portal/rest/v1/calendar/events/myEventId", * subject: "..", description: "...", * from: "...", to: "...", * calendar: "...", categories: ["...", ""], * location: "", priority: "", * repeat: {...}, * recurrenceId: "...", originalEvent: "...", * reminder: [], attachment: [], participants: [], * privacy: "", availability: "" * }, * {id...} * ] * * @return List of occurrence events * * @authentication * * @anchor CalendarRestApi.getOccurrencesFromEvent */ @SuppressWarnings({ "unchecked", "rawtypes" }) @GET @RolesAllowed("users") @Path("/events/{id}/occurrences") @Produces(MediaType.APPLICATION_JSON) public Response getOccurrencesFromEvent(@PathParam("id") String id, @QueryParam("offset") int offset, @QueryParam("limit") int limit, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("fields") String fields, @QueryParam("jsonp") String jsonp, @QueryParam("expand") String expand, @QueryParam("returnSize") boolean returnSize, @Context UriInfo uriInfo) { try { limit = parseLimit(limit); java.util.Calendar[] dates = parseDate(start, end); CalendarEvent recurEvent = calendarServiceInstance().getEventById(id); if (recurEvent == null) return Response.status(HTTPStatus.NOT_FOUND).cacheControl(nc).build(); TimeZone tz = java.util.Calendar.getInstance().getTimeZone(); String timeZone = tz.getID(); Map<String, CalendarEvent> occMap = calendarServiceInstance().getOccurrenceEvents(recurEvent, dates[0], dates[1], timeZone); if (occMap == null || occMap.isEmpty()) { return Response.status(HTTPStatus.NOT_FOUND).cacheControl(nc).build(); } Calendar cal = calendarServiceInstance().getCalendarById(recurEvent.getCalendarId()); boolean inParticipant = false; if (recurEvent.getParticipant() != null) { String[] participant = recurEvent.getParticipant(); Arrays.sort(participant); int i = Arrays.binarySearch(participant, currentUserId()); if (i > -1) inParticipant = true; } if (cal.getPublicUrl() != null || this.hasViewCalendarPermission(cal, currentUserId()) || inParticipant) { Collection data = new ArrayList(); Iterator<CalendarEvent> evIter = occMap.values().iterator(); Utils.skip(evIter, offset); int counter = 0; while (evIter.hasNext()) { data.add(buildEventResource(evIter.next(), uriInfo, expand, fields)); if (++counter == limit) break; } int fullSize = returnSize ? occMap.values().size() : -1; CollectionResource evData = new CollectionResource(data, fullSize); evData.setOffset(offset); evData.setOffset(limit); // ResponseBuilder response = buildJsonP(evData, jsonp); if (returnSize) { response.header(HEADER_LINK, buildFullUrl(uriInfo, offset, limit, evData.getSize())); } return response.build(); } // return Response.status(HTTPStatus.NOT_FOUND).cacheControl(nc).build(); } catch (Exception e) { if (log.isDebugEnabled()) log.debug(e.getMessage()); } return Response.status(HTTPStatus.UNAVAILABLE).cacheControl(nc).build(); }