Search in sources :

Example 21 with PortletPreferences

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";
}
Also used : PortletPreferences(javax.portlet.PortletPreferences) ResourceMapping(org.springframework.web.portlet.bind.annotation.ResourceMapping)

Example 22 with PortletPreferences

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";
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) IGroupMember(org.apereo.portal.groups.IGroupMember) HashMap(java.util.HashMap) PortletPreferences(javax.portlet.PortletPreferences) JsonNode(com.fasterxml.jackson.databind.JsonNode) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 23 with PortletPreferences

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);
}
Also used : TreeSet(java.util.TreeSet) PortletPreferences(javax.portlet.PortletPreferences)

Example 24 with PortletPreferences

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) ModelAndView(org.springframework.web.portlet.ModelAndView) IAuthorizationPrincipal(org.apereo.portal.security.IAuthorizationPrincipal) PortletPreferences(javax.portlet.PortletPreferences) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) RenderMapping(org.springframework.web.portlet.bind.annotation.RenderMapping)

Example 25 with PortletPreferences

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;
}
Also used : LoginAggregationKey(org.apereo.portal.events.aggr.login.LoginAggregationKey) ConcurrentUserAggregationKey(org.apereo.portal.events.aggr.concuser.ConcurrentUserAggregationKey) ArrayList(java.util.ArrayList) LoginAggregationKeyImpl(org.apereo.portal.events.aggr.login.LoginAggregationKeyImpl) LoginAggregation(org.apereo.portal.events.aggr.login.LoginAggregation) DateTime(org.joda.time.DateTime) ConcurrentUserAggregationKeyImpl(org.apereo.portal.events.aggr.concuser.ConcurrentUserAggregationKeyImpl) ConcurrentUserAggregation(org.apereo.portal.events.aggr.concuser.ConcurrentUserAggregation) AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) DateMidnight(org.joda.time.DateMidnight) PortletPreferences(javax.portlet.PortletPreferences) AggregationInterval(org.apereo.portal.events.aggr.AggregationInterval)

Aggregations

PortletPreferences (javax.portlet.PortletPreferences)38 HashMap (java.util.HashMap)10 RenderMapping (org.springframework.web.portlet.bind.annotation.RenderMapping)9 ModelAndView (org.springframework.web.portlet.ModelAndView)6 List (java.util.List)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 IPerson (org.apereo.portal.security.IPerson)5 PortletRequest (javax.portlet.PortletRequest)4 ResourceMapping (org.springframework.web.portlet.bind.annotation.ResourceMapping)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Principal (java.security.Principal)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Header (org.apache.http.Header)2 PortletCategory (org.apereo.portal.portlet.om.PortletCategory)2 MarketplaceEntry (org.apereo.portal.rest.layout.MarketplaceEntry)2 IAuthorizationPrincipal (org.apereo.portal.security.IAuthorizationPrincipal)2