Package org.eurekastreams.commons.actions.context

Examples of org.eurekastreams.commons.actions.context.Principal


     */
    @Override
    public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext,
            final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception
    {
        final Principal principal = inActionContext.getActionContext().getPrincipal();
        ValidationException ve = new ValidationException();
        String creatorUserName = principal.getAccountId();
        final Long creatorPersonId = principal.getId();
        SystemSettings settings = getSystemSettingsMapper.execute(null);

        // Verify that group with given short name doesn't already exist.
        if (getGroupMapper().findByShortName(inGroup.getShortName()) != null)
        {
            ve.addError(SHORTNAME_KEY, DUP_SHORTNAME_MSG);
        }

        // Verify that group has on coordinator.
        if (inGroup.getCoordinators().isEmpty())
        {
            ve.addError("coordinators", "Group must have at least one coordinator");
        }

        if (!ve.getErrors().isEmpty())
        {
            throw ve;
        }

        // if the system requires approval to create groups, set the pending state to true.
        boolean isPending = true;
        if (settings.getAllUsersCanCreateGroups()
                || getSystemAdministratorIdsMapper.execute(null).contains(creatorPersonId))
        {
            isPending = false;
        }
        inGroup.setPending(isPending);

        // Set the current user to the createdby person.
        inGroup.setCreatedBy(personMapper.findByAccountId(creatorUserName));

        getGroupMapper().insert(inGroup);

        // sets the destination entity id for the group's stream scope
        inGroup.getStreamScope().setDestinationEntityId(inGroup.getId());

        queueAsyncAction(inActionContext, inGroup, false);

        // Make all coordinators follow/join the new group
        for (Person coordinator : inGroup.getCoordinators())
        {
            SetFollowingStatusByGroupCreatorRequest currentRequest = new SetFollowingStatusByGroupCreatorRequest(
                    coordinator.getId(), inGroup.getId(), Follower.FollowerStatus.FOLLOWING, inGroup.getName(),
                    inGroup.getShortName(), isPending);
            new InlineExecutionStrategyExecutor().execute(followStrategy, currentRequest, new DefaultPrincipal(
                    creatorUserName, principal.getOpenSocialId(), creatorPersonId), inActionContext
                    .getUserActionRequests());
        }

        // trigger notification if group will be pending approval
        if (isPending)
View Full Code Here


        LinkedList<PersonModelView> people = null;
        try
        {
            if (groupId.getType().equals(Type.friends))
            {
                Principal currentPrincipal = getPrincipal(token);
                if (currentPrincipal == null)
                {
                    throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Server Error");
                }

                GetFollowersFollowingRequest currentRequest = new GetFollowersFollowingRequest(EntityType.PERSON,
                        currentPrincipal.getAccountId(), 0, Integer.MAX_VALUE);

                ServiceActionContext currentContext = new ServiceActionContext(currentRequest, currentPrincipal);

                PagedSet<PersonModelView> peopleResults = (PagedSet<PersonModelView>) serviceActionController.execute(
                        currentContext, getFollowingAction);
View Full Code Here

     *            - current security token for the request.
     * @return Principal object based on the security token or null if an anonymous request.
     */
    private Principal getPrincipal(final SecurityToken inSecurityToken)
    {
        Principal currentUserPrincipal = null;
        if (inSecurityToken.getViewerId() != null)
        {
            currentUserPrincipal = principalDao.execute(inSecurityToken.getViewerId());
        }
        return currentUserPrincipal;
View Full Code Here

        String group = "";
        if (values.containsKey("EUREKA:GROUP"))
        {
            group = (String) values.get("EUREKA:GROUP");
        }
        Principal principal = context.getActionContext().getPrincipal();
        if (values.containsKey("EUREKA:FEEDSUBID"))
        {
            ServiceActionContext deleteAC =
                    new ServiceActionContext(new DeleteFeedSubscriptionRequest((Long) values.get("EUREKA:FEEDSUBID"),
                            group), principal);
            deleteFeedSub.getExecutionStrategy().execute(deleteAC);
        }

        // Put the user in the values hash map so it's on equal footing for the strategies.
        values.put("EUREKA:USER", principal.getAccountId());

        // TODO BUG: context does not contain the right parameters for this execution strategy.
        // Perhaps a new request object needs to be created? Moving on for now.
        ServiceActionContext getFeedContext = new ServiceActionContext(values.get("EUREKA:FEEDURL"), principal);
        String title = (String) getTitleFromFeed.execute(getFeedContext);

        // Find or create the feed.
        GetFeedByUrlRequest request =
                new GetFeedByUrlRequest((Long) values.get("EUREKA:PLUGINID"), (String) values.get("EUREKA:FEEDURL"));
        Feed feed = getMapper.execute(request);
        feed.setTitle(title);

        // And now find or create the subscriber.
        FeedSubscriber feedSubscriber =
                getFeedSubscriberMapper.execute(new GetFeedSubscriberRequest(feed.getId(), getEntityId
                        .getEntityId(values), type, principal.getId()));

        // Add any non system key/value pairs to the feed subscribers conf settings.
        feedSubscriber.getConfSettings().clear();

        for (String key : values.keySet())
        {
            if (!key.contains("REQUIRED:") && !key.contains("EUREKA:"))
            {
                feedSubscriber.getConfSettings().put(key, values.get(key));
            }
        }

        ActivityDTO activity = new ActivityDTO();
        HashMap<String, String> props = new HashMap<String, String>();
        activity.setBaseObjectProperties(props);
        String content = "%EUREKA:ACTORNAME% configured the " + values.get("EUREKA:PLUGINTITLE") + " stream plugin";
        activity.getBaseObjectProperties().put("content", content);

        StreamEntityDTO destination = new StreamEntityDTO();
        if (type.equals(EntityType.PERSON))
        {
            destination.setUniqueIdentifier(principal.getAccountId());
        }
        else
        {
            destination.setUniqueIdentifier(group);
        }
View Full Code Here

            logger.info("Ignoring weekend stats");
            return null;
        }

        UsageMetricDTO umdto = (UsageMetricDTO) inActionContext.getActionContext().getParams();
        Principal principal = inActionContext.getActionContext().getPrincipal();
        Long streamScopeId = null;
        String uniqueKey = null;

        String streamJson = umdto.getMetricDetails();
        logger.info("Stream metric received: " + streamJson);

        if (umdto.isStreamView() && streamJson != null && streamJson.startsWith("{"))
        {
            // {"query":{"recipient":[{"type":"GROUP", "name":"woot"}], "sortBy":"date"}}
            try
            {
                JSONObject jsonObj = JSONObject.fromObject(streamJson);

                if (jsonObj.containsKey("query"))
                {
                    jsonObj = jsonObj.getJSONObject("query");
                    if (jsonObj.containsKey("recipient"))
                    {
                        JSONArray recipients = jsonObj.getJSONArray("recipient");
                        if (recipients.size() == 1)
                        {
                            jsonObj = recipients.getJSONObject(0);
                            if (jsonObj.containsKey("type") && jsonObj.containsKey("name"))
                            {
                                uniqueKey = jsonObj.getString("name");
                                if ("PERSON".equals(jsonObj.getString("type")))
                                {
                                    streamScopeId = personStreamScopeIdMapper.execute(uniqueKey);
                                    logger.debug("Found person stream scope id " + streamScopeId + " from account id: "
                                            + uniqueKey);
                                }
                                else if ("GROUP".equals(jsonObj.getString("type")))
                                {
                                    streamScopeId = groupStreamScopeIdMapper.execute(uniqueKey);
                                    logger.debug("Found group stream scope id " + streamScopeId + " from short name: "
                                            + uniqueKey);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                logger.info("Potentially invalid JSON: " + streamJson);
            }
        }

        UsageMetric um = new UsageMetric(principal.getId(), umdto.isPageView(), umdto.isStreamView(), streamScopeId,
                new Date());

        logger.trace("Registering metric for user: " + principal.getAccountId() + " StreamView:" + umdto.isStreamView()
                + " PageView:" + umdto.isPageView() + " MetricDetails: " + umdto.getMetricDetails());

        inActionContext.getUserActionRequests().add(
                new UserActionRequest("persistUserMetricAsyncAction", null, new PersistenceRequest<UsageMetric>(um)));
        return null;
View Full Code Here

     */
    public PluginAndFeedSubscriptionsResponse execute(final PrincipalActionContext context) throws ExecutionException
    {

        HashMap<String, Serializable> values = new HashMap<String, Serializable>();
        Principal principal = context.getPrincipal();
        values.put("EUREKA:USER", principal.getAccountId());
        values.put("EUREKA:GROUP", (String) context.getParams());

        List<PluginDefinition> plugins = getAllPluginsMapper.execute(new EmptyRequest());
        List<FeedSubscriber> feedSubs =
                getFeedSubsMapper.execute(new GetFeedSubscriberRequest(0L, getEntityId.getEntityId(values), type,
                        principal.getId()));
        for (FeedSubscriber feedSub : feedSubs)
        {
            feedSub.getFeed().getPlugin().getId();
            if (feedSub.getFeed().getLastUpdated() == null)
            {
View Full Code Here

        // get the request.
        GetCurrentUserFollowingStatusRequest inRequest = (GetCurrentUserFollowingStatusRequest) inActionContext
                .getParams();

        // get the user's account id.
        final Principal principal = inActionContext.getPrincipal();
        final String accountId = principal.getAccountId();
        final Long userId = principal.getId();

        // the followed entity's account id.
        String followedEntityId = inRequest.getFollowedEntityId();

        // the followed entity's entity type.
View Full Code Here

TOP

Related Classes of org.eurekastreams.commons.actions.context.Principal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.