private JCRDataStorage getJCRDataStorage() throws Exception {
   if (this.storage_ == null) {
     this.storage_ =
         new JCRDataStorage(
             CommonsUtils.getService(NodeHierarchyCreator.class),
             CommonsUtils.getService(RepositoryService.class),
             CommonsUtils.getService(CacheService.class));
   }
   return this.storage_;
 }
  public void test_2_GetUsersSetting() throws Exception {
    runUpgrade();
    //
    userSettingService.save(
        createUserSetting(
            "root", Arrays.asList("1", "2"), Arrays.asList("3", "4"), Arrays.asList("5", "6")));
    userSettingService.save(
        createUserSetting(
            "john", Arrays.asList("4", "5"), Arrays.asList("2", "8"), Arrays.asList("6", "7")));
    userSettingService.save(
        createUserSetting(
            "mary", Arrays.asList("32", "5"), Arrays.asList("4", "6"), Arrays.asList("1", "9")));
    userSettingService.save(
        createUserSetting(
            "demo", Arrays.asList("2"), Arrays.asList("3", "9"), Arrays.asList("2", "7")));
    //
    List<String> list = userSettingService.getUserSettingByPlugin("2");
    assertEquals(3, list.size()); // root, john, demo

    // disable user "root"
    CommonsUtils.getService(OrganizationService.class)
        .getUserHandler()
        .setEnabled("root", false, true);
    list = userSettingService.getUserSettingByPlugin("2");
    assertEquals(2, list.size()); // john, demo
  }
 private void saveToNewDataFormat(ExoSocialActivity activity) {
   try {
     final JSONObject jsonObject = new JSONObject(activity.getTitle());
     final String docActivityTitle =
         "<a href=\"${" + UIDocActivity.DOCLINK + "}\">" + "${" + UIDocActivity.DOCNAME + "}</a>";
     //
     activity.setTitle(docActivityTitle);
     //
     Map<String, String> activityParams = new HashMap<String, String>();
     activityParams.put(UIDocActivity.DOCNAME, jsonObject.getString(UIDocActivity.DOCNAME));
     activityParams.put(UIDocActivity.DOCLINK, jsonObject.getString(UIDocActivity.DOCLINK));
     activityParams.put(UIDocActivity.DOCPATH, jsonObject.getString(UIDocActivity.DOCPATH));
     activityParams.put(UIDocActivity.REPOSITORY, jsonObject.getString(UIDocActivity.REPOSITORY));
     activityParams.put(UIDocActivity.WORKSPACE, jsonObject.getString(UIDocActivity.WORKSPACE));
     activityParams.put(UIDocActivity.MESSAGE, jsonObject.getString(UIDocActivity.MESSAGE));
     activity.setTemplateParams(activityParams);
     //
     ActivityManager activityManager = CommonsUtils.getService(ActivityManager.class);
     //
     activityManager.saveActivityNoReturn(activity);
     activity = activityManager.getActivity(activity.getId());
   } catch (JSONException je) {
     LOG.error("Error with activity's title data");
   } catch (ActivityStorageException ase) {
     LOG.error("Could not save new data format for document activity.", ase);
   } catch (Exception e) {
     LOG.error("Unknown error  to save document activity.", e);
   }
 }
  public void testDisabledUser() throws Exception {
    User u =
        CommonsUtils.getService(OrganizationService.class)
            .getUserHandler()
            .createUserInstance("binh");
    u.setEmail("email@test");
    u.setFirstName("first");
    u.setLastName("last");
    u.setPassword("pwdADDSomeSaltToBeCompliantWithSomeIS00");
    CommonsUtils.getService(OrganizationService.class).getUserHandler().createUser(u, true);

    userSettingService.save(createUserSetting("binh", null, null, null));
    UserSetting userSetting = userSettingService.get("binh");
    assertTrue(userSetting.isChannelActive(MailChannel.ID));
    assertTrue(userSetting.isEnabled());

    // disable user "root"
    CommonsUtils.getService(OrganizationService.class)
        .getUserHandler()
        .setEnabled("binh", false, true);
    userSetting = userSettingService.get("binh");
    assertTrue(userSetting.isChannelActive(MailChannel.ID));
    assertFalse(userSetting.isEnabled());

    // enable user "root" but not change the active channel status
    CommonsUtils.getService(OrganizationService.class)
        .getUserHandler()
        .setEnabled("binh", true, true);
    userSetting = userSettingService.get("binh");
    assertTrue(userSetting.isChannelActive(MailChannel.ID));
    assertTrue(userSetting.isEnabled());

    CommonsUtils.getService(OrganizationService.class).getUserHandler().removeUser("binh", false);
    assertNull(
        CommonsUtils.getService(OrganizationService.class).getUserHandler().findUserByName("binh"));
  }
 @Override
 public void moveQuestions(List<String> questions, String catId) {
   ActivityManager activityM = CommonsUtils.getService(ActivityManager.class);
   FAQService faqS = CommonsUtils.getService(FAQService.class);
   IdentityManager identityM = CommonsUtils.getService(IdentityManager.class);
   for (String questionId : questions) {
     try {
       Question question = faqS.getQuestionById(questionId);
       String activityId = faqS.getActivityIdForQuestion(question.getPath());
       Identity streamOwner = null;
       Map<String, String> templateParams =
           updateTemplateParams(
               new HashMap<String, String>(),
               question.getId(),
               ActivityUtils.getQuestionRate(question),
               ActivityUtils.getNbOfAnswers(question),
               ActivityUtils.getNbOfComments(question),
               question.getLanguage(),
               question.getLink(),
               Utils.getQuestionPoint(question));
       String questionDetail = ActivityUtils.processContent(question.getDetail());
       Identity spaceIdentity = getSpaceIdentity(catId);
       if (spaceIdentity != null) {
         streamOwner = spaceIdentity;
         templateParams.put(SPACE_GROUP_ID, ActivityUtils.getSpaceGroupId(catId));
       }
       if (activityId != null) {
         ExoSocialActivity oldActivity = activityM.getActivity(activityId);
         activityM.deleteActivity(oldActivity);
         Identity userIdentity =
             identityM.getOrCreateIdentity(
                 OrganizationIdentityProvider.NAME, question.getAuthor(), false);
         ExoSocialActivity activity =
             newActivity(userIdentity, question.getQuestion(), questionDetail, templateParams);
         streamOwner = streamOwner != null ? streamOwner : userIdentity;
         activityM.saveActivityNoReturn(streamOwner, activity);
         faqS.saveActivityIdForQuestion(questionId, activity.getId());
         for (Answer answer : question.getAnswers()) {
           ExoSocialActivity comment = createCommentForAnswer(userIdentity, answer);
           String answerContent = ActivityUtils.processContent(answer.getResponses());
           comment.setTitle("Answer has been submitted: " + answerContent);
           I18NActivityUtils.addResourceKey(comment, "answer-add", answerContent);
           updateActivity(activity, question);
           activityM.updateActivity(activity);
           updateCommentTemplateParms(comment, answer.getId());
           activityM.saveComment(activity, comment);
           faqS.saveActivityIdForAnswer(questionId, answer, comment.getId());
         }
         for (Comment cm : question.getComments()) {
           String message = ActivityUtils.processContent(cm.getComments());
           ExoSocialActivityImpl comment = new ExoSocialActivityImpl();
           Map<String, String> commentTemplateParams = new HashMap<String, String>();
           commentTemplateParams.put(LINK_KEY, cm.getId());
           comment.setTemplateParams(commentTemplateParams);
           comment.setTitle(message);
           comment.setUserId(userIdentity.getId());
           updateActivity(activity, question);
           activityM.updateActivity(activity);
           activityM.saveComment(activity, comment);
           faqS.saveActivityIdForComment(
               questionId, cm.getId(), question.getLanguage(), comment.getId());
         }
       }
     } catch (Exception e) {
       LOG.error("Failed to move questions " + e.getMessage());
     }
   }
 }
 private void reindex(SpaceLifeCycleEvent event) {
   IndexingService indexingService = CommonsUtils.getService(IndexingService.class);
   indexingService.reindex(SpaceIndexingServiceConnector.TYPE, event.getSpace().getId());
 }
 @Override
 public void spaceRemoved(SpaceLifeCycleEvent event) {
   IndexingService indexingService = CommonsUtils.getService(IndexingService.class);
   indexingService.unindex(SpaceIndexingServiceConnector.TYPE, event.getSpace().getId());
   LOG.debug("Handle un-index for removing space !");
 }
 @Override
 public void spaceCreated(SpaceLifeCycleEvent event) {
   IndexingService indexingService = CommonsUtils.getService(IndexingService.class);
   indexingService.index(SpaceIndexingServiceConnector.TYPE, event.getSpace().getId());
   LOG.debug("Handled create index for newly created space!");
 }