Exemple #1
0
  /**
   * SpaceServiceImpl constructor Initialize <tt>org.exoplatform.social.space.impl.JCRStorage</tt>
   *
   * @param params
   * @throws Exception
   */
  @SuppressWarnings("unchecked")
  public SpaceServiceImpl(
      InitParams params, SpaceStorage spaceStorage, IdentityStorage identityStorage)
      throws Exception {

    this.spaceStorage = spaceStorage;
    this.identityStorage = identityStorage;

    // backward compatible
    if (params != null) {
      LOG.warn(
          "The SpaceService configuration you attempt to use is deprecated, please update it by"
              + "using external-component-plugins configuration");
      spaceApplicationConfigPlugin = new SpaceApplicationConfigPlugin();
      Iterator<?> it = params.getValuesParamIterator();

      while (it.hasNext()) {
        ValuesParam param = (ValuesParam) it.next();
        String name = param.getName();
        if (name.endsWith("homeNodeApp")) {
          String homeNodeApp = param.getValue();
          SpaceApplication spaceHomeApplication = new SpaceApplication();
          spaceHomeApplication.setPortletName(homeNodeApp);
          spaceHomeApplication.setAppTitle(homeNodeApp);
          spaceHomeApplication.setIcon("SpaceHomeIcon");
          spaceApplicationConfigPlugin.setHomeApplication(spaceHomeApplication);
        }
        if (name.endsWith("apps")) {
          List<String> apps = param.getValues();
          for (String app : apps) {
            String[] splitedString = app.trim().split(":");
            String appName;
            boolean isRemovable;
            if (splitedString.length >= 2) {
              appName = splitedString[0];
              isRemovable = Boolean.getBoolean(splitedString[1]);
            } else { // suppose app is just the name
              appName = app;
              isRemovable = false;
            }
            SpaceApplication spaceApplication = new SpaceApplication();
            spaceApplication.setPortletName(appName);
            spaceApplication.isRemovable(isRemovable);

            spaceApplicationConfigPlugin.addToSpaceApplicationList(spaceApplication);
          }
        }
      }
    }
  }
Exemple #2
0
  /** {@inheritDoc} */
  @SuppressWarnings("deprecation")
  public Space createSpace(Space space, String creator, String invitedGroupId) {
    // Creates new space by creating new group
    String groupId = null;
    try {
      groupId = SpaceUtils.createGroup(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 (!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]);
    }

    String[] managers = new String[] {creator};
    String[] members = new String[] {creator};
    space.setManagers(managers);
    space.setMembers(members);
    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;
  }