<commit_before>package cn.updev.Events.Group;

/**
 * Created by hypo on 15-11-17.
 */
public class EventGroupFactory {
}<commit_msg>add event group factory<commit_after>package cn.updev.Events.Group;

import cn.updev.Database.HibernateSessionFactory;
import cn.updev.Events.Static.EventGroupWeight;
import cn.updev.Events.Static.IEvent;
import cn.updev.Events.Static.ITeamEvents;
import cn.updev.Events.Static.IUserEvents;
import org.hibernate.Session;
import org.hibernate.Transaction;

import java.util.Date;
import java.util.List;

/**
 * Created by hypo on 15-11-17.
 */
public class EventGroupFactory {

    private Date groupExpect;
    private Integer groupId;
    private String groupTitle;
    private List<IEvent> list;
    private Integer ownerId;
    private EventGroupWeight weight;

    public EventGroupFactory(Date groupExpect, String groupTitle, List<IEvent> list, Integer ownerId, EventGroupWeight weight) {
        this.groupExpect = groupExpect;
        this.groupTitle = groupTitle;
        this.list = list;
        this.ownerId = ownerId;
        this.weight = weight;
    }

    private Date getGroupExpect() {
        return groupExpect;
    }

    private Integer getGroupId() {
        return groupId;
    }

    private String getGroupTitle() {
        if(groupTitle.length() > 20){
            this.groupTitle = groupTitle.substring(0,20);
        }
        return groupTitle;
    }

    private List<IEvent> getList() {
        return list;
    }

    private Integer getOwnerId() {
        return ownerId;
    }

    private EventGroupWeight getWeight() {
        return weight;
    }

    private void save(){

        Session session = HibernateSessionFactory.currentSession();
        Transaction transaction = session.beginTransaction();

        for(IEvent event : getList()){
            EventsGroup eventsGroup = new EventsGroup(event.getEventId(), event.getGroupId(), event.getDoerId());
            session.save(eventsGroup);
        }

        EventGroupInfo groupInfo = new EventGroupInfo(getGroupExpect(), getGroupTitle(), getOwnerId(), getWeight());

        transaction.commit();
        HibernateSessionFactory.closeSession();

        this.groupId = groupInfo.getGroupId();
    }

    public IUserEvents getUserEvents(){

        IUserEvents events = new UserEventGroup(getGroupExpect(), getGroupId(), getGroupTitle(),
                getList(), getOwnerId(), getWeight());

        save();

        return  events;
    }

    public ITeamEvents getTeamEvents(){

        ITeamEvents events = new TeamEventGroup(getGroupExpect(), getGroupId(), getGroupTitle(),
                getList(), getOwnerId(), getWeight());

        save();

        return  events;
    }
}
{'fraction_non_alphanumeric': 0.10283818650939919, 'fraction_numerical': 0.006266126059712496, 'mean_word_length': 2.8882521489971347, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '971711', 'n_tokens_mistral': 783, 'n_tokens_neox': 737, 'n_words': 174}