Example usage for org.apache.commons.lang ArrayUtils add

List of usage examples for org.apache.commons.lang ArrayUtils add

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils add.

Prototype

public static short[] add(short[] array, short element) 

Source Link

Document

Copies the given array and adds the given element at the end of the new array.

Usage

From source file:org.exoplatform.social.core.mysql.storage.ActivityMysqlStorageImpl.java

private String[] remove(String[] mentionerIds, String mentionStr, List<String> addedOrRemovedIds) {
    for (String mentionerId : mentionerIds) {
        if (mentionerId.indexOf(mentionStr) != -1) {
            int numStored = Integer.parseInt(mentionerId.split(MENTION_CHAR)[1]) - 1;

            if (numStored == 0) {
                addedOrRemovedIds.add(mentionStr.replace(MENTION_CHAR, ""));
                return (String[]) ArrayUtils.removeElement(mentionerIds, mentionerId);
            }/*from  w  ww  . j av  a 2s .  co  m*/

            mentionerIds = (String[]) ArrayUtils.removeElement(mentionerIds, mentionerId);
            mentionerIds = (String[]) ArrayUtils.add(mentionerIds, mentionStr + numStored);
            break;
        }
    }
    return mentionerIds;
}

From source file:org.exoplatform.social.core.mysql.storage.ActivityMysqlStorageImpl.java

/**
 * Processes Mentioners who has been mentioned via the Activity.
 * //from  w w  w  . j  a  v  a2  s.c  om
 * @param title
 */
private String[] processMentions(String title) {
    String[] mentionerIds = new String[0];
    if (title == null || title.length() == 0) {
        return ArrayUtils.EMPTY_STRING_ARRAY;
    }

    Matcher matcher = MENTION_PATTERN.matcher(title);
    while (matcher.find()) {
        String remoteId = matcher.group().substring(1);
        if (!USER_NAME_VALIDATOR_REGEX.matcher(remoteId).matches()) {
            continue;
        }
        Identity identity = identityStorage.findIdentity(OrganizationIdentityProvider.NAME, remoteId);
        // if not the right mention then ignore
        if (identity != null) {
            mentionerIds = (String[]) ArrayUtils.add(mentionerIds, identity.getId());
        }
    }
    return mentionerIds;
}

From source file:org.exoplatform.social.core.mysql.storage.ActivityMysqlStorageImpl.java

private String getFeedActivitySQLQuery(Identity ownerIdentity, long time, boolean isNewer, int limit,
        int offset, boolean isCount) {
    List<Identity> relationships = relationshipStorage.getConnections(ownerIdentity);
    Set<String> relationshipIds = new HashSet<String>();
    for (Identity identity : relationships) {
        relationshipIds.add(identity.getId());
    }/*from ww w  .  j  a  v a  2 s.  com*/
    // get spaces where user is member
    List<Space> spaces = spaceStorage.getMemberSpaces(ownerIdentity.getRemoteId());
    String[] spaceIds = new String[0];
    for (Space space : spaces) {
        spaceIds = (String[]) ArrayUtils.add(spaceIds, space.getPrettyName());
    }

    StringBuilder sql = new StringBuilder();
    sql.append(isCount ? "select count(distinct activityId)" : "select distinct activityId")
            .append(" from stream_item where ").append(" ((viewerId ='").append(ownerIdentity.getId())
            .append("'");

    if (CollectionUtils.isNotEmpty(spaces)) {
        sql.append(" or ownerId in ('").append(StringUtils.join(spaceIds, "','")).append("') ");
    }

    if (CollectionUtils.isNotEmpty(relationships)) {
        sql.append(" or (posterId in ('").append(StringUtils.join(relationshipIds, "','")).append("') ")
                .append("and not viewerType like '%SPACE%')");
    }
    sql.append(") and hidable='0'").append(buildSQLQueryByTime(TIME, time, isNewer)).append(")");
    if (!isCount) {
        sql.append(" order by time desc").append(limit > 0 ? " LIMIT " + limit : "")
                .append(offset > 0 ? " OFFSET " + offset : "");
    }
    //
    return sql.toString();
}

From source file:org.exoplatform.social.core.mysql.storage.ActivityMysqlStorageImpl.java

