branch develop updated (0436921 -> c621a55)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository jtimer. See http://git.chorem.org/jtimer.git from 0436921 Bump version new fb6fa54 fixes #1323: Remove xmlrpc web service layer new 7fa8859 fixes #1322: Use java 8 api new 7028f62 refs #1322: Use filter api instead of commons-collection new 5e5054a refs #1322: Manage resources with auto-closeable new 5970b85 refs #1322: Fix some warning and depreciation new c621a55 refs #1320: Update log4j2 The 6 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit c621a557a6fc959cd84c7d4d15d8a55d5a42e5b2 Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 12:18:27 2016 +0100 refs #1320: Update log4j2 commit 5970b85b0b01ad52cdfb36af0a88b126bd4e0770 Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 11:49:28 2016 +0100 refs #1322: Fix some warning and depreciation commit 5e5054ab951665c880b1f96518fc38f2d49de93c Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 11:46:35 2016 +0100 refs #1322: Manage resources with auto-closeable commit 7028f62cef311e7d23f54207cce65e1c4f3850c5 Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 11:32:06 2016 +0100 refs #1322: Use filter api instead of commons-collection commit 7fa885965e8c1f28c8fa3bbb5ce949bdcc3e347a Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 11:21:52 2016 +0100 fixes #1322: Use java 8 api commit fb6fa54f22c60cc4aa0b6f83051c678d741b8e6f Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 11:09:57 2016 +0100 fixes #1323: Remove xmlrpc web service layer Summary of changes: .gitignore | 1 + pom.xml | 55 +- src/main/java/org/chorem/jtimer/JTimer.java | 18 +- src/main/java/org/chorem/jtimer/JTimerConfig.java | 27 +- src/main/java/org/chorem/jtimer/JTimerFactory.java | 62 +- .../java/org/chorem/jtimer/data/TimerCore.java | 18 +- .../org/chorem/jtimer/data/TimerDataManager.java | 2 +- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 412 ++++---- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 25 +- .../chorem/jtimer/ui/alert/AlertCellEditor.java | 6 +- .../chorem/jtimer/ui/alert/AlertCellRenderer.java | 4 +- .../chorem/jtimer/ui/report/ReportGenerator.java | 4 +- .../jtimer/ui/report/tree/CheckBoxTreeModel.java | 22 +- .../java/org/chorem/jtimer/ui/system/unix/Xss.java | 2 +- .../org/chorem/jtimer/ui/system/win32/User32.java | 2 +- .../jtimer/ui/treetable/ProjectsAndTasksModel.java | 19 +- .../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 - src/main/resources/log4j.properties | 51 - src/main/resources/log4j2.xml | 38 + .../java/org/chorem/jtimer/JTimerFactoryTest.java | 19 +- .../chorem/jtimer/data/TimerDataManagerTest.java | 1 + 31 files changed, 302 insertions(+), 2561 deletions(-) delete mode 100644 src/main/java/org/chorem/jtimer/ui/ws/SwingConnectionInformationHandler.java delete mode 100644 src/main/java/org/chorem/jtimer/ui/ws/package-info.java delete mode 100644 src/main/java/org/chorem/jtimer/ws/ConnectionDataHandler.java delete mode 100644 src/main/java/org/chorem/jtimer/ws/ProjectManagement.java delete mode 100644 src/main/java/org/chorem/jtimer/ws/exception/WebServiceException.java delete mode 100644 src/main/java/org/chorem/jtimer/ws/exception/package-info.java delete mode 100644 src/main/java/org/chorem/jtimer/ws/package-info.java delete mode 100644 src/main/java/org/chorem/jtimer/ws/xmlrpc/AbstractXMLRPCClient.java delete mode 100644 src/main/java/org/chorem/jtimer/ws/xmlrpc/ChoremXMLRPCClient.java delete mode 100644 src/main/java/org/chorem/jtimer/ws/xmlrpc/WSDaemon.java delete mode 100644 src/main/java/org/chorem/jtimer/ws/xmlrpc/package-info.java delete mode 100644 src/main/resources/log4j.properties create mode 100644 src/main/resources/log4j2.xml -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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>.
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 7fa885965e8c1f28c8fa3bbb5ce949bdcc3e347a Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 11:21:52 2016 +0100 fixes #1322: Use java 8 api --- pom.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8c6daf8..c8c67c9 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,11 @@ <properties> <projectId>jtimer</projectId> + + <!-- java 8 --> + <javaVersion>1.8</javaVersion> + <signatureArtifactId>java18</signatureArtifactId> + <signatureVersion>1.0</signatureVersion> <!--Main class in JAR --> <maven.jar.main.class>org.chorem.jtimer.JTimer</maven.jar.main.class> @@ -90,7 +95,6 @@ <!--Multilanguage maven-site --> <locales>fr,en</locales> - <xmrpcVersion>3.1.3</xmrpcVersion> <jnaVersion>4.2.1</jnaVersion> <!-- files to deploy to redmine --> @@ -392,7 +396,7 @@ <jar>jtimer.jar</jar> <errTitle>${project.name}</errTitle> <jre> - <minVersion>1.7.0</minVersion> + <minVersion>1.8.0</minVersion> </jre> </configuration> </execution> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 7028f62cef311e7d23f54207cce65e1c4f3850c5 Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 11:32:06 2016 +0100 refs #1322: Use filter api instead of commons-collection --- pom.xml | 5 ----- .../jtimer/ui/report/tree/CheckBoxTreeModel.java | 22 ++++++---------------- .../jtimer/ui/treetable/ProjectsAndTasksModel.java | 19 +++++-------------- 3 files changed, 11 insertions(+), 35 deletions(-) diff --git a/pom.xml b/pom.xml index c8c67c9..5bb391c 100644 --- a/pom.xml +++ b/pom.xml @@ -332,11 +332,6 @@ <dependency> <groupId>org.apache.commons</groupId> - <artifactId>commons-collections4</artifactId> - <version>4.1</version> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.4</version> </dependency> diff --git a/src/main/java/org/chorem/jtimer/ui/report/tree/CheckBoxTreeModel.java b/src/main/java/org/chorem/jtimer/ui/report/tree/CheckBoxTreeModel.java index 85eea50..3ed9d41 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/tree/CheckBoxTreeModel.java +++ b/src/main/java/org/chorem/jtimer/ui/report/tree/CheckBoxTreeModel.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2009 - 2012 CodeLutin, Chatellier Eric + * Copyright (C) 2009 - 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 @@ -24,13 +24,12 @@ package org.chorem.jtimer.ui.report.tree; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import javax.swing.event.TreeModelListener; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.data.TimerCore; @@ -116,7 +115,7 @@ public class CheckBoxTreeModel implements TreeModel { */ protected List<TimerTask> getFiteredSubListFor(Object parent) { - List<TimerTask> result = new ArrayList<TimerTask>(); + List<TimerTask> result = new ArrayList<>(); // get correct list if (parent == root) { // case root node @@ -128,18 +127,9 @@ public class CheckBoxTreeModel implements TreeModel { // filter list, if only show closed if (!showClosed) { - CollectionUtils.filter(result, new Predicate() { - @Override - public boolean evaluate(Object object) { - - boolean result = false; - if (object instanceof TimerTask) { - TimerTask task = (TimerTask) object; - result = !task.isClosed(); - } - return result; - } - }); + result = result.stream() + .filter(task -> !task.isClosed()) + .collect(Collectors.toList()); } // Since sort is not supported by the table, do a manual sorting. diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java index b3cc61f..51afa5b 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.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 @@ -28,13 +28,12 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.swing.SwingUtilities; import javax.swing.table.TableColumn; import javax.swing.tree.TreePath; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.Predicate; import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -235,17 +234,9 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements // filter list, if only show closed if (!showClosedTask) { - CollectionUtils.filter(result, new Predicate() { - @Override - public boolean evaluate(Object object) { - boolean result = false; - if (object instanceof TimerTask) { - TimerTask task = (TimerTask) object; - result = !task.isClosed(); - } - return result; - } - }); + result = result.stream() + .filter(task -> !task.isClosed()) + .collect(Collectors.toList()); } // Since sort is not supported by the table, do a manual sorting. -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 5e5054ab951665c880b1f96518fc38f2d49de93c Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 11:46:35 2016 +0100 refs #1322: Manage resources with auto-closeable --- .../org/chorem/jtimer/data/TimerDataManager.java | 2 +- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 412 ++++++++++----------- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 25 +- .../chorem/jtimer/ui/alert/AlertCellEditor.java | 4 +- .../chorem/jtimer/ui/alert/AlertCellRenderer.java | 4 +- 5 files changed, 222 insertions(+), 225 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index 673c7c2..014d1da 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2010 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 diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 88cd371..2240d8c 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.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 @@ -30,6 +30,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.RandomAccessFile; import java.io.Writer; @@ -47,11 +48,11 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.SortedMap; import java.util.Timer; import java.util.TreeMap; -import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; @@ -62,9 +63,9 @@ import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.data.DataEventListener; import org.chorem.jtimer.data.DataViolationException; import org.chorem.jtimer.entities.TimerAlert; +import org.chorem.jtimer.entities.TimerAlert.Type; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.entities.TimerAlert.Type; /** * Charge et sauve les fichiers au format gTimer. @@ -412,39 +413,44 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, protected TimerProject getProjectFromFile(File projectFile) throws IOException { - Properties prop = new Properties(); - prop.load(new BufferedInputStream(new FileInputStream(projectFile))); - - // log - if (log.isDebugEnabled()) { - log.debug("Load project (" + projectFile.getName() + ") : " - + prop.getProperty("Name")); - } - TimerProject p = null; - if (GTIMER_FILE_VERSION.equals(prop.get("Format"))) { - p = new TimerProject(); - p.setName(prop.getProperty("Name")); - // manage creation timestamp (conversion to long) - try { - String creationTimeStamp = prop.getProperty("Created"); - long timestampinms = Long.parseLong(creationTimeStamp) * 1000; - p.setCreationDate(new Date(timestampinms)); - } catch (NumberFormatException e) { + try (InputStream is = new BufferedInputStream(new FileInputStream(projectFile))) { + Properties prop = new Properties(); + prop.load(is); + + // log + if (log.isDebugEnabled()) { + log.debug("Load project (" + projectFile.getName() + ") : " + + prop.getProperty("Name")); + } + + + if (GTIMER_FILE_VERSION.equals(prop.get("Format"))) { + p = new TimerProject(); + p.setName(prop.getProperty("Name")); + + // manage creation timestamp (conversion to long) + try { + String creationTimeStamp = prop.getProperty("Created"); + long timestampinms = Long.parseLong(creationTimeStamp) * 1000; + p.setCreationDate(new Date(timestampinms)); + } catch (NumberFormatException e) { + if (log.isWarnEnabled()) { + log.warn("Invalid 'Created' timestamp", e); + } + p.setCreationDate(new Date(0)); + } + + p.setClosed(prop.getProperty("Options").equals("1")); + } else { if (log.isWarnEnabled()) { - log.warn("Invalid 'Created' timestamp", e); + log.warn("Invalid file format. Excepted " + GTIMER_FILE_VERSION + + ", found " + prop.get("Format")); } - p.setCreationDate(new Date(0)); - } - - p.setClosed(prop.getProperty("Options").equals("1")); - } else { - if (log.isWarnEnabled()) { - log.warn("Invalid file format. Excepted " + GTIMER_FILE_VERSION - + ", found " + prop.get("Format")); } } + return p; } @@ -465,96 +471,98 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, Pattern dataPattern = Pattern.compile("(\\d{4})(\\d{2})(\\d{2})"); - Properties prop = new Properties(); - prop.load(new BufferedInputStream(new FileInputStream(taskFile))); - - if (GTIMER_FILE_VERSION.equals(prop.get("Format"))) { - t = new TimerTask(); - - // manage creation timestamp (convertion to long) - try { - String creationTimeStamp = prop.getProperty("Created"); - long timestampinms = Long.parseLong(creationTimeStamp) * 1000; - t.setCreationDate(new Date(timestampinms)); - } catch (NumberFormatException e) { - if (log.isWarnEnabled()) { - log.warn("Invalid 'Created' timestamp for " + taskFile, e); + try (InputStream is = new BufferedInputStream(new FileInputStream(taskFile))) { + Properties prop = new Properties(); + prop.load(is); + + if (GTIMER_FILE_VERSION.equals(prop.get("Format"))) { + t = new TimerTask(); + + // manage creation timestamp (convertion to long) + try { + String creationTimeStamp = prop.getProperty("Created"); + long timestampinms = Long.parseLong(creationTimeStamp) * 1000; + t.setCreationDate(new Date(timestampinms)); + } catch (NumberFormatException e) { + if (log.isWarnEnabled()) { + log.warn("Invalid 'Created' timestamp for " + taskFile, e); + } + t.setCreationDate(new Date(0)); } - t.setCreationDate(new Date(0)); - } - - t.setClosed(prop.getProperty("Options").equals("1")); - - // name = task - // name = task/subtask1 - // name = task/subtask1/subsubtask1 - String gtimerTaskName = prop.getProperty("Name"); - t.setName(gtimerTaskName); - // yes put all names - // will be corrected later - - // log - if (log.isDebugEnabled()) { - log.debug("Load task (" + taskFile.getName() + ") : " - + gtimerTaskName); - } - - // analyse des donnees (temps) - for (Object key : prop.keySet()) { - String sKey = (String) key; - - // test if key format match - Matcher m = dataPattern.matcher(sKey); - if (m.find()) { - try { - Date keyDate = GTimerTimeUtil.yyyyMMdd2Date(sKey); - String timeString = (String) prop.get(sKey); - t.setTime(keyDate, Long.valueOf(timeString) * 1000); - } catch (NumberFormatException e) { - if (log.isErrorEnabled()) { - log.error("Can't convert " + prop.get(sKey) - + " into long"); + + t.setClosed(prop.getProperty("Options").equals("1")); + + // name = task + // name = task/subtask1 + // name = task/subtask1/subsubtask1 + String gtimerTaskName = prop.getProperty("Name"); + t.setName(gtimerTaskName); + // yes put all names + // will be corrected later + + // log + if (log.isDebugEnabled()) { + log.debug("Load task (" + taskFile.getName() + ") : " + + gtimerTaskName); + } + + // analyse des donnees (temps) + for (Object key : prop.keySet()) { + String sKey = (String) key; + + // test if key format match + Matcher m = dataPattern.matcher(sKey); + if (m.find()) { + try { + Date keyDate = GTimerTimeUtil.yyyyMMdd2Date(sKey); + String timeString = (String) prop.get(sKey); + t.setTime(keyDate, Long.valueOf(timeString) * 1000); + } catch (NumberFormatException e) { + if (log.isErrorEnabled()) { + log.error("Can't convert " + prop.get(sKey) + + " into long"); + } } } + // else not data entry } - // else not data entry - } - - // find associated project instance with number - String taskProjectNumber = (String) prop.get("Project"); - TimerProject associatedProject = mapNumberProject - .get(taskProjectNumber); - - // fix bug case task has no associated project - // can do that in gtimer - if (associatedProject == null && taskProjectNumber.equals("-1")) { - associatedProject = new TimerProject(); - associatedProject.setName(GTIMER_EMPTY_PROJECT_NAME); - mapNumberProject.put(taskProjectNumber, associatedProject); - } - - if (associatedProject != null) { - // used to correct bug #1636 : [jTimer] Bug du rechargement des - // sous taches - taskToManage.put(t, associatedProject); - - if (log.isDebugEnabled()) { - log.debug("Put " + t.getName() + ", " - + associatedProject.getName()); + + // find associated project instance with number + String taskProjectNumber = (String) prop.get("Project"); + TimerProject associatedProject = mapNumberProject + .get(taskProjectNumber); + + // fix bug case task has no associated project + // can do that in gtimer + if (associatedProject == null && taskProjectNumber.equals("-1")) { + associatedProject = new TimerProject(); + associatedProject.setName(GTIMER_EMPTY_PROJECT_NAME); + mapNumberProject.put(taskProjectNumber, associatedProject); } + + if (associatedProject != null) { + // used to correct bug #1636 : [jTimer] Bug du rechargement des + // sous taches + taskToManage.put(t, associatedProject); + + if (log.isDebugEnabled()) { + log.debug("Put " + t.getName() + ", " + + associatedProject.getName()); + } + } else { + if (log.isWarnEnabled()) { + log.warn("task " + t.getName() + + " is associated with a wrong project number " + + prop.get("Project")); + } + } + } else { if (log.isWarnEnabled()) { - log.warn("task " + t.getName() - + " is associated with a wrong project number " - + prop.get("Project")); + log.warn("Invalid file format. Excepted " + GTIMER_FILE_VERSION + + ", found " + prop.get("Format")); } } - - } else { - if (log.isWarnEnabled()) { - log.warn("Invalid file format. Excepted " + GTIMER_FILE_VERSION - + ", found " + prop.get("Format")); - } } return t; @@ -577,27 +585,28 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, log.debug("Annotations found for task " + task.getName()); } - Properties prop = new Properties(); - prop.load(new BufferedInputStream(new FileInputStream( - annotationsTaskFile))); - - // analyse des donnees (temps) - for (Object key : prop.keySet()) { - String sKey = (String) key; - - // test if key format match - try { - - // key of annotation is in seconds - long timestamp = Long.parseLong(sKey); - Date dateTS = new Date(timestamp * 1000); - - String annoText = (String) prop.get(sKey); - - task.addAnnotation(dateTS, annoText); - } catch (NumberFormatException e) { - if (log.isErrorEnabled()) { - log.error("Can't convert " + sKey + " into long"); + try (InputStream is = new BufferedInputStream(new FileInputStream(annotationsTaskFile))) { + Properties prop = new Properties(); + prop.load(is); + + // analyse des donnees (temps) + for (Object key : prop.keySet()) { + String sKey = (String) key; + + // test if key format match + try { + + // key of annotation is in seconds + long timestamp = Long.parseLong(sKey); + Date dateTS = new Date(timestamp * 1000); + + String annoText = (String) prop.get(sKey); + + task.addAnnotation(dateTS, annoText); + } catch (NumberFormatException e) { + if (log.isErrorEnabled()) { + log.error("Can't convert " + sKey + " into long"); + } } } } @@ -624,45 +633,43 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, log.debug("Alert found for task " + task.getName()); } - BufferedReader alertIn = new BufferedReader(new FileReader( - alertTaskFile)); - - // skip first line : "format: 1.2" - String line = alertIn.readLine(); - while ((line = alertIn.readLine()) != null) { - - line = line.trim(); - if (!line.isEmpty()) { - String alertType = line.substring(0, line.indexOf(' ')); - String alertDuration = line.substring( - line.indexOf(' ') + 1, line.length()); - - try { - if ("reachtotaltime".equals(alertType)) { - Long duration = Long.parseLong(alertDuration) * 1000; - TimerAlert alert = new TimerAlert( - TimerAlert.Type.REACH_TOTAL_TIME, duration); - task.addAlert(alert); - } else if ("reachdailytime".equals(alertType)) { - Long duration = Long.parseLong(alertDuration) * 1000; - TimerAlert alert = new TimerAlert( - TimerAlert.Type.REACH_DAILY_TIME, duration); - task.addAlert(alert); - } else { - if (log.isWarnEnabled()) { - log.warn("Unknow alert type " + alertType); + try (BufferedReader alertIn = new BufferedReader(new FileReader(alertTaskFile))) { + + // skip first line : "format: 1.2" + String line = alertIn.readLine(); + while ((line = alertIn.readLine()) != null) { + + line = line.trim(); + if (!line.isEmpty()) { + String alertType = line.substring(0, line.indexOf(' ')); + String alertDuration = line.substring( + line.indexOf(' ') + 1, line.length()); + + try { + if ("reachtotaltime".equals(alertType)) { + Long duration = Long.parseLong(alertDuration) * 1000; + TimerAlert alert = new TimerAlert( + TimerAlert.Type.REACH_TOTAL_TIME, duration); + task.addAlert(alert); + } else if ("reachdailytime".equals(alertType)) { + Long duration = Long.parseLong(alertDuration) * 1000; + TimerAlert alert = new TimerAlert( + TimerAlert.Type.REACH_DAILY_TIME, duration); + task.addAlert(alert); + } else { + if (log.isWarnEnabled()) { + log.warn("Unknow alert type " + alertType); + } + } + } catch (NumberFormatException e) { + if (log.isErrorEnabled()) { + log.error("Can't convert " + alertDuration + + " into long"); } - } - } catch (NumberFormatException e) { - if (log.isErrorEnabled()) { - log.error("Can't convert " + alertDuration - + " into long"); } } } } - - alertIn.close(); } } @@ -778,13 +785,11 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } // - try { + try (ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(zipFileName))) { + // Create a buffer for reading the files byte[] buffer = new byte[1024]; - ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream( - zipFileName)); - // add in this archive only gtimer files File gtimerdir = new File(saveDirectory); File[] filesInIt = gtimerdir.listFiles(); @@ -793,19 +798,18 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, String filename = fileInIt.getName(); if (isGTimerFile(filename)) { - FileInputStream inFileStream = new FileInputStream(fileInIt); - - outZip.putNextEntry(new ZipEntry(filename)); - - // Transfer bytes from the file to the ZIP file - int len; - while ((len = inFileStream.read(buffer)) > 0) { - outZip.write(buffer, 0, len); + try (FileInputStream inFileStream = new FileInputStream(fileInIt)) { + outZip.putNextEntry(new ZipEntry(filename)); + + // Transfer bytes from the file to the ZIP file + int len; + while ((len = inFileStream.read(buffer)) > 0) { + outZip.write(buffer, 0, len); + } + + // Complete the entry + outZip.closeEntry(); } - - // Complete the entry - outZip.closeEntry(); - inFileStream.close(); } } @@ -865,16 +869,14 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } File backupfile = null; - try { - File projectfile = new File(filename); + File projectfile = new File(filename); + + // encode it to iso-8859-1, because props.load() use this encoding + try (Writer out = new OutputStreamWriter(new FileOutputStream(projectfile), "ISO-8859-1")) { // first try to make backup backupfile = makeBackupFile(projectfile); - // encode it to iso-8859-1, because props.load() use this encoding - Writer out = new OutputStreamWriter(new FileOutputStream( - projectfile), "ISO-8859-1"); - // get creation date long mscreatedtime = project.getCreationDate().getTime(); String createdTime = String.valueOf(mscreatedtime / 1000); @@ -885,13 +887,10 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, out.write("Created: " + createdTime + "\n"); out.write("Options: " + (project.isClosed() ? "1" : "0") + "\n"); - out.close(); - deleteBackupFile(backupfile); } catch (IOException e) { if (log.isDebugEnabled()) { - log.error("Can't save project information, restore backup file", - e); + log.error("Can't save project information, restore backup file", e); } // can be null if backup throw the exception @@ -967,15 +966,14 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } File backupfile = null; - try { - File taskfile = new File(filename); + File taskfile = new File(filename); + + // encode it to iso-8859-1, because props.load() use this encoding + try (Writer out = new OutputStreamWriter(new FileOutputStream(taskfile), "ISO-8859-1")) { + // first make backup backupfile = makeBackupFile(taskfile); - // encode it to iso-8859-1, because props.load() use this encoding - Writer out = new OutputStreamWriter(new FileOutputStream(taskfile), - "ISO-8859-1"); - // Format: 1.2 // Name: Test Tache 1.2 // Created: 1180944724 @@ -1006,8 +1004,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, out.write(gtimerDate + " " + value + "\n"); } - out.close(); - deleteBackupFile(backupfile); } catch (IOException e) { if (log.isErrorEnabled()) { @@ -1037,13 +1033,11 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, && !task.getAllDaysAnnotations().isEmpty()) { File backupfile = null; - try { + try (Writer out = new OutputStreamWriter(new FileOutputStream(annotationTaskFile), "ISO-8859-1")) { + // first make backup backupfile = makeBackupFile(annotationTaskFile); - Writer out = new OutputStreamWriter(new FileOutputStream( - annotationTaskFile), "ISO-8859-1"); - // save time of each day for (Entry<Date, String> entry : task.getAllDaysAnnotations() .entrySet()) { @@ -1054,8 +1048,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, out.write(gtimerTS + " " + entry.getValue() + "\n"); } - out.close(); - deleteBackupFile(backupfile); } catch (IOException e) { if (log.isErrorEnabled()) { @@ -1088,13 +1080,11 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, if (task.getAlerts() != null && !task.getAlerts().isEmpty()) { File backupfile = null; - try { + try (Writer out = new OutputStreamWriter(new FileOutputStream(alertTaskFile), "ISO-8859-1")) { + // first make backup backupfile = makeBackupFile(alertTaskFile); - Writer out = new OutputStreamWriter(new FileOutputStream( - alertTaskFile), "ISO-8859-1"); - out.write("Format: " + GTIMER_FILE_VERSION + "\n"); // save each alert @@ -1113,8 +1103,6 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, } } - out.close(); - deleteBackupFile(backupfile); } catch (IOException e) { if (log.isErrorEnabled()) { diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index d474a65..44b9b41 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2008 - 2011 CodeLutin, Chorlet Stéphane, Chatellier Eric, Chemit Tony + * Copyright (C) 2008 - 2016 CodeLutin, Chorlet Stéphane, Chatellier Eric, Chemit Tony * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -234,7 +234,9 @@ public class TimerTaskEditor extends JDialog implements ActionListener { } /** - * create command panel. + * Create command panel. + * + * @return command panel */ protected JPanel createCommandPanel() { // apply button @@ -276,7 +278,9 @@ public class TimerTaskEditor extends JDialog implements ActionListener { } /** - * create main content. + * Create main content. + * + * @return content panel */ protected JPanel createContentPanel() { JPanel panel = new JPanel(); @@ -297,7 +301,9 @@ public class TimerTaskEditor extends JDialog implements ActionListener { } /** - * create edition panel + * Create edition panel. + * + * @return edition panel */ protected JPanel createEditionPanel() { // timetask label @@ -363,7 +369,9 @@ public class TimerTaskEditor extends JDialog implements ActionListener { } /** - * create JXMonthView + * Create JXMonthView. + * + * @return month view component */ protected JXMonthView createJXMonthView() { monthView = new JXMonthView(); @@ -400,7 +408,9 @@ public class TimerTaskEditor extends JDialog implements ActionListener { } /** - * create three spinners panel + * Create three spinners panel. + * + * @return spinner panel */ protected JPanel createSpinnersPanel() { // hours spinner @@ -435,8 +445,7 @@ public class TimerTaskEditor extends JDialog implements ActionListener { } /** - * Listener on spinnerH, spinnerM and spinnerS - * + * Listener on spinnerH, spinnerM and spinnerS. */ protected class SpinnerListener implements ChangeListener { @Override diff --git a/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java b/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java index e66be7a..564afc5 100644 --- a/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2009 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2009 - 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 @@ -84,7 +84,7 @@ public class AlertCellEditor extends AbstractCellEditor implements TableCellEdit switch (column) { case 0: - JComboBox combo = new JComboBox(); + JComboBox<Type> combo = new JComboBox<>(); combo.addItem(Type.REACH_DAILY_TIME); combo.addItem(Type.REACH_TOTAL_TIME); combo.setSelectedItem(value); diff --git a/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java b/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java index 5d1b335..eab6541 100644 --- a/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java +++ b/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2009 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2009 - 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 @@ -56,7 +56,7 @@ public class AlertCellRenderer extends DefaultTableCellRenderer { Component c = null; switch (column) { case 0: - JComboBox combo = new JComboBox(); + JComboBox<Type> combo = new JComboBox<>(); combo.addItem(Type.REACH_DAILY_TIME); combo.addItem(Type.REACH_TOTAL_TIME); combo.setSelectedItem(value); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 5970b85b0b01ad52cdfb36af0a88b126bd4e0770 Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 11:49:28 2016 +0100 refs #1322: Fix some warning and depreciation --- src/main/java/org/chorem/jtimer/JTimer.java | 4 ++-- src/main/java/org/chorem/jtimer/JTimerConfig.java | 2 +- src/main/java/org/chorem/jtimer/JTimerFactory.java | 2 +- src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java | 2 +- src/main/java/org/chorem/jtimer/ui/report/ReportGenerator.java | 4 ++-- src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java | 2 +- src/main/java/org/chorem/jtimer/ui/system/win32/User32.java | 2 +- src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java | 1 + 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index 26d777d..f48a532 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.java @@ -727,7 +727,7 @@ public class JTimer extends SingleFrameApplication implements RunTaskJob job = null; TaskMonitor tm = getContext().getTaskMonitor(); - for (Task t : tm.getTasks()) { + for (Task<?, ?> t : tm.getTasks()) { TimerTask localtask = ((RunTaskJob) t).getTask(); if (task.equals(localtask)) { job = (RunTaskJob) t; @@ -779,7 +779,7 @@ public class JTimer extends SingleFrameApplication implements public void stopAllTasks() { TaskMonitor tm = getContext().getTaskMonitor(); - for (Task t : tm.getTasks()) { + for (Task<?, ?> t : tm.getTasks()) { // task TimerTask ttask = ((RunTaskJob) t).getTask(); stopTask(ttask); diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index fe9dd33..2812aa8 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -95,7 +95,7 @@ public class JTimerConfig { } } - public Class getIOSaverClass() { + public Class<?> getIOSaverClass() { return appConfig.getOptionAsClass(JTimerOption.IO_SAVER_CLASS.key); } diff --git a/src/main/java/org/chorem/jtimer/JTimerFactory.java b/src/main/java/org/chorem/jtimer/JTimerFactory.java index 396f810..d723519 100644 --- a/src/main/java/org/chorem/jtimer/JTimerFactory.java +++ b/src/main/java/org/chorem/jtimer/JTimerFactory.java @@ -59,7 +59,7 @@ public class JTimerFactory { if (saver == null) { - Class saverClass = JTimer.config.getIOSaverClass(); + Class<?> saverClass = JTimer.config.getIOSaverClass(); // log if (log.isInfoEnabled()) { diff --git a/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java b/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java index 564afc5..a63f8a5 100644 --- a/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java @@ -67,7 +67,7 @@ public class AlertCellEditor extends AbstractCellEditor implements TableCellEdit Object value = null; if (editor instanceof JComboBox) { - value = ((JComboBox)editor).getSelectedItem(); + value = ((JComboBox<?>)editor).getSelectedItem(); } else if (editor instanceof DurationEditor) { value = ((DurationEditor)editor).getDuration(); diff --git a/src/main/java/org/chorem/jtimer/ui/report/ReportGenerator.java b/src/main/java/org/chorem/jtimer/ui/report/ReportGenerator.java index 9a19803..c26e3c2 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/ReportGenerator.java +++ b/src/main/java/org/chorem/jtimer/ui/report/ReportGenerator.java @@ -72,7 +72,7 @@ public class ReportGenerator { */ public ReportGenerator() { - freemarkerConfiguration = new Configuration(); + freemarkerConfiguration = new Configuration(Configuration.VERSION_2_3_23); // needed to overwrite "Defaults to default system encoding." // fix encoding issue on some systems @@ -82,7 +82,7 @@ public class ReportGenerator { ClassTemplateLoader templateLoader = new ClassTemplateLoader(ReportGenerator.class, "/ftl"); freemarkerConfiguration.setTemplateLoader(templateLoader); - freemarkerConfiguration.setObjectWrapper(new BeansWrapper()); + freemarkerConfiguration.setObjectWrapper(new BeansWrapper(Configuration.VERSION_2_3_23)); } /** diff --git a/src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java b/src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java index 441c6a5..884444c 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java +++ b/src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java @@ -59,7 +59,7 @@ public interface Xss extends Library { public NativeLong idle; /* total time since last user input */ public NativeLong eventMask; /* currently selected events for this client */ @Override - protected List getFieldOrder() { + protected List<?> getFieldOrder() { return Arrays.asList(new String[] { "window", "state", "kind", "til_or_since", "idle", "eventMask"}); } } diff --git a/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java b/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java index 6cd0581..95e2ff5 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java +++ b/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java @@ -57,7 +57,7 @@ public interface User32 extends StdCallLibrary { public int dwTime; @Override - protected List getFieldOrder() { + protected List<?> getFieldOrder() { return Arrays.asList(new String[] { "cbSize", "dwTime"}); } } diff --git a/src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java b/src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java index c01445e..171bcdf 100644 --- a/src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java +++ b/src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java @@ -632,5 +632,6 @@ public class TimerDataManagerTest extends AbstractJTimerTest { core.load(); TimerTask task = dataManager.getTaskForPath("jTimer"); + Assert.assertNotNull(task); } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
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 c621a557a6fc959cd84c7d4d15d8a55d5a42e5b2 Author: Eric Chatellier <chatellier@codelutin.com> Date: Tue Feb 23 12:18:27 2016 +0100 refs #1320: Update log4j2 --- pom.xml | 12 ++++++--- src/main/resources/log4j.properties | 51 ------------------------------------- src/main/resources/log4j2.xml | 38 +++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 54 deletions(-) diff --git a/pom.xml b/pom.xml index 5bb391c..4601e82 100644 --- a/pom.xml +++ b/pom.xml @@ -317,9 +317,15 @@ <scope>compile</scope> </dependency> <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.17</version> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.5</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-jcl</artifactId> + <version>2.5</version> <scope>runtime</scope> </dependency> <dependency> diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties deleted file mode 100644 index d425f12..0000000 --- a/src/main/resources/log4j.properties +++ /dev/null @@ -1,51 +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% -### -# Global logging configuration -log4j.rootLogger=WARN, stdout - -# Console output... -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %5p (%F:%L) %m%n - -# File output... -#log4j.appender.fileout=org.apache.log4j.FileAppender -#log4j.appender.fileout.File=jtimer.log -#log4j.appender.fileout.Append=true -#log4j.appender.fileout.Threshold=DEBUG -#log4j.appender.fileout.layout=org.apache.log4j.PatternLayout -#log4j.appender.fileout.layout.ConversionPattern=%5p (%F:%L) %m%n - -# Rolling appender -#log4j.appender.rolling=org.apache.log4j.RollingFileAppender -#log4j.appender.rolling.File=jtimer.log -#log4j.appender.rolling.MaxFileSize=100KB -#log4j.appender.rolling.Append=true -#log4j.appender.rolling.MaxBackupIndex=30 -#log4j.appender.rolling.Threshold=INFO -#log4j.appender.rolling.layout=org.apache.log4j.PatternLayout -#log4j.appender.rolling.layout.ConversionPattern=%d{yyyy/MM/dd hh:mm:ss} %5p (%F:%L) %m%n - -# package level -#log4j.logger.org.chorem.jtimer=DEBUG -#log4j.logger.org.chorem.jtimer.ws=DEBUG -#log4j.logger.org.chorem.jtimer.ui.report=DEBUG diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 0000000..60f69cc --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + jTimer + %% + Copyright (C) 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 + 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% + --> +<Configuration> + + <Appenders> + <Console name="Console" target="SYSTEM_OUT"> + <PatternLayout pattern="%d{yyyy/MM/dd HH:mm:ss} %5p (%c:%L) - %m%n" /> + </Console> + </Appenders> + + <Loggers> + <!-- <Logger name="org.chorem.jtimer" level="debug"/> --> + + <Root level="warn"> + <AppenderRef ref="Console" /> + </Root> + </Loggers> +</Configuration> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm