BrightSide Workbench Full Report + Source Code
elephant-plugins/src/main/java/org/turro/plugin/command/CalendarPlugin.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.plugin.command;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Date;
24 import java.util.HashMap;
25 import java.util.Map;
26 import org.turro.command.Command;
27 import org.turro.command.Context;
28 import org.turro.elephant.context.Application;
29 import org.turro.plugin.calendar.ICalendarEvent;
30 import org.turro.plugin.contacts.IContact;
31 
36 public abstract class CalendarPlugin implements IPlugin, Command {
37 
38  protected Map<String, Object> params;
39  protected Collection<ICalendarEvent> result;
40 
41  @Override
42  public String getName() {
43  return "Calendar";
44  }
45 
46  @Override
47  public boolean stopsPropagating() {
48  return false;
49  }
50 
51  @Override
52  public void setParams(Object params) {
53  this.params = (Map<String, Object>) params;
54  }
55 
56  public IContact getContact() {
57  return (IContact) params.get("contact");
58  }
59 
60  public Date getFrom() {
61  return (Date) params.get("from");
62  }
63 
64  public Date getTo() {
65  return (Date) params.get("to");
66  }
67 
68  @Override
69  public Object execute(Context context) {
70 // if(getName().equals(context.get(CommandFactory.COMMAND_PARS))) {
71 // setParams(context.get(CommandFactory.DATA));
72 // result = (Collection<ICalendarEvent>) context.get(CommandFactory.RESULT);
73 // executePlugin(context);
74 // context.put(CommandFactory.RESULT, result);
75 // if(stopsPropagating()) {
76 // return PROCESSING_COMPLETE;
77 // }
78 // }
79 // return CONTINUE_PROCESSING;
80  return null;
81  };
82 
83  protected void addToResult(Object data) {
84  if(result == null) {
85  result = new ArrayList<>();
86  }
87  if(data instanceof ICalendarEvent) {
88  result.add((ICalendarEvent) data);
89  }
90  }
91 
92  protected abstract void executePlugin(Context context) throws Exception;
93 
94  public static Collection<ICalendarEvent> getCalendarFor(Application app, IContact contact, Date from, Date to) {
95 // Map<String, Object> params = new HashMap<String, Object>();
96 // params.put("contact", contact);
97 // params.put("from", from);
98 // params.put("to", to);
99 // return (Collection<ICalendarEvent>) CommandFactory
100 // .executePlugins(app, params, "Calendar");
101  return null;
102  }
103 
104 }
105 
static Collection< ICalendarEvent > getCalendarFor(Application app, IContact contact, Date from, Date to)
abstract void executePlugin(Context context)