private String getUserSpaceActivitiesQuery(Identity ownerIdentity, long time, boolean isNewer, int offset,
        int limit, boolean isCount) {
    List<Space> spaces = spaceStorage.getMemberSpaces(ownerIdentity.getRemoteId());
    String[] spaceIds = new String[0];
    for (Space space : spaces) {
        spaceIds = (String[]) ArrayUtils.add(spaceIds, space.getPrettyName());
    }//from w w  w  .j  a  va 2 s. com

    StringBuilder getActivitySQL = new StringBuilder();
    getActivitySQL.append(isCount ? "select count(distinct activityId)" : "select distinct activityId")
            .append(" from stream_item where (ownerId in ('").append(StringUtils.join(spaceIds, "','"))
            .append("') and hidable='0'").append(buildSQLQueryByTime(TIME, time, isNewer)).append(")");
    if (!isCount) {
        getActivitySQL.append(" order by time desc").append(limit > 0 ? " LIMIT " + limit : "")
                .append(offset > 0 ? " OFFSET " + offset : "");
    }

    return getActivitySQL.toString();
}

From source file:org.exoplatform.social.core.space.impl.SpaceServiceImpl.java

/**
 * {@inheritDoc}//from   w ww  . j  av a2s.  co m
 */
@SuppressWarnings("deprecation")
public Space createSpace(Space space, String creator, String invitedGroupId) {
    //
    String[] managers = new String[] { creator };
    String[] members = new String[] { creator };
    space.setManagers(managers);
    space.setMembers(members);

    // Creates new space by creating new group
    String groupId = null;
    try {
        groupId = SpaceUtils.createGroup(space.getDisplayName(), space.getPrettyName(), creator);
    } catch (SpaceException e) {
        LOG.error("Error while creating group", e);
    }

    if (invitedGroupId != null) { // Invites user in group join to new created
                                  // space.
                                  // Gets users in group and then invites user to join into space.
        OrganizationService org = getOrgService();
        try {

            // Cannot use due to http://jira.exoplatform.org/browse/EXOGTN-173
            //ListAccess<User> groupMembersAccess = org.getUserHandler().findUsersByGroup(invitedGroupId);
            //User [] users = groupMembersAccess.load(0, groupMembersAccess.getSize());
            PageList<User> groupMembersAccess = org.getUserHandler().findUsersByGroup(invitedGroupId);
            List<User> users = groupMembersAccess.getAll();

            for (User user : users) {
                String userId = user.getUserName();
                if (!userId.equals(creator)) {
                    String[] invitedUsers = space.getInvitedUsers();
                    if (userId.equals(getUserACL().getSuperUser())) {
                        members = space.getMembers();
                        if (!ArrayUtils.contains(members, userId)) {
                            members = (String[]) ArrayUtils.add(members, userId);
                            space.setMembers(members);
                        }
                    } else if (!ArrayUtils.contains(invitedUsers, userId)) {
                        invitedUsers = (String[]) ArrayUtils.add(invitedUsers, userId);
                        space.setInvitedUsers(invitedUsers);
                    }
                }
            }
        } catch (Exception e) {
            LOG.error("Failed to invite users from group " + invitedGroupId, e);
        }
    }

    String prettyName = groupId.split("/")[2];

    if (!prettyName.equals(space.getPrettyName())) {
        //work around for SOC-2366
        space.setPrettyName(groupId.split("/")[2]);
    }

    space.setGroupId(groupId);
    space.setUrl(space.getPrettyName());

    saveSpace(space, true);
    spaceLifeCycle.spaceCreated(space, creator);

    try {
        SpaceApplicationHandler spaceApplicationHandler = getSpaceApplicationHandler(space);
        spaceApplicationHandler.initApps(space, getSpaceApplicationConfigPlugin());
        for (SpaceApplication spaceApplication : getSpaceApplicationConfigPlugin().getSpaceApplicationList()) {
            setApp(space, spaceApplication.getPortletName(), spaceApplication.getAppTitle(),
                    spaceApplication.isRemovable(), Space.ACTIVE_STATUS);
        }
    } catch (Exception e) {
        LOG.warn("Failed to init apps", e);
    }

    saveSpace(space, false);

    return space;
}

From source file:org.exoplatform.social.core.space.impl.SpaceServiceImpl.java

/**
 * {@inheritDoc}//from   w w  w. ja va  2  s . c  o m
 */
public void addMember(Space space, String userId) {
    String[] members = space.getMembers();
    space = this.removeInvited(space, userId);
    space = this.removePending(space, userId);
    if (!ArrayUtils.contains(members, userId)) {
        members = (String[]) ArrayUtils.add(members, userId);
        space.setMembers(members);
        this.updateSpace(space);
        SpaceUtils.addUserToGroupWithMemberMembership(userId, space.getGroupId());
        spaceLifeCycle.memberJoined(space, userId);
    }
}

