package com.ext.utils;

import com.liferay.portal.service.ClassNameLocalServiceUtil;
import com.liferay.portlet.social.model.SocialActivity;

import java.util.*;

/**
 * @author pdeboer
 *         First created on 30/10/13 at 22:25
 */
public class SocialActivityMessageLimitationHelper {
    Set<Long> limitedClassesIds = new HashSet<>();

    public SocialActivityMessageLimitationHelper(Class... limitedClasses) {
        for (Class c : limitedClasses) {
            long id = ClassNameLocalServiceUtil.getClassNameId(c);
            limitedClassesIds.add(id);
        }
    }

    public List<SocialActivity> process(List data) {
        Map<String,SocialActivity> ret = new HashMap<>(data.size()*2);
        for (Object o : data) {
            SocialActivity sa  = (SocialActivity) o;
            ret.put(getKey(sa),sa);
        }
        return new LinkedList<>(ret.values());
    }

    private String getKey(SocialActivity sa) {
        if (limitedClassesIds.contains(sa.getClassNameId())) {
            return ""+sa.getClassNameId();
        }
        else{
            return "0_" + sa.getActivityId();
        }
    }
}

@@ -1016,11 +1016,8 @@
 urn 
-%22%22+
 sa.g
@@ -1027,24 +1027,44 @@
 lassNameId()
++%22_%22+sa.getClassPK()
 ;%0A        %7D%0A

add class pk to only cluster the same proposal