This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jtimer. See http://git.chorem.org/jtimer.git commit fb6fa54f22c60cc4aa0b6f83051c678d741b8e6f Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 11:09:57 2016 +0100 fixes #1323: Remove xmlrpc web service layer --- .gitignore | 1 + pom.xml | 30 - src/main/java/org/chorem/jtimer/JTimer.java | 14 +- src/main/java/org/chorem/jtimer/JTimerConfig.java | 25 +- src/main/java/org/chorem/jtimer/JTimerFactory.java | 60 +- .../java/org/chorem/jtimer/data/TimerCore.java | 18 +- .../ui/ws/SwingConnectionInformationHandler.java | 357 ------- .../java/org/chorem/jtimer/ui/ws/package-info.java | 25 - .../chorem/jtimer/ws/ConnectionDataHandler.java | 48 - .../org/chorem/jtimer/ws/ProjectManagement.java | 141 --- .../jtimer/ws/exception/WebServiceException.java | 56 -- .../chorem/jtimer/ws/exception/package-info.java | 25 - .../java/org/chorem/jtimer/ws/package-info.java | 25 - .../jtimer/ws/xmlrpc/AbstractXMLRPCClient.java | 84 -- .../jtimer/ws/xmlrpc/ChoremXMLRPCClient.java | 1044 -------------------- .../java/org/chorem/jtimer/ws/xmlrpc/WSDaemon.java | 245 ----- .../org/chorem/jtimer/ws/xmlrpc/package-info.java | 25 - .../java/org/chorem/jtimer/JTimerFactoryTest.java | 19 +- 18 files changed, 6 insertions(+), 2236 deletions(-) diff --git a/.gitignore b/.gitignore index e2f61eb..f83a844 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ target/* .project .settings .classpath +jtimer.properties diff --git a/pom.xml b/pom.xml index e19595e..8c6daf8 100644 --- a/pom.xml +++ b/pom.xml @@ -323,24 +323,6 @@ <artifactId>freemarker</artifactId> <version>2.3.23</version> </dependency> - <dependency> - <groupId>org.apache.xmlrpc</groupId> - <artifactId>xmlrpc-client</artifactId> - <version>${xmrpcVersion}</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.apache.xmlrpc</groupId> - <artifactId>xmlrpc-common</artifactId> - <version>${xmrpcVersion}</version> - <scope>compile</scope> - <exclusions> - <exclusion> - <artifactId>junit</artifactId> - <groupId>junit</groupId> - </exclusion> - </exclusions> - </dependency> <!-- commons-xxx lib --> @@ -364,18 +346,6 @@ <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> - <dependency> - <groupId>commons-httpclient</groupId> - <artifactId>commons-httpclient</artifactId> - <version>3.1</version> - <scope>runtime</scope> - <exclusions> - <exclusion> - <groupId>commons-codec</groupId> - <artifactId>commons-codec</artifactId> - </exclusion> - </exclusions> - </dependency> <!-- tests dependencies --> diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index 84eaad9..26d777d 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -77,9 +77,6 @@ import org.chorem.jtimer.ui.tasks.RefreshTreeTask; import org.chorem.jtimer.ui.tasks.RunTaskJob; import org.chorem.jtimer.ui.treetable.ProjectsAndTasksTable; import org.chorem.jtimer.ui.widget.WindowProperty2; -import org.chorem.jtimer.ui.ws.SwingConnectionInformationHandler; -import org.chorem.jtimer.ws.ConnectionDataHandler; -import org.chorem.jtimer.ws.ProjectManagement; import org.jdesktop.application.Action; import org.jdesktop.application.Application; import org.jdesktop.application.ApplicationContext; @@ -199,15 +196,6 @@ public class JTimer extends SingleFrameApplication implements // init timercore core = new TimerCore(); - // handler - ConnectionDataHandler handler = new SwingConnectionInformationHandler( - this); - ProjectManagement managementService = JTimerFactory - .getProjectManagementService(); - if (managementService != null) { - managementService.setConnectionDataHandler(handler); - } - // Systray mgr systrayManager = new SystrayManager(this); core.getData().addDataEventListener(systrayManager); diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index bca2de3..fe9dd33 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2012 Codelutin, Chatellier Eric + * Copyright (C) 2012 - 2016 Codelutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -95,26 +95,6 @@ public class JTimerConfig { } } - public Class getServiceClass() { - Class serviceClass = null; - try { - serviceClass = appConfig.getOptionAsClass(JTimerOption.SERVICE_CLASS.key); - } catch (Exception ex) { - if (log.isWarnEnabled()) { - log.warn("Can't find service class implementation, sync will not work", ex); - } - } - return serviceClass; - } - - public String getServiceEndpoint() { - return appConfig.getOption(JTimerOption.SERVICE_ENDPOINT.key); - } - - public String getServiceResource() { - return appConfig.getOption(JTimerOption.SERVICE_RESOURCE.key); - } - public Class getIOSaverClass() { return appConfig.getOptionAsClass(JTimerOption.IO_SAVER_CLASS.key); } @@ -201,9 +181,6 @@ public class JTimerConfig { protected enum JTimerOption { CONFIG_FILENAME(ApplicationConfig.CONFIG_FILE_NAME, "jtimer.properties"), - SERVICE_CLASS("jtimer.service.class", null), - SERVICE_ENDPOINT("jtimer.service.endpoint", null), - SERVICE_RESOURCE("jtimer.service.resource", "JTimer"), IO_SAVER_CLASS("jtimer.io.saver.class", "org.chorem.jtimer.io.GTimerIncrementalSaver"), IO_SAVER_DIRECTORY("jtimer.io.saver.directory", "${user.home}/.gtimer"), IO_SAVER_AUTOSAVEDELAY("jtimer.io.saver.autosavedelay", "300"), diff --git a/src/main/java/org/chorem/jtimer/JTimerFactory.java b/src/main/java/org/chorem/jtimer/JTimerFactory.java index 812d151..396f810 100644 --- a/src/main/java/org/chorem/jtimer/JTimerFactory.java +++ b/src/main/java/org/chorem/jtimer/JTimerFactory.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,7 +25,6 @@ package org.chorem.jtimer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.io.Saver; -import org.chorem.jtimer.ws.ProjectManagement; /** * JTimer config class. @@ -41,9 +40,6 @@ public class JTimerFactory { /** Logger */ private static Log log = LogFactory.getLog(JTimerFactory.class); - /** ProjectManagement */ - protected static ProjectManagement projectManagement; - /** Saver */ protected static Saver saver; @@ -55,60 +51,6 @@ public class JTimerFactory { } /** - * Return an implementation on a distant web service. - * - * Use jtimer.service.class property to found class and - * jtimer.service.endpoint and jtimer.service.resource to init it. - * - * @return implementation on a distant web service. - */ - public static ProjectManagement getProjectManagementService() { - - if (projectManagement == null) { - - Class implementationClass = JTimer.config.getServiceClass(); - - // log - if (log.isInfoEnabled()) { - log.info("Using service class : " + implementationClass); - log.info(" with service endpoint : " + JTimer.config.getServiceEndpoint()); - log.info(" with service resource : " + JTimer.config.getServiceResource()); - } - - // By default jTimer won't synchronize - // so implementationClass can be null - if (implementationClass != null) { - - try { - // get instance - projectManagement = (ProjectManagement)implementationClass.newInstance(); - - // init instance - projectManagement.setEndpoint(JTimer.config.getServiceEndpoint()); - projectManagement.setResourceName(JTimer.config.getServiceResource()); - } catch (InstantiationException e) { - if (log.isErrorEnabled()) { - log.error("Can't instanciate class : " - + implementationClass, e); - } - } catch (IllegalAccessException e) { - if (log.isErrorEnabled()) { - log.error( - "Can't access class : " + implementationClass, - e); - } - } - } else { - if (log.isInfoEnabled()) { - log.info("No sync information given, won't synchronize"); - } - } - } - - return projectManagement; - } - - /** * Get saver manager. * * @return saver manager diff --git a/src/main/java/org/chorem/jtimer/data/TimerCore.java b/src/main/java/org/chorem/jtimer/data/TimerCore.java index 08db6bf..0c7b8bb 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ b/src/main/java/org/chorem/jtimer/data/TimerCore.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -33,9 +33,6 @@ import org.chorem.jtimer.JTimerFactory; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.io.DataLockingException; import org.chorem.jtimer.io.Saver; -import org.chorem.jtimer.ws.ConnectionDataHandler; -import org.chorem.jtimer.ws.ProjectManagement; -import org.chorem.jtimer.ws.xmlrpc.WSDaemon; /** * TimerCore @@ -57,12 +54,6 @@ public class TimerCore { /** saver io controller. */ protected Saver saver; - /** Web service daemon. */ - protected WSDaemon webServiceDaemon; - - /** connection data handler */ - protected ConnectionDataHandler connectionHandler; - /** * Constructor. */ @@ -82,13 +73,6 @@ public class TimerCore { data.addDataEventListener(saver); } - // web service impl - ProjectManagement managementService = JTimerFactory.getProjectManagementService(); - if (managementService != null) { - managementService.setDataManager(data); - data.addVetoableDataEventListener(managementService); - data.addDataEventListener(managementService); - } } /** diff --git a/src/main/java/org/chorem/jtimer/ui/ws/SwingConnectionInformationHandler.java b/src/main/java/org/chorem/jtimer/ui/ws/SwingConnectionInformationHandler.java deleted file mode 100644 index c833ccc..0000000 --- a/src/main/java/org/chorem/jtimer/ui/ws/SwingConnectionInformationHandler.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2011 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.ui.ws; - -import java.awt.Dialog; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JScrollPane; -import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.entities.ConnectionData; -import org.chorem.jtimer.ws.ConnectionDataHandler; -import org.chorem.jtimer.ws.ProjectManagement; -import org.chorem.jtimer.ws.exception.WebServiceException; -import org.jdesktop.application.ApplicationContext; -import org.jdesktop.application.LocalStorage; -import org.jdesktop.application.ResourceManager; -import org.jdesktop.application.ResourceMap; -import org.jdesktop.application.SingleFrameApplication; - -/** - * Swing ConnectionInformationHandler. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ By : $Author$ - */ -public class SwingConnectionInformationHandler extends Dialog implements - ConnectionDataHandler, ActionListener, ListSelectionListener { - - /** serialVersionUID */ - private static final long serialVersionUID = -4178930926937567471L; - - /** log */ - private static Log log = LogFactory - .getLog(SwingConnectionInformationHandler.class); - - /** Displayed list */ - protected JList list; - - /** Ok button */ - protected JButton okButton; - - /** Clicked button */ - protected JButton selectedButton; - - /** Local storage */ - protected LocalStorage localStorage; - - /** I18n resources map */ - protected ResourceMap resourceMap; - - /** - * Data displayed in graphical list. - */ - protected class LoginListData implements Comparable<LoginListData> { - - /** login */ - protected String login; - /** id */ - protected String id; - - /** - * Constructor. - * - * @param login login - * @param id id - */ - public LoginListData(String login, String id) { - this.login = login; - this.id = id; - } - - /** - * Get id; - * - * @return id - */ - public String getId() { - return id; - } - - /** - * toString only display login. - * - * @return login - */ - public String toString() { - return login; - } - - /* - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(LoginListData o) { - - return login.compareTo(o.login); - } - } - - /** - * Constructor. - * - * @param application parent application reference - */ - public SwingConnectionInformationHandler(SingleFrameApplication application) { - super(application.getMainFrame(), true); - - // set name for swing application framework - setName(SwingConnectionInformationHandler.class.getName()); - - // init resources map - ApplicationContext ctxt = application.getContext(); - ResourceManager mgr = ctxt.getResourceManager(); - resourceMap = mgr - .getResourceMap(SwingConnectionInformationHandler.class); - - localStorage = application.getContext().getLocalStorage(); - } - - /** - * Build storage name (common place). - * - * @param resourceName resource name - * @return storage name - */ - protected String getStorageName(String resourceName) { - - // add unique name, that pass refactor - // data are stored in xml format by reflection - return ConnectionDataHandler.class.getName() + "." + resourceName - + ".xml"; - } - - /* - * (non-Javadoc) - * - * @see org.chorem.jtimer.ws.ConnectionInformationHandler#getConnectionInformation(java.lang.String) - */ - @Override - public ConnectionData getConnectionInformation( - ProjectManagement managementService) { - - // try to get file information - ConnectionData data = null; - try { - data = (ConnectionData) localStorage - .load(getStorageName(managementService.getResourceName())); - - if (data != null) { - if (log.isInfoEnabled()) { - log.info("found user connection information (login=" - + data.getLogin() + ")"); - } - } else { - data = createNewConnectionInformation(managementService); - } - } catch (IOException e) { - - if (log.isDebugEnabled()) { - log.debug("Connection information not found for current user, ask it", - e); - } - - data = createNewConnectionInformation(managementService); - } - - return data; - } - - /** - * Create, store, and return connection data. - * - * @param managementService interface on remote service - * @return correct connection data - */ - protected ConnectionData createNewConnectionInformation( - ProjectManagement managementService) { - if (log.isInfoEnabled()) { - log.info("Connection information not found for current user, ask it"); - } - - ConnectionData data = askUserForInformation(managementService); - - if (data != null) { - try { - localStorage.save(data, getStorageName(managementService - .getResourceName())); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Can't save info for user", e); - } - } - } - - return data; - } - - /** - * Add user for data (swing prompt). - * - * @param managementService interface on remote service - * @return data specified by user - */ - protected ConnectionData askUserForInformation( - ProjectManagement managementService) { - - // data to return - ConnectionData data = null; - - // try to get users list on remote service - - try { - Map<String, String> idLogins = managementService - .getIdAndLoginsMap(); - - List<LoginListData> v = new ArrayList<LoginListData>(); - for (Entry<String, String> entry : idLogins.entrySet()) { - v.add(new LoginListData(entry.getValue(), entry.getKey())); - } - - // sort list in login order - Collections.sort(v); - buildUI(managementService); - list.setListData(v.toArray()); - - // for dialog, call is blocking when modal - setVisible(true); - - // not cancel, ie ok ;) - if (okButton.equals(selectedButton)) { - - LoginListData loginData = (LoginListData) list - .getSelectedValue(); - if (loginData.getId() != null) { - data = new ConnectionData(); - data.setLogin(loginData.getId()); - } - } - } catch (WebServiceException e) { - if (log.isErrorEnabled()) { - log.error("Can't contact remote service", e); - } - } - - return data; - } - - /** - * build ui. - * - * @param managementService management service - */ - protected void buildUI(ProjectManagement managementService) { - - // set title - String title = resourceMap.getString("askInformationTitle"); - setTitle(title); - - // build UI component - setLayout(new GridBagLayout()); - - // image - JLabel labelInfo = new JLabel(resourceMap.getString( - "askInformationMessage", managementService.getResourceName())); - add(labelInfo, new GridBagConstraints(0, 0, 2, 1, 0, 0, GridBagConstraints.CENTER, - GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0)); - - // image - list = new JList(); - list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - list.addListSelectionListener(this); - JScrollPane jsp = new JScrollPane(list); - add(jsp, new GridBagConstraints(0, 1, 2, 1, 1, 1, GridBagConstraints.CENTER, - GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); - - // image - okButton = new JButton(resourceMap.getString("ok")); - okButton.addActionListener(this); - okButton.setEnabled(false); - add(okButton, new GridBagConstraints(0, 2, 1, 1, 1, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, - new Insets(0, 5, 5, 5), 10, 0)); - - // image - JButton cancelButton = new JButton(resourceMap.getString("cancel")); - cancelButton.addActionListener(this); - add(cancelButton, new GridBagConstraints(1, 2, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, - new Insets(0, 0, 5, 0), 10, 0)); - - // fixe size - Dimension dim = getToolkit().getScreenSize(); - setSize(450, 420); - setLocation((dim.width - getSize().width) / 2, - (dim.height - getSize().height) / 2); - } - - /* - * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) - */ - @Override - public void actionPerformed(ActionEvent e) { - - // all action cause close ;) - selectedButton = (JButton) e.getSource(); - setVisible(false); - - } - - /* - * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) - */ - @Override - public void valueChanged(ListSelectionEvent e) { - - okButton.setEnabled(true); - } -} diff --git a/src/main/java/org/chorem/jtimer/ui/ws/package-info.java b/src/main/java/org/chorem/jtimer/ui/ws/package-info.java deleted file mode 100644 index 814db8a..0000000 --- a/src/main/java/org/chorem/jtimer/ui/ws/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -/** - * Graphical handlers for webservices. - */ -package org.chorem.jtimer.ui.ws; diff --git a/src/main/java/org/chorem/jtimer/ws/ConnectionDataHandler.java b/src/main/java/org/chorem/jtimer/ws/ConnectionDataHandler.java deleted file mode 100644 index 3a61cbc..0000000 --- a/src/main/java/org/chorem/jtimer/ws/ConnectionDataHandler.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2011 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.ws; - -import org.chorem.jtimer.entities.ConnectionData; - -/** - * Handler to ask data. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public interface ConnectionDataHandler { - - /** - * Return connection information. - * - * Read property file, or prompt user. - * - * @param managementService interface to remote service - * @return connection data - */ - public ConnectionData getConnectionInformation( - ProjectManagement managementService); -} diff --git a/src/main/java/org/chorem/jtimer/ws/ProjectManagement.java b/src/main/java/org/chorem/jtimer/ws/ProjectManagement.java deleted file mode 100644 index a93d06e..0000000 --- a/src/main/java/org/chorem/jtimer/ws/ProjectManagement.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.ws; - -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.chorem.jtimer.data.DataEventListener; -import org.chorem.jtimer.data.TimerDataManager; -import org.chorem.jtimer.data.VetoableDataEventListener; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.ws.exception.WebServiceException; - -/** - * ProjectManagement. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public interface ProjectManagement extends DataEventListener, VetoableDataEventListener { - - /** - * Set service endpoint. - * - * @param endpoint service endpoint - */ - public void setEndpoint(String endpoint); - - /** - * Set service endpoint. - * - * @return service endpoint - */ - public String getEndpoint(); - - /** - * Set service resource name. - * - * @param name service resource name - */ - public void setResourceName(String name); - - /** - * Get service resource name. - * - * @return service resource name - */ - public String getResourceName(); - - /** - * Set data manager. - * - * @param dataManager data manager - */ - public void setDataManager(TimerDataManager dataManager); - - /** - * Set connection handler. - * - * @param connectionDataHandler connection handler - */ - public void setConnectionDataHandler(ConnectionDataHandler connectionDataHandler); - - /** - * Get id/login map available on remote services. - * - * @throws WebServiceException when call fail - * @return all id/login couple - */ - public Map<String, String> getIdAndLoginsMap() throws WebServiceException; - - /** - * Do login operation - * - * @param user username - * @param password password - * @throws WebServiceException when call fail - * @return user id - */ - public String login(String user, String password) - throws WebServiceException; - - /** - * Get project list - * - * @param userId user id - * - * @throws WebServiceException when call fail - * @return list of project - * @see org.chorem.jtimer.entities.TimerProject - */ - public List<TimerProject> getUserProjects(String userId) - throws WebServiceException; - - /** - * Synchronize a single project. - * - * @param userId user id - * @param projects project list to synchronize - * @throws WebServiceException when call fail - */ - public void synchronize(String userId, List<TimerProject> projects) - throws WebServiceException; - - /** - * Sync a task. - * - * @param userId user id - * @param task task to sync - * @param dateOfDay date - * @param timeOfDay time in seconds - * @throws WebServiceException when call fail - */ - public void syncTask(String userId, TimerTask task, Date dateOfDay, - long timeOfDay) throws WebServiceException; -} diff --git a/src/main/java/org/chorem/jtimer/ws/exception/WebServiceException.java b/src/main/java/org/chorem/jtimer/ws/exception/WebServiceException.java deleted file mode 100644 index 1902f63..0000000 --- a/src/main/java/org/chorem/jtimer/ws/exception/WebServiceException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2008 - 2011 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.ws.exception; - -/** - * Exception thrown by webservices. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ By : $Author$ - */ -public class WebServiceException extends Exception { - - /** serialVersionUID */ - private static final long serialVersionUID = -2217613295889491172L; - - /** - * Constructor. - * - * @param message message - */ - public WebServiceException(String message) { - super(message); - } - - /** - * Constructor. - * - * @param message message - * @param cause cause - */ - public WebServiceException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/src/main/java/org/chorem/jtimer/ws/exception/package-info.java b/src/main/java/org/chorem/jtimer/ws/exception/package-info.java deleted file mode 100644 index 186bc21..0000000 --- a/src/main/java/org/chorem/jtimer/ws/exception/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -/** - * Exception thrown by webservices. - */ -package org.chorem.jtimer.ws.exception; diff --git a/src/main/java/org/chorem/jtimer/ws/package-info.java b/src/main/java/org/chorem/jtimer/ws/package-info.java deleted file mode 100644 index 87af606..0000000 --- a/src/main/java/org/chorem/jtimer/ws/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -/** - * Webservices layers. - */ -package org.chorem.jtimer.ws; diff --git a/src/main/java/org/chorem/jtimer/ws/xmlrpc/AbstractXMLRPCClient.java b/src/main/java/org/chorem/jtimer/ws/xmlrpc/AbstractXMLRPCClient.java deleted file mode 100644 index 6f810d4..0000000 --- a/src/main/java/org/chorem/jtimer/ws/xmlrpc/AbstractXMLRPCClient.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.ws.xmlrpc; - -import java.net.URL; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.xmlrpc.XmlRpcException; -import org.apache.xmlrpc.client.XmlRpcClient; -import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; -import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory; - -/** - * AbstractXMLRPCClient - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public abstract class AbstractXMLRPCClient { - - /** Log. */ - private static Log log = LogFactory.getLog(AbstractXMLRPCClient.class); - - /** - * Get endpoint address. - * - * @return endpoint address - */ - protected abstract String getEndpoint(); - - /** - * Make get service call. - * - * @param serviceName method to call - * @param args method arguments - * - * @return result remote method result - * - * @throws XmlRpcException when there is an exception - */ - protected Object get(String serviceName, Object... args) - throws XmlRpcException { - Object result = null; - XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); - try { - config.setServerURL(new URL(getEndpoint())); - XmlRpcClient client = new XmlRpcClient(); - client.setTransportFactory(new XmlRpcCommonsTransportFactory( - client)); - client.setConfig(config); - result = client.execute(serviceName, args); - } catch (java.net.MalformedURLException e) { - if (log.isErrorEnabled()) { - log.error("Malformed URL Exception", e); - } - } - - return result; - } -} diff --git a/src/main/java/org/chorem/jtimer/ws/xmlrpc/ChoremXMLRPCClient.java b/src/main/java/org/chorem/jtimer/ws/xmlrpc/ChoremXMLRPCClient.java deleted file mode 100644 index 388a1af..0000000 --- a/src/main/java/org/chorem/jtimer/ws/xmlrpc/ChoremXMLRPCClient.java +++ /dev/null @@ -1,1044 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2012 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.ws.xmlrpc; - -import java.net.ConnectException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Timer; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.xmlrpc.XmlRpcException; -import org.chorem.jtimer.data.DataViolationException; -import org.chorem.jtimer.data.TimerDataManager; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.entities.TimerTaskHelper; -import org.chorem.jtimer.ws.ConnectionDataHandler; -import org.chorem.jtimer.ws.ProjectManagement; -import org.chorem.jtimer.ws.exception.WebServiceException; - -/** - * ChoremXMLRPCClient. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date: 2008-06-13 17:56:15 +0200 (ven., 13 juin 2008)$ - * By : $Author$ - */ -public class ChoremXMLRPCClient extends AbstractXMLRPCClient implements - ProjectManagement { - - /** log. */ - private static Log log = LogFactory.getLog(ChoremXMLRPCClient.class); - - /** Endpoint. */ - protected String endpoint; - - /** Resource name. */ - protected String resourceName; - - /** Map des task vers les topiaId. */ - protected Map<List<String>, String> taskToTopiaId; - - /** Connection handler. */ - protected ConnectionDataHandler connectionDataHandler; - - /** Data manager */ - protected TimerDataManager dataManager; - - /* - * @see org.chorem.jtimer.ws.ProjectManagement#setDataManager(org.chorem.jtimer.data.TimerDataManager) - */ - @Override - public void setDataManager(TimerDataManager dataManager) { - this.dataManager = dataManager; - } - - /* - * @see org.chorem.jtimer.ws.ProjectManagement#setEndpoint(java.lang.String) - */ - @Override - public void setEndpoint(String endpoint) { - this.endpoint = endpoint; - } - - /* - * @see org.chorem.jtimer.ws.xmlrpc.AbstractXMLRPCClient#getEndpoint() - */ - @Override - public String getEndpoint() { - return endpoint; - } - - /* - * @see org.chorem.jtimer.ws.ProjectManagement#getResourceName() - */ - @Override - public String getResourceName() { - return resourceName; - } - - /* - * @see org.chorem.jtimer.ws.ProjectManagement#setResourceName(java.lang.String) - */ - @Override - public void setResourceName(String resourceName) { - this.resourceName = resourceName; - } - - /* - * @see org.chorem.jtimer.ws.ProjectManagement#setConnectionDataHandler(org.chorem.jtimer.ws.ConnectionDataHandler) - */ - @Override - public void setConnectionDataHandler( - ConnectionDataHandler connectionDataHandler) { - this.connectionDataHandler = connectionDataHandler; - } - - /** - * Redefine get to prefix service name - * - * @param serviceName service name - * @param args service params - * @return service result - * @throws XmlRpcException when xml-rpc exception - */ - protected Object get(String serviceName, Object... args) - throws XmlRpcException { - Object result = null; - try { - result = super.get(resourceName + "." + serviceName, args); - } catch (XmlRpcException e) { - if (e.getCause() instanceof ConnectException) { - if (log.isTraceEnabled()) { - log.trace("Can't connect through xmlrpc to " + endpoint, e); - } else if (log.isErrorEnabled()) { - log.error("Can't connect through xmlrpc to " + endpoint); - } - } - throw e; - } - return result; - } - - /* - * @see org.chorem.jtimer.ws.ProjectManagement#getLoginAndIdsMap() - */ - @Override - public Map<String, String> getIdAndLoginsMap() throws WebServiceException { - // method name - String methodName = "getEmployees"; - - // ws call - Map<String, String> idAndLogins = null; - try { - Object idAndLoginsObject = get(methodName); - - if (idAndLoginsObject instanceof Map) { - idAndLogins = (Map<String, String>) idAndLoginsObject; - } - } catch (Exception e) { - if (log.isDebugEnabled()) { - log.debug("Exception on xml-rpc service call (" + methodName - + ")", e); - } - - throw new WebServiceException("Can't call " + methodName + "!", e); - } - - return idAndLogins; - } - - /* - * @see org.chorem.jtimer.ws.ProjectManagement#login(java.lang.String, java.lang.String) - */ - public String login(String login, String password) - throws WebServiceException { - - // method name - String methodName = "login"; - - // ws call - String topiaId = null; - try { - Object topiaIdObject = get(methodName, login, password); - - if (topiaIdObject instanceof String) { - topiaId = (String) topiaIdObject; - } - } catch (Exception e) { - if (log.isDebugEnabled()) { - log.debug("Exception on xml-rpc service call (" + methodName - + ")", e); - } - - throw new WebServiceException("Can't call " + methodName + "!", e); - } - - return topiaId; - } - - /* - * @see org.chorem.jtimer.ws.ProjectManagement#getUserProjects(java.lang.String) - */ - public List<TimerProject> getUserProjects(String userId) - throws WebServiceException { - // method name - // this is called getTasks in chorem - String methodName = "getTasks"; - - // map of timer name > timer project instance - Map<String, TimerProject> result = new HashMap<String, TimerProject>(); - taskToTopiaId = new HashMap<List<String>, String>(); - - try { - Object oMapTopiaidTaskPath = get(methodName, userId); - - if (oMapTopiaidTaskPath instanceof Map) { - - Map<String, Object[]> mapResult = (Map<String, Object[]>) oMapTopiaidTaskPath; - for (String topiaId : mapResult.keySet()) { - - // ? can't get list<string> from ws ? - Object[] oTaskNames = mapResult.get(topiaId); - List<String> lTaskNames = new ArrayList<String>(); - for (Object oTaskName : oTaskNames) { - - // FIXME tmp bugfix, if remote task - // have / in their name - String taskName = (String) oTaskName; - taskName = taskName.replaceAll("/", "-"); - - lTaskNames.add(taskName); - } - - if (log.isDebugEnabled()) { - log.debug(" task found (" + topiaId + ") : " - + lTaskNames); - } - - // ask this task in tree - addTask(result, lTaskNames); - - // remember assoc between task path and topiaIds - taskToTopiaId.put(lTaskNames, topiaId); - } - } else { - if (log.isDebugEnabled()) { - log.debug("Result found but not Map type : " - + oMapTopiaidTaskPath); - } - } - - } catch (XmlRpcException e) { - if (log.isDebugEnabled()) { - log.debug("Exception on xml-rpc service call (" + methodName - + ")", e); - } - - throw new WebServiceException("Can't call " + methodName + "!", e); - } - - return new ArrayList<TimerProject>(result.values()); - } - - /** - * Add new task in current tree. - * - * @param mapOfProjects map of already seen projects - * @param taskNames task name path - */ - protected void addTask(Map<String, TimerProject> mapOfProjects, - List<String> taskNames) { - - // project name - String projectName = taskNames.get(0); - if (log.isDebugEnabled()) { - log.debug("Manage project : " + projectName); - } - - // found this project in current map - TimerProject project = mapOfProjects.get(projectName); - if (project == null) { - project = new TimerProject(); - // prefix name to set it synchronized - project.setName(TimerProject.SYNCHRONIZED_PROJECT_NAME_PREFIX - + projectName); - - // add creation timestamp - project.setCreationDate(new Date()); - - mapOfProjects.put(projectName, project); - } - - // add it - addTask(project, taskNames.subList(1, taskNames.size())); - } - - /** - * Add task in task subtask. - * - * @param task task to add into - * @param taskNames task names - */ - protected void addTask(TimerTask task, List<String> taskNames) { - - if (taskNames.size() > 0) { - - String taskName = taskNames.get(0); - - TimerTask currentTask = null; - for (TimerTask subtask : task.getSubTasks()) { - if (subtask.getName().equals(taskName)) { - currentTask = subtask; - } - } - - // task doesn't exist - if (currentTask == null) { - currentTask = new TimerTask(); - currentTask.setName(taskName); - - // Fix creation date - currentTask.setCreationDate(new Date()); - - task.addTask(currentTask); - } - - addTask(currentTask, taskNames.subList(1, taskNames.size())); - } - - } - - /** - * Get last update date from remote server. - * - * @param userId user id - * @return date of last update or <tt>null</tt> - */ - protected Date getLastUpdate(String userId) { - - // method name - String methodName = "getLastUpdate"; - - // date - Date result = null; - - try { - Object tmpResult = get(methodName, userId); - - if (tmpResult instanceof Date) { - - result = (Date) tmpResult; - - if (log.isDebugEnabled()) { - log.debug("getLastUpdate() = " + result); - } - } - - } catch (XmlRpcException e) { - if (log.isDebugEnabled()) { - log.debug("Exception on xml-rpc service call (" + methodName - + ")", e); - } - } - - return result; - } - - /* - * @see org.chorem.jtimer.ws.ProjectManagement#synchronize(java.lang.String, java.util.List) - */ - @Override - public void synchronize(String userId, List<TimerProject> projects) - throws WebServiceException { - - // get last update date - Date lastUpdateDate = getLastUpdate(userId); - - // if date is null, take 1st january 1970 to force init - if (lastUpdateDate == null) { - lastUpdateDate = new Date(0); - } - - for (TimerProject project : projects) { - if (project.isSynchronized()) { - - // get project name without synchonized prefix name - String nonSynchonizedProjectName = project.getName().substring( - TimerProject.SYNCHRONIZED_PROJECT_NAME_PREFIX.length()); - List<String> pathNames = new ArrayList<String>(1); - pathNames.add(nonSynchonizedProjectName); - - // call recursive task sync - synchronizeTask(userId, project, lastUpdateDate, pathNames); - } - } - } - - /** - * Synchronize a single task. - * - * @param userId user id - * @param task task to sync - * @param lastUpdateDate last update date (can be null) - * @param currentTaskPath current task path - * @throws WebServiceException when call fail - */ - protected void synchronizeTask(String userId, TimerTask task, - Date lastUpdateDate, List<String> currentTaskPath) - throws WebServiceException { - - // log - if (log.isDebugEnabled()) { - log.debug("Manage task path : " + currentTaskPath); - } - - Date firstDate = TimerTaskHelper.getTaskFirstDateOfTiming(task); - Date lastDate = TimerTaskHelper.getTaskLastDateOfTiming(task); - - // if task has timing - if (firstDate != null && lastDate != null) { - - Calendar firstCalendar = Calendar.getInstance(); - firstCalendar.setTime(firstDate); - Calendar lastCalendar = Calendar.getInstance(); - firstCalendar.setTime(lastDate); - - Calendar lastUpdateCalendar = Calendar.getInstance(); - lastUpdateCalendar.setTimeInMillis(lastUpdateDate.getTime()); - lastUpdateCalendar.add(Calendar.DAY_OF_YEAR, 1); - - Calendar yesterdayCalendar = Calendar.getInstance(); - yesterdayCalendar.add(Calendar.DAY_OF_YEAR, -1); - - Calendar fromDay = firstCalendar.compareTo(lastUpdateCalendar) < 0 ? lastUpdateCalendar - : firstCalendar; - Calendar toDay = lastCalendar.compareTo(yesterdayCalendar) < 0 ? lastCalendar - : yesterdayCalendar; - - // define date interval - if (log.isDebugEnabled()) { - log.debug(" Sync task time : " + task.getName()); - log.debug(" from " + fromDay.get(Calendar.DAY_OF_MONTH) + "/" - + (fromDay.get(Calendar.MONTH) + 1) + "/" - + fromDay.get(Calendar.YEAR)); - log.debug(" to " + toDay.get(Calendar.DAY_OF_MONTH) + "/" - + (toDay.get(Calendar.MONTH) + 1) + "/" - + toDay.get(Calendar.YEAR)); - } - - // call syncTask on each day - for (; fromDay.compareTo(toDay) <= 0; fromDay.add( - Calendar.DAY_OF_YEAR, 1)) { - - long timeOfCurrentDay = task.getTime(fromDay.getTime()); - if (log.isDebugEnabled()) { - log.debug("time of day " - + fromDay.get(Calendar.DAY_OF_MONTH) + "/" - + (fromDay.get(Calendar.MONTH) + 1) + "/" - + fromDay.get(Calendar.YEAR) + " = " - + timeOfCurrentDay + " (calendar = " + fromDay - + ")"); - } - if (timeOfCurrentDay > 0) { - String topiaId = taskToTopiaId.get(currentTaskPath); - - if (topiaId == null) { - String superTopiaId = taskToTopiaId.get(currentTaskPath - .subList(0, currentTaskPath.size() - 1)); - topiaId = addTask(userId, superTopiaId, task.getName()); - - // save topiaId of added task - if (topiaId != null) { - taskToTopiaId.put(currentTaskPath, topiaId); - } - - // log - if (log.isDebugEnabled()) { - log.debug("Add task : " + currentTaskPath - + " topiaId = " + topiaId); - } - } - - if (topiaId != null) { - if (log.isDebugEnabled()) { - log.debug(" sending time for " + topiaId + " = " - + timeOfCurrentDay); - } - syncTask(userId, topiaId, fromDay.getTime(), - timeOfCurrentDay * 1000); - } else { - if (log.isFatalEnabled()) { - log.fatal("Can't get topiaId for task : " - + task.getName()); - log.fatal("Chorem error ?"); - } - } - } - } - } else { - // task has no timing, but add it on remote SI - // not add all task (only if has subtasks) - if (task.getSubTasks() != null && !task.getSubTasks().isEmpty()) { - String topiaId = taskToTopiaId.get(currentTaskPath); - - if (topiaId == null) { - String superTopiaId = taskToTopiaId.get(currentTaskPath - .subList(0, currentTaskPath.size() - 1)); - topiaId = addTask(userId, superTopiaId, task.getName()); - - // save topiaId of added task - if (topiaId != null) { - taskToTopiaId.put(currentTaskPath, topiaId); - } - - // log - if (log.isDebugEnabled()) { - log.debug("Add task : " + currentTaskPath - + " topiaId = " + topiaId); - } - } - } - } - - // make recursive call on subtask - for (TimerTask subTask : task.getSubTasks()) { - - // list path for childreen - List<String> childTaskPath = new ArrayList<String>(currentTaskPath); - childTaskPath.add(subTask.getName()); - - synchronizeTask(userId, subTask, lastUpdateDate, childTaskPath); - } - - } - - /** - * Add task on remote server. - * - * @param userId user id - * @param superTopiaId parent task topiaId - * @param name name of task to add - * @return topiaId of created task - */ - protected String addTask(String userId, String superTopiaId, String name) { - - // method name - String methodName = "addTask"; - - // topiaId of added task - String topiaId = null; - - try { - Object oTopiaId = get(methodName, userId, superTopiaId, name); - - if (oTopiaId instanceof String) { - - topiaId = (String) oTopiaId; - - if (log.isDebugEnabled()) { - log.debug(methodName + "() = " + topiaId); - } - } - - } catch (XmlRpcException e) { - if (log.isDebugEnabled()) { - log.debug("Exception on xml-rpc service call (" + methodName - + ")", e); - } - } - - return topiaId; - } - - /** - * Sync a task, call xmlrpc. - * - * @param userId user id - * @param topiaId task topiaId - * @param dateOfDay date - * @param timeOfDay time in seconds - * @throws WebServiceException when call fail - */ - protected void syncTask(String userId, String topiaId, Date dateOfDay, - long timeOfDay) throws WebServiceException { - - // method name - String methodName = "syncTask"; - - try { - // debug - if (log.isDebugEnabled()) { - log.debug(methodName + "(" + userId + ", " + topiaId + ", " - + dateOfDay + ", " + timeOfDay + ")"); - } - - get(methodName, userId, topiaId, dateOfDay, (int) timeOfDay); - - } catch (XmlRpcException e) { - if (log.isDebugEnabled()) { - log.debug("Exception on xml-rpc service call (" + methodName - + ")", e); - } - - throw new WebServiceException("Can't call " + methodName + "!", e); - } - } - - /* - * @see org.chorem.jtimer.ws.ProjectManagement#syncTask(java.lang.String, org.chorem.jtimer.entities.TimerTask, java.util.Date, long) - */ - @Override - public void syncTask(String userId, TimerTask task, Date dateOfDay, - long timeOfDay) throws WebServiceException { - - if (task != null - && TimerTaskHelper.getTaskProject(task).isSynchronized()) { - - // init task to topiaId association - if (taskToTopiaId == null) { - getUserProjects(userId); - } - - // build task path - List<String> taskPath = TimerTaskHelper.getTaskPath(task); - - // search for topiaId - String topiaId = taskToTopiaId.get(taskPath); - - if (topiaId != null) { - // sync task - syncTask(userId, topiaId, dateOfDay, timeOfDay); - - } else { - // iterate over all parent tasks and add them if needed - // toIndex is exclusive - for (int toIndex = 1; toIndex < taskPath.size(); toIndex++) { - String superTopiaId = taskToTopiaId.get(taskPath.subList(0, - toIndex)); - - if (superTopiaId != null) { - topiaId = taskToTopiaId.get(taskPath.subList(0, - toIndex + 1)); - - if (topiaId == null) { - topiaId = addTask(userId, superTopiaId, taskPath - .get(toIndex)); - - // save topiaId of added task - if (topiaId != null) { - taskToTopiaId.put(taskPath.subList(0, - toIndex + 1), topiaId); - } else { - // add task fail ? - if (log.isWarnEnabled()) { - log.warn("Add new task failed on chorem"); - } - } - } - } - } - - // task should have been previously added - topiaId = taskToTopiaId.get(taskPath); - if (topiaId != null) { - syncTask(userId, topiaId, dateOfDay, timeOfDay); - } else { - if (log.isWarnEnabled()) { - log.warn("Try to add time on an unknown synchronized task"); - } - } - } - } - } - - /** - * Synchronization (from server). - */ - protected void synchronization() { - // log - if (log.isInfoEnabled()) { - log.info("Synchronization"); - } - - WSDaemon webServicesDeamon = new WSDaemon(this, dataManager); - webServicesDeamon.setConnectionDataHandler(connectionDataHandler); - - Timer timer = new Timer(); - - Calendar date = Calendar.getInstance(); - date.set(Calendar.HOUR_OF_DAY, 0); - date.set(Calendar.MINUTE, 0); - date.set(Calendar.SECOND, 0); - date.set(Calendar.MILLISECOND, 0); // start one timer at startup - - // Schedule to run every day in midnight - // task,firstTime,period - timer.schedule(webServicesDeamon, date.getTime(), // at date - 1000 * 60 * 60 * 24 // every day - ); - } - - /* - * @see org.chorem.jtimer.data.DataEventListener#addProject(org.chorem.jtimer.entities.TimerProject) - */ - @Override - public void addProject(TimerProject project) { - } - - /* - * @see org.chorem.jtimer.event.DataEventListener#addTask(org.chorem.jtimer.entities.TimerTask) - */ - @Override - public void addTask(TimerTask task) { - - } - - /* - * @see org.chorem.jtimer.event.DataEventListener#dataLoaded(java.util.Collection) - */ - @Override - public void dataLoaded(Collection<TimerProject> projects) { - synchronization(); - } - - /* - * @see org.chorem.jtimer.event.DataEventListener#deleteProject(org.chorem.jtimer.entities.TimerProject) - */ - @Override - public void deleteProject(TimerProject project) { - - } - - /* - * @see org.chorem.jtimer.event.DataEventListener#deleteTask(org.chorem.jtimer.entities.TimerTask) - */ - @Override - public void deleteTask(TimerTask task) { - - } - - /* - * @see org.chorem.jtimer.event.DataEventListener#modifyProject(org.chorem.jtimer.entities.TimerProject) - */ - @Override - public void modifyProject(TimerProject project) { - - } - - /* - * @see org.chorem.jtimer.event.DataEventListener#modifyTask(org.chorem.jtimer.entities.TimerTask) - */ - @Override - public void modifyTask(TimerTask task) { - - } - - /* - * @see org.chorem.jtimer.event.DataEventListener#changeClosedState(org.chorem.jtimer.entities.TimerTask) - */ - @Override - public void changeClosedState(TimerTask task) { - - } - - /* - * @see org.chorem.jtimer.event.DataEventListener#postMoveTask(org.chorem.jtimer.entities.TimerTask) - */ - @Override - public void moveTask(TimerTask task) { - - } - - /* - * @see org.chorem.jtimer.data.DataEventListener#postMergeTasks(org.chorem.jtimer.entities.TimerTask, java.util.List) - */ - @Override - public void postMergeTasks(TimerTask destinationTask, - List<TimerTask> otherTasks) { - - } - - /* - * @see org.chorem.jtimer.data.DataEventListener#preMergeTasks(org.chorem.jtimer.entities.TimerTask, java.util.List) - */ - @Override - public void preMergeTasks(TimerTask destinationTask, - List<TimerTask> otherTasks) { - - } - - /* - * @see org.chorem.jtimer.event.DataEventListener#preMoveTask(org.chorem.jtimer.entities.TimerTask) - */ - @Override - public void preMoveTask(TimerTask task) { - - } - - /* - * @see org.chorem.jtimer.event.DataEventListener#startTask(org.chorem.jtimer.entities.TimerTask) - */ - @Override - public void startTask(TimerTask task) { - - } - - /* - * @see org.chorem.jtimer.event.DataEventListener#stopTask(org.chorem.jtimer.entities.TimerTask) - */ - @Override - public void stopTask(TimerTask task) { - - } - - /** - * {@inheritDoc} - */ - @Override - public void checkSetAnnotation(TimerTask task, Date date, String annotation) { - - /*TimerProject project = TimerTaskHelper.getTaskProject(task); - - if (project.isSynchronized()) { - if (log.isDebugEnabled()) { - log.debug("Project is synchronized, checkSetAnnotation won't pass"); - } - throw new DataViolationException("Can't set annotation", - "vetoable.ws.chorem.cant.modify.synchronized.project"); - }*/ - } - - /** - * {@inheritDoc} - */ - @Override - public void setAnnotation(TimerTask task, Date date, String annotation) { - - } - - /** - * {@inheritDoc} - */ - @Override - public void checkSetTaskTime(TimerTask task, Date date, Long value) { - - } - - /** - * {@inheritDoc} - */ - @Override - public void setTaskTime(TimerTask task, Date date, Long time) { - - if (task != null - && TimerTaskHelper.getTaskProject(task).isSynchronized()) { - - // check if day is passed - // in this case, sync - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MILLISECOND, 0); - - if (calendar.getTime().before(date)) { - if (log.isDebugEnabled()) { - log.debug("Today modification, can't synchronize"); - } - } else { - if (log.isDebugEnabled()) { - log.debug("Sync task " + task.getName()); - log.debug(" date = " + date); - log.debug(" value =" + time); - } - - try { - String login = connectionDataHandler - .getConnectionInformation(this).getLogin(); - if (login != null) { - syncTask(login, task, date, time * 1000); - } - // else login not found so raise no error - } catch (WebServiceException e) { - throw new RuntimeException(e); - } - } - } - } - - /** - * {@inheritDoc} - * - * Synchronized projects are added by synchronization. - */ - @Override - public void checkAddProject(TimerProject project) { - - } - - /** - * {@inheritDoc} - * - * can add, even in sync projects - */ - @Override - public void checkAddTask(TimerTask parent, TimerTask task) { - - } - - /** - * {@inheritDoc} - */ - @Override - public void checkChangeClosedState(TimerTask task) { - - } - - /** - * {@inheritDoc} - */ - @Override - public void checkDeleteProject(TimerProject project) { - - } - - /** - * {@inheritDoc} - */ - @Override - public void checkDeleteTask(TimerTask task) { - - TimerProject project = TimerTaskHelper.getTaskProject(task); - - if (project.isSynchronized()) { - if (log.isDebugEnabled()) { - log.debug("Project is synchronized, checkDeleteTask won't pass"); - } - throw new DataViolationException("Can't delete task projet", - "vetoable.ws.chorem.cant.modify.synchronized.project"); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void checkModifyProject(TimerProject project) { - - if (project.isSynchronized()) { - if (log.isDebugEnabled()) { - log.debug("Project is synchronized, checkModifyProject won't pass"); - } - throw new DataViolationException("Can't modify projet", - "vetoable.ws.chorem.cant.modify.synchronized.project"); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void checkModifyTask(TimerTask task) { - - TimerProject project = TimerTaskHelper.getTaskProject(task); - - if (project.isSynchronized()) { - if (log.isDebugEnabled()) { - log.debug("Project is synchronized, checkModifyTask won't pass"); - } - throw new DataViolationException("Can't modify task", - "vetoable.ws.chorem.cant.modify.synchronized.project"); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void checkMoveTask(TimerTask destination, Collection<TimerTask> tasksToMove) { - - boolean syncProject = false; - // destination (single) - TimerProject project1 = TimerTaskHelper.getTaskProject(destination); - if (project1.isSynchronized()) { - syncProject = true; - } - - // sources (multiples) - for (TimerTask taskToMove : tasksToMove) { - TimerProject project2 = TimerTaskHelper.getTaskProject(taskToMove); - - if (project2.isSynchronized()) { - syncProject = true; - } - } - - if (syncProject) { - if (log.isDebugEnabled()) { - log.debug("Project is synchronized, checkMoveTask won't pass"); - } - throw new DataViolationException("Can't modify task", - "vetoable.ws.chorem.cant.modify.synchronized.project"); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void checkMergeTasks(TimerTask destinationTask, - List<TimerTask> otherTasks) { - - TimerProject project1 = TimerTaskHelper.getTaskProject(destinationTask); - - if (project1.isSynchronized()) { - if (log.isDebugEnabled()) { - log.debug("Project is synchronized, checkMergeTask won't pass"); - } - throw new DataViolationException("Can't modify task", - "vetoable.ws.chorem.cant.modify.synchronized.project"); - } - - for (TimerTask otherTask : otherTasks) { - TimerProject otherProject = TimerTaskHelper - .getTaskProject(otherTask); - if (otherProject.isSynchronized()) { - if (log.isDebugEnabled()) { - log.debug("Project is synchronized, checkMergeTask won't pass"); - } - throw new DataViolationException("Can't modify task", - "vetoable.ws.chorem.cant.modify.synchronized.project"); - } - } - } -} diff --git a/src/main/java/org/chorem/jtimer/ws/xmlrpc/WSDaemon.java b/src/main/java/org/chorem/jtimer/ws/xmlrpc/WSDaemon.java deleted file mode 100644 index b24286f..0000000 --- a/src/main/java/org/chorem/jtimer/ws/xmlrpc/WSDaemon.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.ws.xmlrpc; - -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.data.TimerDataManager; -import org.chorem.jtimer.entities.ConnectionData; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.ws.ConnectionDataHandler; -import org.chorem.jtimer.ws.exception.WebServiceException; - -/** - * WSDaemon. Do synchronization with remote service. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class WSDaemon extends java.util.TimerTask { - - /** Log */ - private static Log log = LogFactory.getLog(WSDaemon.class); - - /** Data manager */ - protected TimerDataManager dataManager; - - /** Web service implementation */ - protected ChoremXMLRPCClient managementService; - - /** Connection handler */ - protected ConnectionDataHandler connectionDataHandler; - - /** - * Constructor. - * - * @param managementService managementService to use - * @param dataManager data - */ - public WSDaemon(ChoremXMLRPCClient managementService, TimerDataManager dataManager) { - // data manager - this.dataManager = dataManager; - - // web service impl - this.managementService = managementService; - } - - /** - * Set connection handler. - * - * @param connectionDataHandler connection handler - */ - public void setConnectionDataHandler( - ConnectionDataHandler connectionDataHandler) { - - this.connectionDataHandler = connectionDataHandler; - } - - /* - * @see java.lang.Runnable#run() - */ - @Override - public void run() { - - // fix NPE (happen in tests) - // but must not happen in main line - if (connectionDataHandler == null) { - if (log.isDebugEnabled()) { - log.debug("No handler set, can't synchronize"); - } - - return; - } - - // get connection info - // if can't be found, ask user - ConnectionData cData = connectionDataHandler - .getConnectionInformation(managementService); - - if (cData != null) { - String login = cData.getLogin(); - - if (log.isInfoEnabled()) { - log.info("Refresh..."); - } - - // managementService.getUserProjects(); - try { - String userId = managementService.login(login, ""); - - if (log.isDebugEnabled()) { - log.debug("UserId = " + userId); - } - - if (userId == null || userId.isEmpty()) { - // reask user for connection identifier - if (log.isWarnEnabled()) { - log.warn("TODO : Unknown user identifier, should reask here"); - } - } else { - // first, get updated project list - refreshProjectList(userId); - if (log.isInfoEnabled()) { - log.info("Project list refreshed"); - } - - // now send local time to server - managementService.synchronize(userId, dataManager - .getProjectsList()); - if (log.isInfoEnabled()) { - log.info("Times updated"); - } - - if (log.isInfoEnabled()) { - log.info("Refresh complete"); - } - } - - } catch (WebServiceException e) { - if (log.isErrorEnabled()) { - log.error("Can't synchronize with remote service", e); - } - } - } else { - if (log.isInfoEnabled()) { - log.info("Can't do synchronization"); - } - } - } - - /** - * Refresh projects and task list. - * - * @param userId user id - */ - protected void refreshProjectList(String userId) { - - try { - List<TimerProject> projects = managementService - .getUserProjects(userId); - - if (projects != null) { - // Manage each remote project - for (TimerProject project : projects) { - String projectName = project.getName(); - - TimerProject localProject = getProjectByName(projectName); - if (localProject != null) { - synchronizeTask(localProject, project); - } else { - // else only notify project added ? - dataManager.addProject(project); - } - } - } - } catch (WebServiceException e) { - if (log.isErrorEnabled()) { - log.error("Can't synchronize with remote service", e); - } - } - } - - /** - * Found project by name in local projects. - * - * @param projectName project name to find - * @return local project found - */ - protected TimerProject getProjectByName(String projectName) { - - TimerProject projectFound = null; - - for (TimerProject project : dataManager.getProjectsList()) { - if (project.getName().equals(projectName)) { - projectFound = project; - } - } - - return projectFound; - } - - /** - * Found task by name in a task subtask - * - * @param task task - * @param taskName task name to found - * - * @return local task found - */ - protected TimerTask getTaskByName(TimerTask task, String taskName) { - - TimerTask taskFound = null; - - for (TimerTask lTask : task.getSubTasks()) { - if (lTask.getName().equals(taskName)) { - taskFound = lTask; - } - } - - return taskFound; - } - - /** - * Synchronize two projects. - * - * @param localTask local project - * @param task other task - */ - protected void synchronizeTask(TimerTask localTask, TimerTask task) { - - for (TimerTask lTask : task.getSubTasks()) { - TimerTask localTaskFound = getTaskByName(localTask, lTask.getName()); - if (localTaskFound != null) { - synchronizeTask(localTaskFound, lTask); - } else { - dataManager.addTask(localTask, lTask); - } - } - } -} diff --git a/src/main/java/org/chorem/jtimer/ws/xmlrpc/package-info.java b/src/main/java/org/chorem/jtimer/ws/xmlrpc/package-info.java deleted file mode 100644 index eb3371a..0000000 --- a/src/main/java/org/chorem/jtimer/ws/xmlrpc/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -/** - * Chorem webservices implementation. - */ -package org.chorem.jtimer.ws.xmlrpc; diff --git a/src/test/java/org/chorem/jtimer/JTimerFactoryTest.java b/src/test/java/org/chorem/jtimer/JTimerFactoryTest.java index 39a6f00..5d83e4c 100644 --- a/src/test/java/org/chorem/jtimer/JTimerFactoryTest.java +++ b/src/test/java/org/chorem/jtimer/JTimerFactoryTest.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2008 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2008 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -26,8 +26,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.io.GTimerIncrementalSaver; import org.chorem.jtimer.io.Saver; -import org.chorem.jtimer.ws.ProjectManagement; -import org.chorem.jtimer.ws.xmlrpc.ChoremXMLRPCClient; import org.testng.Assert; import org.testng.annotations.Test; @@ -55,10 +53,6 @@ public class JTimerFactoryTest extends AbstractJTimerTest { log.info("Test property loading " + JTimerFactoryTest.class); } - Assert.assertEquals(JTimer.config.getServiceClass(), ChoremXMLRPCClient.class); - Assert.assertEquals(JTimer.config.getServiceResource(), "JTimer"); - Assert.assertEquals(JTimer.config.getServiceEndpoint(), "http://localhost:8080"); - Assert.assertEquals(JTimer.config.getIdleTime(), 299); Assert.assertEquals(JTimer.config.getIOSaverClass(), GTimerIncrementalSaver.class); @@ -79,15 +73,4 @@ public class JTimerFactoryTest extends AbstractJTimerTest { Assert.assertNotNull(saver); } - /** - * Test que le composant gerant les webservices s'est bien initialise. - */ - @Test - public void getProjectManagementService() { - ProjectManagement projectManagement = JTimerFactory.getProjectManagementService(); - - Assert.assertNotNull(projectManagement); - Assert.assertEquals(projectManagement.getEndpoint(), "http://localhost:8080"); - Assert.assertEquals(projectManagement.getResourceName(), "JTimer"); - } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.