From source file:org.exoplatform.social.core.space.impl.SpaceServiceImpl.java

/**
 * {@inheritDoc}//  w  w w .  j  a va2s .  co m
 */
private Space addPending(Space space, String userId) {
    String[] pendingUsers = space.getPendingUsers();
    if (!ArrayUtils.contains(pendingUsers, userId)) {
        pendingUsers = (String[]) ArrayUtils.add(pendingUsers, userId);
        space.setPendingUsers(pendingUsers);
    }
    return space;
}

From source file:org.exoplatform.social.core.space.impl.SpaceServiceImpl.java

/**
 * {@inheritDoc}/*from  w ww . j  a  va 2s.com*/
 */
private Space addInvited(Space space, String userId) {
    String[] invitedUsers = space.getInvitedUsers();
    if (!ArrayUtils.contains(invitedUsers, userId)) {
        invitedUsers = (String[]) ArrayUtils.add(invitedUsers, userId);
        space.setInvitedUsers(invitedUsers);
    }
    return space;
}

From source file:org.exoplatform.social.core.space.impl.SpaceServiceImpl.java

/**
 * {@inheritDoc}/*w ww. j a va2  s  .c  o  m*/
 */
public void setManager(Space space, String userId, boolean isManager) {
    String[] managers = space.getManagers();
    if (isManager) {
        if (!ArrayUtils.contains(managers, userId)) {
            managers = (String[]) ArrayUtils.add(managers, userId);
            space.setManagers(managers);
            this.updateSpace(space);
            SpaceUtils.addUserToGroupWithManagerMembership(userId, space.getGroupId());
            spaceLifeCycle.grantedLead(space, userId);
        }
    } else {
        if (ArrayUtils.contains(managers, userId)) {
            managers = (String[]) ArrayUtils.removeElement(managers, userId);
            space.setManagers(managers);
            this.updateSpace(space);
            SpaceUtils.removeUserFromGroupWithManagerMembership(userId, space.getGroupId());
            Space updatedSpace = getSpaceById(space.getId());
            if (isMember(updatedSpace, userId)) {
                spaceLifeCycle.revokedLead(space, userId);
            }
        }
    }
}

From source file:org.exoplatform.social.core.storage.cache.CachedActivityStorageTestCase.java

@MaxQueryNumber(926)
public void testUpdateActivity() throws Exception {
    ExoSocialActivity activity = new ExoSocialActivityImpl();
    activity.setTitle("hello");
    activity.setUserId(identity.getId());
    activityStorage.saveActivity(identity, activity);

    ///* w  w w. j  a  v  a 2 s .  com*/
    assertEquals(1, cacheService.getActivityCache().getCacheSize());
    assertEquals(0, cacheService.getActivitiesCache().getCacheSize());

    //
    activityStorage.getActivityFeed(identity, 0, 20);

    //
    assertEquals(1, cacheService.getActivityCache().getCacheSize());
    assertEquals(1, cacheService.getActivitiesCache().getCacheSize());

    //
    List<ExoSocialActivity> idActivities = activityStorage.getUserActivities(identity, 0, 5);
    assertEquals(1, idActivities.size());

    List<ExoSocialActivity> id2Activities = activityStorage.getUserActivities(identity2, 0, 5);
    assertEquals(0, id2Activities.size());

    // identity2 like activity of identity1
    ExoSocialActivity gotActivity = activityStorage.getUserActivities(identity, 0, 5).get(0);
    String[] likeIdentityIds = gotActivity.getLikeIdentityIds();
    likeIdentityIds = (String[]) ArrayUtils.add(likeIdentityIds, identity2.getId());
    gotActivity.setLikeIdentityIds(likeIdentityIds);
    activityStorage.updateActivity(gotActivity);

    assertEquals(0, cacheService.getActivityCache().getCacheSize());
    assertEquals(0, cacheService.getActivitiesCache().getCacheSize());

    id2Activities = activityStorage.getUserActivities(identity2, 0, 5);
    assertEquals(1, id2Activities.size());

    assertEquals(1, cacheService.getActivityCache().getCacheSize());
    assertEquals(1, cacheService.getActivitiesCache().getCacheSize());

    //
    activityStorage.deleteActivity(activity.getId());
}