001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Thomas Roger <troger@nuxeo.com>
018 */
019
020package org.nuxeo.ecm.activity;
021
022import java.util.Date;
023
024/**
025 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
026 * @since 5.5
027 */
028public final class ActivityBuilder {
029
030    private String actor;
031
032    private String displayActor;
033
034    private String verb;
035
036    private String object;
037
038    private String displayObject;
039
040    private String target;
041
042    private String displayTarget;
043
044    private String context;
045
046    private Date publishedDate;
047
048    public ActivityBuilder() {
049        // Empty constructor
050    }
051
052    public ActivityBuilder(Activity fromActivity) {
053        actor(fromActivity.getActor());
054        context(fromActivity.getContext());
055        displayActor(fromActivity.getDisplayActor());
056        displayTarget(fromActivity.getDisplayTarget());
057        displayObject(fromActivity.getDisplayObject());
058        target(fromActivity.getTarget());
059        verb(fromActivity.getVerb());
060        object(fromActivity.getObject());
061    }
062
063    public ActivityBuilder actor(String actor) {
064        this.actor = actor;
065        return this;
066    }
067
068    public ActivityBuilder displayActor(String displayActor) {
069        this.displayActor = displayActor;
070        return this;
071    }
072
073    public ActivityBuilder verb(String verb) {
074        this.verb = verb;
075        return this;
076    }
077
078    public ActivityBuilder object(String object) {
079        this.object = object;
080        return this;
081    }
082
083    public ActivityBuilder displayObject(String displayObject) {
084        this.displayObject = displayObject;
085        return this;
086    }
087
088    public ActivityBuilder target(String target) {
089        this.target = target;
090        return this;
091    }
092
093    public ActivityBuilder displayTarget(String displayTarget) {
094        this.displayTarget = displayTarget;
095        return this;
096    }
097
098    public ActivityBuilder context(String context) {
099        this.context = context;
100        return this;
101    }
102
103    public ActivityBuilder publishedDate(Date publishedDate) {
104        this.publishedDate = publishedDate;
105        return this;
106    }
107
108    public Activity build() {
109        Activity activity = new ActivityImpl();
110        activity.setActor(actor);
111        activity.setDisplayActor(displayActor);
112        activity.setObject(object);
113        activity.setDisplayObject(displayObject);
114        activity.setTarget(target);
115        activity.setDisplayTarget(displayTarget);
116        activity.setContext(context);
117        activity.setVerb(verb);
118        Date date = publishedDate != null ? publishedDate : new Date();
119        activity.setPublishedDate(date);
120        activity.setLastUpdatedDate(date);
121        return activity;
122    }
123
124}