@Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    SocialActivitySetting newSocialActivitySetting = _persistence.create(pk);

    newSocialActivitySetting.setGroupId(RandomTestUtil.nextLong());

    newSocialActivitySetting.setCompanyId(RandomTestUtil.nextLong());

    newSocialActivitySetting.setClassNameId(RandomTestUtil.nextLong());

    newSocialActivitySetting.setActivityType(RandomTestUtil.nextInt());

    newSocialActivitySetting.setName(RandomTestUtil.randomString());

    newSocialActivitySetting.setValue(RandomTestUtil.randomString());

    _persistence.update(newSocialActivitySetting);

    SocialActivitySetting existingSocialActivitySetting =
        _persistence.findByPrimaryKey(newSocialActivitySetting.getPrimaryKey());

    Assert.assertEquals(
        existingSocialActivitySetting.getActivitySettingId(),
        newSocialActivitySetting.getActivitySettingId());
    Assert.assertEquals(
        existingSocialActivitySetting.getGroupId(), newSocialActivitySetting.getGroupId());
    Assert.assertEquals(
        existingSocialActivitySetting.getCompanyId(), newSocialActivitySetting.getCompanyId());
    Assert.assertEquals(
        existingSocialActivitySetting.getClassNameId(), newSocialActivitySetting.getClassNameId());
    Assert.assertEquals(
        existingSocialActivitySetting.getActivityType(),
        newSocialActivitySetting.getActivityType());
    Assert.assertEquals(
        existingSocialActivitySetting.getName(), newSocialActivitySetting.getName());
    Assert.assertEquals(
        existingSocialActivitySetting.getValue(), newSocialActivitySetting.getValue());
  }
示例#2
0
  protected Map<String, Boolean> getActivitySettingsMap(ThemeDisplay themeDisplay)
      throws Exception {

    Map<String, Boolean> activitySettingsMap = new LinkedHashMap<>();

    List<SocialActivitySetting> activitySettings =
        SocialActivitySettingServiceUtil.getActivitySettings(
            themeDisplay.getSiteGroupIdOrLiveGroupId());

    String[] modelNames = SocialConfigurationUtil.getActivityModelNames();

    Comparator<String> comparator = new ModelResourceComparator(themeDisplay.getLocale());

    Arrays.sort(modelNames, comparator);

    for (String modelName : modelNames) {
      List<SocialActivityDefinition> activityDefinitions =
          SocialActivitySettingServiceUtil.getActivityDefinitions(
              themeDisplay.getScopeGroupId(), modelName);

      for (SocialActivityDefinition activityDefinition : activityDefinitions) {

        if (activityDefinition.isCountersEnabled()) {
          activitySettingsMap.put(modelName, false);

          break;
        }
      }
    }

    for (SocialActivitySetting activitySetting : activitySettings) {
      String name = activitySetting.getName();

      if (name.equals("enabled")
          && activitySettingsMap.containsKey(activitySetting.getClassName())) {

        activitySettingsMap.put(
            activitySetting.getClassName(), GetterUtil.getBoolean(activitySetting.getValue()));
      }
    }

    return activitySettingsMap;
  }