Author: tchemit Date: 2012-10-16 22:18:19 +0200 (Tue, 16 Oct 2012) New Revision: 367 Url: http://nuiton.org/repositories/revision/jredmine/367 Log: fixes #2354: Do not use any longer helper-m-p rest api but simple httpcomponents client Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequest.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestHelper.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/AbstractRedmineService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineAnonymousService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineAnonymousService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineConfigurationUtil.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineLogguedService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceConfiguration.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceException.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceLoginException.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineAnonymousServiceTest.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineServiceAsAnonymousTest.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineServiceTest.java Removed: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineConfigurationUtil.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineLogguedService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceException.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceLoginException.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceTest.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceAsAnonymousTest.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceTest.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java Modified: trunk/jredmine-client/pom.xml trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssueCategoryXpp3Reader.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssuePriorityXpp3Reader.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssueStatusXpp3Reader.java trunk/jredmine-client/src/site/apt/redmine_service.apt trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/AbstractRedmineFixtures.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineAnonymousFixtureClassRule.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineFixtureClassRule.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineServer.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineAnonymousServiceTCK.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineServiceAsAnonymousTCK.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineServiceTCK.java trunk/jredmine-maven-plugin/pom.xml trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoWithProject.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoWithProjectAndVersion.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/DisplayDataMojo.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/GenerateChangesMojo.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/IssuesCollector.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/LoginMojo.java trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractIssuesReport.java trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineAnonymousFixtureClassRule.java trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineFixtures.java trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineLogguedFixtureClassRule.java trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractAnonymousRedmineMojoTest.java trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractLogguedRedmineMojoTest.java trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoTest.java trunk/pom.xml Modified: trunk/jredmine-client/pom.xml =================================================================== --- trunk/jredmine-client/pom.xml 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/pom.xml 2012-10-16 20:18:19 UTC (rev 367) @@ -77,8 +77,8 @@ </dependency> <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpcore</artifactId> </dependency> <dependency> Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,250 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.io.rest.RestClientConfiguration; -import org.nuiton.jredmine.model.Attachment; -import org.nuiton.jredmine.model.Issue; -import org.nuiton.jredmine.model.IssueCategory; -import org.nuiton.jredmine.model.IssuePriority; -import org.nuiton.jredmine.model.IssueStatus; -import org.nuiton.jredmine.model.ModelHelper; -import org.nuiton.jredmine.model.News; -import org.nuiton.jredmine.model.Project; -import org.nuiton.jredmine.model.TimeEntry; -import org.nuiton.jredmine.model.Tracker; -import org.nuiton.jredmine.model.User; -import org.nuiton.jredmine.model.Version; - -/** - * Default implementation of {@link RedmineAnonymousService}. - * <p/> - * Created: 2 janv. 2010 - * - * @author tchemit <chemit@codelutin.com> - * @plexus.component role="org.nuiton.jredmine.RedmineAnonymousService" role-hint="default" - * @see RestClientConfiguration#isAnonymous() - * @since 1.0.3 - */ -public class DefaultRedmineAnonymousService implements RedmineAnonymousService { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(DefaultRedmineAnonymousService.class); - - /** - * Delegate all the technical layer to an implementor. - * - * @see RedmineServiceImplementor - */ - protected final RedmineServiceImplementor delegateImplementor; - - /** - * Default constructor. - * <p/> - * Make this service use the default {@link RedmineServiceImplementor}. - * - * @see DefaultRedmineServiceImplementor - * @since 1.4 - */ - public DefaultRedmineAnonymousService() { - this(new DefaultRedmineServiceImplementor()); - } - - /** - * Service constructor using the givne implementator to deal this technical layer. - * - * @param delegateImplementor the implementator to use - * @since 1.4 - */ - public DefaultRedmineAnonymousService(RedmineServiceImplementor delegateImplementor) { - this.delegateImplementor = delegateImplementor; - } - - /////////////////////////////////////////////////////////////////////////// - /// RedmineAnonymousService implementation - /////////////////////////////////////////////////////////////////////////// - - @Override - public void init(RedmineServiceConfiguration configuration) throws RedmineServiceException { - // Force to not be loggued - configuration.setAnonymous(true); - if (log.isDebugEnabled()) { - log.debug("init service with configuration: " + configuration); - } - if (!delegateImplementor.isInit()) { - - // only init once - delegateImplementor.init(configuration); - } - } - - @Override - public void destroy() throws RedmineServiceException { - delegateImplementor.destroy(); - } - - @Override - public RedmineServiceImplementor getDelegateImplementor() { - return delegateImplementor; - } - - @Override - public IssueStatus[] getIssueStatuses() throws RedmineServiceException { - return delegateImplementor.getDatas(ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME, - IssueStatus.class - ); - } - - @Override - public IssuePriority[] getIssuePriorities() throws RedmineServiceException { - return delegateImplementor.getDatas(ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME, - IssuePriority.class - ); - } - - @Override - public Project[] getProjects() throws RedmineServiceException { - return delegateImplementor.getDatas(ModelHelper.GET_ALL_PROJECT_REQUEST_NAME, Project.class); - } - - @Override - public IssueCategory[] getIssueCategories(String projectName) throws RedmineServiceException { - return delegateImplementor.getDatas(ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME, - IssueCategory.class, - projectName - ); - } - - @Override - public Project getProject(String projectName) throws RedmineServiceException { - return delegateImplementor.getData(ModelHelper.GET_PROJECT_REQUEST_NAME, - Project.class, - projectName - ); - } - - @Override - public Tracker[] getTrackers(String projectName) throws RedmineServiceException { - return delegateImplementor.getDatas(ModelHelper.GET_ALL_TRACKER_REQUEST_NAME, - Tracker.class, - projectName - ); - } - - @Override - public News[] getNews(String projectName) throws RedmineServiceException { - return delegateImplementor.getDatas(ModelHelper.GET_ALL_NEWS_REQUEST_NAME, - News.class, - projectName - ); - } - - @Override - public User[] getProjectMembers(String projectName) throws RedmineServiceException { - return delegateImplementor.getDatas(ModelHelper.GET_ALL_USER_REQUEST_NAME, - User.class, - projectName - ); - } - - @Override - public Version[] getVersions(String projectName) throws RedmineServiceException { - return delegateImplementor.getDatas(ModelHelper.GET_ALL_VERSION_REQUEST_NAME, - Version.class, - projectName - ); - } - - @Override - public Version getVersion(String projectName, - String versionName) throws RedmineServiceException { - return delegateImplementor.getData(ModelHelper.GET_VERSION_REQUEST_NAME, - Version.class, - projectName, - versionName - ); - } - - @Override - public Attachment[] getAttachments(String projectName, - String versionName) throws RedmineServiceException { - return delegateImplementor.getDatas(ModelHelper.GET_ALL_ATTACHMENTS_REQUEST_NAME, - Attachment.class, - projectName, - versionName - ); - } - - @Override - public Issue[] getIssues(String projectName, - String versionName) throws RedmineServiceException { - return delegateImplementor.getDatas(ModelHelper.GET_ALL_ISSUES_REQUEST_NAME, - Issue.class, - projectName, - versionName - ); - } - - @Override - public TimeEntry[] getIssueTimeEntries(String projectName, - String issueId) throws RedmineServiceException { - return delegateImplementor.getDatas(ModelHelper.GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME, - TimeEntry.class, - projectName, - issueId - ); - } - - @Override - public Issue[] getIssues(String projectName) throws RedmineServiceException { - Issue[] result = delegateImplementor.getDatas(ModelHelper.GET_ALL_PROJECT_ISSUES_REQUEST_NAME, - Issue.class, - projectName - ); - return result; - } - - @Override - public Issue[] getOpenedIssues(String projectName) throws RedmineServiceException { - Issue[] result = delegateImplementor.getDatas(ModelHelper.GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME, - Issue.class, - projectName - ); - return result; - } - - @Override - public Issue[] getClosedIssues(String projectName) throws RedmineServiceException { - Issue[] result = delegateImplementor.getDatas(ModelHelper.GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME, - Issue.class, - projectName - ); - return result; - } - -} Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,314 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.jredmine.model.Attachment; -import org.nuiton.jredmine.model.Issue; -import org.nuiton.jredmine.model.IssueCategory; -import org.nuiton.jredmine.model.IssuePriority; -import org.nuiton.jredmine.model.IssueStatus; -import org.nuiton.jredmine.model.ModelHelper; -import org.nuiton.jredmine.model.News; -import org.nuiton.jredmine.model.Project; -import org.nuiton.jredmine.model.TimeEntry; -import org.nuiton.jredmine.model.Tracker; -import org.nuiton.jredmine.model.User; -import org.nuiton.jredmine.model.Version; - -/** - * Default {@link RedmineService} implementation. - * - * @author tchemit <chemit@codelutin.com> - * @plexus.component role="org.nuiton.jredmine.RedmineService" role-hint="default" - * @since 1.0.0 - */ -public class DefaultRedmineService implements RedmineService { - - protected static final Log log = LogFactory.getLog(DefaultRedmineService.class); - - /** - * Delegate all the technical layer to a implementor. - * - * @see RedmineServiceImplementor - * @since 1.4 - */ - protected final RedmineServiceImplementor delegateImplementor; - - /** - * Delegate all anonymous call to the anonymous service. - * - * @see RedmineAnonymousService - * @since 1.4 - */ - protected final RedmineAnonymousService anonymousService; - - /** - * Default constructor. - * <p/> - * Make this service use the default {@link RedmineServiceImplementor}. - * - * @see DefaultRedmineServiceImplementor - * @since 1.4 - */ - public DefaultRedmineService() { - this(new DefaultRedmineServiceImplementor()); - } - - /** - * Service constructor using the givne implementator to deal this technical layer. - * - * @param delegateImplementor the implementator to use - * @since 1.4 - */ - public DefaultRedmineService(RedmineServiceImplementor delegateImplementor) { - this.delegateImplementor = delegateImplementor; - this.anonymousService = new DefaultRedmineAnonymousService(delegateImplementor); - } - - /////////////////////////////////////////////////////////////////////////// - /// RedmineAnonymousService implementation - /////////////////////////////////////////////////////////////////////////// - - @Override - public void init(RedmineServiceConfiguration configuration) throws RedmineServiceException { - if (log.isDebugEnabled()) { - log.debug("init service with configuration: " + configuration); - } - if (!delegateImplementor.isInit()) { - - // only init once - delegateImplementor.init(configuration); - } - } - - @Override - public void destroy() throws RedmineServiceException { - delegateImplementor.destroy(); - } - - @Override - public RedmineServiceImplementor getDelegateImplementor() { - return delegateImplementor; - } - - @Override - public IssueStatus[] getIssueStatuses() throws RedmineServiceException { - IssueStatus[] result = anonymousService.getIssueStatuses(); - return result; - } - - @Override - public IssuePriority[] getIssuePriorities() throws RedmineServiceException { - IssuePriority[] result = anonymousService.getIssuePriorities(); - return result; - } - - @Override - public Project[] getProjects() throws RedmineServiceException { - Project[] result = anonymousService.getProjects(); - return result; - } - - @Override - public IssueCategory[] getIssueCategories(String projectName) throws RedmineServiceException { - IssueCategory[] result = anonymousService.getIssueCategories(projectName); - return result; - } - - @Override - public Project getProject(String projectName) throws RedmineServiceException { - Project result = anonymousService.getProject(projectName); - return result; - } - - @Override - public Tracker[] getTrackers(String projectName) throws RedmineServiceException { - Tracker[] result = anonymousService.getTrackers(projectName); - return result; - } - - @Override - public News[] getNews(String projectName) throws RedmineServiceException { - News[] result = anonymousService.getNews(projectName); - return result; - } - - @Override - public User[] getProjectMembers(String projectName) throws RedmineServiceException { - User[] result = anonymousService.getProjectMembers(projectName); - return result; - } - - @Override - public Version[] getVersions(String projectName) throws RedmineServiceException { - Version[] result = anonymousService.getVersions(projectName); - return result; - } - - @Override - public Version getVersion(String projectName, - String versionName) throws RedmineServiceException { - Version result = anonymousService.getVersion(projectName, versionName); - return result; - } - - @Override - public Attachment[] getAttachments(String projectName, - String versionName) throws RedmineServiceException { - Attachment[] result = anonymousService.getAttachments(projectName, versionName); - return result; - } - - @Override - public Issue[] getIssues(String projectName, - String versionName) throws RedmineServiceException { - Issue[] result = anonymousService.getIssues(projectName, versionName); - return result; - } - - @Override - public TimeEntry[] getIssueTimeEntries(String projectName, - String issueId) throws RedmineServiceException { - TimeEntry[] result = anonymousService.getIssueTimeEntries(projectName, issueId); - return result; - } - - @Override - public Issue[] getIssues(String projectName) throws RedmineServiceException { - Issue[] result = anonymousService.getIssues(projectName); - return result; - } - - @Override - public Issue[] getOpenedIssues(String projectName) throws RedmineServiceException { - Issue[] result = anonymousService.getOpenedIssues(projectName); - return result; - } - - @Override - public Issue[] getClosedIssues(String projectName) throws RedmineServiceException { - Issue[] result = anonymousService.getClosedIssues(projectName); - return result; - } - - /////////////////////////////////////////////////////////////////////////// - /// RedmineLogguedService implementation - /////////////////////////////////////////////////////////////////////////// - - @Override - public Project[] getUserProjects() throws RedmineServiceException { - delegateImplementor.checkLoggued(); - Project[] result = delegateImplementor.getDatas(ModelHelper.GET_USER_PROJECTS_REQUEST_NAME, - Project.class); - return result; - } - - @Override - public Version addVersion(String projectName, - Version version) throws RedmineServiceException { - - // send data and obtain created version - Version result = delegateImplementor.sendData(ModelHelper.ADD_VERSION_REQUEST_NAME, - Version.class, - projectName, - version - ); - return result; - } - - @Override - public Version updateVersion(String projectName, - Version version) throws RedmineServiceException { - - // send data and obtain updated version - Version result = delegateImplementor.sendData(ModelHelper.UPDATE_VERSION_REQUEST_NAME, - Version.class, - projectName, - version - ); - return result; - } - - @Override - public Version nextVersion(String projectName, - String oldVersionName, - Version newVersion) throws RedmineServiceException { - - // send data and obtain updated or created new version - Version result = delegateImplementor.sendData(ModelHelper.NEXT_VERSION_REQUEST_NAME, - Version.class, - projectName, - newVersion, - oldVersionName - ); - return result; - } - - @Override - public Attachment addAttachment(String projectName, - String versionName, - Attachment attachement) throws RedmineServiceException { - - // send data and obtain created attachment - Attachment result = delegateImplementor.sendData(ModelHelper.ADD_ATTACHMENT_REQUEST_NAME, - Attachment.class, - projectName, - versionName, - attachement - ); - return result; - } - - @Override - public News addNews(String projectName, - News news) throws RedmineServiceException { - - // send data and obtain created news - News result = delegateImplementor.sendData(ModelHelper.ADD_NEWS_REQUEST_NAME, - News.class, - projectName, - news - ); - return result; - } - - @Override - public TimeEntry addIssueTimeEntry(String projectName, - String issueId, - TimeEntry entry) throws RedmineServiceException { - - // send data and obtain created time entry - TimeEntry result = delegateImplementor.sendData(ModelHelper.ADD_ISSUE_TIME_ENTRY_REQUEST_NAME, - TimeEntry.class, - projectName, - issueId, - entry - ); - return result; - } - -} Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,267 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -import com.google.common.base.Preconditions; -import org.nuiton.io.rest.RestRequest; -import org.nuiton.jredmine.model.io.xpp3.RedmineXpp3Helper; -import org.nuiton.jredmine.client.RedmineClient; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Default Redmine technical service implementation. - * <p/> - * Created: 2 janv. 2010 - * - * @author tchemit <chemit@codelutin.com> - * @see RedmineServiceImplementor - * @since 1.0.3 - */ -public class DefaultRedmineServiceImplementor implements RedmineServiceImplementor { - - /** - * Redmine client. - * - * @since 1.5 - */ - protected RedmineClient client; - - /** xpp3 xpp3Helper to transform xml stream to pojo */ - protected final RedmineXpp3Helper xpp3Helper; - - /** internal state to known if service was init */ - protected boolean init; - - public DefaultRedmineServiceImplementor() { - xpp3Helper = new RedmineXpp3Helper(); - } - - /////////////////////////////////////////////////////////////////////////// - /// RedmineServiceImplementor implementation - /////////////////////////////////////////////////////////////////////////// - - @Override - public boolean isInit() { - return init; - } - - @Override - public RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException { - Preconditions.checkNotNull(configuration, "the client configuration was not be null!"); - Preconditions.checkState(!init, "the client " + this + " was already init!"); - client = new RedmineClient(configuration); - try { - - client.open(); - - init = true; - } catch (Exception e) { - throw new RedmineServiceException( - "could not init service for reason " + e.getMessage(), e); - } - return this; - } - - @Override - public void destroy() throws RedmineServiceException { - if (isInit()) { - try { - if (client.isOpen()) { - try { - client.close(); - } catch (IOException e) { - throw new RedmineServiceException( - "has problem while closing Rest client " + - e.getMessage(), e); - } - } - } finally { - if (client != null) { - client = null; - } - init = false; - } - } - } - - @Override - public RedmineClient getClient() { - return client; - } - - @Override - public <T> T getData(String requestName, - Class<T> type, - Object... args) throws RedmineServiceException { - checkInit(); - InputStream stream = askDataStream(requestName, args); - T result = getDataFromStream(type, stream); - return result; - } - - @Override - public <T> T[] getDatas(String requestName, - Class<T> type, - Object... args) throws RedmineServiceException { - checkInit(); - InputStream stream = askDataStream(requestName, args); - T[] result = getDatasFromStream(type, stream); - return result; - } - - @Override - public <T> T sendData(String requestName, - Class<T> klazz, - Object... args) throws RedmineServiceException { - checkLoggued(); - InputStream stream = sendDataStream(requestName, args); - T result = getDataFromStream(klazz, stream); - return result; - } - - @Override - public <T> T[] sendDatas(String requestName, - Class<T> klazz, - Object... args) throws RedmineServiceException { - checkLoggued(); - InputStream stream = sendDataStream(requestName, args); - T[] result = getDatasFromStream(klazz, stream); - return result; - } - - @Override - public void checkLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException { - checkInit(); - checkSessionNotNull(); - checkSessionConfigurationNotNull(); - if (client.getConfiguration().isAnonymous()) { - throw new RedmineServiceLoginException( - "can not access this service in anonymous mode"); - } - } - - protected InputStream askDataStream(String requestName, - Object... args) throws RedmineServiceException { - - RestRequest r = getRequest(requestName, args); - - // obtain data from rest client - try { - - InputStream stream = client.executeRequest(r); - return stream; - } catch (Exception e) { - throw new RedmineServiceException( - "could not obtain data stream for request " + requestName + - " for reason " + e.getMessage(), e); - } - } - - protected InputStream sendDataStream(String requestName, - Object... args) throws RedmineServiceException { - - RestRequest r = getRequest(requestName, args); - - // obtain data from rest client - try { - - InputStream stream = client.executeRequest(r); - return stream; - } catch (Exception e) { - throw new RedmineServiceException( - "could not send data stream for request " + requestName + - " for reason " + e.getMessage(), e); - } - } - - protected RestRequest getRequest(String requestName, - Object... args) throws RedmineServiceException { - RestRequest r; - try { - r = client.getRequest(requestName, args); - } catch (Exception e) { - throw new RedmineServiceException( - "could not find the request named " + requestName + - " for reason " + e.getMessage(), e); - } - if (r == null) { - throw new RedmineServiceException( - "could not find the request named " + requestName); - } - return r; - } - - protected <T> T getDataFromStream(Class<T> type, - InputStream stream) throws RedmineServiceException { - try { - T result = null; - if (stream != null) { - result = xpp3Helper.readObject(type, stream, false); - } - return result; - } catch (Exception ex) { - throw new RedmineServiceException( - "could not obtain datas of type " + type + " for reason " + - ex.getMessage(), ex); - } - } - - protected <T> T[] getDatasFromStream(Class<T> type, - InputStream stream) throws RedmineServiceException { - try { - T[] result = null; - if (stream != null) { - result = xpp3Helper.readObjects(type, stream, false); - } - return result; - } catch (Exception ex) { - throw new RedmineServiceException( - "could not obtain datas of type " + type + " for reason " + - ex.getMessage(), ex); - } - } - - protected void checkInit() throws IllegalStateException { - if (!init) { - throw new IllegalStateException( - "the client " + this + " is not init!"); - } - } - - protected void checkSessionNotNull() { - if (client == null) { - throw new NullPointerException("session can not be null"); - } - } - - protected void checkSessionConfigurationNotNull() { - if (client.getConfiguration() == null) { - throw new NullPointerException( - "session configuration can not be null"); - } - } -} Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,246 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -import org.nuiton.jredmine.model.Attachment; -import org.nuiton.jredmine.model.Issue; -import org.nuiton.jredmine.model.IssueCategory; -import org.nuiton.jredmine.model.IssuePriority; -import org.nuiton.jredmine.model.IssueStatus; -import org.nuiton.jredmine.model.News; -import org.nuiton.jredmine.model.Project; -import org.nuiton.jredmine.model.TimeEntry; -import org.nuiton.jredmine.model.Tracker; -import org.nuiton.jredmine.model.User; -import org.nuiton.jredmine.model.Version; - -/** - * Contract of all redmine operations which do not requires any login to server. - * <p/> - * A default implementation is {@link DefaultRedmineAnonymousService}. - * <p/> - * Created: 2 janv. 2010 - * - * @author tchemit <chemit@codelutin.com> - * @see DefaultRedmineAnonymousService - * @since 1.0.3 - */ -public interface RedmineAnonymousService { - - /** - * Initialize the service. - * - * @param configuration the configuration to be used to init the internal redmine client - * @throws RedmineServiceException if any pb - */ - void init(RedmineServiceConfiguration configuration) throws RedmineServiceException; - - /** - * Close the service and destroy any connexion to the redmine service. - * - * @throws RedmineServiceException if any pb - */ - void destroy() throws RedmineServiceException; - - /** - * Get the technical layer. - * - * @return the technical layer. - * @since 1.4 - */ - RedmineServiceImplementor getDelegateImplementor(); - - /** - * Obtain all accessible projects. - * - * @return all the projects - * @throws RedmineServiceException if any pb while retriving datas - * @see Project - */ - Project[] getProjects() throws RedmineServiceException; - - /** - * Obtain all the priorities defined on a {@link Issue}. - * <p/> - * <b>Note : </b> The priorities are common for all projects. - * - * @return all the issue properties - * @throws RedmineServiceException if any pb while retriving datas - * @see IssuePriority - */ - IssuePriority[] getIssuePriorities() throws RedmineServiceException; - - /** - * Obtain all the statuses defined on a {@link Issue}. - * <p/> - * <b>Note : </b> The statuses are common for all projects. - * - * @return all the issue statuses - * @throws RedmineServiceException if any pb while retriving datas - * @see IssueStatus - */ - IssueStatus[] getIssueStatuses() throws RedmineServiceException; - - /** - * Obtain a project given his name. - * - * @param projectName the name of the project - * @return the project - * @throws RedmineServiceException if any pb while retriving datas - * @see Project - */ - Project getProject(String projectName) throws RedmineServiceException; - - /** - * Obtain all categories defined on issues for a given project. - * - * @param projectName the name of the project - * @return the categories of issues for the given project. - * @throws RedmineServiceException if any pb while retriving datas - * @see IssueCategory - */ - IssueCategory[] getIssueCategories(String projectName) throws RedmineServiceException; - - /** - * Obtain all trackers defined on a given project. - * - * @param projectName the name of the project - * @return the trackers for the given project. - * @throws RedmineServiceException if any pb while retriving datas - * @see Tracker - */ - Tracker[] getTrackers(String projectName) throws RedmineServiceException; - - /** - * Obtain all news defined on a given project. - * - * @param projectName the name of the project - * @return the news for the given project. - * @throws RedmineServiceException if any pb while retriving datas - * @see News - */ - News[] getNews(String projectName) throws RedmineServiceException; - - /** - * Obtain all users defined on a given project. - * - * @param projectName the name of the project - * @return the users for the given project. - * @throws RedmineServiceException if any pb while retriving datas - * @see User - */ - User[] getProjectMembers(String projectName) throws RedmineServiceException; - - /** - * Obtain all versions defined on a given project. - * - * @param projectName the name of the project - * @return the versions of the given project. - * @throws RedmineServiceException if any pb while retriving datas - * @see Version - */ - Version[] getVersions(String projectName) throws RedmineServiceException; - - /** - * Obtain a specific version for a given project. - * - * @param projectName the name of the project - * @param versionName the name of the version - * @return the version - * @throws RedmineServiceException if any pb while retriving datas - * @see Version - */ - Version getVersion(String projectName, - String versionName) throws RedmineServiceException; - - /** - * Obtain all issues for a given project. - * - * @param projectName the name of the project - * @return the issues - * @throws RedmineServiceException if any pb while retriving datas - * @see Issue - * @since 1.0.3 - */ - Issue[] getIssues(String projectName) throws RedmineServiceException; - - /** - * Obtain all opened issues for a given project. - * - * @param projectName the name of the project - * @return the issues - * @throws RedmineServiceException if any pb while retriving datas - * @see Issue - * @since 1.0.3 - */ - Issue[] getOpenedIssues(String projectName) throws RedmineServiceException; - - /** - * Obtain all closed issues for a given project. - * - * @param projectName the name of the project - * @return the issues - * @throws RedmineServiceException if any pb while retriving datas - * @see Issue - * @since 1.0.3 - */ - Issue[] getClosedIssues(String projectName) throws RedmineServiceException; - - /** - * Obtain all issues for a specific version on a given project. - * - * @param projectName the name of the project - * @param versionName the name of the version - * @return the issues - * @throws RedmineServiceException if any pb while retriving datas - * @see Issue - */ - Issue[] getIssues(String projectName, - String versionName) throws RedmineServiceException; - - /** - * Obtain for a given issue of a given project all the time entries. - * - * @param projectName the name of the project - * @param issueId the id of the issue - * @return the time entries of the issue - * @throws RedmineServiceException if any pb while retrieving time entries of the issue - * @since 1.0.3 - */ - TimeEntry[] getIssueTimeEntries(String projectName, - String issueId) throws RedmineServiceException; - - /** - * Obtain all attachments for a specific version on a given project. - * - * @param projectName the name of the project - * @param versionName the name of the version - * @return the attachments - * @throws RedmineServiceException if any pb while retriving datas - * @see Attachment - */ - Attachment[] getAttachments(String projectName, - String versionName) throws RedmineServiceException; -} Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineConfigurationUtil.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineConfigurationUtil.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineConfigurationUtil.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,358 +0,0 @@ -package org.nuiton.jredmine; -/* - * #%L - * JRedmine :: Client - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.beanutils.BeanUtilsBean; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.jredmine.client.RedmineClient; -import org.nuiton.jredmine.client.RedmineClientAuthConfiguration; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Properties; - -/** - * Helper methods about configuration. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.5 - */ -public class RedmineConfigurationUtil { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(RedmineConfigurationUtil.class); - - public static final String PROPERTY_PREFIX = "jredmine-test."; - - protected RedmineConfigurationUtil() { - // avoid instance - } - - public static RedmineServiceConfiguration obtainRedmineConfiguration(RedmineServiceConfiguration anoConf) throws IOException { - - RedmineServiceConfiguration conf = newLogguedConfiguration(anoConf); - - boolean ok = false; - - RedmineClient client = new RedmineClient(conf); - - try { - - client.open(); - ok = client.isOpen(); - } catch (Exception e) { - - if (log.isDebugEnabled()) { - log.debug("Could not connect to redmine with configuration: " + conf, e); - } - - } finally { - try { - client.close(); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not close session", e); - } - } - } - - if (!ok) { - - // try to connect anonymous - conf = cloneConfiguration(anoConf); - - client = new RedmineClient(conf); - - try { - - client.open(); - ok = client.isOpen(); - } catch (Exception e) { - - if (log.isDebugEnabled()) { - log.debug("Could not connect to redmine with configuration: " + conf, e); - } - } finally { - try { - client.close(); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not close session", e); - } - } - } - } - - if (!ok) { - - // no conf available - conf = null; - } - return conf; - } - - public static RedmineServiceConfiguration newAnonymousConfiguration(String propertiesFromEnv, - String classPathPropertiesLocation) - throws IOException { - - Properties props = new Properties(); - - InputStream in = null; - try { - String jredmineConfiguration = System.getenv(propertiesFromEnv); - if (jredmineConfiguration == null) { - if (log.isWarnEnabled()) { - log.warn("Could not find environement variable " + - "'jredmine-test.properties' will use " + - "default test configuration"); - } - - in = RedmineConfigurationUtil.class.getResourceAsStream(classPathPropertiesLocation); - } else { - - File file = new File(jredmineConfiguration); - - if (!file.exists()) { - throw new IllegalStateException("Could not find " + jredmineConfiguration + - " file"); - } - in = FileUtils.openInputStream(file); - } - props.load(in); - in.close(); - } finally { - IOUtils.closeQuietly(in); - } - - RedmineServiceConfiguration result = new SimpleRedmineServiceConfiguration(); - - RedmineClientAuthConfiguration authConfiguration = - new RedmineClientAuthConfiguration(); - result.setAuthConfiguration(authConfiguration); - overridePropertyFromProperties(result, "url", props); - overridePropertyFromProperties(result, "encoding", props); - overridePropertyFromProperties(result, "verbose", props); - - overridePropertyFromEnv(result, "url"); - overridePropertyFromEnv(result, "encoding"); - overridePropertyFromEnv(result, "verbose"); - result.setAnonymous(true); - return result; - } - - public static RedmineServiceConfiguration newLogguedConfiguration(RedmineServiceConfiguration anoConf) - throws IOException { - - // use anonymous configuration - - RedmineServiceConfiguration result = cloneConfiguration(anoConf); - - RedmineClientAuthConfiguration authConfiguration = - result.getAuthConfiguration(); - overridePropertyFromEnv(authConfiguration, "username"); - overridePropertyFromEnv(authConfiguration, "password"); - overridePropertyFromEnv(authConfiguration, "apiKey"); - - result.setAnonymous(false); - - return result; - } - - public static RedmineServiceConfiguration cloneConfiguration( - RedmineServiceConfiguration src) { - RedmineServiceConfiguration dst = new SimpleRedmineServiceConfiguration(); - copyConfiguration(src, dst); - return dst; - } - - public static void copyConfiguration(RedmineServiceConfiguration src, - RedmineServiceConfiguration dst) { - dst.setUrl(src.getUrl()); - dst.setEncoding(src.getEncoding()); - dst.setVerbose(src.isVerbose()); - dst.setAnonymous(src.isAnonymous()); - - RedmineClientAuthConfiguration authConfiguration = new RedmineClientAuthConfiguration(); - authConfiguration.setApiKey(src.getAuthConfiguration().getApiKey()); - authConfiguration.setUsername(src.getAuthConfiguration().getUsername()); - authConfiguration.setPassword(src.getAuthConfiguration().getPassword()); - dst.setAuthConfiguration(authConfiguration); - } - - protected static void overridePropertyFromProperties(Object conf, - String prop, - Properties props) throws IOException { - String value = props.getProperty(PROPERTY_PREFIX + prop); - if (StringUtils.isNotEmpty(value)) { - try { - BeanUtilsBean.getInstance().setProperty(conf, prop, value); - } catch (Exception e) { - throw new IOException( - "Could not set property '" + prop + - "' with value '" + value + "' to configuration"); - } - } - } - - protected static void overridePropertyFromEnv(Object conf, - String prop) throws IOException { - String value = System.getenv(PROPERTY_PREFIX + prop); - if (StringUtils.isNotEmpty(value) && !"null".equals(value)) { - try { - BeanUtilsBean.getInstance().setProperty(conf, prop, value); - } catch (Exception e) { - throw new IOException( - "Could not set property '" + prop + - "' with value '" + value + "' to configuration"); - } - } - } - - /** - * Configuration of a redmine service for test purposes. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ - public static class SimpleRedmineServiceConfiguration implements RedmineServiceConfiguration { - - URL url; - - boolean verbose; - - boolean anonymous; - - String encoding; - - RedmineClientAuthConfiguration authConfiguration; - - @Override - public RedmineClientAuthConfiguration getAuthConfiguration() { - return authConfiguration; - } - - @Override - public void setAuthConfiguration(RedmineClientAuthConfiguration authConfiguration) { - this.authConfiguration = authConfiguration; - } - - @Override - public String getEncoding() { - return encoding; - } - - @Override - public void setEncoding(String encoding) { - this.encoding = encoding; - } - -// @Override -// public String getPassword() { -// return restPassword; -// } -// -// @Override -// public void setPassword(String password) { -// this.restPassword = password; -// } - - @Override - public URL getUrl() { - return url; - } - - @Override - public void setUrl(URL url) { - this.url = url; - } - -// @Override -// public String getUsername() { -// return restUsername; -// } -// -// @Override -// public void setUsername(String username) { -// this.restUsername = username; -// } - - @Override - public boolean isVerbose() { - return verbose; - } - - @Override - public void setVerbose(boolean verbose) { - this.verbose = verbose; - } - - @Override - public boolean isAnonymous() { - return anonymous; - } - - @Override - public void setAnonymous(boolean anonymous) { - this.anonymous = anonymous; - } - - @Override - public String toString() { - ToStringBuilder b = new ToStringBuilder( - this, - ToStringStyle.MULTI_LINE_STYLE - ); - b.append("redmineUrl", url); - if (anonymous) { - b.append("anonymous", true); - } else { - b.append("apiKey", authConfiguration.getApiKey()); - b.append("username", authConfiguration.getUsername()); - b.append("password", "***"); - } - b.append("encoding", encoding); - b.append("verbose", verbose); - return b.toString(); - } - -// @Override -// public String getApiKey() { -// return apiKey; -// } -// -// @Override -// public void setApiKey(String apiKey) { -// this.apiKey = apiKey; -// } - } -} Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineLogguedService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineLogguedService.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineLogguedService.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,161 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -import org.nuiton.jredmine.model.Attachment; -import org.nuiton.jredmine.model.Issue; -import org.nuiton.jredmine.model.News; -import org.nuiton.jredmine.model.Project; -import org.nuiton.jredmine.model.TimeEntry; -import org.nuiton.jredmine.model.Version; - - -/** - * Contract of all redmine operations that needs a login to be performed. - * <p/> - * A default implementation is offered in {@link DefaultRedmineService}. - * <p/> - * Created: 2 janv. 2010 - * - * @author tchemit <chemit@codelutin.com> - * @see RedmineAnonymousService - * @see RedmineService - * @since 1.0.3 - */ -public interface RedmineLogguedService { - - /** - * Obtain for the loggued user, all projets where he belongs. - * <p/> - * <b>Note:</b> This method requires to be loggued on redmine server. - * - * @return all the projects belonged by the loggued user - * @throws RedmineServiceException if any pb while retriving datas - * @see Project - * @since 1.0.3 - */ - Project[] getUserProjects() throws RedmineServiceException; - - /** - * Add a version for a given project. - * <p/> - * b>Note:</b> This method requires to be loggued on redmine server. - * - * @param projectName the name of the project - * @param version the version to add - * @return the added version - * @throws RedmineServiceException if any pb while sending and retriving - * datas to redmine server - * @see Version - */ - Version addVersion(String projectName, - Version version) throws RedmineServiceException; - - /** - * Update a version for a given project. - * <p/> - * b>Note:</b> This method requires to be loggued on redmine server. - * - * @param projectName the name of the project - * @param version the version to update - * @return the updated version - * @throws RedmineServiceException if any pb while sending and retriving - * datas to redmine server - * @see Version - */ - Version updateVersion(String projectName, - Version version) throws RedmineServiceException; - - /** - * Prepare a new version (create it or update it). - * <p/> - * If the {@code oldVersionName} is given, then all issues unclosed from this - * old version will be move to the new version. - * <p/> - * b>Note:</b> This method requires to be loggued on redmine server. - * - * @param projectName the name of the project - * @param oldVersionName the name of the old version (optional) - * @param newVersion the newVersion to create or update - * @return the created version - * @throws RedmineServiceException if any pb while sending and retriving - * datas to redmine server - * @see Version - */ - Version nextVersion(String projectName, - String oldVersionName, - Version newVersion) throws RedmineServiceException; - - /** - * Add a news for a given project. - * <p/> - * b>Note:</b> This method requires to be loggued on redmine server. - * - * @param projectName the name of the project - * @param news the news to add - * @return the added news. - * @throws RedmineServiceException if any pb while sending and retriving - * datas to redmine server - * @see News - */ - News addNews(String projectName, News news) throws RedmineServiceException; - - /** - * Add a attachment for a given version of a given project. - * <p/> - * b>Note:</b> This method requires to be loggued on redmine server. - * - * @param projectName the name of the project - * @param versionName the name of the version - * @param attachement the attachment to add - * @return the added attachment - * @throws RedmineServiceException if any pb while sending and retriving - * datas to redmine server - * @see Attachment - */ - Attachment addAttachment(String projectName, - String versionName, - Attachment attachement) throws RedmineServiceException; - - /** - * Add a new time entry to the given issue for the given project and - * return the updated time entry. - * <p/> - * b>Note:</b> This method requires to be loggued on redmine server. - * - * @param projectName the name of the project - * @param issueId the id of the issue to update - * @param entry time entry to add - * @return the created time entry - * @throws RedmineServiceException if any pb while sending or retrieving - * datas to redmine server - * @see Issue - * @see TimeEntry - * @since 1.0.3 - */ - TimeEntry addIssueTimeEntry(String projectName, - String issueId, - TimeEntry entry) throws RedmineServiceException; -} Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineService.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineService.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,42 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -/** - * The full redmine service with anonymous and loggued methods. - * <p/> - * <b>Note:</b> A default implementation is offered : - * {@link DefaultRedmineService} - * - * @author tchemit <chemit@codelutin.com> - * @see DefaultRedmineService - * @since 1.0.0 - */ -public interface RedmineService extends RedmineAnonymousService, RedmineLogguedService { - - /** Plexus lookup name. */ - String ROLE = RedmineService.class.getName(); - -} Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,36 +0,0 @@ -package org.nuiton.jredmine; -/* - * #%L - * JRedmine :: Client - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.jredmine.client.RedmineClientConfiguration; - -/** - * Contract of a redmine service configuration. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public interface RedmineServiceConfiguration extends RedmineClientConfiguration { - -} \ No newline at end of file Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceException.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceException.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceException.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,51 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -/** - * An exception to throw when something is wrong in a {@link RedmineService}. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0.0 - */ -public class RedmineServiceException extends Exception { - - private static final long serialVersionUID = 1L; - - public RedmineServiceException(Throwable cause) { - super(cause); - } - - public RedmineServiceException(String message, Throwable cause) { - super(message, cause); - } - - public RedmineServiceException(String message) { - super(message); - } - - public RedmineServiceException() { - } -} Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,135 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -import org.nuiton.io.rest.RestClient; -import org.nuiton.jredmine.client.RedmineClient; - -/** - * Technical contract to implements a redmine service which wrap the - * {@link RedmineClient}. - * <p/> - * A default implementation is offered in {@link DefaultRedmineServiceImplementor}. - * <p/> - * Any concrete implentation of a redmine service should implements this. - * - * @author tchemit <chemit@codelutin.com> - * @see DefaultRedmineServiceImplementor - * @since 1.0.0 - */ -public interface RedmineServiceImplementor { - - /** - * Tests if the service is loogued to the redmine service. - * - * @return {@code true} is service is init and loggued to Redmine service, - * {@code false} otherwise. - */ - boolean isInit(); - - /** - * Initialize the service given a client configuration. - * - * @param configuration the configuration to be used to init the internal redmine client - * @return the initialized service - * @throws RedmineServiceException if any pb - */ - RedmineServiceImplementor init(RedmineServiceConfiguration configuration) throws RedmineServiceException; - - /** - * Close the service and destroy any connexion to the redmine service. - * - * @throws RedmineServiceException if any pb - */ - void destroy() throws RedmineServiceException; - - /** - * Gets the transport layer based on {@link RestClient}. - * - * @return the transport layer. - */ - RedmineClient getClient(); - - /** - * Generic method to obtain a single data from a redmine server. - * - * @param <T> the type of data to obtain - * @param requestName the name of the request to use - * @param type the type of data to obtain - * @param args the parameters to obtain the data - * @return the obtained data - * @throws RedmineServiceException if any pb - */ - <T> T getData(String requestName, Class<T> type, Object... args) throws RedmineServiceException; - - /** - * Generic method to obtain a array of data from a redmine server. - * - * @param <T> the type of data to obtain - * @param requestName the name of the request to use - * @param type the type of data to obtain - * @param args the parameters to obtain the datas - * @return the obtained datas - * @throws RedmineServiceException if any pb - */ - <T> T[] getDatas(String requestName, Class<T> type, Object... args) throws RedmineServiceException; - - /** - * Generic method to send a data to a redmine server and return the single - * data updated from the redmine server. - * - * @param requestName the name of the request used - * @param klazz the type of data to treate - * @param args the parameters of the request - * @param <T> the type of data to treate - * @return the updated data - * @throws RedmineServiceException if any pb - */ - <T> T sendData(String requestName, Class<T> klazz, Object... args) throws RedmineServiceException; - - - /** - * Generic method to send a data (or more ) to a redmine server and - * return the array of data from the redmine server. - * - * @param requestName the name of the request used - * @param klazz the type of data to treate - * @param args the parameters of the request - * @param <T> the type of data to treate - * @return the updated data - * @throws RedmineServiceException if any pb - */ - <T> T[] sendDatas(String requestName, Class<T> klazz, Object... args) throws RedmineServiceException; - - /** - * Checks if the current session is not a anonymous one. - * - * @throws IllegalStateException if service not init - * @throws RedmineServiceLoginException if not loggued - * @throws NullPointerException if something is null - */ - void checkLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException; - -} Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceLoginException.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceLoginException.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceLoginException.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,54 +0,0 @@ -/* - * #%L - * JRedmine :: Client - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.jredmine; - -/** - * An exception to be thrown when a problem with authentication state in a - * {@link RedmineService}. - * <p/> - * Created: 2 janv. 2010 - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0.3 - */ -public class RedmineServiceLoginException extends RedmineServiceException { - - private static final long serialVersionUID = 1L; - - public RedmineServiceLoginException() { - } - - public RedmineServiceLoginException(Throwable cause) { - super(cause); - } - - public RedmineServiceLoginException(String message) { - super(message); - } - - public RedmineServiceLoginException(String message, Throwable cause) { - super(message, cause); - } -} Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java 2012-10-16 20:18:19 UTC (rev 367) @@ -24,6 +24,10 @@ * #L% */ +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpEntity; @@ -31,26 +35,28 @@ import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.StatusLine; +import org.apache.http.client.CookieStore; import org.apache.http.client.HttpClient; +import org.apache.http.client.ResponseHandler; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.client.protocol.ClientContext; import org.apache.http.client.utils.URIBuilder; import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.FileBody; import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.params.CoreProtocolPNames; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; -import org.nuiton.io.rest.RestDataNotFoundException; -import org.nuiton.io.rest.RestException; -import org.nuiton.io.rest.RestRequest; -import org.nuiton.jredmine.model.ModelHelper; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.nuiton.jredmine.model.io.xpp3.RedmineXpp3Helper; import java.io.Closeable; import java.io.File; @@ -58,7 +64,6 @@ import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.Map; /** @@ -72,6 +77,9 @@ /** Logger. */ private static final Log log = LogFactory.getLog(RedmineClient.class); + /** xpp3 xpp3Helper to transform xml stream to pojo */ + protected final RedmineXpp3Helper xpp3Helper; + protected final RedmineClientConfiguration configuration; protected final HttpClient client; @@ -80,18 +88,25 @@ protected final HttpContext clientContext; - protected final RedmineRequestFactory requestFactory; - protected boolean showRequest; protected boolean open; + protected Map<String, String> defaultHeaders = Maps.newHashMap(); + public RedmineClient(RedmineClientConfiguration configuration) { this.configuration = configuration; + xpp3Helper = new RedmineXpp3Helper(); showRequest = configuration.isVerbose(); client = new DefaultHttpClient(); clientContext = new BasicHttpContext(); + // Create a local instance of cookie store + CookieStore cookieStore = new BasicCookieStore(); + + // Bind custom cookie store to the local context + clientContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); + int port = configuration.getUrl().getPort(); if (port == -1) { @@ -108,29 +123,69 @@ CoreProtocolPNames.HTTP_CONTENT_CHARSET, configuration.getEncoding()); - requestFactory = new RedmineRequestFactory(); - requestFactory.addDefaultRequests(); - } + if (!configuration.isAnonymous()) { + RedmineClientAuthConfiguration authConfiguration = + configuration.getAuthConfiguration(); + if (authConfiguration.isUseApiKey()) { - public RedmineRequestFactory getRequestFactory() { - return requestFactory; + if (log.isInfoEnabled()) { + log.info("Will use api key for authentication"); + } + + // keep apiKey to put to every request + defaultHeaders.put("X-Redmine-API-Key", + authConfiguration.getApiKey()); + } + } } public boolean isOpen() { return open; } - public void open() throws RestException, IOException { + public void open() throws IOException { if (!isOpen()) { // first ping - ping(); + RedmineRequest<String> pingRequest = RedmineRequestHelper.action("ping", String.class); + open = true; + + try { + String content = executeRequest(pingRequest); + boolean ok = "ping".equals(content); + if (!ok) { + throw new IOException("can not connect to " + configuration.getUrl()); + } + } catch (RuntimeException e) { + open = false; + throw e; + } catch (IOException e) { + open = false; + throw e; + } + if (!configuration.isAnonymous()) { // log in - login(); + RedmineClientAuthConfiguration conf = + getConfiguration().getAuthConfiguration(); + RedmineRequest<Void> loginRequest; + + if (false && conf.isUseApiKey()) { + + // use api key to login + loginRequest = RedmineRequestHelper.postAction("login", void.class). + parameter("apiKey", conf.getApiKey()); + } else { + // use normal login / password + loginRequest = RedmineRequestHelper.postAction("login", void.class). + parameter("username", conf.getUsername()). + parameter("password", conf.getPassword()); + } + + executeRequest(loginRequest); } open = true; @@ -142,52 +197,51 @@ * * @param request request used for asking data * @return the stream of the response - * @throws RestException if any pb while asking data + * @throws IOException if any pb while do request or receive result */ - public InputStream executeRequest(RestRequest request) throws RestException { + public <T> T executeRequest(RedmineRequest<T> request) throws IOException { if (!isOpen()) { throw new IllegalStateException("the client is not opened"); } try { - if (!open) { - throw new IllegalStateException("the session is not opened"); - } HttpRequestBase gm = prepareRequest(request); - HttpResponse response = executeRequest(gm); + ResponseHandler<T> responseHandler = new RedmineSimpleResponseHandler<T>(false, request.getType(), xpp3Helper, gm.getURI().toString()); - StatusLine sl = response.getStatusLine(); - int statusCode = sl.getStatusCode(); + T result = client.execute(gm, responseHandler, clientContext); + return result; + } finally { + releaseConnection(); + } + } - if (log.isDebugEnabled()) { - log.debug("status code " + statusCode + " for " + gm.getURI()); + /** + * Ask some data from the server + * + * @param request request used for asking data + * @return the stream of the response + * @throws IOException if any pb while do request or receive result + */ + public <T> T[] executeRequests(RedmineRequest<T> request) throws IOException { + if (!isOpen()) { + throw new IllegalStateException("the client is not opened"); + } + + try { + if (!open) { + throw new IllegalStateException("the session is not opened"); } - HttpEntity entity = response.getEntity(); + HttpRequestBase gm = prepareRequest(request); - if (statusCode == HttpStatus.SC_NOT_FOUND) { - String responseAsString = EntityUtils.toString(entity); - throw new RestDataNotFoundException( - "could not retreave some datas : " + - responseAsString); - } + ResponseHandler<T[]> responseHandler = new RedmineArrayResponseHandler<T>(false, request.getType(), xpp3Helper, gm.getURI().toString()); - if (statusCode != HttpStatus.SC_OK) { - String responseAsString = EntityUtils.toString(entity); - log.error("Error = " + responseAsString); - releaseConnection(); - throw new RestException( - "Got error code <" + statusCode + ":" + - sl.getReasonPhrase() + "> on " + gm.getURI()); - } - InputStream stream = entity.getContent(); - return stream; - } catch (IOException e) { - throw new RestException( - "could not ask data to server to reason " + - e.getMessage(), e); + T[] result = client.execute(gm, responseHandler, clientContext); + return result; + } finally { + releaseConnection(); } } @@ -201,13 +255,9 @@ try { - releaseConnection(); - - RestRequest request = getRequest(ModelHelper.LOGOUT_REQUEST_NAME); - HttpRequestBase httpRequest = prepareRequest(request); - - HttpResponse response = executeRequest(httpRequest); - EntityUtils.consume(response.getEntity()); + RedmineRequest<Void> request = + RedmineRequestHelper.action("logout", void.class); + executeRequest(request); } catch (Exception e) { throw new IOException( "could not close client for reason " + @@ -225,23 +275,14 @@ } } - protected HttpResponse executeRequest(HttpRequestBase gm) throws IOException { - // always release any previous connection - releaseConnection(); + protected <T> HttpRequestBase prepareRequest(RedmineRequest<T> request) throws IOException { - HttpResponse response = client.execute(gm, clientContext); - return response; - } - - protected HttpRequestBase prepareRequest(RestRequest request) throws IOException { - if (showRequest) { log.info("prepareRequest " + getRequestUrl(request)); } if (log.isDebugEnabled()) { - log.debug("prepareRequest with parameters : " + - Arrays.toString(request.getParameters())); + log.debug("prepareRequest with parameters: " + request.getParams()); } HttpRequestBase gm; @@ -265,62 +306,49 @@ "Can not deal with method " + request.getMethod()); } - if (getConfiguration().getAuthConfiguration().isUseApiKey()) { - - gm.addHeader("X-Redmine-API-Key", - getConfiguration().getAuthConfiguration().getApiKey()); + for (Map.Entry<String, String> entry : defaultHeaders.entrySet()) { + gm.addHeader(entry.getKey(), entry.getValue()); } -// Map<String, String> headers = request.getHeaders(); -// if (MapUtils.isNotEmpty(headers)) { -// -// for (Map.Entry<String, String> entry : headers.entrySet()) { -// gm.addHeader(entry.getKey(), entry.getValue()); -// } -// } return gm; } - protected String getRequestUrl(RestRequest request) { + + protected <T> String getRequestUrl(RedmineRequest<T> request) { String uri = host.toURI(); String result = request.toPath(uri); return result; } - protected HttpGet prepareGetRequest(RestRequest request) throws IOException { + protected <T> HttpGet prepareGetRequest(RedmineRequest<T> request) throws IOException { String uri = getRequestUrl(request); - String[] parameters = request.getParameters(); + Map<String, String> parameters = request.getParams(); Map<String, File> attachments = request.getAttachments(); - if (attachments != null) { + // multi-part request + //not possible with a simple Get method + Preconditions.checkState( + MapUtils.isEmpty(attachments), + "Can not do a GET request with multi-parts, use a POST or UPDATE request"); - // multi-part request - //not possible with a simple Get method - - throw new IllegalStateException("Can not do a GET request with multi-parts, use a POST or UPDATE request"); - } - HttpGet gm = new HttpGet(uri); - addParams(gm, parameters); - return gm; } - protected HttpDelete prepareDeleteRequest(RestRequest request) throws IOException { + protected <T> HttpDelete prepareDeleteRequest(RedmineRequest<T> request) throws IOException { String uri = getRequestUrl(request); - String[] parameters = request.getParameters(); + Map<String, String> parameters = request.getParams(); Map<String, File> attachments = request.getAttachments(); - if (attachments != null) { + // multi-part request + //not possible with a simple Get method + Preconditions.checkState( + MapUtils.isEmpty(attachments), + "Can not do a GET request with multi-parts, use a POST or UPDATE request"); - // multi-part request - //not possible with a simple Get method - throw new IllegalStateException("Can not do a DELETE request with multi-parts, use a POST or UPDATE request"); - } - HttpDelete gm = new HttpDelete(uri); addParams(gm, parameters); @@ -328,15 +356,15 @@ return gm; } - protected HttpPost preparePostRequest(RestRequest request) throws IOException { + protected <T> HttpPost preparePostRequest(RedmineRequest<T> request) throws IOException { String uri = getRequestUrl(request); - String[] parameters = request.getParameters(); + Map<String, String> parameters = request.getParams(); Map<String, File> attachments = request.getAttachments(); HttpPost gm = new HttpPost(uri); - if (attachments == null) { + if (MapUtils.isEmpty(attachments)) { // not a multi-part request addParams(gm, parameters); @@ -348,15 +376,15 @@ return gm; } - protected HttpPut preparePutRequest(RestRequest request) throws IOException { + protected <T> HttpPut preparePutRequest(RedmineRequest<T> request) throws IOException { String uri = getRequestUrl(request); - String[] parameters = request.getParameters(); + Map<String, String> parameters = request.getParams(); Map<String, File> attachments = request.getAttachments(); HttpPut gm = new HttpPut(uri); - if (attachments == null) { + if (MapUtils.isEmpty(attachments)) { // not a multi-part request addParams(gm, parameters); @@ -370,17 +398,16 @@ } protected void addParams(HttpRequestBase gm, - String... parameters) throws IOException { + Map<String, String> parameters) throws IOException { - if (parameters.length > 0) { + if (MapUtils.isNotEmpty(parameters)) { // add parameters URIBuilder uriBuilder = new URIBuilder(gm.getURI()); - int nbParams = parameters.length / 2; - for (int i = 0; i < nbParams; i++) { - String key = parameters[2 * i]; - String value = parameters[2 * i + 1]; + for (Map.Entry<String, String> entry : parameters.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); if (value == null) { if (log.isDebugEnabled()) { log.debug("skip null parameter " + key); @@ -389,6 +416,7 @@ } uriBuilder.addParameter(key, value); } + try { URI uri = uriBuilder.build(); gm.setURI(uri); @@ -398,20 +426,20 @@ } } + protected void prepareMultiPart(HttpEntityEnclosingRequestBase gm, Map<String, File> attachments, - String... parameters) throws IOException { + Map<String, String> parameters) throws IOException { MultipartEntity entity = new MultipartEntity(); - if (parameters.length > 0) { + if (MapUtils.isNotEmpty(parameters)) { // add parameters as part of multi-part - int nbParams = parameters.length / 2; - for (int i = 0; i < nbParams; i++) { - String key = parameters[2 * i]; - String value = parameters[2 * i + 1]; + for (Map.Entry<String, String> entry : parameters.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); if (value == null) { if (log.isDebugEnabled()) { log.debug("skip null parameter " + key); @@ -419,9 +447,6 @@ continue; } entity.addPart(key, new StringBody(value)); - if (log.isDebugEnabled()) { - log.debug("add parameter [" + key + "]=" + value); - } } } @@ -453,96 +478,122 @@ } } - protected void ping() throws RestException, IOException { + protected void releaseConnection() { + client.getConnectionManager().closeExpiredConnections(); + } - RestRequest request = getRequest(ModelHelper.PING_REQUEST_NAME); + protected static abstract class AbstractRedmineResponseHandler<T> { - HttpRequestBase gm = prepareRequest(request); + final boolean strict; - HttpResponse response = executeRequest(gm); + final Class<T> type; - try { + protected final RedmineXpp3Helper xpp3Helper; + + final String uri; + + AbstractRedmineResponseHandler(boolean strict, + Class<T> type, + RedmineXpp3Helper xpp3Helper, String uri) { + this.strict = strict; + this.type = type; + this.xpp3Helper = xpp3Helper; + this.uri = uri; + } + + protected void checkResponse(HttpResponse response) throws IOException { StatusLine sl = response.getStatusLine(); int statusCode = sl.getStatusCode(); + if (log.isDebugEnabled()) { - log.debug("status code " + statusCode + " for " + gm.getURI()); + log.debug("status code " + statusCode + " for " + uri); } - if (statusCode != HttpStatus.SC_OK) { + HttpEntity entity = response.getEntity(); - throw new RestException( - "Could not ping to " + gm.getURI() + - " statusCode: " + statusCode + ", reason: " + - sl.getReasonPhrase()); + if (statusCode == HttpStatus.SC_NOT_FOUND) { + String responseAsString = EntityUtils.toString(entity); + throw new IOException( + "could not retreave some datas : " + + responseAsString); } - String content = EntityUtils.toString(response.getEntity()); - - boolean ok = "ping".equals(content); - if (!ok) { + if (statusCode != HttpStatus.SC_OK) { + String responseAsString = EntityUtils.toString(entity); + log.error("Error = " + responseAsString); throw new IOException( - "can not connect to " + configuration.getUrl()); + "Got error code <" + statusCode + ":" + + sl.getReasonPhrase() + "> on " + uri); } - } finally { - EntityUtils.consume(response.getEntity()); } } - protected void login() throws IOException, RestException { - RedmineClientAuthConfiguration conf = - getConfiguration().getAuthConfiguration(); - RestRequest request; - String apiKey = conf.getApiKey(); - boolean useApiKey = conf.isUseApiKey(); - if (useApiKey) { + protected static class RedmineSimpleResponseHandler<T> extends AbstractRedmineResponseHandler<T> implements ResponseHandler<T> { - // use api key to login - request = getRequest(ModelHelper.LOGIN_BY_API_KEY_REQUEST_NAME, - apiKey); - } else { - // use normal login / password - request = getRequest(ModelHelper.LOGIN_REQUEST_NAME, - conf.getUsername(), - conf.getPassword()); + RedmineSimpleResponseHandler(boolean strict, + Class<T> type, + RedmineXpp3Helper xpp3Helper, + String uri) { + super(strict, type, xpp3Helper, uri); } - HttpRequestBase gm = prepareRequest(request); + @Override + public T handleResponse(HttpResponse response) throws IOException { + checkResponse(response); + T result; - HttpResponse response = executeRequest(gm); + HttpEntity entity = response.getEntity(); - try { - StatusLine sl = response.getStatusLine(); - int statusCode = sl.getStatusCode(); - if (log.isDebugEnabled()) { - log.debug("status code " + statusCode + " for " + gm.getURI()); - } + if (Void.class == type || void.class == type) { - if (statusCode != HttpStatus.SC_OK) { - throw new RestException( - "Got error code <" + statusCode + ":" + - sl.getReasonPhrase() + "> on " + gm.getURI()); + EntityUtils.consume(entity); + result = null; + } else if (String.class == type) { + + result = (T) EntityUtils.toString(entity); + } else { + InputStream inputStream = entity.getContent(); + try { + result = this.xpp3Helper.readObject( + type, inputStream, strict); + inputStream.close(); + } catch (XmlPullParserException e) { + throw new IOException( + "Could not parse response fro type " + type, e); + } finally { + IOUtils.closeQuietly(inputStream); + } } - - // ok session is logged in - } finally { - EntityUtils.consume(response.getEntity()); + return result; } } - /** - * Obtain a request given his id and the args given. - * - * @param id id of the request - * @param args args passed to build the request - * @return the new request - */ - public RestRequest getRequest(String id, Object... args) { - RestRequest r = requestFactory.getRequest(id, args); - return r; - } + protected static class RedmineArrayResponseHandler<T> extends AbstractRedmineResponseHandler<T> implements ResponseHandler<T[]> { - protected void releaseConnection() { - client.getConnectionManager().closeExpiredConnections(); + RedmineArrayResponseHandler(boolean strict, + Class<T> type, + RedmineXpp3Helper xpp3Helper, String uri) { + super(strict, type, xpp3Helper, uri); + } + + @Override + public T[] handleResponse(HttpResponse response) throws IOException { + checkResponse(response); + + HttpEntity entity = response.getEntity(); + InputStream inputStream = entity.getContent(); + try { + T[] result = this.xpp3Helper.readObjects( + type, inputStream, strict); + inputStream.close(); + return result; + } catch (XmlPullParserException e) { + throw new IOException( + "Could not parse response fro type " + type, e); + } finally { + IOUtils.closeQuietly(inputStream); + } + } } } Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequest.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequest.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,119 @@ +package org.nuiton.jredmine.client; + +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + +import java.io.File; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * Simple way to create a redmine request to be consumed by the {@link RedmineClient}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.5 + */ +public class RedmineRequest<T> { + + public enum Method { + GET, + PUT, + POST, + DELETE, + HEAD, + OPTION + } + + protected final Method method; + + protected final Class<T> type; + + protected final List<String> path; + + protected final Map<String, String> params; + + protected final Map<String, File> attachments; + + + public static <T> RedmineRequest<T> get(Class<T> type, String... path) { + return on(Method.GET, type, path); + } + + public static <T> RedmineRequest<T> put(Class<T> type, String... path) { + return on(Method.PUT, type, path); + } + + public static <T> RedmineRequest<T> delete(Class<T> type, String... path) { + return on(Method.DELETE, type, path); + } + + public static <T> RedmineRequest<T> post(Class<T> type, String... path) { + return on(Method.POST, type, path); + } + + public static <T> RedmineRequest<T> head(Class<T> type, String... path) { + return on(Method.HEAD, type, path); + } + + public static <T> RedmineRequest<T> option(Class<T> type, String... path) { + return on(Method.OPTION, type, path); + } + + public static <T> RedmineRequest<T> on(Method method, Class<T> type, String... path) { + RedmineRequest<T> result = new RedmineRequest<T>(method, type); + result.path(path); + return result; + } + + public RedmineRequest(Method method, Class<T> type) { + this.method = method; + this.type = type; + params = Maps.newHashMap(); + attachments = Maps.newHashMap(); + path = Lists.newArrayList(); + } + + public RedmineRequest<T> path(String... path) { + Collections.addAll(this.path, path); + return this; + } + + public RedmineRequest<T> parameter(String name, String value) { + params.put(name, value); + return this; + } + + public RedmineRequest<T> attachment(String name, File value) { + attachments.put(name, value); + return this; + } + + public String[] getPath() { + return path.toArray(new String[path.size()]); + } + + public Method getMethod() { + return method; + } + + public Map<String, String> getParams() { + return params; + } + + public Map<String, File> getAttachments() { + return attachments; + } + + public Class<T> getType() { + return type; + } + + public String toPath(String uri) { + String result = uri + "/" + + Joiner.on('/').join(getPath()); + return result; + } + +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,450 +0,0 @@ -package org.nuiton.jredmine.client; -/* - * #%L - * JRedmine :: Client - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Strings; -import org.nuiton.io.rest.AbstractRequestFactory; -import org.nuiton.io.rest.RestMethod; -import org.nuiton.io.rest.RestRequestBuilder; -import org.nuiton.jredmine.model.Attachment; -import org.nuiton.jredmine.model.ModelHelper; -import org.nuiton.jredmine.model.News; -import org.nuiton.jredmine.model.TimeEntry; -import org.nuiton.jredmine.model.Version; -import org.nuiton.jredmine.model.VersionStatusEnum; - -import java.io.File; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * Request factory for the redmine client. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class RedmineRequestFactory extends AbstractRequestFactory { - - public static String getRequestScope(RestRequestBuilder requestBuilder) { - String scope; - if (requestBuilder instanceof DefaultRequestBuilder) { - - scope = ((DefaultRequestBuilder) requestBuilder).getScope(); - } else { - scope = null; - } - return scope; - } - - @Override - public void addDefaultRequests() { - - // misc requests - - addRequestBuilder(new DefaultRequestBuilder(ModelHelper.PING_REQUEST_NAME, RestMethod.GET, "jredmine", "ping")); - addRequestBuilder(new DefaultRequestBuilder(ModelHelper.LOGOUT_REQUEST_NAME, RestMethod.GET, "jredmine", "logout")); - addRequestBuilder(new DefaultRequestBuilder(ModelHelper.LOGIN_REQUEST_NAME, RestMethod.POST, "jredmine", "login") { - - private static final long serialVersionUID = 1L; - - @Override - public void checkRequestArgs(Object... args) { - checkRequestArgs(2, "userName, password", args); - } - - @Override - public String[] getParameters(Object... args) { - String login = (String) args[0]; - String password = (String) args[1]; - return new String[]{"username", login, "password", password}; - } - }); - - addRequestBuilder(new DefaultRequestBuilder(ModelHelper.LOGIN_BY_API_KEY_REQUEST_NAME, RestMethod.POST, "jredmine", "login") { - - private static final long serialVersionUID = 1L; - - @Override - public void checkRequestArgs(Object... args) { - checkRequestArgs(1, "apiKey", args); - } - -// @Override -// public Map<String, String> getHeaders(Object... args) { -// Map<String, String> headers = Maps.newHashMap(); -// String apiKey = (String) args[0]; -// headers.put("X-Redmine-API-Key", apiKey); -// return headers; -// } - }); - - // data with no scope requests - - addRequestBuilder(new DefaultRequestBuilder(ModelHelper.GET_ALL_PROJECT_REQUEST_NAME, RestMethod.GET, "jredmine", "get_projects.xml")); - addRequestBuilder(new DefaultRequestBuilder(ModelHelper.GET_USER_PROJECTS_REQUEST_NAME, RestMethod.GET, "jredmine", "get_user_projects.xml")); - addRequestBuilder(new DefaultRequestBuilder(ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME, RestMethod.GET, "jredmine", "get_issue_statuses.xml")); - addRequestBuilder(new DefaultRequestBuilder(ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME, RestMethod.GET, "jredmine", "get_issue_priorities.xml")); - - // data with project scope requests - - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.GET_PROJECT_REQUEST_NAME, RestMethod.GET, "jredmine", "get_project.xml")); - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.GET_ALL_PROJECT_ISSUES_REQUEST_NAME, RestMethod.GET, "jredmine", "get_project_issues.xml")); - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME, RestMethod.GET, "jredmine", "get_project_opened_issues.xml")); - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME, RestMethod.GET, "jredmine", "get_project_closed_issues.xml")); - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.GET_ALL_VERSION_REQUEST_NAME, RestMethod.GET, "jredmine", "get_project_versions.xml")); - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME, RestMethod.GET, "jredmine", "get_issue_categories.xml")); - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.GET_ALL_TRACKER_REQUEST_NAME, RestMethod.GET, "jredmine", "get_project_trackers.xml")); - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.GET_ALL_USER_REQUEST_NAME, RestMethod.GET, "jredmine", "get_project_users.xml")); - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.GET_ALL_NEWS_REQUEST_NAME, RestMethod.GET, "jredmine", "get_project_news.xml")); - - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.ADD_VERSION_REQUEST_NAME, RestMethod.POST, "jredmine", "add_version.xml") { - private static final long serialVersionUID = 1L; - - @Override - public void checkRequestArgs(Object... args) { - checkRequestArgs(2, "projectName, version", args); - } - - @Override - public String[] getParameters(Object... args) { - Version version = (Version) args[1]; - String date = getVersionEffectiveDate(version); - String status = getVersionStatus(version); - return new String[]{ - "version[name]", version.getName(), - "version[description]", version.getDescription(), - "version[effective_date]", date, - "version[status]", status - }; - } - }); - - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.UPDATE_VERSION_REQUEST_NAME, RestMethod.POST, "jredmine", "update_version.xml") { - private static final long serialVersionUID = 1L; - - @Override - public void checkRequestArgs(Object... args) { - checkRequestArgs(2, "projectName, version", args); - } - - @Override - public String[] getParameters(Object... args) { - Version version = (Version) args[1]; - String date = getVersionEffectiveDate(version); - String status = getVersionStatus(version); - return new String[]{ - "version[name]", version.getName(), - "version[description]", version.getDescription(), - "version[effective_date]", date, - "version[status]", status - }; - } - }); - - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.NEXT_VERSION_REQUEST_NAME, RestMethod.POST, "jredmine", "next_version.xml") { - private static final long serialVersionUID = 1L; - - @Override - public void checkRequestArgs(Object... args) { - checkRequestArgs(3, - "projectName, version, oldVersionName", args); - } - - @Override - public String[] getParameters(Object... args) { - - Version version = (Version) args[1]; - String date = getVersionEffectiveDate(version); - String status = getVersionStatus(version); - String oldVersionName = (String) args[2]; - return new String[]{ - "oldVersionName", oldVersionName, - "version[name]", version.getName(), - "version[description]", version.getDescription(), - "version[effective_date]", date, - "version[status]", status - }; - } - }); - - addRequestBuilder(new ProjectScopeRequestBuilder(ModelHelper.ADD_NEWS_REQUEST_NAME, RestMethod.POST, "jredmine", "add_news.xml") { - private static final long serialVersionUID = 1L; - - @Override - public void checkRequestArgs(Object... args) { - checkRequestArgs(2, "projectName, news", args); - } - - @Override - public String[] getParameters(Object... args) { - News news = (News) args[1]; - return new String[]{ - "news[title]", news.getTitle(), - "news[summary]", news.getSummary(), - "news[description]", news.getDescription() - }; - } - }); - - // version scope requests - - addRequestBuilder(new VersionScopeRequestBuilder(ModelHelper.GET_VERSION_REQUEST_NAME, RestMethod.GET, "jredmine", "get_version.xml")); - addRequestBuilder(new VersionScopeRequestBuilder(ModelHelper.GET_ALL_ISSUES_REQUEST_NAME, RestMethod.GET, "jredmine", "get_version_issues.xml")); - addRequestBuilder(new VersionScopeRequestBuilder(ModelHelper.GET_ALL_ATTACHMENTS_REQUEST_NAME, RestMethod.GET, "jredmine", "get_version_attachments.xml")); - addRequestBuilder(new VersionScopeRequestBuilder(ModelHelper.ADD_ATTACHMENT_REQUEST_NAME, RestMethod.POST, "jredmine", "add_version_attachment.xml") { - private static final long serialVersionUID = 1L; - - @Override - public void checkRequestArgs(Object... args) { - checkRequestArgs(3, - "projectName, versionName, attachment", args); - } - - @Override - public String[] getParameters(Object... args) { - String versionId = (String) args[1]; - Attachment attachment = (Attachment) args[2]; - return new String[]{ - "version_name", versionId, - "attachment[description]", attachment.getDescription() - }; - } - - @Override - public Map<String, File> getAttachments(Object... args) { - Map<String, File> upload = new HashMap<String, File>(); - Attachment attachment = (Attachment) args[2]; - upload.put("attachment[file]", attachment.getToUpload()); - return upload; - } - }); - - // issue scope requests - - addRequestBuilder(new IssueScopeRequestBuilder(ModelHelper.GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME, RestMethod.GET, "jredmine", "get_issue_times.xml")); - - addRequestBuilder(new IssueScopeRequestBuilder(ModelHelper.ADD_ISSUE_TIME_ENTRY_REQUEST_NAME, RestMethod.POST, "jredmine", "add_issue_time.xml") { - private static final long serialVersionUID = 1L; - - @Override - public void checkRequestArgs(Object... args) { - checkRequestArgs(3, - "projectName, issueId, timeEntry", args); - } - - @Override - public String[] getParameters(Object... args) { - String issueId = (String) args[1]; - TimeEntry timeEntry = (TimeEntry) args[2]; - Date d = timeEntry.getSpentOn(); - if (d == null) { - d = new Date(); - } - String date = DATE_FORMAT.format(d); - return new String[]{ - "issue_id", issueId, - "time_entry[activity_id]", timeEntry.getActivityId() + "", - "time_entry[spent_on]", date, - "time_entry[hours]", timeEntry.getHours() + "", - "time_entry[comments]", timeEntry.getComments() == null ? "" : timeEntry.getComments() - }; - } - }); - } - - protected static String getVersionStatus(Version version) { - String status = version.getStatus(); - if (Strings.isNullOrEmpty(status)) { - - // use default open status - status = VersionStatusEnum.open.name(); - } - return status; - } - - protected static String getVersionEffectiveDate(Version version) { - return version.getEffectiveDate() == null ? "" : - DATE_FORMAT.format(version.getEffectiveDate()); - } - - /** - * Default {@link RestRequestBuilder} to be used in {@link RedmineClient}. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0.0 - */ - protected static class DefaultRequestBuilder extends AbstractRequestBuilder { - - private static final long serialVersionUID = 1L; - - protected String scope; - - public DefaultRequestBuilder(String name, - RestMethod method, - String... action) { - this(name, null, method, action); - } - - public DefaultRequestBuilder(String name, - String scope, - RestMethod method, - String... action) { - super(name, method, action); - this.scope = scope; - } - - /** - * Gets the scope of this request (scope can be null,project, - * version issue,...). - * - * @return the scope of this request - */ - public final String getScope() { - return scope; - } - - @Override - public void checkRequestArgs(Object... args) { - - // by default request have no ags - checkRequestArgs(0, "", args); - } - } - - /** - * Builder of requests which are in a project context. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0.0 - */ - protected static class ProjectScopeRequestBuilder extends DefaultRequestBuilder { - - private static final long serialVersionUID = 1L; - - public ProjectScopeRequestBuilder(String name, - RestMethod method, - String... action) { - this(name, ModelHelper.PROJECT_SCOPE, method, action); - } - - public ProjectScopeRequestBuilder(String name, - String scope, - RestMethod method, - String... action) { - super(name, scope, method, action); - } - - @Override - public void checkRequestArgs(Object... args) { - checkRequestArgs(1, "projectName", args); - } - - @Override - public String[] getPath(Object... args) { - - // one args : projectName - - String projectName = (String) args[0]; - - String[] result = new String[action.length + 1]; - System.arraycopy(action, 0, result, 0, action.length); - result[action.length] = projectName; - return result; - } - } - - /** - * Builder of requests which are in a project and issue context. - * <p/> - * Created: 1 janv. 2010 - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0.3 - */ - protected static class IssueScopeRequestBuilder extends ProjectScopeRequestBuilder { - - private static final long serialVersionUID = 1L; - - public IssueScopeRequestBuilder(String name, - RestMethod method, - String... action) { - super(name, ModelHelper.ISSUE_SCOPE, method, action); - } - - @Override - public void checkRequestArgs(Object... args) { - checkRequestArgs(2, "projectName, issueId", args); - } - - @Override - public String[] getParameters(Object... args) { - - // args 1 = project id - // args 2 = issue id - - String issueId = (String) args[1]; - - return new String[]{ - "issue_id", issueId - }; - } - } - - /** - * Builder of requests which are in a project and version context. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0.0 - */ - protected static class VersionScopeRequestBuilder extends ProjectScopeRequestBuilder { - - private static final long serialVersionUID = 1L; - - public VersionScopeRequestBuilder(String name, - RestMethod method, - String... action) { - super(name, ModelHelper.VERSION_SCOPE, method, action); - } - - @Override - public void checkRequestArgs(Object... args) { - checkRequestArgs(2, "projectName, versionName", args); - } - - @Override - public String[] getParameters(Object... args) { - - // args 1 = project id - // args 2 = version name - - String versionName = (String) args[1]; - - return new String[]{ - "version_name", versionName - }; - } - } - -} Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestHelper.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestHelper.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestHelper.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,50 @@ +package org.nuiton.jredmine.client; + +/** + * Helper around {@link RedmineRequest}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.5 + */ +public class RedmineRequestHelper { + + protected RedmineRequestHelper() { + // do not instanciate helper + } + + public static <T> RedmineRequest<T> action(String action, Class<T> type) { + return RedmineRequest.get(type, "jredmine", action); + } + + public static <T> RedmineRequest<T> actionWithProject(String action, Class<T> type, String projectName) { + return RedmineRequest.get(type, "jredmine", action, projectName); + } + + public static <T> RedmineRequest<T> actionWithProjectAndVersion(String action, Class<T> type, String projectName, String versionName) { + return RedmineRequest.get(type, "jredmine", action, projectName). + parameter("version_name", versionName); + } + + public static <T> RedmineRequest<T> actionWithProjectAndIssue(String action, Class<T> type, String projectName, String issueId) { + return RedmineRequest.get(type, "jredmine", action, projectName). + parameter("issue_id", issueId); + } + + public static <T> RedmineRequest<T> postAction(String action, Class<T> type) { + return RedmineRequest.post(type, "jredmine", action); + } + + public static <T> RedmineRequest<T> postWithProject(String action, Class<T> type, String projectName) { + return RedmineRequest.post(type, "jredmine", action, projectName); + } + + public static <T> RedmineRequest<T> postWithProjectAndIssue(String action, Class<T> type, String projectName, String issueId) { + return RedmineRequest.post(type, "jredmine", action, projectName). + parameter("issue_id", issueId); + } + + public static <T> RedmineRequest<T> postWithProjectAndVersion(String action, Class<T> type, String projectName, String versionName) { + return RedmineRequest.post(type, "jredmine", action, projectName). + parameter("version_name", versionName); + } +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestHelper.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssueCategoryXpp3Reader.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssueCategoryXpp3Reader.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssueCategoryXpp3Reader.java 2012-10-16 20:18:19 UTC (rev 367) @@ -45,12 +45,12 @@ @Override protected void initMappers() throws IntrospectionException { - addTagTextContentMappers( RedmineDataConverter.Integer, true, + addTagTextContentMappers(RedmineDataConverter.Integer, true, "project-id", "assigned-to-id", "id"); - addTagTextContentMappers( RedmineDataConverter.Text, true, + addTagTextContentMappers(RedmineDataConverter.Text, true, "name"); } } Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssuePriorityXpp3Reader.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssuePriorityXpp3Reader.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssuePriorityXpp3Reader.java 2012-10-16 20:18:19 UTC (rev 367) @@ -46,17 +46,17 @@ protected void initMappers() throws IntrospectionException { - addTagTextContentMappers(RedmineDataConverter.Integer, true, + addTagTextContentMappers(RedmineDataConverter.Integer, true, "id", "parent-id", "project-id", "position"); - addTagTextContentMappers(RedmineDataConverter.Boolean, true, + addTagTextContentMappers(RedmineDataConverter.Boolean, true, "is-default", "active"); - addTagTextContentMappers(RedmineDataConverter.Text, true, + addTagTextContentMappers(RedmineDataConverter.Text, true, "name", "opt"); } Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssueStatusXpp3Reader.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssueStatusXpp3Reader.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/io/xpp3/IssueStatusXpp3Reader.java 2012-10-16 20:18:19 UTC (rev 367) @@ -45,16 +45,16 @@ @Override protected void initMappers() throws IntrospectionException { - addTagTextContentMappers(RedmineDataConverter.Integer, true, + addTagTextContentMappers(RedmineDataConverter.Integer, true, "id", "position", "default-done-ratio"); - addTagTextContentMappers(RedmineDataConverter.Boolean, true, + addTagTextContentMappers(RedmineDataConverter.Boolean, true, "is-closed", "is-default"); - addTagTextContentMappers(RedmineDataConverter.Text, true, + addTagTextContentMappers(RedmineDataConverter.Text, true, "name"); } } Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/AbstractRedmineService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/AbstractRedmineService.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/AbstractRedmineService.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,119 @@ +package org.nuiton.jredmine.service; + +import com.google.common.base.Preconditions; +import org.nuiton.jredmine.client.RedmineClient; +import org.nuiton.jredmine.client.RedmineRequest; + +import java.io.IOException; + +/** + * Abstract redmine service which boxes the technical {@link RedmineClient}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.5 + */ +public abstract class AbstractRedmineService { + + /** + * Redmine client. + * + * @since 1.5 + */ + private RedmineClient client; + + public boolean isInit() { + return client != null && client.isOpen(); + } + + public void init(RedmineServiceConfiguration configuration) throws RedmineServiceException { + Preconditions.checkNotNull(configuration, "the client configuration was not be null!"); + Preconditions.checkState(!isInit(), "the client " + this + " was already init!"); + client = new RedmineClient(configuration); + try { + + client.open(); + } catch (Exception e) { + throw new RedmineServiceException( + "could not init service for reason " + e.getMessage(), e); + } + } + + public void destroy() throws RedmineServiceException { + if (isInit()) { + try { + if (client.isOpen()) { + try { + client.close(); + } catch (IOException e) { + throw new RedmineServiceException( + "has problem while closing Rest client " + + e.getMessage(), e); + } + } + } finally { + if (client != null) { + client = null; + } + } + } + } + + public RedmineClient getClient() { + return client; + } + + protected <T> T executeRequestAndReturnData(RedmineRequest<T> request) throws RedmineServiceException { + checkInit(); + try { + T result = client.executeRequest(request); + return result; + } catch (Exception ex) { + throw new RedmineServiceException( + "could not obtain datas of type " + request.getType() + " for reason " + + ex.getMessage(), ex); + } + } + + protected <T> T[] executeRequestAndReturnDatas(RedmineRequest<T> request) throws RedmineServiceException { + checkInit(); + try { + T[] result = client.executeRequests(request); + return result; + } catch (Exception ex) { + throw new RedmineServiceException( + "could not obtain datas of type " + request.getType() + " for reason " + + ex.getMessage(), ex); + } + } + + protected void checkInit() throws IllegalStateException { + if (!isInit()) { + throw new IllegalStateException( + "the client " + this + " is not init!"); + } + } + + protected void checkSessionNotNull() { + if (client == null) { + throw new NullPointerException("session can not be null"); + } + } + + protected void checkSessionConfigurationNotNull() { + if (client.getConfiguration() == null) { + throw new NullPointerException( + "session configuration can not be null"); + } + } + + protected void checkLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException { + checkInit(); + checkSessionNotNull(); + checkSessionConfigurationNotNull(); + if (client.getConfiguration().isAnonymous()) { + throw new RedmineServiceLoginException( + "can not access this service in anonymous mode"); + } + } + +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/AbstractRedmineService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineAnonymousService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineAnonymousService.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineAnonymousService.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,208 @@ +package org.nuiton.jredmine.service; + +import com.google.common.base.Preconditions; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jredmine.client.RedmineRequest; +import org.nuiton.jredmine.client.RedmineRequestHelper; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; + + +/** + * Default implementation of {@link RedmineAnonymousService}. + * + * @author tchemit <chemit@codelutin.com> + * @plexus.component role="org.nuiton.jredmine.service.RedmineAnonymousService" role-hint="default" + * @since 1.5 + */ +public class DefaultRedmineAnonymousService extends AbstractRedmineService implements RedmineAnonymousService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(DefaultRedmineAnonymousService.class); + + @Override + public void init(RedmineServiceConfiguration configuration) throws RedmineServiceException { + Preconditions.checkNotNull(configuration, "the client configuration was not be null!"); + + // always clone the configuration to keep it in the service + RedmineServiceConfiguration serviceConfiguration = + RedmineConfigurationUtil.cloneConfiguration(configuration); + + // Force to not be loggued + serviceConfiguration.setAnonymous(true); + + if (log.isDebugEnabled()) { + log.debug("init service with configuration: " + serviceConfiguration); + } + if (!isInit()) { + super.init(serviceConfiguration); + } + } + + /////////////////////////////////////////////////////////////////////////// + /// RedmineAnonymousService + /////////////////////////////////////////////////////////////////////////// + + @Override + public IssueStatus[] getIssueStatuses() throws RedmineServiceException { + RedmineRequest<IssueStatus> request = + RedmineRequestHelper.action("get_issue_statuses.xml", + IssueStatus.class); + return executeRequestAndReturnDatas(request); + } + + @Override + public IssuePriority[] getIssuePriorities() throws RedmineServiceException { + RedmineRequest<IssuePriority> request = RedmineRequestHelper.action( + "get_issue_priorities.xml", IssuePriority.class); + return executeRequestAndReturnDatas(request); + } + + @Override + public Project[] getProjects() throws RedmineServiceException { + RedmineRequest<Project> request = RedmineRequestHelper.action( + "get_projects.xml", Project.class); + return executeRequestAndReturnDatas(request); + } + + @Override + public IssueCategory[] getIssueCategories(String projectName) throws RedmineServiceException { + RedmineRequest<IssueCategory> request = + RedmineRequestHelper.actionWithProject( + "get_issue_categories.xml", + IssueCategory.class, + projectName); + return executeRequestAndReturnDatas(request); + } + + @Override + public Project getProject(String projectName) throws RedmineServiceException { + RedmineRequest<Project> request = + RedmineRequestHelper.actionWithProject("get_project.xml", + Project.class, + projectName); + return executeRequestAndReturnData(request + ); + } + + @Override + public Tracker[] getTrackers(String projectName) throws RedmineServiceException { + RedmineRequest<Tracker> request = + RedmineRequestHelper.actionWithProject("get_project_trackers.xml", + Tracker.class, + projectName); + return executeRequestAndReturnDatas(request); + } + + @Override + public News[] getNews(String projectName) throws RedmineServiceException { + RedmineRequest<News> request = + RedmineRequestHelper.actionWithProject("get_project_news.xml", + News.class, + projectName); + return executeRequestAndReturnDatas(request); + } + + @Override + public User[] getProjectMembers(String projectName) throws RedmineServiceException { + RedmineRequest<User> request = + RedmineRequestHelper.actionWithProject("get_project_users.xml", + User.class, + projectName); + return executeRequestAndReturnDatas(request); + } + + @Override + public Version[] getVersions(String projectName) throws RedmineServiceException { + RedmineRequest<Version> request = + RedmineRequestHelper.actionWithProject("get_project_versions.xml", + Version.class, + projectName); + return executeRequestAndReturnDatas(request); + } + + @Override + public Version getVersion(String projectName, + String versionName) throws RedmineServiceException { + RedmineRequest<Version> request = + RedmineRequestHelper.actionWithProjectAndVersion("get_version.xml", + Version.class, + projectName, + versionName); + return executeRequestAndReturnData(request); + } + + @Override + public Attachment[] getAttachments(String projectName, + String versionName) throws RedmineServiceException { + RedmineRequest<Attachment> request = + RedmineRequestHelper.actionWithProjectAndVersion("get_version_attachments.xml", + Attachment.class, + projectName, + versionName); + return executeRequestAndReturnDatas(request); + } + + @Override + public Issue[] getIssues(String projectName, + String versionName) throws RedmineServiceException { + RedmineRequest<Issue> request = + RedmineRequestHelper.actionWithProjectAndVersion("get_version_issues.xml", + Issue.class, + projectName, + versionName); + return executeRequestAndReturnDatas(request); + } + + @Override + public TimeEntry[] getIssueTimeEntries(String projectName, + String issueId) throws RedmineServiceException { + RedmineRequest<TimeEntry> request = + RedmineRequestHelper.actionWithProjectAndIssue("get_issue_times.xml", + TimeEntry.class, + projectName, + issueId); + return executeRequestAndReturnDatas(request); + } + + @Override + public Issue[] getIssues(String projectName) throws RedmineServiceException { + RedmineRequest<Issue> request = + RedmineRequestHelper.actionWithProject("get_project_issues.xml", + Issue.class, + projectName); + Issue[] result = executeRequestAndReturnDatas(request); + return result; + } + + @Override + public Issue[] getOpenedIssues(String projectName) throws RedmineServiceException { + RedmineRequest<Issue> request = + RedmineRequestHelper.actionWithProject("get_project_opened_issues.xml", + Issue.class, + projectName); + Issue[] result = executeRequestAndReturnDatas(request); + return result; + } + + @Override + public Issue[] getClosedIssues(String projectName) throws RedmineServiceException { + RedmineRequest<Issue> request = + RedmineRequestHelper.actionWithProject("get_project_closed_issues.xml", + Issue.class, + projectName); + Issue[] result = executeRequestAndReturnDatas(request); + return result; + } +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineAnonymousService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineService.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineService.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,339 @@ +package org.nuiton.jredmine.service; + +import com.google.common.base.Strings; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jredmine.client.RedmineRequest; +import org.nuiton.jredmine.client.RedmineRequestHelper; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.model.VersionStatusEnum; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Default implementation of the {@link RedmineService}. + * + * @author tchemit <chemit@codelutin.com> + * @plexus.component role="org.nuiton.jredmine.service.RedmineService" role-hint="default" + * @since 1.5 + */ +public class DefaultRedmineService extends AbstractRedmineService implements RedmineService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(DefaultRedmineService.class); + + /** + * Delegate all anonymous call to the anonymous service. + * + * @see RedmineAnonymousService + * @since 1.5 + */ + protected final RedmineAnonymousService anonymousService; + + public DefaultRedmineService() { + this.anonymousService = new DefaultRedmineAnonymousService(); + } + + @Override + public void init(RedmineServiceConfiguration configuration) throws RedmineServiceException { + if (log.isDebugEnabled()) { + log.debug("init service with configuration: " + configuration); + } + if (!isInit()) { + + // always clone the configuration to keep it in the service + RedmineServiceConfiguration serviceConfiguration = + RedmineConfigurationUtil.cloneConfiguration(configuration); + + // init the service using the configuration + super.init(serviceConfiguration); + + // init the anonymous service + anonymousService.init(configuration); + } + } + + /////////////////////////////////////////////////////////////////////////// + /// RedmineAnonymousService implementation + /////////////////////////////////////////////////////////////////////////// + + @Override + public IssueStatus[] getIssueStatuses() throws RedmineServiceException { + IssueStatus[] result = anonymousService.getIssueStatuses(); + return result; + } + + @Override + public IssuePriority[] getIssuePriorities() throws RedmineServiceException { + IssuePriority[] result = anonymousService.getIssuePriorities(); + return result; + } + + @Override + public Project[] getProjects() throws RedmineServiceException { + Project[] result = anonymousService.getProjects(); + return result; + } + + @Override + public IssueCategory[] getIssueCategories(String projectName) throws RedmineServiceException { + IssueCategory[] result = anonymousService.getIssueCategories(projectName); + return result; + } + + @Override + public Project getProject(String projectName) throws RedmineServiceException { + Project result = anonymousService.getProject(projectName); + return result; + } + + @Override + public Tracker[] getTrackers(String projectName) throws RedmineServiceException { + Tracker[] result = anonymousService.getTrackers(projectName); + return result; + } + + @Override + public News[] getNews(String projectName) throws RedmineServiceException { + News[] result = anonymousService.getNews(projectName); + return result; + } + + @Override + public User[] getProjectMembers(String projectName) throws RedmineServiceException { + User[] result = anonymousService.getProjectMembers(projectName); + return result; + } + + @Override + public Version[] getVersions(String projectName) throws RedmineServiceException { + Version[] result = anonymousService.getVersions(projectName); + return result; + } + + @Override + public Version getVersion(String projectName, + String versionName) throws RedmineServiceException { + Version result = anonymousService.getVersion(projectName, versionName); + return result; + } + + @Override + public Attachment[] getAttachments(String projectName, + String versionName) throws RedmineServiceException { + Attachment[] result = anonymousService.getAttachments(projectName, versionName); + return result; + } + + @Override + public Issue[] getIssues(String projectName, + String versionName) throws RedmineServiceException { + Issue[] result = anonymousService.getIssues(projectName, versionName); + return result; + } + + @Override + public TimeEntry[] getIssueTimeEntries(String projectName, + String issueId) throws RedmineServiceException { + TimeEntry[] result = anonymousService.getIssueTimeEntries(projectName, issueId); + return result; + } + + @Override + public Issue[] getIssues(String projectName) throws RedmineServiceException { + Issue[] result = anonymousService.getIssues(projectName); + return result; + } + + @Override + public Issue[] getOpenedIssues(String projectName) throws RedmineServiceException { + Issue[] result = anonymousService.getOpenedIssues(projectName); + return result; + } + + @Override + public Issue[] getClosedIssues(String projectName) throws RedmineServiceException { + Issue[] result = anonymousService.getClosedIssues(projectName); + return result; + } + + /////////////////////////////////////////////////////////////////////////// + /// RedmineLogguedService implementation + /////////////////////////////////////////////////////////////////////////// + + @Override + public Project[] getUserProjects() throws RedmineServiceException { + checkLoggued(); + RedmineRequest<Project> request = RedmineRequestHelper.action( + "get_user_projects.xml", Project.class); + Project[] result = executeRequestAndReturnDatas(request); + return result; + } + + @Override + public Version addVersion(String projectName, + Version version) throws RedmineServiceException { + checkLoggued(); + + RedmineRequest<Version> request = + RedmineRequestHelper.postWithProject("add_version.xml", + Version.class, + projectName); + String date = getVersionEffectiveDate(version); + String status = getVersionStatus(version); + + request.parameter("version[name]", version.getName()); + request.parameter("version[description]", version.getDescription()); + request.parameter("version[effective_date]", date); + request.parameter("version[status]", status); + + // send data and obtain created version + Version result = executeRequestAndReturnData(request); + return result; + } + + @Override + public Version updateVersion(String projectName, + Version version) throws RedmineServiceException { + checkLoggued(); + + RedmineRequest<Version> request = + RedmineRequestHelper.postWithProject("update_version.xml", + Version.class, + projectName); + + String date = getVersionEffectiveDate(version); + String status = getVersionStatus(version); + + request.parameter("version[name]", version.getName()); + request.parameter("version[description]", version.getDescription()); + request.parameter("version[effective_date]", date); + request.parameter("version[status]", status); + + // send data and obtain updated version + Version result = executeRequestAndReturnData(request); + return result; + } + + @Override + public Version nextVersion(String projectName, + String oldVersionName, + Version version) throws RedmineServiceException { + checkLoggued(); + + RedmineRequest<Version> request = + RedmineRequestHelper.postWithProject("next_version.xml", + Version.class, + projectName); + String date = getVersionEffectiveDate(version); + String status = getVersionStatus(version); + + request.parameter("oldVersionName", oldVersionName); + request.parameter("version[name]", version.getName()); + request.parameter("version[description]", version.getDescription()); + request.parameter("version[effective_date]", date); + request.parameter("version[status]", status); + + // send data and obtain updated or created new version + Version result = executeRequestAndReturnData(request); + return result; + } + + @Override + public Attachment addAttachment(String projectName, + String versionName, + Attachment attachment) throws RedmineServiceException { + checkLoggued(); + + RedmineRequest<Attachment> request = + RedmineRequestHelper.postWithProjectAndVersion("add_version_attachment.xml", + Attachment.class, + projectName, + versionName); + + request.parameter("attachment[description]", attachment.getDescription()); + request.attachment("attachment[file]", attachment.getToUpload()); + + // send data and obtain created attachment + Attachment result = executeRequestAndReturnData(request); + return result; + } + + @Override + public News addNews(String projectName, + News news) throws RedmineServiceException { + checkLoggued(); + + RedmineRequest<News> request = + RedmineRequestHelper.postWithProject("add_news.xml", + News.class, + projectName); + + request.parameter("news[title]", news.getTitle()); + request.parameter("news[summary]", news.getSummary()); + request.parameter("news[description]", news.getDescription()); + + // send data and obtain created news + News result = executeRequestAndReturnData(request); + return result; + } + + @Override + public TimeEntry addIssueTimeEntry(String projectName, + String issueId, + TimeEntry timeEntry) throws RedmineServiceException { + checkLoggued(); + + RedmineRequest<TimeEntry> request = + RedmineRequestHelper.postWithProjectAndIssue("add_issue_time.xml", + TimeEntry.class, + projectName, + issueId); + + Date d = timeEntry.getSpentOn(); + if (d == null) { + d = new Date(); + } + String date = DATE_FORMAT.format(d); + + request.parameter("time_entry[activity_id]", timeEntry.getActivityId() + ""); + request.parameter("time_entry[spent_on]", date); + request.parameter("time_entry[hours]", timeEntry.getHours() + ""); + request.parameter("time_entry[comments]", timeEntry.getComments() == null ? "" : timeEntry.getComments()); + + // send data and obtain created time entry + TimeEntry result = executeRequestAndReturnData(request); + return result; + } + + protected final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); + + protected String getVersionStatus(Version version) { + String status = version.getStatus(); + if (Strings.isNullOrEmpty(status)) { + + // use default open status + status = VersionStatusEnum.open.name(); + } + return status; + } + + protected String getVersionEffectiveDate(Version version) { + return version.getEffectiveDate() == null ? "" : + DATE_FORMAT.format(version.getEffectiveDate()); + } + +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineAnonymousService.java (from rev 366, trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java) =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineAnonymousService.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineAnonymousService.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,246 @@ +/* + * #%L + * JRedmine :: Client + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.jredmine.service; + +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; + +/** + * Contract of all redmine operations which do not requires any login to server. + * <p/> + * A default implementation is {@link DefaultRedmineAnonymousService}. + * <p/> + * Created: 2 janv. 2010 + * + * @author tchemit <chemit@codelutin.com> + * @see DefaultRedmineAnonymousService + * @since 1.0.3 + */ +public interface RedmineAnonymousService { + + /** + * Initialize the service. + * + * @param configuration the configuration to be used to init the internal redmine client + * @throws RedmineServiceException if any pb + */ + void init(RedmineServiceConfiguration configuration) throws RedmineServiceException; + + /** + * Tells if service was successful initialized. + * + * @return {@code true} if service was successfull initialized via + * method {@link #init(RedmineServiceConfiguration)}, {@code false} otherwise. + */ + boolean isInit(); + + /** + * Close the service and destroy any connexion to the redmine service. + * + * @throws RedmineServiceException if any pb + */ + void destroy() throws RedmineServiceException; + + /** + * Obtain all accessible projects. + * + * @return all the projects + * @throws RedmineServiceException if any pb while retriving datas + * @see Project + */ + Project[] getProjects() throws RedmineServiceException; + + /** + * Obtain all the priorities defined on a {@link Issue}. + * <p/> + * <b>Note : </b> The priorities are common for all projects. + * + * @return all the issue properties + * @throws RedmineServiceException if any pb while retriving datas + * @see IssuePriority + */ + IssuePriority[] getIssuePriorities() throws RedmineServiceException; + + /** + * Obtain all the statuses defined on a {@link Issue}. + * <p/> + * <b>Note : </b> The statuses are common for all projects. + * + * @return all the issue statuses + * @throws RedmineServiceException if any pb while retriving datas + * @see IssueStatus + */ + IssueStatus[] getIssueStatuses() throws RedmineServiceException; + + /** + * Obtain a project given his name. + * + * @param projectName the name of the project + * @return the project + * @throws RedmineServiceException if any pb while retriving datas + * @see Project + */ + Project getProject(String projectName) throws RedmineServiceException; + + /** + * Obtain all categories defined on issues for a given project. + * + * @param projectName the name of the project + * @return the categories of issues for the given project. + * @throws RedmineServiceException if any pb while retriving datas + * @see IssueCategory + */ + IssueCategory[] getIssueCategories(String projectName) throws RedmineServiceException; + + /** + * Obtain all trackers defined on a given project. + * + * @param projectName the name of the project + * @return the trackers for the given project. + * @throws RedmineServiceException if any pb while retriving datas + * @see Tracker + */ + Tracker[] getTrackers(String projectName) throws RedmineServiceException; + + /** + * Obtain all news defined on a given project. + * + * @param projectName the name of the project + * @return the news for the given project. + * @throws RedmineServiceException if any pb while retriving datas + * @see News + */ + News[] getNews(String projectName) throws RedmineServiceException; + + /** + * Obtain all users defined on a given project. + * + * @param projectName the name of the project + * @return the users for the given project. + * @throws RedmineServiceException if any pb while retriving datas + * @see User + */ + User[] getProjectMembers(String projectName) throws RedmineServiceException; + + /** + * Obtain all versions defined on a given project. + * + * @param projectName the name of the project + * @return the versions of the given project. + * @throws RedmineServiceException if any pb while retriving datas + * @see Version + */ + Version[] getVersions(String projectName) throws RedmineServiceException; + + /** + * Obtain a specific version for a given project. + * + * @param projectName the name of the project + * @param versionName the name of the version + * @return the version + * @throws RedmineServiceException if any pb while retriving datas + * @see Version + */ + Version getVersion(String projectName, + String versionName) throws RedmineServiceException; + + /** + * Obtain all issues for a given project. + * + * @param projectName the name of the project + * @return the issues + * @throws RedmineServiceException if any pb while retriving datas + * @see Issue + * @since 1.0.3 + */ + Issue[] getIssues(String projectName) throws RedmineServiceException; + + /** + * Obtain all opened issues for a given project. + * + * @param projectName the name of the project + * @return the issues + * @throws RedmineServiceException if any pb while retriving datas + * @see Issue + * @since 1.0.3 + */ + Issue[] getOpenedIssues(String projectName) throws RedmineServiceException; + + /** + * Obtain all closed issues for a given project. + * + * @param projectName the name of the project + * @return the issues + * @throws RedmineServiceException if any pb while retriving datas + * @see Issue + * @since 1.0.3 + */ + Issue[] getClosedIssues(String projectName) throws RedmineServiceException; + + /** + * Obtain all issues for a specific version on a given project. + * + * @param projectName the name of the project + * @param versionName the name of the version + * @return the issues + * @throws RedmineServiceException if any pb while retriving datas + * @see Issue + */ + Issue[] getIssues(String projectName, + String versionName) throws RedmineServiceException; + + /** + * Obtain for a given issue of a given project all the time entries. + * + * @param projectName the name of the project + * @param issueId the id of the issue + * @return the time entries of the issue + * @throws RedmineServiceException if any pb while retrieving time entries of the issue + * @since 1.0.3 + */ + TimeEntry[] getIssueTimeEntries(String projectName, + String issueId) throws RedmineServiceException; + + /** + * Obtain all attachments for a specific version on a given project. + * + * @param projectName the name of the project + * @param versionName the name of the version + * @return the attachments + * @throws RedmineServiceException if any pb while retriving datas + * @see Attachment + */ + Attachment[] getAttachments(String projectName, + String versionName) throws RedmineServiceException; +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineAnonymousService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineConfigurationUtil.java (from rev 366, trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineConfigurationUtil.java) =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineConfigurationUtil.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineConfigurationUtil.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,359 @@ +package org.nuiton.jredmine.service; +/* + * #%L + * JRedmine :: Client + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.beanutils.BeanUtilsBean; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jredmine.client.RedmineClient; +import org.nuiton.jredmine.client.RedmineClientAuthConfiguration; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Properties; + +/** + * Helper methods about configuration. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.5 + */ +public class RedmineConfigurationUtil { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(RedmineConfigurationUtil.class); + + public static final String PROPERTY_PREFIX = "jredmine-test."; + + protected RedmineConfigurationUtil() { + // avoid instance + } + + public static RedmineServiceConfiguration obtainRedmineConfiguration( + RedmineServiceConfiguration anoConf) throws IOException { + + RedmineServiceConfiguration conf = newLogguedConfiguration(anoConf); + + boolean ok = false; + + RedmineClient client = new RedmineClient(conf); + + try { + + client.open(); + ok = client.isOpen(); + } catch (Exception e) { + + if (log.isDebugEnabled()) { + log.debug("Could not connect to redmine with configuration: " + conf, e); + } + + } finally { + try { + client.close(); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Could not close session", e); + } + } + } + + if (!ok) { + + // try to connect anonymous + conf = cloneConfiguration(anoConf); + + client = new RedmineClient(conf); + + try { + + client.open(); + ok = client.isOpen(); + } catch (Exception e) { + + if (log.isDebugEnabled()) { + log.debug("Could not connect to redmine with configuration: " + conf, e); + } + } finally { + try { + client.close(); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Could not close session", e); + } + } + } + } + + if (!ok) { + + // no conf available + conf = null; + } + return conf; + } + + public static RedmineServiceConfiguration newAnonymousConfiguration(String propertiesFromEnv, + String classPathPropertiesLocation) + throws IOException { + + Properties props = new Properties(); + + InputStream in = null; + try { + String jredmineConfiguration = System.getenv(propertiesFromEnv); + if (jredmineConfiguration == null) { + if (log.isInfoEnabled()) { + log.info("Could not find environement variable " + + "'jredmine-test.properties' will use " + + "default test configuration"); + } + + in = RedmineConfigurationUtil.class.getResourceAsStream(classPathPropertiesLocation); + } else { + + File file = new File(jredmineConfiguration); + + if (!file.exists()) { + throw new IllegalStateException("Could not find " + jredmineConfiguration + + " file"); + } + in = FileUtils.openInputStream(file); + } + props.load(in); + in.close(); + } finally { + IOUtils.closeQuietly(in); + } + + RedmineServiceConfiguration result = new SimpleRedmineServiceConfiguration(); + + RedmineClientAuthConfiguration authConfiguration = + new RedmineClientAuthConfiguration(); + result.setAuthConfiguration(authConfiguration); + overridePropertyFromProperties(result, "url", props); + overridePropertyFromProperties(result, "encoding", props); + overridePropertyFromProperties(result, "verbose", props); + + overridePropertyFromEnv(result, "url"); + overridePropertyFromEnv(result, "encoding"); + overridePropertyFromEnv(result, "verbose"); + result.setAnonymous(true); + return result; + } + + public static RedmineServiceConfiguration newLogguedConfiguration(RedmineServiceConfiguration anoConf) + throws IOException { + + // use anonymous configuration + + RedmineServiceConfiguration result = cloneConfiguration(anoConf); + + RedmineClientAuthConfiguration authConfiguration = + result.getAuthConfiguration(); + overridePropertyFromEnv(authConfiguration, "username"); + overridePropertyFromEnv(authConfiguration, "password"); + overridePropertyFromEnv(authConfiguration, "apiKey"); + + result.setAnonymous(false); + + return result; + } + + public static RedmineServiceConfiguration cloneConfiguration( + RedmineServiceConfiguration src) { + RedmineServiceConfiguration dst = new SimpleRedmineServiceConfiguration(); + copyConfiguration(src, dst); + return dst; + } + + public static void copyConfiguration(RedmineServiceConfiguration src, + RedmineServiceConfiguration dst) { + dst.setUrl(src.getUrl()); + dst.setEncoding(src.getEncoding()); + dst.setVerbose(src.isVerbose()); + dst.setAnonymous(src.isAnonymous()); + + RedmineClientAuthConfiguration authConfiguration = new RedmineClientAuthConfiguration(); + authConfiguration.setApiKey(src.getAuthConfiguration().getApiKey()); + authConfiguration.setUsername(src.getAuthConfiguration().getUsername()); + authConfiguration.setPassword(src.getAuthConfiguration().getPassword()); + dst.setAuthConfiguration(authConfiguration); + } + + protected static void overridePropertyFromProperties(Object conf, + String prop, + Properties props) throws IOException { + String value = props.getProperty(PROPERTY_PREFIX + prop); + if (StringUtils.isNotEmpty(value)) { + try { + BeanUtilsBean.getInstance().setProperty(conf, prop, value); + } catch (Exception e) { + throw new IOException( + "Could not set property '" + prop + + "' with value '" + value + "' to configuration"); + } + } + } + + protected static void overridePropertyFromEnv(Object conf, + String prop) throws IOException { + String value = System.getenv(PROPERTY_PREFIX + prop); + if (StringUtils.isNotEmpty(value) && !"null".equals(value)) { + try { + BeanUtilsBean.getInstance().setProperty(conf, prop, value); + } catch (Exception e) { + throw new IOException( + "Could not set property '" + prop + + "' with value '" + value + "' to configuration"); + } + } + } + + /** + * Configuration of a redmine service for test purposes. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ + public static class SimpleRedmineServiceConfiguration implements RedmineServiceConfiguration { + + URL url; + + boolean verbose; + + boolean anonymous; + + String encoding; + + RedmineClientAuthConfiguration authConfiguration; + + @Override + public RedmineClientAuthConfiguration getAuthConfiguration() { + return authConfiguration; + } + + @Override + public void setAuthConfiguration(RedmineClientAuthConfiguration authConfiguration) { + this.authConfiguration = authConfiguration; + } + + @Override + public String getEncoding() { + return encoding; + } + + @Override + public void setEncoding(String encoding) { + this.encoding = encoding; + } + +// @Override +// public String getPassword() { +// return restPassword; +// } +// +// @Override +// public void setPassword(String password) { +// this.restPassword = password; +// } + + @Override + public URL getUrl() { + return url; + } + + @Override + public void setUrl(URL url) { + this.url = url; + } + +// @Override +// public String getUsername() { +// return restUsername; +// } +// +// @Override +// public void setUsername(String username) { +// this.restUsername = username; +// } + + @Override + public boolean isVerbose() { + return verbose; + } + + @Override + public void setVerbose(boolean verbose) { + this.verbose = verbose; + } + + @Override + public boolean isAnonymous() { + return anonymous; + } + + @Override + public void setAnonymous(boolean anonymous) { + this.anonymous = anonymous; + } + + @Override + public String toString() { + ToStringBuilder b = new ToStringBuilder( + this, + ToStringStyle.MULTI_LINE_STYLE + ); + b.append("redmineUrl", url); + if (anonymous) { + b.append("anonymous", true); + } else { + b.append("apiKey", authConfiguration.getApiKey()); + b.append("username", authConfiguration.getUsername()); + b.append("password", "***"); + } + b.append("encoding", encoding); + b.append("verbose", verbose); + return b.toString(); + } + +// @Override +// public String getApiKey() { +// return apiKey; +// } +// +// @Override +// public void setApiKey(String apiKey) { +// this.apiKey = apiKey; +// } + } +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineConfigurationUtil.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineLogguedService.java (from rev 366, trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineLogguedService.java) =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineLogguedService.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineLogguedService.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,161 @@ +/* + * #%L + * JRedmine :: Client + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.jredmine.service; + +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Version; + + +/** + * Contract of all redmine operations that needs a login to be performed. + * <p/> + * A default implementation is offered in {@link DefaultRedmineService}. + * <p/> + * Created: 2 janv. 2010 + * + * @author tchemit <chemit@codelutin.com> + * @see RedmineAnonymousService + * @see RedmineService + * @since 1.0.3 + */ +public interface RedmineLogguedService { + + /** + * Obtain for the loggued user, all projets where he belongs. + * <p/> + * <b>Note:</b> This method requires to be loggued on redmine server. + * + * @return all the projects belonged by the loggued user + * @throws RedmineServiceException if any pb while retriving datas + * @see Project + * @since 1.0.3 + */ + Project[] getUserProjects() throws RedmineServiceException; + + /** + * Add a version for a given project. + * <p/> + * b>Note:</b> This method requires to be loggued on redmine server. + * + * @param projectName the name of the project + * @param version the version to add + * @return the added version + * @throws RedmineServiceException if any pb while sending and retriving + * datas to redmine server + * @see Version + */ + Version addVersion(String projectName, + Version version) throws RedmineServiceException; + + /** + * Update a version for a given project. + * <p/> + * b>Note:</b> This method requires to be loggued on redmine server. + * + * @param projectName the name of the project + * @param version the version to update + * @return the updated version + * @throws RedmineServiceException if any pb while sending and retriving + * datas to redmine server + * @see Version + */ + Version updateVersion(String projectName, + Version version) throws RedmineServiceException; + + /** + * Prepare a new version (create it or update it). + * <p/> + * If the {@code oldVersionName} is given, then all issues unclosed from this + * old version will be move to the new version. + * <p/> + * b>Note:</b> This method requires to be loggued on redmine server. + * + * @param projectName the name of the project + * @param oldVersionName the name of the old version (optional) + * @param newVersion the newVersion to create or update + * @return the created version + * @throws RedmineServiceException if any pb while sending and retriving + * datas to redmine server + * @see Version + */ + Version nextVersion(String projectName, + String oldVersionName, + Version newVersion) throws RedmineServiceException; + + /** + * Add a news for a given project. + * <p/> + * b>Note:</b> This method requires to be loggued on redmine server. + * + * @param projectName the name of the project + * @param news the news to add + * @return the added news. + * @throws RedmineServiceException if any pb while sending and retriving + * datas to redmine server + * @see News + */ + News addNews(String projectName, News news) throws RedmineServiceException; + + /** + * Add a attachment for a given version of a given project. + * <p/> + * b>Note:</b> This method requires to be loggued on redmine server. + * + * @param projectName the name of the project + * @param versionName the name of the version + * @param attachement the attachment to add + * @return the added attachment + * @throws RedmineServiceException if any pb while sending and retriving + * datas to redmine server + * @see Attachment + */ + Attachment addAttachment(String projectName, + String versionName, + Attachment attachement) throws RedmineServiceException; + + /** + * Add a new time entry to the given issue for the given project and + * return the updated time entry. + * <p/> + * b>Note:</b> This method requires to be loggued on redmine server. + * + * @param projectName the name of the project + * @param issueId the id of the issue to update + * @param entry time entry to add + * @return the created time entry + * @throws RedmineServiceException if any pb while sending or retrieving + * datas to redmine server + * @see Issue + * @see TimeEntry + * @since 1.0.3 + */ + TimeEntry addIssueTimeEntry(String projectName, + String issueId, + TimeEntry entry) throws RedmineServiceException; +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineLogguedService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineService.java (from rev 366, trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineService.java) =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineService.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineService.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,42 @@ +/* + * #%L + * JRedmine :: Client + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.jredmine.service; + +/** + * The full redmine service with anonymous and loggued methods. + * <p/> + * <b>Note:</b> A default implementation is offered : + * {@link DefaultRedmineService} + * + * @author tchemit <chemit@codelutin.com> + * @see DefaultRedmineService + * @since 1.0.0 + */ +public interface RedmineService extends RedmineAnonymousService, RedmineLogguedService { + + /** Plexus lookup name. */ + String ROLE = RedmineService.class.getName(); + +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceConfiguration.java (from rev 366, trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java) =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceConfiguration.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceConfiguration.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,36 @@ +package org.nuiton.jredmine.service; +/* + * #%L + * JRedmine :: Client + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.nuiton.jredmine.client.RedmineClientConfiguration; + +/** + * Contract of a redmine service configuration. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public interface RedmineServiceConfiguration extends RedmineClientConfiguration { + +} \ No newline at end of file Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceConfiguration.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceException.java (from rev 366, trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceException.java) =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceException.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceException.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,51 @@ +/* + * #%L + * JRedmine :: Client + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.jredmine.service; + +/** + * An exception to throw when something is wrong in a {@link RedmineService}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0.0 + */ +public class RedmineServiceException extends Exception { + + private static final long serialVersionUID = 1L; + + public RedmineServiceException(Throwable cause) { + super(cause); + } + + public RedmineServiceException(String message, Throwable cause) { + super(message, cause); + } + + public RedmineServiceException(String message) { + super(message); + } + + public RedmineServiceException() { + } +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceLoginException.java (from rev 366, trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceLoginException.java) =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceLoginException.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceLoginException.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,54 @@ +/* + * #%L + * JRedmine :: Client + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.jredmine.service; + +/** + * An exception to be thrown when a problem with authentication state in a + * {@link RedmineService}. + * <p/> + * Created: 2 janv. 2010 + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0.3 + */ +public class RedmineServiceLoginException extends RedmineServiceException { + + private static final long serialVersionUID = 1L; + + public RedmineServiceLoginException() { + } + + public RedmineServiceLoginException(Throwable cause) { + super(cause); + } + + public RedmineServiceLoginException(String message) { + super(message); + } + + public RedmineServiceLoginException(String message, Throwable cause) { + super(message, cause); + } +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineServiceLoginException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/jredmine-client/src/site/apt/redmine_service.apt =================================================================== --- trunk/jredmine-client/src/site/apt/redmine_service.apt 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/site/apt/redmine_service.apt 2012-10-16 20:18:19 UTC (rev 367) @@ -33,15 +33,15 @@ L'api java sépare depuis la version 1.0.3 les services publiques et privés. -* org.nuiton.jredmine.RedmineAnonymousService +* org.nuiton.jredmine.service.RedmineAnonymousService Ce contrat permet d'exécuter les services publiques (services anonymes). -* org.nuiton.jredmine.RedmineLogguedService +* org.nuiton.jredmine.service.RedmineLogguedService Ce contrat permet d'exécuter les services privés (services avec login). -* org.nuiton.jredmine.RedmineService +* org.nuiton.jredmine.service.RedmineService Ce contrat regroupe les deux précédents et constitue l'ensemble des services connus par redmine. @@ -51,13 +51,13 @@ L'api offre deux implentations de service. -* org.nuiton.jredmine.DefaultRedmineAnonymousService +* org.nuiton.jredmine.service.DefaultRedmineAnonymousService Ce service peut-être appelé pour tout opération publique, la session sous-jacente au service (RedmineRestClient) n'établiera pas d'authentification vers les serveur redmine. -* org.nuiton.jredmine.DefaultRedmineService +* org.nuiton.jredmine.service.DefaultRedmineService Ce service peut-être appelé pour toute opération vers le serveur redmine. Deleted: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceTest.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceTest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,180 +0,0 @@ -package org.nuiton.jredmine; -/* - * #%L - * JRedmine :: Client - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.junit.Assert; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.nuiton.jredmine.model.Attachment; -import org.nuiton.jredmine.model.Issue; -import org.nuiton.jredmine.model.IssueCategory; -import org.nuiton.jredmine.model.IssuePriority; -import org.nuiton.jredmine.model.IssueStatus; -import org.nuiton.jredmine.model.News; -import org.nuiton.jredmine.model.Project; -import org.nuiton.jredmine.model.TimeEntry; -import org.nuiton.jredmine.model.Tracker; -import org.nuiton.jredmine.model.User; -import org.nuiton.jredmine.model.Version; -import org.nuiton.jredmine.test.RedmineAnonymousFixtureClassRule; -import org.nuiton.jredmine.test.RedmineServer; - -/** - * Tests the {@link RedmineAnonymousService} service. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class RedmineAnonymousServiceTest { - - @ClassRule - public static final RedmineAnonymousFixtureClassRule<RedmineFixtures> classRule = - RedmineAnonymousFixtureClassRule.newFixtures(RedmineFixtures.class); - - @Rule - public final RedmineServer<RedmineAnonymousService, RedmineFixtures> server = - RedmineServer.newAnonymousServer(classRule); - - protected RedmineFixtures getFixtures() { - return server.getFixtures(); - } - - protected RedmineAnonymousService getService() { - return server.getService(); - } - - @Test - public void getProjects() throws Exception { - Project[] projects = getService().getProjects(); - Assert.assertNotNull(projects); - Assert.assertTrue(projects.length > 0); - } - - @Test - public void getProject() throws Exception { - Project project = getService().getProject(getFixtures().projectName()); - Assert.assertNotNull(project); - } - - @Test - public void getNews() throws Exception { - News[] news = getService().getNews(getFixtures().projectName()); - Assert.assertNotNull(news); - Assert.assertTrue(news.length > 0); - } - - @Test - public void getProjectIssues() throws Exception { - Issue[] issues = getService().getIssues(getFixtures().projectName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getVersions() throws Exception { - Version[] versions = getService().getVersions(getFixtures().projectName()); - Assert.assertNotNull(versions); - Assert.assertTrue(versions.length > 0); - } - - @Test - public void getVersion() throws Exception { - Version version = getService().getVersion(getFixtures().projectName(), getFixtures().versionName()); - Assert.assertNotNull(version); - } - - @Test - public void getIssueCategories() throws Exception { - // Need to be loggued ? don't know why :( Need to report a bug - IssueCategory[] issueCategories = getService().getIssueCategories(getFixtures().projectName()); - Assert.assertNotNull(issueCategories); - Assert.assertTrue(issueCategories.length > 0); - } - - @Test - public void getProjectMembers() throws Exception { - // Need to be loggued ? don't know why :( Need to report a bug - User[] users = getService().getProjectMembers(getFixtures().projectName()); - Assert.assertNotNull(users); - Assert.assertTrue(users.length > 0); - } - - @Test - public void getOpenedIssues() throws Exception { - Issue[] issues = getService().getOpenedIssues(getFixtures().projectName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getClosedIssues() throws Exception { - Issue[] issues = getService().getClosedIssues(getFixtures().projectName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getIssueTimeEntries() throws Exception { - TimeEntry[] timeEntries = getService().getIssueTimeEntries(getFixtures().projectName(), getFixtures().issueId()); - Assert.assertNotNull(timeEntries); - Assert.assertTrue(timeEntries.length > 0); - } - - @Test - public void getIssuePriorities() throws Exception { - IssuePriority[] issuePriorities = getService().getIssuePriorities(); - Assert.assertNotNull(issuePriorities); - Assert.assertTrue(issuePriorities.length > 0); - } - - @Test - public void getIssueStatuses() throws Exception { - IssueStatus[] issueStatuses = getService().getIssueStatuses(); - Assert.assertNotNull(issueStatuses); - Assert.assertTrue(issueStatuses.length > 0); - } - - @Test - public void getTrackers() throws Exception { - Tracker[] trackers = getService().getTrackers(getFixtures().projectName()); - Assert.assertNotNull(trackers); - Assert.assertTrue(trackers.length > 0); - } - - @Test - public void getVersionIssues() throws Exception { - Issue[] issues = getService().getIssues(getFixtures().projectName(), getFixtures().versionName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getAttachments() throws Exception { - Attachment[] attachments = getService().getAttachments(getFixtures().projectName(), getFixtures().versionName()); - Assert.assertNotNull(attachments); - Assert.assertTrue(attachments.length > 0); - } - -} \ No newline at end of file Deleted: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceAsAnonymousTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceAsAnonymousTest.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceAsAnonymousTest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,215 +0,0 @@ -package org.nuiton.jredmine; -/* - * #%L - * JRedmine :: Client - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.junit.Assert; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.nuiton.jredmine.model.Attachment; -import org.nuiton.jredmine.model.Issue; -import org.nuiton.jredmine.model.IssueCategory; -import org.nuiton.jredmine.model.IssuePriority; -import org.nuiton.jredmine.model.IssueStatus; -import org.nuiton.jredmine.model.News; -import org.nuiton.jredmine.model.Project; -import org.nuiton.jredmine.model.TimeEntry; -import org.nuiton.jredmine.model.Tracker; -import org.nuiton.jredmine.model.User; -import org.nuiton.jredmine.model.Version; -import org.nuiton.jredmine.test.RedmineAnonymousFixtureClassRule; -import org.nuiton.jredmine.test.RedmineServer; - -/** - * Tests the {@link RedmineService} service with anonymous configuration. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class RedmineServiceAsAnonymousTest { - - @ClassRule - public static final RedmineAnonymousFixtureClassRule<RedmineFixtures> classRule = - RedmineAnonymousFixtureClassRule.newFixtures(RedmineFixtures.class); - - - protected RedmineFixtures getFixtures() { - return server.getFixtures(); - } - - @Rule - public final RedmineServer<RedmineService, RedmineFixtures> server = - RedmineServer.newLogguedServerAsAnonymous(classRule); - - protected RedmineService getService() { - return server.getService(); - } - - @Test - public void getProjects() throws Exception { - Project[] projects = getService().getProjects(); - Assert.assertNotNull(projects); - Assert.assertTrue(projects.length > 0); - } - - @Test - public void getProject() throws Exception { - Project project = getService().getProject(getFixtures().projectName()); - Assert.assertNotNull(project); - } - - @Test - public void getNews() throws Exception { - News[] news = getService().getNews(getFixtures().projectName()); - Assert.assertNotNull(news); - Assert.assertTrue(news.length > 0); - } - - @Test - public void getProjectIssues() throws Exception { - Issue[] issues = getService().getIssues(getFixtures().projectName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getVersions() throws Exception { - Version[] versions = getService().getVersions(getFixtures().projectName()); - Assert.assertNotNull(versions); - Assert.assertTrue(versions.length > 0); - } - - @Test - public void getVersion() throws Exception { - Version version = getService().getVersion(getFixtures().projectName(), getFixtures().versionName()); - Assert.assertNotNull(version); - } - - @Test - public void getIssueCategories() throws Exception { - // Need to be loggued ? don't know why :( Need to report a bug - IssueCategory[] issueCategories = getService().getIssueCategories(getFixtures().projectName()); - Assert.assertNotNull(issueCategories); - Assert.assertTrue(issueCategories.length > 0); - } - - @Test - public void getProjectMembers() throws Exception { - // Need to be loggued ? don't know why :( Need to report a bug - User[] users = getService().getProjectMembers(getFixtures().projectName()); - Assert.assertNotNull(users); - Assert.assertTrue(users.length > 0); - } - - @Test - public void getOpenedIssues() throws Exception { - Issue[] issues = getService().getOpenedIssues(getFixtures().projectName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getClosedIssues() throws Exception { - Issue[] issues = getService().getClosedIssues(getFixtures().projectName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getIssueTimeEntries() throws Exception { - TimeEntry[] timeEntries = getService().getIssueTimeEntries(getFixtures().projectName(), getFixtures().issueId()); - Assert.assertNotNull(timeEntries); - Assert.assertTrue(timeEntries.length > 0); - } - - @Test - public void getIssuePriorities() throws Exception { - IssuePriority[] issuePriorities = getService().getIssuePriorities(); - Assert.assertNotNull(issuePriorities); - Assert.assertTrue(issuePriorities.length > 0); - } - - @Test - public void getIssueStatuses() throws Exception { - IssueStatus[] issueStatuses = getService().getIssueStatuses(); - Assert.assertNotNull(issueStatuses); - Assert.assertTrue(issueStatuses.length > 0); - } - - @Test - public void getTrackers() throws Exception { - Tracker[] trackers = getService().getTrackers(getFixtures().projectName()); - Assert.assertNotNull(trackers); - Assert.assertTrue(trackers.length > 0); - } - - @Test - public void getVersionIssues() throws Exception { - Issue[] issues = getService().getIssues(getFixtures().projectName(), getFixtures().versionName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getAttachments() throws Exception { - Attachment[] attachments = getService().getAttachments(getFixtures().projectName(), getFixtures().versionName()); - Assert.assertNotNull(attachments); - Assert.assertTrue(attachments.length > 0); - } - - @Test(expected = RedmineServiceLoginException.class) - public void getUserProjects() throws Exception { - getService().getUserProjects(); - } - - @Test(expected = RedmineServiceLoginException.class) - public void addVersion() throws Exception { - getService().addVersion(getFixtures().projectName(), new Version()); - } - - @Test(expected = RedmineServiceLoginException.class) - public void addAttachment() throws Exception { - getService().addAttachment(getFixtures().projectName(), getFixtures().versionName(), new Attachment()); - } - - @Test(expected = RedmineServiceLoginException.class) - public void addNews() throws Exception { - getService().addNews(getFixtures().projectName(), new News()); - } - - @Test(expected = RedmineServiceLoginException.class) - public void updateVersion() throws Exception { - getService().updateVersion(getFixtures().projectName(), new Version()); - } - - @Test(expected = RedmineServiceLoginException.class) - public void nextVersion() throws Exception { - getService().nextVersion(getFixtures().projectName(), getFixtures().versionName(), new Version()); - } - - @Test(expected = RedmineServiceLoginException.class) - public void addIssueTime() throws Exception { - getService().addIssueTimeEntry(getFixtures().projectName(), getFixtures().issueId(), new TimeEntry()); - } -} Deleted: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceTest.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceTest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,223 +0,0 @@ -package org.nuiton.jredmine; -/* - * #%L - * JRedmine :: Client - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.junit.Assert; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.nuiton.jredmine.model.Attachment; -import org.nuiton.jredmine.model.Issue; -import org.nuiton.jredmine.model.IssueCategory; -import org.nuiton.jredmine.model.IssuePriority; -import org.nuiton.jredmine.model.IssueStatus; -import org.nuiton.jredmine.model.News; -import org.nuiton.jredmine.model.Project; -import org.nuiton.jredmine.model.TimeEntry; -import org.nuiton.jredmine.model.Tracker; -import org.nuiton.jredmine.model.User; -import org.nuiton.jredmine.model.Version; -import org.nuiton.jredmine.test.RedmineFixtureClassRule; -import org.nuiton.jredmine.test.RedmineServer; - -/** - * Tests the {@link RedmineService} service with loggued configuration. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class RedmineServiceTest { - - @ClassRule - public static final RedmineFixtureClassRule<RedmineFixtures> classRule = - RedmineFixtureClassRule.newFixtures(RedmineFixtures.class); - - @Rule - public final RedmineServer<RedmineService, RedmineFixtures> server = - RedmineServer.newLogguedServer(classRule); - - protected RedmineFixtures getFixtures() { - return server.getFixtures(); - } - - protected RedmineService getService() { - return server.getService(); - } - - @Test - public void getProjects() throws Exception { - Project[] projects = getService().getProjects(); - Assert.assertNotNull(projects); - Assert.assertTrue(projects.length > 0); - } - - @Test - public void getProject() throws Exception { - Project project = getService().getProject(getFixtures().projectName()); - Assert.assertNotNull(project); - } - - @Test - public void getNews() throws Exception { - News[] news = getService().getNews(getFixtures().projectName()); - Assert.assertNotNull(news); - Assert.assertTrue(news.length > 0); - } - - @Test - public void getProjectIssues() throws Exception { - Issue[] issues = getService().getIssues(getFixtures().projectName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getVersions() throws Exception { - Version[] versions = getService().getVersions(getFixtures().projectName()); - Assert.assertNotNull(versions); - Assert.assertTrue(versions.length > 0); - } - - @Test - public void getVersion() throws Exception { - Version version = getService().getVersion(getFixtures().projectName(), getFixtures().versionName()); - Assert.assertNotNull(version); - } - - @Test - public void getIssueCategories() throws Exception { - // Need to be loggued ? don't know why :( Need to report a bug - IssueCategory[] issueCategories = getService().getIssueCategories(getFixtures().projectName()); - Assert.assertNotNull(issueCategories); - Assert.assertTrue(issueCategories.length > 0); - } - - @Test - public void getProjectMembers() throws Exception { - // Need to be loggued ? don't know why :( Need to report a bug - User[] users = getService().getProjectMembers(getFixtures().projectName()); - Assert.assertNotNull(users); - Assert.assertTrue(users.length > 0); - } - - @Test - public void getOpenedIssues() throws Exception { - Issue[] issues = getService().getOpenedIssues(getFixtures().projectName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getClosedIssues() throws Exception { - Issue[] issues = getService().getClosedIssues(getFixtures().projectName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getIssueTimeEntries() throws Exception { - TimeEntry[] timeEntries = getService().getIssueTimeEntries(getFixtures().projectName(), getFixtures().issueId()); - Assert.assertNotNull(timeEntries); - Assert.assertTrue(timeEntries.length > 0); - } - - @Test - public void getIssuePriorities() throws Exception { - IssuePriority[] issuePriorities = getService().getIssuePriorities(); - Assert.assertNotNull(issuePriorities); - Assert.assertTrue(issuePriorities.length > 0); - } - - @Test - public void getIssueStatuses() throws Exception { - IssueStatus[] issueStatuses = getService().getIssueStatuses(); - Assert.assertNotNull(issueStatuses); - Assert.assertTrue(issueStatuses.length > 0); - } - - @Test - public void getTrackers() throws Exception { - Tracker[] trackers = getService().getTrackers(getFixtures().projectName()); - Assert.assertNotNull(trackers); - Assert.assertTrue(trackers.length > 0); - } - - @Test - public void getVersionIssues() throws Exception { - Issue[] issues = getService().getIssues(getFixtures().projectName(), getFixtures().versionName()); - Assert.assertNotNull(issues); - Assert.assertTrue(issues.length > 0); - } - - @Test - public void getAttachments() throws Exception { - Attachment[] attachments = getService().getAttachments(getFixtures().projectName(), getFixtures().versionName()); - Assert.assertNotNull(attachments); - Assert.assertTrue(attachments.length > 0); - } - - @Ignore - @Test - public void addVersion() throws Exception { - getService().addVersion(getFixtures().projectName(), getFixtures().versionToAdd()); - } - - @Ignore - @Test - public void addAttachment() throws Exception { - Version version = getFixtures().versionToUpdate(); - Attachment attachment = getFixtures().attachmentToAdd(); - Attachment updatedAttachment = getService().addAttachment( - getFixtures().projectName(), - version.getName(), - attachment - ); - Assert.assertNotNull(updatedAttachment); - } - - @Ignore - @Test - public void addNews() throws Exception { - getService().addNews(getFixtures().projectName(), getFixtures().newsToAdd()); - } - - @Ignore - @Test - public void updateVersion() throws Exception { - getService().updateVersion(getFixtures().projectName(), getFixtures().versionToUpdate()); - } - - @Ignore - @Test - public void nextVersion() throws Exception { - getService().nextVersion(getFixtures().projectName(), getFixtures().versionName(), getFixtures().versionToUpdate()); - } - - @Ignore - @Test - public void addIssueTime() throws Exception { - getService().addIssueTimeEntry(getFixtures().projectName(), getFixtures().issueId(), getFixtures().timeEntryToAdd()); - } -} Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -26,20 +26,28 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.codehaus.plexus.util.IOUtil; import org.junit.After; import org.junit.Assert; import org.junit.Assume; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; -import org.nuiton.io.rest.RestRequest; import org.nuiton.jredmine.RedmineFixtures; -import org.nuiton.jredmine.RedmineServiceConfiguration; -import org.nuiton.jredmine.model.ModelHelper; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; import org.nuiton.jredmine.test.RedmineFixtureClassRule; -import java.io.InputStream; +import java.util.Arrays; /** * Tests the {@link RedmineClient}. @@ -104,98 +112,144 @@ @Test public void getProjects() throws Exception { - - askData(ModelHelper.GET_ALL_PROJECT_REQUEST_NAME); + RedmineRequest<Project> request = RedmineRequestHelper.action( + "get_projects.xml", Project.class); + askDatas(request); } @Test public void getIssuePriorities() throws Exception { - - askData(ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME); + RedmineRequest<IssuePriority> request = RedmineRequestHelper.action( + "get_issue_priorities.xml", IssuePriority.class); + askDatas(request); } @Test public void getIssueStatuses() throws Exception { - - askData(ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME); + RedmineRequest<IssueStatus> request = + RedmineRequestHelper.action("get_issue_statuses.xml", + IssueStatus.class); + askDatas(request); } @Test public void getProject() throws Exception { - - askData(ModelHelper.GET_PROJECT_REQUEST_NAME, projectName); + RedmineRequest<Project> request = + RedmineRequestHelper.actionWithProject("get_project.xml", + Project.class, + projectName); + askData(request); } @Test public void getIssueCategories() throws Exception { - - askData(ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME, projectName); + RedmineRequest<IssueCategory> request = + RedmineRequestHelper.actionWithProject( + "get_issue_categories.xml", + IssueCategory.class, + projectName); + askDatas(request); } @Test public void getTrackers() throws Exception { - - askData(ModelHelper.GET_ALL_TRACKER_REQUEST_NAME, projectName); + RedmineRequest<Tracker> request = + RedmineRequestHelper.actionWithProject("get_project_trackers.xml", + Tracker.class, + projectName); + askDatas(request); } @Test public void getNews() throws Exception { - - askData(ModelHelper.GET_ALL_NEWS_REQUEST_NAME, projectName); + RedmineRequest<News> request = + RedmineRequestHelper.actionWithProject("get_project_news.xml", + News.class, + projectName); + askDatas(request); } @Test public void getProjectMembers() throws Exception { - - askData(ModelHelper.GET_ALL_USER_REQUEST_NAME, projectName); + RedmineRequest<User> request = + RedmineRequestHelper.actionWithProject("get_project_users.xml", + User.class, + projectName); + askDatas(request); } @Test public void getProjectIssues() throws Exception { - - askData(ModelHelper.GET_ALL_PROJECT_ISSUES_REQUEST_NAME, projectName); + RedmineRequest<Issue> request = + RedmineRequestHelper.actionWithProjectAndVersion("get_version_issues.xml", + Issue.class, + projectName, + versionName); + askDatas(request); } @Test public void getVersions() throws Exception { - - askData(ModelHelper.GET_ALL_VERSION_REQUEST_NAME, projectName); + RedmineRequest<Version> request = + RedmineRequestHelper.actionWithProject("get_project_versions.xml", + Version.class, + projectName); + askDatas(request); } @Test public void getVersion() throws Exception { - - askData(ModelHelper.GET_VERSION_REQUEST_NAME, projectName, versionName); + RedmineRequest<Version> request = + RedmineRequestHelper.actionWithProjectAndVersion("get_version.xml", + Version.class, + projectName, + versionName); + askData(request); } @Test public void getVersionIssues() throws Exception { - - askData(ModelHelper.GET_ALL_ISSUES_REQUEST_NAME, projectName, versionName); + RedmineRequest<Issue> request = + RedmineRequestHelper.actionWithProjectAndVersion("get_version_issues.xml", + Issue.class, + projectName, + versionName); + askDatas(request); } @Test public void getOpenedIssues() throws Exception { - - askData(ModelHelper.GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME, projectName); + RedmineRequest<Issue> request = + RedmineRequestHelper.actionWithProject("get_project_opened_issues.xml", + Issue.class, + projectName); + askDatas(request); } @Test public void getClosedIssues() throws Exception { - - askData(ModelHelper.GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME, projectName); + RedmineRequest<Issue> request = + RedmineRequestHelper.actionWithProject("get_project_closed_issues.xml", + Issue.class, + projectName); + askDatas(request); } @Test public void getIssueTimeEntries() throws Exception { - - askData(ModelHelper.GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME, projectName, issueId); + RedmineRequest<TimeEntry> request = + RedmineRequestHelper.actionWithProjectAndIssue("get_issue_times.xml", + TimeEntry.class, + projectName, + issueId); + askDatas(request); } @Test public void getAttachments() throws Exception { - - askData(ModelHelper.GET_ALL_ATTACHMENTS_REQUEST_NAME, projectName, versionName); + RedmineRequest<Attachment> request = RedmineRequestHelper.actionWithProjectAndVersion( + "get_version_attachments.xml", Attachment.class, projectName, versionName); + askDatas(request); } @Test @@ -218,7 +272,9 @@ public void getUserProjects() throws Exception { Assume.assumeTrue(!getConfiguration().isAnonymous()); - askData(ModelHelper.GET_USER_PROJECTS_REQUEST_NAME); + RedmineRequest<Project> request = RedmineRequestHelper.action( + "get_user_projects.xml", Project.class); + askDatas(request); } @Test @@ -257,18 +313,30 @@ //TODO } - protected void askData(String requestId, Object... params) throws Exception { + protected <T> void askData(RedmineRequest<T> request) throws Exception { + T askData = client.executeRequest(request); + if (getConfiguration().isVerbose() && log.isInfoEnabled()) { + String toString; + if (askData == null) { + toString = "Return is null!"; + } else { + toString = askData.toString(); + } + log.info(toString); + } + } - RestRequest request = client.getRequest(requestId, params); - InputStream askData = client.executeRequest(request); - try { - String toString = IOUtil.toString(askData); - if (getConfiguration().isVerbose() && log.isInfoEnabled()) { - log.info(toString); + protected <T> void askDatas(RedmineRequest<T> request) throws Exception { + + T[] askData = client.executeRequests(request); + if (getConfiguration().isVerbose() && log.isInfoEnabled()) { + String toString; + if (askData == null) { + toString = "Return is null!"; + } else { + toString = Arrays.toString((Object[]) askData); } - askData.close(); - } finally { - IOUtil.close(askData); + log.info(toString); } } Deleted: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -1,244 +0,0 @@ -package org.nuiton.jredmine.client; -/* - * #%L - * JRedmine :: Client - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.nuiton.io.rest.RequestFactory; -import org.nuiton.io.rest.RestRequest; -import org.nuiton.jredmine.RedmineFixtures; -import org.nuiton.jredmine.model.Attachment; -import org.nuiton.jredmine.model.ModelHelper; -import org.nuiton.jredmine.model.News; -import org.nuiton.jredmine.model.TimeEntry; -import org.nuiton.jredmine.model.Version; -import org.nuiton.jredmine.client.RedmineRequestFactory; - -import java.util.Arrays; - -/** - * Tests the {@link RedmineRequestFactory}. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class RedmineRequestFactoryTest { - - protected static final RedmineFixtures fixtures = new RedmineFixtures(); - - protected RequestFactory factory; - - protected String projectName; - - protected String versionName; - - protected String issueId; - - @Before - public void setUp() throws Exception { - factory = new RedmineRequestFactory(); - - factory.addDefaultRequests(); - - projectName = fixtures.projectName(); - versionName = fixtures.versionName(); - issueId = fixtures.issueId(); - } - - @Test - public void login() { - assertRequestParameters( - assertRequestUrl("/jredmine/login", ModelHelper.LOGIN_REQUEST_NAME, "redmineuser", "redminepassword"), - "username", "redmineuser", "password", "redminepassword"); - } - - @Test - public void loginByApiKey() { - assertRequestParameters(assertRequestUrl("/jredmine/login", ModelHelper.LOGIN_BY_API_KEY_REQUEST_NAME, "apiKey")); - } - - @Test - public void logout() { - assertRequestParameters(assertRequestUrl("/jredmine/logout", ModelHelper.LOGOUT_REQUEST_NAME)); - } - - @Test - public void ping() { - assertRequestParameters(assertRequestUrl("/jredmine/ping", ModelHelper.PING_REQUEST_NAME)); - } - - @Test - public void getAllProjects() { - assertRequestParameters(assertRequestUrl("/jredmine/get_projects.xml", ModelHelper.GET_ALL_PROJECT_REQUEST_NAME)); - } - - @Test - public void getAllIssueStatuses() { - assertRequestParameters(assertRequestUrl("/jredmine/get_issue_statuses.xml", ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME)); - } - - @Test - public void getAllIssuePriorities() { - assertRequestParameters(assertRequestUrl("/jredmine/get_issue_priorities.xml", ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME)); - } - - @Test - public void getProject() { - assertRequestParameters(assertRequestUrl("/jredmine/get_project.xml/" + projectName, ModelHelper.GET_PROJECT_REQUEST_NAME, projectName)); - } - - @Test - public void getAllIssues() { - assertRequestParameters(assertRequestUrl("/jredmine/get_project_issues.xml/" + projectName, ModelHelper.GET_ALL_PROJECT_ISSUES_REQUEST_NAME, projectName)); - } - - @Test - public void getAllOpenedIssues() { - assertRequestParameters(assertRequestUrl("/jredmine/get_project_opened_issues.xml/" + projectName, ModelHelper.GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME, projectName)); - } - - @Test - public void getAllClosesIssues() { - assertRequestParameters(assertRequestUrl("/jredmine/get_project_closed_issues.xml/" + projectName, ModelHelper.GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME, projectName)); - } - - @Test - public void getAllVersions() { - assertRequestParameters(assertRequestUrl("/jredmine/get_project_versions.xml/" + projectName, ModelHelper.GET_ALL_VERSION_REQUEST_NAME, projectName)); - } - - @Test - public void getAllIssueCategories() { - assertRequestParameters(assertRequestUrl("/jredmine/get_issue_categories.xml/" + projectName, ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME, projectName)); - } - - @Test - public void getAllTrackers() { - assertRequestParameters(assertRequestUrl("/jredmine/get_project_trackers.xml/" + projectName, ModelHelper.GET_ALL_TRACKER_REQUEST_NAME, projectName)); - } - - @Test - public void getAllUsers() { - assertRequestParameters(assertRequestUrl("/jredmine/get_project_users.xml/" + projectName, ModelHelper.GET_ALL_USER_REQUEST_NAME, projectName)); - } - - @Test - public void getAllNews() { - assertRequestParameters(assertRequestUrl("/jredmine/get_project_news.xml/" + projectName, ModelHelper.GET_ALL_NEWS_REQUEST_NAME, projectName)); - } - - @Test - public void addVersion() { - Version version = fixtures.versionToAdd(); - assertRequestParameters(assertRequestUrl("/jredmine/add_version.xml/" + projectName, ModelHelper.ADD_VERSION_REQUEST_NAME, projectName, version), - "version[name]", "1.3_" + RedmineFixtures.TIMESTAMP, "version[description]", "Version to add", "version[effective_date]", "", "version[status]", "open"); - } - - @Test - public void updateVersion() { - Version version = fixtures.versionToUpdate(); - assertRequestParameters(assertRequestUrl("/jredmine/update_version.xml/" + projectName, ModelHelper.UPDATE_VERSION_REQUEST_NAME, projectName, version), - "version[name]", "1.3", "version[description]", "Version to update", "version[effective_date]", "", "version[status]", "open"); - } - - @Test - public void nextVersion() { - Version version = fixtures.versionToUpdate(); - String oldVersionName = fixtures.oldVersionName(); - assertRequestParameters(assertRequestUrl("/jredmine/next_version.xml/" + projectName, ModelHelper.NEXT_VERSION_REQUEST_NAME, projectName, version, oldVersionName), - "oldVersionName", oldVersionName, "version[name]", "1.3", "version[description]", "Version to update", "version[effective_date]", "", "version[status]", "open"); - } - - @Test - public void addNews() { - News newsToAdd = fixtures.newsToAdd(); - assertRequestParameters(assertRequestUrl("/jredmine/add_news.xml/" + projectName, ModelHelper.ADD_NEWS_REQUEST_NAME, projectName, newsToAdd), - "news[title]", newsToAdd.getTitle(), - "news[summary]", newsToAdd.getSummary(), - "news[description]", newsToAdd.getDescription()); - } - - @Test - public void getVersion() { - assertRequestParameters(assertRequestUrl("/jredmine/get_version.xml/" + projectName, ModelHelper.GET_VERSION_REQUEST_NAME, projectName, versionName), - "version_name", versionName); - } - - @Test - public void getAllVersionIssues() { - assertRequestParameters(assertRequestUrl("/jredmine/get_version_issues.xml/" + projectName, ModelHelper.GET_ALL_ISSUES_REQUEST_NAME, projectName, versionName), - "version_name", versionName); - } - - @Test - public void getAllAttachments() { - assertRequestParameters(assertRequestUrl("/jredmine/get_version_attachments.xml/" + projectName, ModelHelper.GET_ALL_ATTACHMENTS_REQUEST_NAME, projectName, versionName), - "version_name", versionName); - } - - @Test - public void addAttachment() { - Attachment attachment = fixtures.attachmentToAdd(); - - assertRequestParameters(assertRequestUrl("/jredmine/add_version_attachment.xml/" + projectName, ModelHelper.ADD_ATTACHMENT_REQUEST_NAME, projectName, versionName, attachment), - "version_name", versionName, - "attachment[description]", attachment.getDescription()); - } - - @Test - public void getAllIssueTimeEntires() { - assertRequestParameters(assertRequestUrl("/jredmine/get_issue_times.xml/" + projectName, ModelHelper.GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME, projectName, issueId), - "issue_id", issueId); - } - - @Test - public void addIssueTimeEntry() { - TimeEntry timeEntry = fixtures.timeEntryToAdd(); - assertRequestParameters(assertRequestUrl("/jredmine/add_issue_time.xml/" + projectName, ModelHelper.ADD_ISSUE_TIME_ENTRY_REQUEST_NAME, projectName, issueId, timeEntry), - "issue_id", issueId, - "time_entry[activity_id]", timeEntry.getActivityId() + "", - "time_entry[spent_on]", "2012-07-15", - "time_entry[hours]", timeEntry.getHours() + "", - "time_entry[comments]", timeEntry.getComments()); - } - - protected RestRequest assertRequestUrl(String expectedUrl, - String requestId, - Object... args) { - - RestRequest request = factory.getRequest(requestId, args); - - Assert.assertNotNull(request); - String actual = request.toPath(""); - Assert.assertEquals(expectedUrl, actual); - return request; - } - - protected void assertRequestParameters(RestRequest request, - String... expectedParams) { - String[] actual = request.getParameters(); - Assert.assertArrayEquals("Expected:" + Arrays.toString(expectedParams) + " but was:" + Arrays.toString(actual), expectedParams, actual); - } -} Copied: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineAnonymousServiceTest.java (from rev 366, trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineAnonymousServiceTest.java) =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineAnonymousServiceTest.java (rev 0) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineAnonymousServiceTest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,181 @@ +package org.nuiton.jredmine.service; +/* + * #%L + * JRedmine :: Client + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.jredmine.RedmineFixtures; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.test.RedmineAnonymousFixtureClassRule; +import org.nuiton.jredmine.test.RedmineServer; + +/** + * Tests the {@link RedmineAnonymousService} service. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class RedmineAnonymousServiceTest { + + @ClassRule + public static final RedmineAnonymousFixtureClassRule<RedmineFixtures> classRule = + RedmineAnonymousFixtureClassRule.newFixtures(RedmineFixtures.class); + + @Rule + public final RedmineServer<RedmineAnonymousService, RedmineFixtures> server = + RedmineServer.newAnonymousServer(classRule); + + protected RedmineFixtures getFixtures() { + return server.getFixtures(); + } + + protected RedmineAnonymousService getService() { + return server.getService(); + } + + @Test + public void getProjects() throws Exception { + Project[] projects = getService().getProjects(); + Assert.assertNotNull(projects); + Assert.assertTrue(projects.length > 0); + } + + @Test + public void getProject() throws Exception { + Project project = getService().getProject(getFixtures().projectName()); + Assert.assertNotNull(project); + } + + @Test + public void getNews() throws Exception { + News[] news = getService().getNews(getFixtures().projectName()); + Assert.assertNotNull(news); + Assert.assertTrue(news.length > 0); + } + + @Test + public void getProjectIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getVersions() throws Exception { + Version[] versions = getService().getVersions(getFixtures().projectName()); + Assert.assertNotNull(versions); + Assert.assertTrue(versions.length > 0); + } + + @Test + public void getVersion() throws Exception { + Version version = getService().getVersion(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(version); + } + + @Test + public void getIssueCategories() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + IssueCategory[] issueCategories = getService().getIssueCategories(getFixtures().projectName()); + Assert.assertNotNull(issueCategories); + Assert.assertTrue(issueCategories.length > 0); + } + + @Test + public void getProjectMembers() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + User[] users = getService().getProjectMembers(getFixtures().projectName()); + Assert.assertNotNull(users); + Assert.assertTrue(users.length > 0); + } + + @Test + public void getOpenedIssues() throws Exception { + Issue[] issues = getService().getOpenedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getClosedIssues() throws Exception { + Issue[] issues = getService().getClosedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getIssueTimeEntries() throws Exception { + TimeEntry[] timeEntries = getService().getIssueTimeEntries(getFixtures().projectName(), getFixtures().issueId()); + Assert.assertNotNull(timeEntries); + Assert.assertTrue(timeEntries.length > 0); + } + + @Test + public void getIssuePriorities() throws Exception { + IssuePriority[] issuePriorities = getService().getIssuePriorities(); + Assert.assertNotNull(issuePriorities); + Assert.assertTrue(issuePriorities.length > 0); + } + + @Test + public void getIssueStatuses() throws Exception { + IssueStatus[] issueStatuses = getService().getIssueStatuses(); + Assert.assertNotNull(issueStatuses); + Assert.assertTrue(issueStatuses.length > 0); + } + + @Test + public void getTrackers() throws Exception { + Tracker[] trackers = getService().getTrackers(getFixtures().projectName()); + Assert.assertNotNull(trackers); + Assert.assertTrue(trackers.length > 0); + } + + @Test + public void getVersionIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getAttachments() throws Exception { + Attachment[] attachments = getService().getAttachments(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(attachments); + Assert.assertTrue(attachments.length > 0); + } + +} \ No newline at end of file Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineAnonymousServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineServiceAsAnonymousTest.java (from rev 366, trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceAsAnonymousTest.java) =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineServiceAsAnonymousTest.java (rev 0) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineServiceAsAnonymousTest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,215 @@ +package org.nuiton.jredmine.service; +/* + * #%L + * JRedmine :: Client + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.jredmine.RedmineFixtures; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.test.RedmineAnonymousFixtureClassRule; +import org.nuiton.jredmine.test.RedmineServer; + +/** + * Tests the {@link RedmineService} service with anonymous configuration. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class RedmineServiceAsAnonymousTest { + + @ClassRule + public static final RedmineAnonymousFixtureClassRule<RedmineFixtures> classRule = + RedmineAnonymousFixtureClassRule.newFixtures(RedmineFixtures.class); + + @Rule + public final RedmineServer<RedmineService, RedmineFixtures> server = + RedmineServer.newLogguedServerAsAnonymous(classRule); + + protected RedmineFixtures getFixtures() { + return server.getFixtures(); + } + + protected RedmineService getService() { + return server.getService(); + } + + @Test + public void getProjects() throws Exception { + Project[] projects = getService().getProjects(); + Assert.assertNotNull(projects); + Assert.assertTrue(projects.length > 0); + } + + @Test + public void getProject() throws Exception { + Project project = getService().getProject(getFixtures().projectName()); + Assert.assertNotNull(project); + } + + @Test + public void getNews() throws Exception { + News[] news = getService().getNews(getFixtures().projectName()); + Assert.assertNotNull(news); + Assert.assertTrue(news.length > 0); + } + + @Test + public void getProjectIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getVersions() throws Exception { + Version[] versions = getService().getVersions(getFixtures().projectName()); + Assert.assertNotNull(versions); + Assert.assertTrue(versions.length > 0); + } + + @Test + public void getVersion() throws Exception { + Version version = getService().getVersion(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(version); + } + + @Test + public void getIssueCategories() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + IssueCategory[] issueCategories = getService().getIssueCategories(getFixtures().projectName()); + Assert.assertNotNull(issueCategories); + Assert.assertTrue(issueCategories.length > 0); + } + + @Test + public void getProjectMembers() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + User[] users = getService().getProjectMembers(getFixtures().projectName()); + Assert.assertNotNull(users); + Assert.assertTrue(users.length > 0); + } + + @Test + public void getOpenedIssues() throws Exception { + Issue[] issues = getService().getOpenedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getClosedIssues() throws Exception { + Issue[] issues = getService().getClosedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getIssueTimeEntries() throws Exception { + TimeEntry[] timeEntries = getService().getIssueTimeEntries(getFixtures().projectName(), getFixtures().issueId()); + Assert.assertNotNull(timeEntries); + Assert.assertTrue(timeEntries.length > 0); + } + + @Test + public void getIssuePriorities() throws Exception { + IssuePriority[] issuePriorities = getService().getIssuePriorities(); + Assert.assertNotNull(issuePriorities); + Assert.assertTrue(issuePriorities.length > 0); + } + + @Test + public void getIssueStatuses() throws Exception { + IssueStatus[] issueStatuses = getService().getIssueStatuses(); + Assert.assertNotNull(issueStatuses); + Assert.assertTrue(issueStatuses.length > 0); + } + + @Test + public void getTrackers() throws Exception { + Tracker[] trackers = getService().getTrackers(getFixtures().projectName()); + Assert.assertNotNull(trackers); + Assert.assertTrue(trackers.length > 0); + } + + @Test + public void getVersionIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getAttachments() throws Exception { + Attachment[] attachments = getService().getAttachments(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(attachments); + Assert.assertTrue(attachments.length > 0); + } + + @Test(expected = RedmineServiceLoginException.class) + public void getUserProjects() throws Exception { + getService().getUserProjects(); + } + + @Test(expected = RedmineServiceLoginException.class) + public void addVersion() throws Exception { + getService().addVersion(getFixtures().projectName(), new Version()); + } + + @Test(expected = RedmineServiceLoginException.class) + public void addAttachment() throws Exception { + getService().addAttachment(getFixtures().projectName(), getFixtures().versionName(), new Attachment()); + } + + @Test(expected = RedmineServiceLoginException.class) + public void addNews() throws Exception { + getService().addNews(getFixtures().projectName(), new News()); + } + + @Test(expected = RedmineServiceLoginException.class) + public void updateVersion() throws Exception { + getService().updateVersion(getFixtures().projectName(), new Version()); + } + + @Test(expected = RedmineServiceLoginException.class) + public void nextVersion() throws Exception { + getService().nextVersion(getFixtures().projectName(), getFixtures().versionName(), new Version()); + } + + @Test(expected = RedmineServiceLoginException.class) + public void addIssueTime() throws Exception { + getService().addIssueTimeEntry(getFixtures().projectName(), getFixtures().issueId(), new TimeEntry()); + } +} Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineServiceAsAnonymousTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineServiceTest.java (from rev 366, trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineServiceTest.java) =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineServiceTest.java (rev 0) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineServiceTest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -0,0 +1,224 @@ +package org.nuiton.jredmine.service; +/* + * #%L + * JRedmine :: Client + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.nuiton.jredmine.RedmineFixtures; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.Issue; +import org.nuiton.jredmine.model.IssueCategory; +import org.nuiton.jredmine.model.IssuePriority; +import org.nuiton.jredmine.model.IssueStatus; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.Project; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Tracker; +import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.test.RedmineFixtureClassRule; +import org.nuiton.jredmine.test.RedmineServer; + +/** + * Tests the {@link RedmineService} service with loggued configuration. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class RedmineServiceTest { + + @ClassRule + public static final RedmineFixtureClassRule<RedmineFixtures> classRule = + RedmineFixtureClassRule.newFixtures(RedmineFixtures.class); + + @Rule + public final RedmineServer<RedmineService, RedmineFixtures> server = + RedmineServer.newLogguedServer(classRule); + + protected RedmineFixtures getFixtures() { + return server.getFixtures(); + } + + protected RedmineService getService() { + return server.getService(); + } + + @Test + public void getProjects() throws Exception { + Project[] projects = getService().getProjects(); + Assert.assertNotNull(projects); + Assert.assertTrue(projects.length > 0); + } + + @Test + public void getProject() throws Exception { + Project project = getService().getProject(getFixtures().projectName()); + Assert.assertNotNull(project); + } + + @Test + public void getNews() throws Exception { + News[] news = getService().getNews(getFixtures().projectName()); + Assert.assertNotNull(news); + Assert.assertTrue(news.length > 0); + } + + @Test + public void getProjectIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getVersions() throws Exception { + Version[] versions = getService().getVersions(getFixtures().projectName()); + Assert.assertNotNull(versions); + Assert.assertTrue(versions.length > 0); + } + + @Test + public void getVersion() throws Exception { + Version version = getService().getVersion(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(version); + } + + @Test + public void getIssueCategories() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + IssueCategory[] issueCategories = getService().getIssueCategories(getFixtures().projectName()); + Assert.assertNotNull(issueCategories); + Assert.assertTrue(issueCategories.length > 0); + } + + @Test + public void getProjectMembers() throws Exception { + // Need to be loggued ? don't know why :( Need to report a bug + User[] users = getService().getProjectMembers(getFixtures().projectName()); + Assert.assertNotNull(users); + Assert.assertTrue(users.length > 0); + } + + @Test + public void getOpenedIssues() throws Exception { + Issue[] issues = getService().getOpenedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getClosedIssues() throws Exception { + Issue[] issues = getService().getClosedIssues(getFixtures().projectName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getIssueTimeEntries() throws Exception { + TimeEntry[] timeEntries = getService().getIssueTimeEntries(getFixtures().projectName(), getFixtures().issueId()); + Assert.assertNotNull(timeEntries); + Assert.assertTrue(timeEntries.length > 0); + } + + @Test + public void getIssuePriorities() throws Exception { + IssuePriority[] issuePriorities = getService().getIssuePriorities(); + Assert.assertNotNull(issuePriorities); + Assert.assertTrue(issuePriorities.length > 0); + } + + @Test + public void getIssueStatuses() throws Exception { + IssueStatus[] issueStatuses = getService().getIssueStatuses(); + Assert.assertNotNull(issueStatuses); + Assert.assertTrue(issueStatuses.length > 0); + } + + @Test + public void getTrackers() throws Exception { + Tracker[] trackers = getService().getTrackers(getFixtures().projectName()); + Assert.assertNotNull(trackers); + Assert.assertTrue(trackers.length > 0); + } + + @Test + public void getVersionIssues() throws Exception { + Issue[] issues = getService().getIssues(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(issues); + Assert.assertTrue(issues.length > 0); + } + + @Test + public void getAttachments() throws Exception { + Attachment[] attachments = getService().getAttachments(getFixtures().projectName(), getFixtures().versionName()); + Assert.assertNotNull(attachments); + Assert.assertTrue(attachments.length > 0); + } + + @Ignore + @Test + public void addVersion() throws Exception { + getService().addVersion(getFixtures().projectName(), getFixtures().versionToAdd()); + } + + @Ignore + @Test + public void addAttachment() throws Exception { + Version version = getFixtures().versionToUpdate(); + Attachment attachment = getFixtures().attachmentToAdd(); + Attachment updatedAttachment = getService().addAttachment( + getFixtures().projectName(), + version.getName(), + attachment + ); + Assert.assertNotNull(updatedAttachment); + } + + @Ignore + @Test + public void addNews() throws Exception { + getService().addNews(getFixtures().projectName(), getFixtures().newsToAdd()); + } + + @Ignore + @Test + public void updateVersion() throws Exception { + getService().updateVersion(getFixtures().projectName(), getFixtures().versionToUpdate()); + } + + @Ignore + @Test + public void nextVersion() throws Exception { + getService().nextVersion(getFixtures().projectName(), getFixtures().versionName(), getFixtures().versionToUpdate()); + } + + @Ignore + @Test + public void addIssueTime() throws Exception { + getService().addIssueTimeEntry(getFixtures().projectName(), getFixtures().issueId(), getFixtures().timeEntryToAdd()); + } +} Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/service/RedmineServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/AbstractRedmineFixtures.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/AbstractRedmineFixtures.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/AbstractRedmineFixtures.java 2012-10-16 20:18:19 UTC (rev 367) @@ -23,13 +23,13 @@ * #L% */ -import org.nuiton.jredmine.DefaultRedmineAnonymousService; -import org.nuiton.jredmine.DefaultRedmineService; -import org.nuiton.jredmine.RedmineAnonymousService; -import org.nuiton.jredmine.RedmineConfigurationUtil; -import org.nuiton.jredmine.RedmineService; -import org.nuiton.jredmine.RedmineServiceConfiguration; -import org.nuiton.jredmine.RedmineServiceException; +import org.nuiton.jredmine.service.DefaultRedmineAnonymousService; +import org.nuiton.jredmine.service.DefaultRedmineService; +import org.nuiton.jredmine.service.RedmineAnonymousService; +import org.nuiton.jredmine.service.RedmineConfigurationUtil; +import org.nuiton.jredmine.service.RedmineService; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; +import org.nuiton.jredmine.service.RedmineServiceException; import java.io.IOException; Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineAnonymousFixtureClassRule.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineAnonymousFixtureClassRule.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineAnonymousFixtureClassRule.java 2012-10-16 20:18:19 UTC (rev 367) @@ -29,7 +29,7 @@ import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; -import org.nuiton.jredmine.RedmineServiceConfiguration; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; import java.io.IOException; Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineFixtureClassRule.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineFixtureClassRule.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineFixtureClassRule.java 2012-10-16 20:18:19 UTC (rev 367) @@ -29,7 +29,7 @@ import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; -import org.nuiton.jredmine.RedmineServiceConfiguration; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; import java.io.IOException; Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineServer.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineServer.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/RedmineServer.java 2012-10-16 20:18:19 UTC (rev 367) @@ -25,10 +25,10 @@ import org.junit.rules.TestWatcher; import org.junit.runner.Description; -import org.nuiton.jredmine.RedmineAnonymousService; -import org.nuiton.jredmine.RedmineService; -import org.nuiton.jredmine.RedmineServiceConfiguration; -import org.nuiton.jredmine.RedmineServiceException; +import org.nuiton.jredmine.service.RedmineAnonymousService; +import org.nuiton.jredmine.service.RedmineService; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; +import org.nuiton.jredmine.service.RedmineServiceException; import java.io.IOException; Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineAnonymousServiceTCK.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineAnonymousServiceTCK.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineAnonymousServiceTCK.java 2012-10-16 20:18:19 UTC (rev 367) @@ -27,7 +27,6 @@ import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.nuiton.jredmine.RedmineAnonymousService; import org.nuiton.jredmine.model.Attachment; import org.nuiton.jredmine.model.Issue; import org.nuiton.jredmine.model.IssueCategory; @@ -39,6 +38,7 @@ import org.nuiton.jredmine.model.Tracker; import org.nuiton.jredmine.model.User; import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.service.RedmineAnonymousService; import org.nuiton.jredmine.test.RedmineAnonymousFixtureClassRule; import org.nuiton.jredmine.test.RedmineServer; Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineServiceAsAnonymousTCK.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineServiceAsAnonymousTCK.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineServiceAsAnonymousTCK.java 2012-10-16 20:18:19 UTC (rev 367) @@ -27,8 +27,6 @@ import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; -import org.nuiton.jredmine.RedmineService; -import org.nuiton.jredmine.RedmineServiceLoginException; import org.nuiton.jredmine.model.Attachment; import org.nuiton.jredmine.model.Issue; import org.nuiton.jredmine.model.IssueCategory; @@ -40,6 +38,8 @@ import org.nuiton.jredmine.model.Tracker; import org.nuiton.jredmine.model.User; import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.service.RedmineService; +import org.nuiton.jredmine.service.RedmineServiceLoginException; import org.nuiton.jredmine.test.RedmineAnonymousFixtureClassRule; import org.nuiton.jredmine.test.RedmineServer; Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineServiceTCK.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineServiceTCK.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/test/tck/RedmineServiceTCK.java 2012-10-16 20:18:19 UTC (rev 367) @@ -28,7 +28,6 @@ import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; -import org.nuiton.jredmine.RedmineService; import org.nuiton.jredmine.model.Attachment; import org.nuiton.jredmine.model.Issue; import org.nuiton.jredmine.model.IssueCategory; @@ -40,6 +39,7 @@ import org.nuiton.jredmine.model.Tracker; import org.nuiton.jredmine.model.User; import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.service.RedmineService; import org.nuiton.jredmine.test.RedmineFixtureClassRule; import org.nuiton.jredmine.test.RedmineServer; Modified: trunk/jredmine-maven-plugin/pom.xml =================================================================== --- trunk/jredmine-maven-plugin/pom.xml 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/pom.xml 2012-10-16 20:18:19 UTC (rev 367) @@ -64,11 +64,6 @@ </dependency> <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - </dependency> - - <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java 2012-10-16 20:18:19 UTC (rev 367) @@ -30,9 +30,9 @@ import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import org.nuiton.jredmine.RedmineService; -import org.nuiton.jredmine.RedmineServiceConfiguration; import org.nuiton.jredmine.client.RedmineClientAuthConfiguration; +import org.nuiton.jredmine.service.RedmineService; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; import org.nuiton.plugin.AbstractPlugin; import java.net.URL; Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoWithProject.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoWithProject.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoWithProject.java 2012-10-16 20:18:19 UTC (rev 367) @@ -26,10 +26,10 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.plexus.util.StringUtils; -import org.nuiton.jredmine.RedmineServiceException; import org.nuiton.jredmine.model.ModelHelper; import org.nuiton.jredmine.model.Project; import org.nuiton.jredmine.model.User; +import org.nuiton.jredmine.service.RedmineServiceException; /** * Abstract redmine mojo whihc need a redmine project context. Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoWithProjectAndVersion.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoWithProjectAndVersion.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoWithProjectAndVersion.java 2012-10-16 20:18:19 UTC (rev 367) @@ -26,9 +26,9 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.plexus.util.StringUtils; -import org.nuiton.jredmine.RedmineServiceException; import org.nuiton.jredmine.model.ModelHelper; import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.service.RedmineServiceException; /** * Abstract redmine mojo which needs a redmine project and version context. Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/DisplayDataMojo.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/DisplayDataMojo.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/DisplayDataMojo.java 2012-10-16 20:18:19 UTC (rev 367) @@ -29,9 +29,8 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import org.nuiton.io.rest.RequestFactory; -import org.nuiton.io.rest.RestRequestBuilder; -import org.nuiton.jredmine.RedmineServiceImplementor; +import org.nuiton.jredmine.client.RedmineRequest; +import org.nuiton.jredmine.client.RedmineRequestHelper; import org.nuiton.jredmine.model.I18nAble; import org.nuiton.jredmine.model.IdAble; import org.nuiton.jredmine.model.Issue; @@ -44,9 +43,10 @@ import org.nuiton.jredmine.model.Tracker; import org.nuiton.jredmine.model.User; import org.nuiton.jredmine.model.Version; -import org.nuiton.jredmine.client.RedmineRequestFactory; +import org.nuiton.jredmine.service.AbstractRedmineService; import org.nuiton.plugin.PluginHelper; +import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -128,24 +128,29 @@ /////////////////////////////////////////////////////////////////////////// /** list of actions to perform */ - protected Map<String, Class<?>> actions; + protected List<String> actions; - private final Map<Class<?>, String> typesToRequestName; + private final Map<String, Class<? extends IdAble>> namesToType; - private final Map<String, Class<?>> namesToType; + private final Map<String, DataScope> namestoScope; + private enum DataScope {NONE, PROJECT, VERSION} + public DisplayDataMojo() { - typesToRequestName = Maps.newHashMap(); - typesToRequestName.put(Project.class, ModelHelper.GET_ALL_PROJECT_REQUEST_NAME); - typesToRequestName.put(Version.class, ModelHelper.GET_ALL_VERSION_REQUEST_NAME); - typesToRequestName.put(Issue.class, ModelHelper.GET_ALL_ISSUES_REQUEST_NAME); - typesToRequestName.put(News.class, ModelHelper.GET_ALL_NEWS_REQUEST_NAME); - typesToRequestName.put(IssueStatus.class, ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME); - typesToRequestName.put(IssuePriority.class, ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME); - typesToRequestName.put(IssueCategory.class, ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME); - typesToRequestName.put(Tracker.class, ModelHelper.GET_ALL_TRACKER_REQUEST_NAME); - typesToRequestName.put(User.class, ModelHelper.GET_ALL_USER_REQUEST_NAME); + namestoScope = Maps.newHashMap(); + + namestoScope.put("project", DataScope.NONE); + namestoScope.put("version", DataScope.PROJECT); + namestoScope.put("issue", DataScope.VERSION); + namestoScope.put("news", DataScope.PROJECT); + namestoScope.put("issuestatus", DataScope.NONE); + namestoScope.put("issuepriority", DataScope.NONE); + namestoScope.put("issuecategory", DataScope.PROJECT); + namestoScope.put("tracker", DataScope.PROJECT); + namestoScope.put("user", DataScope.PROJECT); + + namesToType = Maps.newHashMap(); namesToType.put("project", Project.class); namesToType.put("version", Version.class); @@ -255,34 +260,33 @@ protected void doAction() throws Exception { StringBuilder buffer = new StringBuilder("\n"); - for (Map.Entry<String, Class<?>> entry : actions.entrySet()) { + for (String dataTypeName : actions) { - Class<?> type = entry.getValue(); - String dataTypeName = entry.getKey(); - String scope = getDataScope(type); - String requestName = typesToRequestName.get(type); + DataScope scope = namestoScope.get(dataTypeName); IdAble[] datas; - RedmineServiceImplementor implementor = - service.getDelegateImplementor(); + if (DataScope.VERSION.equals(scope)) { - if (ModelHelper.VERSION_SCOPE.equals(scope)) { - datas = (IdAble[]) implementor.getDatas(requestName, type, projectId, versionId); - } else if (ModelHelper.PROJECT_SCOPE.equals(scope)) { - datas = (IdAble[]) implementor.getDatas(requestName, type, projectId); + datas = getDatasWithProjectAndVersion(dataTypeName); + + } else if (DataScope.PROJECT.equals(scope)) { + + datas = getDatasWithProject(dataTypeName); } else { - datas = (IdAble[]) implementor.getDatas(requestName, type); + + datas = getDatas(dataTypeName); } List<IdAble> list = Arrays.asList(datas); if (sortById) { Collections.sort(list, ModelHelper.ID_ABLE_COMPARATOR); } buffer.append("\nValues of '").append(dataTypeName).append('\''); - if (ModelHelper.VERSION_SCOPE.equals(scope) || ModelHelper.PROJECT_SCOPE.equals(scope)) { + if (DataScope.VERSION.equals(scope) || + DataScope.PROJECT.equals(scope)) { buffer.append(" for project '").append(projectId).append("'"); } - if (ModelHelper.VERSION_SCOPE.equals(scope)) { + if (DataScope.VERSION.equals(scope)) { buffer.append(" and version '").append(versionId).append("'"); } buffer.append('\n'); @@ -301,61 +305,95 @@ /// Others /////////////////////////////////////////////////////////////////////////// - protected Map<String, Class<?>> getDownloadActions() throws MojoFailureException { + protected List<String> getDownloadActions() throws MojoFailureException { - Map<String, Class<?>> results = Maps.newTreeMap(); + List<String> results = Lists.newArrayList(); - List<Class<?>> universeList = Lists.newArrayList(typesToRequestName.keySet()); + List<String> universeList = Lists.newArrayList(namestoScope.keySet()); for (String dataType : types.split(",")) { dataType = dataType.toLowerCase(Locale.ENGLISH); - Class<?> result = namesToType.get(dataType); - - if (result == null || !universeList.contains(result)) { + if (!universeList.contains(dataType)) { // can not accept these value throw new MojoFailureException( - "The data type '" + result + + "The data type '" + dataType + "' can not be used, Accepted types are : " + universeList); } - String scope = getDataScope(result); + DataScope scope = namestoScope.get(dataType); - if (ModelHelper.VERSION_SCOPE.equals(scope) || ModelHelper.PROJECT_SCOPE.equals(scope)) { + if (DataScope.VERSION.equals(scope) || + DataScope.PROJECT.equals(scope)) { // check projectId used if (projectId == null || projectId.isEmpty()) { throw new MojoFailureException( - "The data type '" + result + + "The data type '" + dataType + "', depends on a project, but the 'projectId' was " + "not filled."); } } - if (ModelHelper.VERSION_SCOPE.equals(scope)) { + if (DataScope.VERSION.equals(scope)) { + // check versionId use if (versionId == null || versionId.isEmpty()) { throw new MojoFailureException( - "The data type '" + result + + "The data type '" + dataType + "', depends on a version, but the 'versionId' was " + "not filled."); } } - results.put(dataType, result); + results.add(dataType); } return results; } - protected String getDataScope(Class<?> type) { + protected IdAble[] getDatas(String type) throws IOException { - RequestFactory requestFactory = - service.getDelegateImplementor().getClient().getRequestFactory(); + Class<? extends IdAble> dataType = namesToType.get(type); + RedmineRequest<? extends IdAble> request = RedmineRequest.get(dataType, "jredmine"); + if ("project".equals(type)) { + request.path("get_projects.xml"); + } else if ("issuestatus".equals(type)) { + request.path("get_issue_statuses.xml"); + } else if ("issuepriority".equals(type)) { + request.path("get_issue_priorities.xml"); + } + IdAble[] result = ((AbstractRedmineService) service).getClient().executeRequests(request); + return result; + } - String requestName = typesToRequestName.get(type); - RestRequestBuilder requestBuilder = - requestFactory.getRequestBuilder(requestName); + protected IdAble[] getDatasWithProject(String type) throws IOException { + Class<? extends IdAble> dataType = namesToType.get(type); + String action = null; + if ("version".equals(type)) { + action = "get_project_versions.xml"; + } else if ("news".equals(type)) { + action = "get_project_news.xml"; + } else if ("issuecategory".equals(type)) { + action = "get_issue_categories.xml"; + } else if ("tracker".equals(type)) { + action = "get_project_trackers.xml"; + } else if ("user".equals(type)) { + action = "get_project_users.xml"; + } + RedmineRequest<? extends IdAble> request = RedmineRequestHelper.actionWithProject(action, dataType, projectId); - return RedmineRequestFactory.getRequestScope(requestBuilder); + IdAble[] result = ((AbstractRedmineService) service).getClient().executeRequests(request); + return result; } + + protected IdAble[] getDatasWithProjectAndVersion(String type) throws IOException { + Class<? extends IdAble> dataType = namesToType.get(type); + String action = null; + if ("issue".equals(type)) { + action = "get_version_issues.xml"; + } + RedmineRequest<? extends IdAble> request = RedmineRequestHelper.actionWithProjectAndVersion(action, dataType, projectId, versionId); + IdAble[] result = ((AbstractRedmineService) service).getClient().executeRequests(request); + return result; + } } Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/GenerateChangesMojo.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/GenerateChangesMojo.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/GenerateChangesMojo.java 2012-10-16 20:18:19 UTC (rev 367) @@ -36,7 +36,6 @@ import org.apache.maven.plugins.changes.model.io.xpp3.ChangesXpp3Writer; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.XmlStreamWriter; -import org.nuiton.jredmine.RedmineServiceException; import org.nuiton.jredmine.model.Issue; import org.nuiton.jredmine.model.IssueCategory; import org.nuiton.jredmine.model.IssueStatus; @@ -44,6 +43,7 @@ import org.nuiton.jredmine.model.Tracker; import org.nuiton.jredmine.model.User; import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.service.RedmineServiceException; import org.nuiton.plugin.PluginHelper; import java.io.File; Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/IssuesCollector.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/IssuesCollector.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/IssuesCollector.java 2012-10-16 20:18:19 UTC (rev 367) @@ -25,8 +25,6 @@ package org.nuiton.jredmine.plugin; import org.apache.maven.plugin.logging.Log; -import org.nuiton.jredmine.RedmineService; -import org.nuiton.jredmine.RedmineServiceException; import org.nuiton.jredmine.model.Issue; import org.nuiton.jredmine.model.IssueCategory; import org.nuiton.jredmine.model.IssuePriority; @@ -34,6 +32,8 @@ import org.nuiton.jredmine.model.ModelHelper; import org.nuiton.jredmine.model.Tracker; import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.service.RedmineService; +import org.nuiton.jredmine.service.RedmineServiceException; import java.util.ArrayList; import java.util.Arrays; @@ -168,7 +168,7 @@ * clean all internal states. * <p/> * Note : this method is invoked at the begin of each - * {@link #collect(org.nuiton.jredmine.RedmineService, org.nuiton.jredmine.plugin.IssueCollectorConfiguration)} method. + * {@link #collect(RedmineService, org.nuiton.jredmine.plugin.IssueCollectorConfiguration)} method. */ public void clearFilters() { maxEntries = null; Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/LoginMojo.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/LoginMojo.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/LoginMojo.java 2012-10-16 20:18:19 UTC (rev 367) @@ -32,10 +32,9 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.settings.Settings; import org.nuiton.helper.plugin.ShareServerSecretPlugin; -import org.nuiton.jredmine.RedmineService; -import org.nuiton.jredmine.RedmineServiceConfiguration; -import org.nuiton.jredmine.RedmineServiceImplementor; import org.nuiton.jredmine.client.RedmineClientAuthConfiguration; +import org.nuiton.jredmine.service.RedmineService; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; import org.nuiton.plugin.AbstractPlugin; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; @@ -330,10 +329,10 @@ try { - ((RedmineServiceImplementor) service).init(this); - if (!((RedmineServiceImplementor) service).isInit()) { - throw new MojoExecutionException("could not logged to redmine server"); - } + service.init(this); +// if (!((RedmineServiceImplementor) service).isInit()) { +// throw new MojoExecutionException("could not logged to redmine server"); +// } } catch (Exception e) { if (safe) { @@ -352,15 +351,13 @@ @Override protected void afterExecute() { if (service != null) { - RedmineServiceImplementor i; - i = ((RedmineServiceImplementor) service); - if (i.isInit()) { + if (service.isInit()) { try { if (verbose) { getLog().info("<<< Close redmine rest client..."); } - i.destroy(); + service.destroy(); } catch (Exception ex) { getLog().error("could not close redmine client for reason " + ex.getMessage(), ex); } Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractIssuesReport.java =================================================================== --- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractIssuesReport.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractIssuesReport.java 2012-10-16 20:18:19 UTC (rev 367) @@ -25,10 +25,10 @@ package org.nuiton.jredmine.plugin.report; import org.apache.maven.reporting.MavenReportException; -import org.nuiton.jredmine.RedmineServiceException; import org.nuiton.jredmine.model.Issue; import org.nuiton.jredmine.plugin.IssueCollectorConfiguration; import org.nuiton.jredmine.plugin.IssuesCollector; +import org.nuiton.jredmine.service.RedmineServiceException; import org.nuiton.plugin.PluginHelper; import java.util.HashMap; Modified: trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineAnonymousFixtureClassRule.java =================================================================== --- trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineAnonymousFixtureClassRule.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineAnonymousFixtureClassRule.java 2012-10-16 20:18:19 UTC (rev 367) @@ -29,6 +29,7 @@ import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; import java.io.IOException; Modified: trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineFixtures.java =================================================================== --- trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineFixtures.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineFixtures.java 2012-10-16 20:18:19 UTC (rev 367) @@ -25,6 +25,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.jredmine.service.DefaultRedmineAnonymousService; +import org.nuiton.jredmine.service.DefaultRedmineService; +import org.nuiton.jredmine.service.RedmineAnonymousService; +import org.nuiton.jredmine.service.RedmineConfigurationUtil; +import org.nuiton.jredmine.service.RedmineService; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; +import org.nuiton.jredmine.service.RedmineServiceException; import java.io.IOException; Modified: trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineLogguedFixtureClassRule.java =================================================================== --- trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineLogguedFixtureClassRule.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/RedmineLogguedFixtureClassRule.java 2012-10-16 20:18:19 UTC (rev 367) @@ -29,6 +29,7 @@ import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; import java.io.IOException; Modified: trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractAnonymousRedmineMojoTest.java =================================================================== --- trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractAnonymousRedmineMojoTest.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractAnonymousRedmineMojoTest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -27,7 +27,7 @@ import org.junit.ClassRule; import org.nuiton.jredmine.RedmineAnonymousFixtureClassRule; import org.nuiton.jredmine.RedmineFixtures; -import org.nuiton.jredmine.RedmineServiceConfiguration; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; import java.io.IOException; Modified: trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractLogguedRedmineMojoTest.java =================================================================== --- trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractLogguedRedmineMojoTest.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractLogguedRedmineMojoTest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -27,7 +27,7 @@ import org.junit.ClassRule; import org.nuiton.jredmine.RedmineFixtures; import org.nuiton.jredmine.RedmineLogguedFixtureClassRule; -import org.nuiton.jredmine.RedmineServiceConfiguration; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; import java.io.IOException; Modified: trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoTest.java =================================================================== --- trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoTest.java 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoTest.java 2012-10-16 20:18:19 UTC (rev 367) @@ -30,9 +30,9 @@ import org.codehaus.plexus.util.StringUtils; import org.junit.After; import org.junit.Assert; -import org.nuiton.jredmine.RedmineConfigurationUtil; +import org.nuiton.jredmine.service.RedmineConfigurationUtil; import org.nuiton.jredmine.RedmineFixtures; -import org.nuiton.jredmine.RedmineServiceConfiguration; +import org.nuiton.jredmine.service.RedmineServiceConfiguration; import org.nuiton.jredmine.client.RedmineClientAuthConfiguration; import org.nuiton.plugin.AbstractMojoTest; Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-10-14 09:24:18 UTC (rev 366) +++ trunk/pom.xml 2012-10-16 20:18:19 UTC (rev 367) @@ -60,7 +60,10 @@ <!-- must be on a fixed version, not on the snapshot to make possible release --> <jredminePluginVersion>1.4</jredminePluginVersion> + + <!-- remoe this with mavenpom 3.4.1 --> <helperPluginVersion>1.6-SNAPSHOT</helperPluginVersion> + <httpCommonsHttpclientVersion>4.2.1</httpCommonsHttpclientVersion> <doxiaVersion>1.3</doxiaVersion> @@ -95,8 +98,14 @@ <dependency> <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpcore</artifactId> + <version>${httpCommonsHttpclientVersion}</version> + </dependency> + + <dependency> + <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> - <version>4.2.1</version> + <version>${httpCommonsHttpclientVersion}</version> <exclusions> <exclusion> <groupId>commons-codec</groupId> @@ -108,9 +117,10 @@ <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> - <version>4.2.1</version> + <version>${httpCommonsHttpclientVersion}</version> </dependency> + <dependency> <groupId>org.nuiton</groupId> <artifactId>helper-maven-plugin</artifactId>