001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thomas Roger <troger@nuxeo.com>
016 */
017
018package org.nuxeo.ecm.activity;
019
020import java.util.ArrayList;
021import java.util.Collections;
022import java.util.List;
023
024import org.nuxeo.common.xmap.annotation.XNode;
025import org.nuxeo.common.xmap.annotation.XNodeList;
026import org.nuxeo.common.xmap.annotation.XObject;
027
028/**
029 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
030 * @since 5.5
031 */
032@XObject("activityStream")
033public class ActivityStream {
034
035    @XNode("@name")
036    String name;
037
038    @XNode("verbs@append")
039    boolean appendVerbs;
040
041    @XNodeList(value = "verbs/verb", type = ArrayList.class, componentType = String.class)
042    List<String> verbs;
043
044    @XNode("relationshipKinds@append")
045    boolean appendRelationshipKinds;
046
047    @XNodeList(value = "relationshipKinds/relationshipKind", type = ArrayList.class, componentType = String.class)
048    List<String> relationshipKinds;
049
050    public String getName() {
051        return name;
052    }
053
054    public void setName(String name) {
055        this.name = name;
056    }
057
058    public boolean isAppendVerbs() {
059        return appendVerbs;
060    }
061
062    public void setAppendVerbs(boolean appendVerbs) {
063        this.appendVerbs = appendVerbs;
064    }
065
066    public List<String> getVerbs() {
067        if (verbs == null) {
068            return Collections.emptyList();
069        }
070        return verbs;
071    }
072
073    public void setVerbs(List<String> verbs) {
074        this.verbs = verbs;
075    }
076
077    public boolean isAppendRelationshipKinds() {
078        return appendRelationshipKinds;
079    }
080
081    public void setAppendRelationshipKinds(boolean appendRelationshipKinds) {
082        this.appendRelationshipKinds = appendRelationshipKinds;
083    }
084
085    public List<String> getRelationshipKinds() {
086        if (relationshipKinds == null) {
087            return Collections.emptyList();
088        }
089        return relationshipKinds;
090    }
091
092    public void setRelationshipKinds(List<String> relationshipKinds) {
093        this.relationshipKinds = relationshipKinds;
094    }
095
096    @Override
097    public ActivityStream clone() {
098        ActivityStream clone = new ActivityStream();
099        clone.setName(getName());
100        clone.setAppendVerbs(isAppendVerbs());
101        List<String> verbs = getVerbs();
102        if (verbs != null) {
103            List<String> newVerbs = new ArrayList<String>();
104            for (String verb : verbs) {
105                newVerbs.add(verb);
106            }
107            clone.setVerbs(newVerbs);
108        }
109        clone.setAppendRelationshipKinds(isAppendRelationshipKinds());
110        List<String> relationshipKinds = getRelationshipKinds();
111        if (relationshipKinds != null) {
112            List<String> newRelationshipKinds = new ArrayList<String>();
113            for (String kind : relationshipKinds) {
114                newRelationshipKinds.add(kind);
115            }
116            clone.setRelationshipKinds(newRelationshipKinds);
117        }
118        return clone;
119    }
120}