use of javax.portlet.PortletPreferences in project uPortal by Jasig.
the class GoogleAnalyticsConfigController method storeData.
@ResourceMapping("storeData")
public String storeData(ResourceRequest request, @RequestParam JsonNode config) throws ValidatorException, IOException, ReadOnlyException {
final PortletPreferences preferences = request.getPreferences();
this.portletPreferencesJsonDao.storeJson(preferences, CONFIG_PREF_NAME, config);
return "jsonView";
}
use of javax.portlet.PortletPreferences in project uPortal by Jasig.
the class GoogleAnalyticsController method renderAnalyticsHeader.
@RenderMapping
public String renderAnalyticsHeader(RenderRequest request, ModelMap model) throws IOException {
// For which user account are we logging portal activity?
final HttpServletRequest req = portalRequestUtils.getCurrentPortalRequest();
final IPerson person = personManager.getPerson(req);
final String username = person.getUserName();
final IGroupMember groupMember = GroupService.getGroupMember(username, IPerson.class);
final Map<String, Boolean> isMemberCache = new HashMap<>();
final PortletPreferences preferences = request.getPreferences();
final JsonNode config = this.portletPreferencesJsonDao.getJsonNode(preferences, GoogleAnalyticsConfigController.CONFIG_PREF_NAME);
final JsonNode propertyConfig = config.get("defaultConfig");
this.filterAnalyticsGroups(groupMember, propertyConfig, isMemberCache);
final JsonNode hosts = config.get("hosts");
if (hosts != null) {
for (final Iterator<JsonNode> hostsItr = hosts.elements(); hostsItr.hasNext(); ) {
final JsonNode institution = hostsItr.next();
this.filterAnalyticsGroups(groupMember, institution, isMemberCache);
}
}
model.put("data", config);
if (propertyConfig == null || propertyConfig.get("propertyId") == null) {
return "jsp/GoogleAnalytics/noop";
} else {
return "jsp/GoogleAnalytics/init";
}
}
use of javax.portlet.PortletPreferences in project uPortal by Jasig.
the class ConfigurablePreferencesBasedTokenGenerator method generateToken.
/**
* Returns a String hashcode of the values for the portlet preferences that are configurable by the Dynamic Skin
* portlet. The hashcode is generated in a repeatable fashion by calculating it based on sorted portlet preference
* names. Though hashcode does not guarantee uniqueness, from a practical perspective we'll have so few different
* values we can reasonably assume preference value combinations will be unique.
*
* @see DynamicSkinUniqueTokenGenerator#generateToken(DynamicSkinInstanceData)
*/
public String generateToken(final DynamicSkinInstanceData data) {
final PortletPreferences preferences = data.getPortletRequest().getPreferences();
int hash = 0;
// Add the list of preference names to an ordered list so we can get reliable hashcode calculations.
final Map<String, String[]> prefs = preferences.getMap();
final TreeSet<String> orderedNames = new TreeSet<String>(prefs.keySet());
final Iterator<String> iterator = orderedNames.iterator();
while (iterator.hasNext()) {
final String preferenceName = iterator.next();
if (preferenceName.startsWith(DynamicRespondrSkinConstants.CONFIGURABLE_PREFIX)) {
hash = hash * 31 + preferences.getValue(preferenceName, "").trim().hashCode();
}
}
return Integer.toString(hash);
}
use of javax.portlet.PortletPreferences in project uPortal by Jasig.
the class DynamicRespondrSkinViewController method displaySkinCssHeader.
/**
* Display Skin CSS include based on skin's configuration values from portlet preferences.<br>
* dynamic=false: load the pre-built css file from the skins directory and default skin name;
* e.g. RELATIVE_ROOT/{defaultSkin}.css dynamic=true: Process the default skin less file if
* needed at RELATIVE_ROOT/{defaultSkin}.less to create a customized skin css file
* (RELATIVE_ROOT/skin-ID#.css to load.
*/
@RenderMapping
public ModelAndView displaySkinCssHeader(RenderRequest request, RenderResponse response, Model model) throws IOException {
if (PortletRequest.RENDER_HEADERS.equals(request.getAttribute(PortletRequest.RENDER_PART))) {
PortletPreferences prefs = request.getPreferences();
Boolean enabled = Boolean.valueOf(prefs.getValue(DynamicRespondrSkinConstants.PREF_DYNAMIC, "false"));
String skinName = prefs.getValue(DynamicRespondrSkinConstants.PREF_SKIN_NAME, DynamicRespondrSkinConstants.DEFAULT_SKIN_NAME);
String cssUrl = enabled ? calculateDynamicSkinUrlPathToUse(request, skinName) : calculateDefaultSkinCssLocationInWebapp(skinName);
model.addAttribute(DynamicRespondrSkinConstants.SKIN_CSS_URL_MODEL_ATTRIBUTE_NAME, cssUrl);
return new ModelAndView("jsp/DynamicRespondrSkin/skinHeader");
} else {
// We need to know if this user can CONFIG this skin
// Default
boolean canAccessSkinConfig = false;
final HttpServletRequest httpr = portalRequestUtils.getCurrentPortalRequest();
final IPerson user = personManager.getPerson(httpr);
final IAuthorizationPrincipal principal = AuthorizationPrincipalHelper.principalFromUser(user);
final IPortletWindowId portletWindowId = portletWindowRegistry.getPortletWindowId(httpr, request.getWindowID());
final IPortletWindow portletWindow = portletWindowRegistry.getPortletWindow(httpr, portletWindowId);
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
if (principal.canConfigure(portletEntity.getPortletDefinitionId().toString())) {
canAccessSkinConfig = true;
}
// RENDER_MARKUP
return new ModelAndView("jsp/DynamicRespondrSkin/skinBody", DynamicRespondrSkinConstants.CAN_ACCESS_SKIN_CONFIG_MODEL_NAME, canAccessSkinConfig);
}
}
use of javax.portlet.PortletPreferences in project uPortal by Jasig.
the class ActivityController method buildPortalActivity.
private PortalActivity buildPortalActivity(PortletRequest request, int timeframe) {
PortletPreferences prefs = request.getPreferences();
DateTime begin, end;
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;
}
Aggregations