Jredmine-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
October 2012
- 2 participants
- 66 discussions
r372 - trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin
by tchemit@users.nuiton.org 16 Oct '12
by tchemit@users.nuiton.org 16 Oct '12
16 Oct '12
Author: tchemit
Date: 2012-10-17 01:24:12 +0200 (Wed, 17 Oct 2012)
New Revision: 372
Url: http://nuiton.org/repositories/revision/jredmine/372
Log:
use new apis
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/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/NextVersionMojo.java
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-16 23:21:58 UTC (rev 371)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoWithProject.java 2012-10-16 23:24:12 UTC (rev 372)
@@ -26,7 +26,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.util.StringUtils;
-import org.nuiton.jredmine.model.ModelHelper;
import org.nuiton.jredmine.model.Project;
import org.nuiton.jredmine.model.User;
import org.nuiton.jredmine.service.RedmineServiceException;
@@ -176,7 +175,7 @@
try {
users = service.getProjectMembers(projectId);
- User user = ModelHelper.byLogin(username, users);
+ User user = User.byLogin(username, users);
if (user == null) {
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-16 23:21:58 UTC (rev 371)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoWithProjectAndVersion.java 2012-10-16 23:24:12 UTC (rev 372)
@@ -26,7 +26,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.util.StringUtils;
-import org.nuiton.jredmine.model.ModelHelper;
import org.nuiton.jredmine.model.Version;
import org.nuiton.jredmine.service.RedmineServiceException;
@@ -149,7 +148,7 @@
}
protected Version getProjectVersion(String versionId) {
- Version v = ModelHelper.byVersionName(versionId, projectVersions);
+ Version v = Version.byVersionName(versionId, projectVersions);
return v;
}
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-16 23:21:58 UTC (rev 371)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/DisplayDataMojo.java 2012-10-16 23:24:12 UTC (rev 372)
@@ -33,11 +33,11 @@
import org.nuiton.jredmine.client.RedmineRequestHelper;
import org.nuiton.jredmine.model.I18nAble;
import org.nuiton.jredmine.model.IdAble;
+import org.nuiton.jredmine.model.IdAbles;
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.Tracker;
@@ -279,7 +279,7 @@
}
List<IdAble> list = Arrays.asList(datas);
if (sortById) {
- Collections.sort(list, ModelHelper.ID_ABLE_COMPARATOR);
+ Collections.sort(list, IdAbles.ID_ABLE_COMPARATOR);
}
buffer.append("\nValues of '").append(dataTypeName).append('\'');
if (DataScope.VERSION.equals(scope) ||
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-16 23:21:58 UTC (rev 371)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/GenerateChangesMojo.java 2012-10-16 23:24:12 UTC (rev 372)
@@ -36,10 +36,10 @@
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.model.IdAbles;
import org.nuiton.jredmine.model.Issue;
import org.nuiton.jredmine.model.IssueCategory;
import org.nuiton.jredmine.model.IssueStatus;
-import org.nuiton.jredmine.model.ModelHelper;
import org.nuiton.jredmine.model.Tracker;
import org.nuiton.jredmine.model.User;
import org.nuiton.jredmine.model.Version;
@@ -399,7 +399,7 @@
Integer id = Integer.valueOf(parts[1].trim());
- Tracker t = ModelHelper.byId(id, releaseTrackers);
+ Tracker t = IdAbles.byId(id, releaseTrackers);
if (t == null) {
throw new MojoExecutionException("could not obtain the tracker with id " + id);
@@ -417,7 +417,7 @@
for (String s : statusIds.split(",")) {
Integer id = Integer.valueOf(s.trim());
- IssueStatus t = ModelHelper.byId(id, statuses);
+ IssueStatus t = IdAbles.byId(id, statuses);
if (t == null) {
throw new MojoExecutionException("could not obtain the status with id " + id);
@@ -435,7 +435,7 @@
for (String s : categoryIds.split(",")) {
Integer id = Integer.valueOf(s.trim());
- IssueCategory t = ModelHelper.byId(id, categories);
+ IssueCategory t = IdAbles.byId(id, categories);
if (t == null) {
throw new MojoExecutionException("could not obtain the category with id " + id);
@@ -604,7 +604,7 @@
boolean treateReleaseVersion = v.getId() == version.getId();
- Issue[] issuesForVersion = ModelHelper.byVersionId(v.getId(), issues);
+ Issue[] issuesForVersion = Issue.byVersionId(v.getId(), issues);
Release release = new Release();
body.addRelease(release);
@@ -640,7 +640,7 @@
String type = entry.getValue();
// get issues for the tracker
- Issue[] issuesForTracker = ModelHelper.byTrackerId(entry.getKey(), issuesForVersion);
+ Issue[] issuesForTracker = Issue.byTrackerId(entry.getKey(), issuesForVersion);
for (Issue issue : issuesForTracker) {
@@ -670,7 +670,7 @@
getLog().warn("issue " + issue.getSubject() + " is not created to any user, this is not normal...");
id = issue.getAuthorId();
}
- a = ModelHelper.byId(id, users);
+ a = IdAbles.byId(id, users);
if (a != null) {
action.setDueTo(a.getFirstname() + " " + a.getLastname());
@@ -684,7 +684,7 @@
getLog().warn("issue " + issue.getSubject() + " is not assigned to any user, this is not normal...");
id = issue.getAuthorId();
}
- a = ModelHelper.byId(id, users);
+ a = IdAbles.byId(id, users);
if (a != null) {
//TODO should check this is a developper name on pom.xml
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-16 23:21:58 UTC (rev 371)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/IssuesCollector.java 2012-10-16 23:24:12 UTC (rev 372)
@@ -25,11 +25,11 @@
package org.nuiton.jredmine.plugin;
import org.apache.maven.plugin.logging.Log;
+import org.nuiton.jredmine.model.IdAbles;
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.Tracker;
import org.nuiton.jredmine.model.Version;
import org.nuiton.jredmine.service.RedmineService;
@@ -104,7 +104,7 @@
versions = service.getVersions(projectId);
if (versionIds != null) {
// filtre sur version
- versions = ModelHelper.byIds(Version.class, versions, versionIds.toArray(new Integer[versionIds.size()]));
+ versions = IdAbles.byIds(Version.class, versions, versionIds.toArray(new Integer[versionIds.size()]));
}
int nbIssues = 0;
Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/NextVersionMojo.java
===================================================================
--- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/NextVersionMojo.java 2012-10-16 23:21:58 UTC (rev 371)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/NextVersionMojo.java 2012-10-16 23:24:12 UTC (rev 372)
@@ -28,7 +28,6 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.util.StringUtils;
-import org.nuiton.jredmine.model.ModelHelper;
import org.nuiton.jredmine.model.Version;
import org.nuiton.plugin.PluginHelper;
@@ -224,7 +223,7 @@
if (StringUtils.isNotBlank(previousVersionName)) {
// retrieve previous version
- Version previousVersion = ModelHelper.byVersionName(previousVersionName);
+ Version previousVersion = Version.byVersionName(previousVersionName);
if (previousVersion == null) {
getLog().warn("can not find the previous version " + previousVersionName);
} else {
1
0
r371 - in trunk/jredmine-client/src: it/redmine-1.4.x main/java/org/nuiton/jredmine/client main/java/org/nuiton/jredmine/model main/java/org/nuiton/jredmine/service
by tchemit@users.nuiton.org 16 Oct '12
by tchemit@users.nuiton.org 16 Oct '12
16 Oct '12
Author: tchemit
Date: 2012-10-17 01:21:58 +0200 (Wed, 17 Oct 2012)
New Revision: 371
Url: http://nuiton.org/repositories/revision/jredmine/371
Log:
- add missing svn properties and license headers
- improve some code (remove the ModelHelper class)
- use apiKey to test the redmine-1.4.x client it
- improve test configuration
Added:
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/IdAbles.java
Removed:
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/ModelHelper.java
Modified:
trunk/jredmine-client/src/it/redmine-1.4.x/pom.xml
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java
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/model/Issue.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/User.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/Version.java
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/RedmineConfigurationUtil.java
Modified: trunk/jredmine-client/src/it/redmine-1.4.x/pom.xml
===================================================================
--- trunk/jredmine-client/src/it/redmine-1.4.x/pom.xml 2012-10-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/it/redmine-1.4.x/pom.xml 2012-10-16 23:21:58 UTC (rev 371)
@@ -88,7 +88,7 @@
</goals>
<phase>initialize</phase>
<configuration>
- <serverId>jredmine-test-it</serverId>
+ <serverId>jredmine-test-it-1.4.x</serverId>
<usernameOut>jredmine-test.username</usernameOut>
<passwordOut>jredmine-test.password</passwordOut>
<privateKeyOut>jredmine-test.apiKey</privateKeyOut>
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-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -173,7 +173,7 @@
getConfiguration().getAuthConfiguration();
RedmineRequest<Void> loginRequest;
- if (false && conf.isUseApiKey()) {
+ if (conf.isUseApiKey()) {
// use api key to login
loginRequest = RedmineRequestHelper.postAction("login", void.class).
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequest.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequest.java 2012-10-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequest.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -1,5 +1,29 @@
package org.nuiton.jredmine.client;
+/*
+ * #%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 com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequest.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestHelper.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestHelper.java 2012-10-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestHelper.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -1,5 +1,29 @@
package org.nuiton.jredmine.client;
+/*
+ * #%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%
+ */
+
/**
* Helper around {@link RedmineRequest}.
*
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestHelper.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/IdAbles.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/IdAbles.java (rev 0)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/IdAbles.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -0,0 +1,68 @@
+package org.nuiton.jredmine.model;
+
+/*
+ * #%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 java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * Helper methods around {@link IdAble}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public class IdAbles {
+ public static final Comparator<IdAble> ID_ABLE_COMPARATOR = new Comparator<IdAble>() {
+
+ @Override
+ public int compare(IdAble o1, IdAble o2) {
+ return o1.getId() - o2.getId();
+ }
+ };
+
+ public static <T extends IdAble> T byId(int id, T... datas) {
+ for (T data : datas) {
+ if (data.getId() == id) {
+ return data;
+ }
+ }
+ return null;
+ }
+
+ public static <T extends IdAble> T[] byIds(Class<T> type, T[] result, Integer... ids) {
+
+ List<Integer> lIds = Arrays.asList(ids);
+ List<T> filter = new ArrayList<T>(lIds.size());
+ for (T v : result) {
+ if (lIds.contains(v.getId())) {
+ filter.add(v);
+ }
+ }
+ return filter.toArray((T[]) Array.newInstance(type, filter.size()));
+ }
+}
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/IdAbles.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/Issue.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/Issue.java 2012-10-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/Issue.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -24,7 +24,9 @@
*/
package org.nuiton.jredmine.model;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
/**
* An issue on redmine's server.
@@ -80,6 +82,26 @@
protected boolean isPrivate;
+ public static Issue[] byTrackerId(int trackerId, Issue... issues) {
+ List<Issue> result = new ArrayList<Issue>();
+ for (Issue i : issues) {
+ if (i.getTrackerId() == trackerId) {
+ result.add(i);
+ }
+ }
+ return result.toArray(new Issue[result.size()]);
+ }
+
+ public static Issue[] byVersionId(int versionId, Issue... issues) {
+ List<Issue> result = new ArrayList<Issue>();
+ for (Issue i : issues) {
+ if (i.getFixedVersionId() == versionId) {
+ result.add(i);
+ }
+ }
+ return result.toArray(new Issue[result.size()]);
+ }
+
@Override
public int getId() {
return id;
Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/ModelHelper.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/ModelHelper.java 2012-10-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/ModelHelper.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -1,167 +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.model;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-
-/**
- * Some usefull methods on redmine's entities, mainly to filter datas.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.0.0
- */
-public class ModelHelper {
-
- public static final String GET_ALL_ISSUE_STATUS_REQUEST_NAME = "IssueStatus/all";
-
- public static final String GET_ALL_ISSUE_PRIORITY_REQUEST_NAME = "IssuePriority/all";
-
- public static final String GET_ALL_ISSUE_CATEGORY_REQUEST_NAME = "IssueCategory/all";
-
- public static final String GET_USER_PROJECTS_REQUEST_NAME = "User/Project/all";
-
- public static final String GET_ALL_PROJECT_REQUEST_NAME = "Project/all";
-
- public static final String GET_PROJECT_REQUEST_NAME = "Project/detail";
-
- public static final String GET_ALL_VERSION_REQUEST_NAME = "Project/Version/all";
-
- public static final String GET_ALL_TRACKER_REQUEST_NAME = "Project/Tracker/all";
-
- public static final String GET_ALL_PROJECT_ISSUES_REQUEST_NAME = "Project/Issue/all";
-
- public static final String GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME = "Project/Issue/opened";
-
- public static final String GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME = "Project/Issue/closed";
-
- public static final String GET_ALL_USER_REQUEST_NAME = "Project/User/all";
-
- public static final String GET_ALL_NEWS_REQUEST_NAME = "Project/News/all";
-
- public static final String GET_VERSION_REQUEST_NAME = "Project/Version/detail";
-
- public static final String GET_ALL_ISSUES_REQUEST_NAME = "Project/Version/Issue/all";
-
- public static final String GET_ALL_ATTACHMENTS_REQUEST_NAME = "Project/Version/Attachment/all";
-
- public static final String ADD_ATTACHMENT_REQUEST_NAME = "Project/Version/Attachment/add";
-
- public static final String ADD_VERSION_REQUEST_NAME = "Project/Version/add";
-
- public static final String UPDATE_VERSION_REQUEST_NAME = "Project/Version/update";
-
- public static final String NEXT_VERSION_REQUEST_NAME = "Project/Version/next";
-
- public static final String ADD_NEWS_REQUEST_NAME = "Project/News/add";
-
- public static final String GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME = "Project/Issue/TimeEntry/all";
-
- public static final String ADD_ISSUE_TIME_ENTRY_REQUEST_NAME = "Project/Issue/TimeEntry/add";
-
- public static final String LOGIN_REQUEST_NAME = "Login";
-
- public static final String LOGIN_BY_API_KEY_REQUEST_NAME = "LoginByAPiKey";
-
- public static final String LOGOUT_REQUEST_NAME = "Logout";
-
- public static final String PING_REQUEST_NAME = "Ping";
-
- public static final String VERSION_SCOPE = "version";
-
- public static final String PROJECT_SCOPE = "project";
-
- public static final String ISSUE_SCOPE = "issue";
-
- public static <T extends IdAble> T byId(int id, T... datas) {
- for (T data : datas) {
- if (data.getId() == id) {
- return data;
- }
- }
- return null;
- }
-
- public static User byLogin(String login, User... users) {
- for (User u : users) {
- if (u.getLogin().equals(login)) {
- return u;
- }
- }
- return null;
- }
-
- public static Version byVersionName(String name, Version... versions) {
- for (Version u : versions) {
- if (u.getName().equals(name)) {
- return u;
- }
- }
- return null;
- }
-
- public static Issue[] byTrackerId(int trackerId, Issue... issues) {
- List<Issue> result = new ArrayList<Issue>();
- for (Issue i : issues) {
- if (i.getTrackerId() == trackerId) {
- result.add(i);
- }
- }
- return result.toArray(new Issue[result.size()]);
- }
-
- public static Issue[] byVersionId(int versionId, Issue... issues) {
- List<Issue> result = new ArrayList<Issue>();
- for (Issue i : issues) {
- if (i.getFixedVersionId() == versionId) {
- result.add(i);
- }
- }
- return result.toArray(new Issue[result.size()]);
- }
-
- public static <T extends IdAble> T[] byIds(Class<T> type, T[] result, Integer... ids) {
-
- List<Integer> lIds = Arrays.asList(ids);
- List<T> filter = new ArrayList<T>(lIds.size());
- for (T v : result) {
- if (lIds.contains(v.getId())) {
- filter.add(v);
- }
- }
- return filter.toArray((T[]) Array.newInstance(type, filter.size()));
- }
-
- public static final Comparator<IdAble> ID_ABLE_COMPARATOR = new Comparator<IdAble>() {
-
- @Override
- public int compare(IdAble o1, IdAble o2) {
- return o1.getId() - o2.getId();
- }
- };
-}
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/User.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/User.java 2012-10-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/User.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -68,6 +68,15 @@
protected String salt;
+ public static User byLogin(String login, User... users) {
+ for (User u : users) {
+ if (u.getLogin().equals(login)) {
+ return u;
+ }
+ }
+ return null;
+ }
+
public boolean isAdmin() {
return admin;
}
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/Version.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/Version.java 2012-10-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/Version.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -52,6 +52,15 @@
protected int projectId;
+ public static Version byVersionName(String name, Version... versions) {
+ for (Version u : versions) {
+ if (u.getName().equals(name)) {
+ return u;
+ }
+ }
+ return null;
+ }
+
public Date getCreatedOn() {
return createdOn;
}
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/AbstractRedmineService.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/AbstractRedmineService.java 2012-10-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/AbstractRedmineService.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -1,5 +1,29 @@
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 com.google.common.base.Preconditions;
import org.nuiton.jredmine.client.RedmineClient;
import org.nuiton.jredmine.client.RedmineRequest;
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/AbstractRedmineService.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineAnonymousService.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineAnonymousService.java 2012-10-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineAnonymousService.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -1,5 +1,29 @@
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 com.google.common.base.Preconditions;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineAnonymousService.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineService.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineService.java 2012-10-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineService.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -1,5 +1,29 @@
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 com.google.common.base.Strings;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/DefaultRedmineService.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineConfigurationUtil.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineConfigurationUtil.java 2012-10-16 23:15:36 UTC (rev 370)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/service/RedmineConfigurationUtil.java 2012-10-16 23:21:58 UTC (rev 371)
@@ -163,6 +163,9 @@
overridePropertyFromProperties(result, "url", props);
overridePropertyFromProperties(result, "encoding", props);
overridePropertyFromProperties(result, "verbose", props);
+ overridePropertyFromProperties(authConfiguration, "username", props);
+ overridePropertyFromProperties(authConfiguration, "password", props);
+ overridePropertyFromProperties(authConfiguration, "apiKey", props);
overridePropertyFromEnv(result, "url");
overridePropertyFromEnv(result, "encoding");
1
0
r370 - trunk/jredmine-client/src/main/redmine/jredmine-1.x/app/controllers
by tchemit@users.nuiton.org 16 Oct '12
by tchemit@users.nuiton.org 16 Oct '12
16 Oct '12
Author: tchemit
Date: 2012-10-17 01:15:36 +0200 (Wed, 17 Oct 2012)
New Revision: 370
Url: http://nuiton.org/repositories/revision/jredmine/370
Log:
refs #2197: Can use api Key to connect to redmine (do it for jredmine-1.x)
Modified:
trunk/jredmine-client/src/main/redmine/jredmine-1.x/app/controllers/jredmine_controller.rb
Modified: trunk/jredmine-client/src/main/redmine/jredmine-1.x/app/controllers/jredmine_controller.rb
===================================================================
--- trunk/jredmine-client/src/main/redmine/jredmine-1.x/app/controllers/jredmine_controller.rb 2012-10-16 22:37:06 UTC (rev 369)
+++ trunk/jredmine-client/src/main/redmine/jredmine-1.x/app/controllers/jredmine_controller.rb 2012-10-16 23:15:36 UTC (rev 370)
@@ -55,7 +55,8 @@
render_status 405, "POST method required"
else
# Authenticate user
- user = User.try_to_login(params[:username], params[:password])
+ #user = User.try_to_login(params[:username], params[:password])
+ user = find_current_user
if user.nil?
# Invalid credentials
render_status 401, "Invalid credentials"
@@ -453,15 +454,37 @@
# Returns the current user or nil if no user is logged in
def find_current_user
+ user = nil
if session[:user_id]
# existing session
- (User.active.find(session[:user_id]) rescue nil)
+ user = (User.active.find(session[:user_id]) rescue nil)
elsif cookies[:autologin]
# auto-login feature
- User.find_by_autologin_key(cookies[:autologin])
+ user = User.find_by_autologin_key(cookies[:autologin])
end
+ if user.nil? && Setting.rest_api_enabled?
+ if (key = api_key_from_request)
+ # Use API key
+ user = User.find_by_api_key(key)
+ else
+ # HTTP Basic, either username/password or API key/random
+ authenticate_with_http_basic do |username, password|
+ user = User.try_to_login(username, password) || User.find_by_api_key(username)
+ end
+ end
+ end
+ user
end
+ # Returns the API key present in the request
+ def api_key_from_request
+ if params[:key].present?
+ params[:key].to_s
+ elsif request.headers["X-Redmine-API-Key"].present?
+ request.headers["X-Redmine-API-Key"].to_s
+ end
+ end
+
def find_project( pid = params[:pid] )
begin
@project = Project.find(pid)
1
0
r369 - trunk/jredmine-client/src/main/redmine/jredmine-2.x/app/controllers
by tchemit@users.nuiton.org 16 Oct '12
by tchemit@users.nuiton.org 16 Oct '12
16 Oct '12
Author: tchemit
Date: 2012-10-17 00:37:06 +0200 (Wed, 17 Oct 2012)
New Revision: 369
Url: http://nuiton.org/repositories/revision/jredmine/369
Log:
refs #2197: Can use api Key to connect to redmine (do it for jredmine-2.x
Modified:
trunk/jredmine-client/src/main/redmine/jredmine-2.x/app/controllers/jredmine_controller.rb
Modified: trunk/jredmine-client/src/main/redmine/jredmine-2.x/app/controllers/jredmine_controller.rb
===================================================================
--- trunk/jredmine-client/src/main/redmine/jredmine-2.x/app/controllers/jredmine_controller.rb 2012-10-16 20:19:50 UTC (rev 368)
+++ trunk/jredmine-client/src/main/redmine/jredmine-2.x/app/controllers/jredmine_controller.rb 2012-10-16 22:37:06 UTC (rev 369)
@@ -55,13 +55,14 @@
render_status 405, "POST method required"
else
# Authenticate user
- user = User.try_to_login(params[:username], params[:password])
+ #user = User.try_to_login(params[:username], params[:password])
+ user = find_current_user
if user.nil?
# Invalid credentials
render_status 401, "Invalid credentials"
- elsif user.new_record?
- # Onthefly creation failed,
- render_status 401, "User not activated"
+ #elsif user.new_record?
+ # # Onthefly creation failed,
+ # render_status 401, "User not activated"
else
# Valid user
self.logged_user = user
@@ -453,15 +454,37 @@
# Returns the current user or nil if no user is logged in
def find_current_user
+ user = nil
if session[:user_id]
# existing session
- (User.active.find(session[:user_id]) rescue nil)
+ user = (User.active.find(session[:user_id]) rescue nil)
elsif cookies[:autologin]
# auto-login feature
- User.find_by_autologin_key(cookies[:autologin])
+ user = User.find_by_autologin_key(cookies[:autologin])
end
+ if user.nil? && Setting.rest_api_enabled?
+ if (key = api_key_from_request)
+ # Use API key
+ user = User.find_by_api_key(key)
+ else
+ # HTTP Basic, either username/password or API key/random
+ authenticate_with_http_basic do |username, password|
+ user = User.try_to_login(username, password) || User.find_by_api_key(username)
+ end
+ end
+ end
+ user
end
+ # Returns the API key present in the request
+ def api_key_from_request
+ if params[:key].present?
+ params[:key].to_s
+ elsif request.headers["X-Redmine-API-Key"].present?
+ request.headers["X-Redmine-API-Key"].to_s
+ end
+ end
+
def find_project( pid = params[:pid] )
begin
@project = Project.find(pid)
1
0
r368 - in trunk/jredmine-client/src: main/java/org/nuiton/jredmine test/java/org/nuiton/jredmine
by tchemit@users.nuiton.org 16 Oct '12
by tchemit@users.nuiton.org 16 Oct '12
16 Oct '12
Author: tchemit
Date: 2012-10-16 22:19:50 +0200 (Tue, 16 Oct 2012)
New Revision: 368
Url: http://nuiton.org/repositories/revision/jredmine/368
Log:
fixes #2354: Do not use any longer helper-m-p rest api but simple httpcomponents client
Removed:
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/
trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/
1
0
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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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>
1
0
14 Oct '12
Author: tchemit
Date: 2012-10-14 11:24:18 +0200 (Sun, 14 Oct 2012)
New Revision: 366
Url: http://nuiton.org/repositories/revision/jredmine/366
Log:
upgrade to version 1.5
Modified:
trunk/jredmine-client/pom.xml
trunk/jredmine-maven-plugin/pom.xml
trunk/pom.xml
Modified: trunk/jredmine-client/pom.xml
===================================================================
--- trunk/jredmine-client/pom.xml 2012-10-13 21:53:56 UTC (rev 365)
+++ trunk/jredmine-client/pom.xml 2012-10-14 09:24:18 UTC (rev 366)
@@ -30,7 +30,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jredmine</artifactId>
- <version>1.4.1-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jredmine</groupId>
Modified: trunk/jredmine-maven-plugin/pom.xml
===================================================================
--- trunk/jredmine-maven-plugin/pom.xml 2012-10-13 21:53:56 UTC (rev 365)
+++ trunk/jredmine-maven-plugin/pom.xml 2012-10-14 09:24:18 UTC (rev 366)
@@ -28,7 +28,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>jredmine</artifactId>
- <version>1.4.1-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>org.nuiton.jredmine</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-10-13 21:53:56 UTC (rev 365)
+++ trunk/pom.xml 2012-10-14 09:24:18 UTC (rev 366)
@@ -31,7 +31,7 @@
</parent>
<artifactId>jredmine</artifactId>
- <version>1.4.1-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
<name>JRedmine</name>
<description>JRedmine is a java redmine client</description>
1
0
r365 - in trunk/jredmine-client/src: main/java/org/nuiton/jredmine/client test/java/org/nuiton/jredmine/client
by tchemit@users.nuiton.org 13 Oct '12
by tchemit@users.nuiton.org 13 Oct '12
13 Oct '12
Author: tchemit
Date: 2012-10-13 23:53:56 +0200 (Sat, 13 Oct 2012)
New Revision: 365
Url: http://nuiton.org/repositories/revision/jredmine/365
Log:
add svn properties and license headers
Modified:
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientAuthConfiguration.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientConfiguration.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java
trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java
trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java
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-13 21:50:04 UTC (rev 364)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java 2012-10-13 21:53:56 UTC (rev 365)
@@ -1,5 +1,29 @@
package org.nuiton.jredmine.client;
+/*
+ * #%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.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientAuthConfiguration.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientAuthConfiguration.java 2012-10-13 21:50:04 UTC (rev 364)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientAuthConfiguration.java 2012-10-13 21:53:56 UTC (rev 365)
@@ -1,5 +1,29 @@
package org.nuiton.jredmine.client;
+/*
+ * #%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.lang3.StringUtils;
/**
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientAuthConfiguration.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientConfiguration.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientConfiguration.java 2012-10-13 21:50:04 UTC (rev 364)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientConfiguration.java 2012-10-13 21:53:56 UTC (rev 365)
@@ -3,7 +3,7 @@
* Maven helper plugin
*
* $Id$
- * $HeadURL: http://svn.nuiton.org/svn/maven-helper-plugin/trunk/src/main/java/org/nuito… $
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2010 Tony Chemit, CodeLutin
* %%
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientConfiguration.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: 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-13 21:50:04 UTC (rev 364)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java 2012-10-13 21:53:56 UTC (rev 365)
@@ -3,7 +3,7 @@
* #%L
* JRedmine :: Client
* $Id$
- * $HeadURL: http://svn.nuiton.org/svn/jredmine/branches/jredmine-1.x/jredmine-client/sr… $
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin
* %%
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
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-13 21:50:04 UTC (rev 364)
+++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java 2012-10-13 21:53:56 UTC (rev 365)
@@ -3,7 +3,7 @@
* JRedmine :: Client
*
* $Id$
- * $HeadURL: http://svn.nuiton.org/svn/jredmine/branches/jredmine-1.x/jredmine-client/sr… $
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin
* %%
Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: 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-13 21:50:04 UTC (rev 364)
+++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java 2012-10-13 21:53:56 UTC (rev 365)
@@ -3,7 +3,7 @@
* #%L
* JRedmine :: Client
* $Id$
- * $HeadURL: http://svn.nuiton.org/svn/jredmine/branches/jredmine-1.x/jredmine-client/sr… $
+ * $HeadURL$
* %%
* Copyright (C) 2009 - 2012 Tony Chemit, CodeLutin
* %%
Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
1
0
Author: tchemit
Date: 2012-10-13 23:50:04 +0200 (Sat, 13 Oct 2012)
New Revision: 364
Url: http://nuiton.org/repositories/revision/jredmine/364
Log:
refs #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/
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientAuthConfiguration.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientConfiguration.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java
trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/
trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java
trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java
Removed:
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRequestFactory.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRestClient.java
trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRequestFactoryTest.java
trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java
Modified:
trunk/jredmine-client/pom.xml
trunk/jredmine-client/src/it/redmine-1.4.x/pom.xml
trunk/jredmine-client/src/it/redmine-2.0.x/pom.xml
trunk/jredmine-client/src/it/redmine-2.1.x/pom.xml
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineConfigurationUtil.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java
trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java
trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineFixtures.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/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/LoginMojo.java
trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/NextVersionMojo.java
trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishAttachmentsMojo.java
trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishNewsMojo.java
trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/UpdateVersionMojo.java
trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AbstractAnnouncementMojo.java
trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AnnouncementGenerator.java
trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AnnouncementGeneratorConfiguration.java
trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractRedmineReport.java
trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoTest.java
Modified: trunk/jredmine-client/pom.xml
===================================================================
--- trunk/jredmine-client/pom.xml 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/pom.xml 2012-10-13 21:50:04 UTC (rev 364)
@@ -21,7 +21,9 @@
#L%
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -56,6 +58,10 @@
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ </exclusion>
</exclusions>
</dependency>
@@ -71,11 +77,21 @@
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpmime</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
@@ -163,7 +179,7 @@
</plugins>
</reporting>
-
+
</profile>
<profile>
<id>assembly-profile</id>
@@ -196,8 +212,10 @@
<descriptorRef>full</descriptorRef>
</descriptorRefs>
<descriptors>
- <descriptor>src/main/assembly/jredmine_rails-1.x.xml</descriptor>
- <descriptor>src/main/assembly/jredmine_rails-2.x.xml</descriptor>
+ <descriptor>src/main/assembly/jredmine_rails-1.x.xml
+ </descriptor>
+ <descriptor>src/main/assembly/jredmine_rails-2.x.xml
+ </descriptor>
</descriptors>
</configuration>
</plugin>
@@ -225,7 +243,8 @@
<mergeUserSettings>true</mergeUserSettings>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<settingsFile>src/it/settings.xml</settingsFile>
- <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
+ <localRepositoryPath>${project.build.directory}/local-repo
+ </localRepositoryPath>
</configuration>
<executions>
<execution>
Modified: trunk/jredmine-client/src/it/redmine-1.4.x/pom.xml
===================================================================
--- trunk/jredmine-client/src/it/redmine-1.4.x/pom.xml 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/it/redmine-1.4.x/pom.xml 2012-10-13 21:50:04 UTC (rev 364)
@@ -89,8 +89,9 @@
<phase>initialize</phase>
<configuration>
<serverId>jredmine-test-it</serverId>
- <usernameOut>jredmine-test.login</usernameOut>
+ <usernameOut>jredmine-test.username</usernameOut>
<passwordOut>jredmine-test.password</passwordOut>
+ <privateKeyOut>jredmine-test.apiKey</privateKeyOut>
</configuration>
</execution>
</executions>
Modified: trunk/jredmine-client/src/it/redmine-2.0.x/pom.xml
===================================================================
--- trunk/jredmine-client/src/it/redmine-2.0.x/pom.xml 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/it/redmine-2.0.x/pom.xml 2012-10-13 21:50:04 UTC (rev 364)
@@ -89,8 +89,9 @@
<phase>initialize</phase>
<configuration>
<serverId>jredmine-test-it</serverId>
- <usernameOut>jredmine-test.login</usernameOut>
+ <usernameOut>jredmine-test.username</usernameOut>
<passwordOut>jredmine-test.password</passwordOut>
+ <privateKeyOut>jredmine-test.apiKey</privateKeyOut>
</configuration>
</execution>
</executions>
Modified: trunk/jredmine-client/src/it/redmine-2.1.x/pom.xml
===================================================================
--- trunk/jredmine-client/src/it/redmine-2.1.x/pom.xml 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/it/redmine-2.1.x/pom.xml 2012-10-13 21:50:04 UTC (rev 364)
@@ -89,8 +89,9 @@
<phase>initialize</phase>
<configuration>
<serverId>jredmine-test-it</serverId>
- <usernameOut>jredmine-test.login</usernameOut>
+ <usernameOut>jredmine-test.username</usernameOut>
<passwordOut>jredmine-test.password</passwordOut>
+ <privateKeyOut>jredmine-test.apiKey</privateKeyOut>
</configuration>
</execution>
</executions>
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -25,12 +25,11 @@
package org.nuiton.jredmine;
import com.google.common.base.Preconditions;
-import org.nuiton.io.rest.RestClient;
-import org.nuiton.io.rest.RestException;
import org.nuiton.io.rest.RestRequest;
import org.nuiton.jredmine.model.io.xpp3.RedmineXpp3Helper;
-import org.nuiton.jredmine.rest.RedmineRestClient;
+import org.nuiton.jredmine.client.RedmineClient;
+import java.io.IOException;
import java.io.InputStream;
/**
@@ -44,8 +43,12 @@
*/
public class DefaultRedmineServiceImplementor implements RedmineServiceImplementor {
- /** Redmine Client Rest. */
- protected RestClient session;
+ /**
+ * Redmine client.
+ *
+ * @since 1.5
+ */
+ protected RedmineClient client;
/** xpp3 xpp3Helper to transform xml stream to pojo */
protected final RedmineXpp3Helper xpp3Helper;
@@ -70,13 +73,10 @@
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!");
- session = new RedmineRestClient();
- session.setConfiguration(configuration);
+ client = new RedmineClient(configuration);
try {
- if (!session.isOpen()) {
- session.open();
- }
+ client.open();
init = true;
} catch (Exception e) {
@@ -90,18 +90,18 @@
public void destroy() throws RedmineServiceException {
if (isInit()) {
try {
- if (session.isOpen()) {
+ if (client.isOpen()) {
try {
- session.close();
- } catch (RestException ex) {
+ client.close();
+ } catch (IOException e) {
throw new RedmineServiceException(
"has problem while closing Rest client " +
- ex.getMessage(), ex);
+ e.getMessage(), e);
}
}
} finally {
- if (session != null) {
- session = null;
+ if (client != null) {
+ client = null;
}
init = false;
}
@@ -109,8 +109,8 @@
}
@Override
- public RestClient getSession() {
- return session;
+ public RedmineClient getClient() {
+ return client;
}
@Override
@@ -156,25 +156,14 @@
@Override
public void checkLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException {
checkInit();
- checkSessionNotNull(session);
- checkSessionConfigurationNotNull(session);
- if (session.getConfiguration().isAnonymous()) {
+ checkSessionNotNull();
+ checkSessionConfigurationNotNull();
+ if (client.getConfiguration().isAnonymous()) {
throw new RedmineServiceLoginException(
"can not access this service in anonymous mode");
}
}
- @Override
- public void checkNotLoggued(RestClient session) throws RedmineServiceLoginException, NullPointerException {
-// checkInit();
- checkSessionNotNull(session);
- checkSessionConfigurationNotNull(session);
- if (!session.getConfiguration().isAnonymous()) {
- throw new RedmineServiceLoginException(
- "session must be anonymous in this service");
- }
- }
-
protected InputStream askDataStream(String requestName,
Object... args) throws RedmineServiceException {
@@ -183,7 +172,7 @@
// obtain data from rest client
try {
- InputStream stream = session.askData(r);
+ InputStream stream = client.executeRequest(r);
return stream;
} catch (Exception e) {
throw new RedmineServiceException(
@@ -200,7 +189,7 @@
// obtain data from rest client
try {
- InputStream stream = session.sendData(r);
+ InputStream stream = client.executeRequest(r);
return stream;
} catch (Exception e) {
throw new RedmineServiceException(
@@ -213,7 +202,7 @@
Object... args) throws RedmineServiceException {
RestRequest r;
try {
- r = session.getRequest(requestName, args);
+ r = client.getRequest(requestName, args);
} catch (Exception e) {
throw new RedmineServiceException(
"could not find the request named " + requestName +
@@ -263,14 +252,14 @@
}
}
- protected void checkSessionNotNull(RestClient session) {
- if (session == null) {
+ protected void checkSessionNotNull() {
+ if (client == null) {
throw new NullPointerException("session can not be null");
}
}
- protected void checkSessionConfigurationNotNull(RestClient session) {
- if (session.getConfiguration() == null) {
+ protected void checkSessionConfigurationNotNull() {
+ if (client.getConfiguration() == null) {
throw new NullPointerException(
"session configuration can not be null");
}
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineConfigurationUtil.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineConfigurationUtil.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineConfigurationUtil.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -31,8 +31,8 @@
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.io.rest.RestException;
-import org.nuiton.jredmine.rest.RedmineRestClient;
+import org.nuiton.jredmine.client.RedmineClient;
+import org.nuiton.jredmine.client.RedmineClientAuthConfiguration;
import java.io.File;
import java.io.IOException;
@@ -64,7 +64,7 @@
boolean ok = false;
- RedmineRestClient client = new RedmineRestClient(conf);
+ RedmineClient client = new RedmineClient(conf);
try {
@@ -79,7 +79,7 @@
} finally {
try {
client.close();
- } catch (RestException e) {
+ } catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("Could not close session", e);
}
@@ -91,7 +91,7 @@
// try to connect anonymous
conf = cloneConfiguration(anoConf);
- client = new RedmineRestClient(conf);
+ client = new RedmineClient(conf);
try {
@@ -105,7 +105,7 @@
} finally {
try {
client.close();
- } catch (RestException e) {
+ } catch (IOException e) {
if (log.isErrorEnabled()) {
log.error("Could not close session", e);
}
@@ -156,11 +156,14 @@
RedmineServiceConfiguration result = new SimpleRedmineServiceConfiguration();
- overridePropertyFromProperties(result, "url", "restUrl", props);
+ RedmineClientAuthConfiguration authConfiguration =
+ new RedmineClientAuthConfiguration();
+ result.setAuthConfiguration(authConfiguration);
+ overridePropertyFromProperties(result, "url", props);
overridePropertyFromProperties(result, "encoding", props);
overridePropertyFromProperties(result, "verbose", props);
- overridePropertyFromEnv(result, "url", "restUrl");
+ overridePropertyFromEnv(result, "url");
overridePropertyFromEnv(result, "encoding");
overridePropertyFromEnv(result, "verbose");
result.setAnonymous(true);
@@ -174,9 +177,11 @@
RedmineServiceConfiguration result = cloneConfiguration(anoConf);
- overridePropertyFromEnv(result, "login", "restUsername");
- overridePropertyFromEnv(result, "password", "restPassword");
- overridePropertyFromEnv(result, "apiKey", "apiKey");
+ RedmineClientAuthConfiguration authConfiguration =
+ result.getAuthConfiguration();
+ overridePropertyFromEnv(authConfiguration, "username");
+ overridePropertyFromEnv(authConfiguration, "password");
+ overridePropertyFromEnv(authConfiguration, "apiKey");
result.setAnonymous(false);
@@ -186,61 +191,45 @@
public static RedmineServiceConfiguration cloneConfiguration(
RedmineServiceConfiguration src) {
RedmineServiceConfiguration dst = new SimpleRedmineServiceConfiguration();
- dst.setRestUrl(src.getRestUrl());
- dst.setRestUsername(src.getRestUsername());
- dst.setRestPassword(src.getRestPassword());
- dst.setApiKey(src.getApiKey());
- dst.setEncoding(src.getEncoding());
- dst.setVerbose(src.isVerbose());
- dst.setAnonymous(src.isAnonymous());
+ copyConfiguration(src, dst);
return dst;
}
public static void copyConfiguration(RedmineServiceConfiguration src,
RedmineServiceConfiguration dst) {
- dst.setRestUrl(src.getRestUrl());
- dst.setRestUsername(src.getRestUsername());
- dst.setRestPassword(src.getRestPassword());
- dst.setApiKey(src.getApiKey());
+ dst.setUrl(src.getUrl());
dst.setEncoding(src.getEncoding());
dst.setVerbose(src.isVerbose());
dst.setAnonymous(src.isAnonymous());
- }
- protected static void overridePropertyFromProperties(RedmineServiceConfiguration conf,
- String prop,
- Properties props) throws IOException {
- overridePropertyFromProperties(conf, prop, prop, props);
+ 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(RedmineServiceConfiguration conf,
+ protected static void overridePropertyFromProperties(Object conf,
String prop,
- String beanProp,
Properties props) throws IOException {
String value = props.getProperty(PROPERTY_PREFIX + prop);
if (StringUtils.isNotEmpty(value)) {
try {
- BeanUtilsBean.getInstance().setProperty(conf, beanProp, value);
+ BeanUtilsBean.getInstance().setProperty(conf, prop, value);
} catch (Exception e) {
throw new IOException(
- "Could not set property '" + beanProp +
+ "Could not set property '" + prop +
"' with value '" + value + "' to configuration");
}
}
}
- protected static void overridePropertyFromEnv(RedmineServiceConfiguration conf,
+ protected static void overridePropertyFromEnv(Object conf,
String prop) throws IOException {
- overridePropertyFromEnv(conf, prop, prop);
- }
-
- protected static void overridePropertyFromEnv(RedmineServiceConfiguration conf,
- String prop,
- String beanProp) throws IOException {
String value = System.getenv(PROPERTY_PREFIX + prop);
if (StringUtils.isNotEmpty(value) && !"null".equals(value)) {
try {
- BeanUtilsBean.getInstance().setProperty(conf, beanProp, value);
+ BeanUtilsBean.getInstance().setProperty(conf, prop, value);
} catch (Exception e) {
throw new IOException(
"Could not set property '" + prop +
@@ -257,59 +246,65 @@
*/
public static class SimpleRedmineServiceConfiguration implements RedmineServiceConfiguration {
- URL restUrl;
+ URL url;
- String restUsername;
-
- String restPassword;
-
boolean verbose;
boolean anonymous;
String encoding;
- String apiKey;
+ RedmineClientAuthConfiguration authConfiguration;
@Override
- public String getEncoding() {
- return encoding;
+ public RedmineClientAuthConfiguration getAuthConfiguration() {
+ return authConfiguration;
}
@Override
- public void setEncoding(String encoding) {
- this.encoding = encoding;
+ public void setAuthConfiguration(RedmineClientAuthConfiguration authConfiguration) {
+ this.authConfiguration = authConfiguration;
}
@Override
- public String getRestPassword() {
- return restPassword;
+ public String getEncoding() {
+ return encoding;
}
@Override
- public void setRestPassword(String restPassword) {
- this.restPassword = restPassword;
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
}
- @Override
- public URL getRestUrl() {
- return restUrl;
- }
+// @Override
+// public String getPassword() {
+// return restPassword;
+// }
+//
+// @Override
+// public void setPassword(String password) {
+// this.restPassword = password;
+// }
@Override
- public void setRestUrl(URL restUrl) {
- this.restUrl = restUrl;
+ public URL getUrl() {
+ return url;
}
@Override
- public String getRestUsername() {
- return restUsername;
+ public void setUrl(URL url) {
+ this.url = url;
}
- @Override
- public void setRestUsername(String restUsername) {
- this.restUsername = restUsername;
- }
+// @Override
+// public String getUsername() {
+// return restUsername;
+// }
+//
+// @Override
+// public void setUsername(String username) {
+// this.restUsername = username;
+// }
@Override
public boolean isVerbose() {
@@ -337,26 +332,27 @@
this,
ToStringStyle.MULTI_LINE_STYLE
);
- b.append("redmineUrl", restUrl);
+ b.append("redmineUrl", url);
if (anonymous) {
b.append("anonymous", true);
} else {
- b.append("redmineUsername", restUsername);
- b.append("redminePassword", "***");
+ 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;
- }
+// @Override
+// public String getApiKey() {
+// return apiKey;
+// }
+//
+// @Override
+// public void setApiKey(String apiKey) {
+// this.apiKey = apiKey;
+// }
}
}
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceConfiguration.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -23,7 +23,7 @@
* #L%
*/
-import org.nuiton.io.rest.RestClientConfiguration;
+import org.nuiton.jredmine.client.RedmineClientConfiguration;
/**
* Contract of a redmine service configuration.
@@ -31,10 +31,6 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.4
*/
-public interface RedmineServiceConfiguration extends RestClientConfiguration {
+public interface RedmineServiceConfiguration extends RedmineClientConfiguration {
- String getApiKey();
-
- void setApiKey(String apiKey);
-
}
\ No newline at end of file
Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -25,15 +25,15 @@
package org.nuiton.jredmine;
import org.nuiton.io.rest.RestClient;
-import org.nuiton.jredmine.rest.RedmineRestClient;
+import org.nuiton.jredmine.client.RedmineClient;
/**
* Technical contract to implements a redmine service which wrap the
- * {@link RedmineRestClient}.
+ * {@link RedmineClient}.
* <p/>
* A default implementation is offered in {@link DefaultRedmineServiceImplementor}.
* <p/>
- * Any concrete implentation of a redmine service should implements this..
+ * Any concrete implentation of a redmine service should implements this.
*
* @author tchemit <chemit(a)codelutin.com>
* @see DefaultRedmineServiceImplementor
@@ -70,7 +70,7 @@
*
* @return the transport layer.
*/
- RestClient getSession();
+ RedmineClient getClient();
/**
* Generic method to obtain a single data from a redmine server.
@@ -132,12 +132,4 @@
*/
void checkLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException;
- /**
- * Checks if the current session is anonymous.
- *
- * @param session the session to test
- * @throws RedmineServiceLoginException if not anonymous
- * @throws NullPointerException if something is null
- */
- void checkNotLoggued(RestClient session) throws RedmineServiceLoginException, NullPointerException;
}
Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java (rev 0)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -0,0 +1,524 @@
+package org.nuiton.jredmine.client;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.StatusLine;
+import org.apache.http.client.HttpClient;
+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.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.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 java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.Map;
+
+/**
+ * A simple redmine client.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public class RedmineClient implements Closeable {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(RedmineClient.class);
+
+ protected final RedmineClientConfiguration configuration;
+
+ protected final HttpClient client;
+
+ protected final HttpHost host;
+
+ protected final HttpContext clientContext;
+
+ protected final RedmineRequestFactory requestFactory;
+
+ protected boolean showRequest;
+
+ protected boolean open;
+
+ public RedmineClient(RedmineClientConfiguration configuration) {
+ this.configuration = configuration;
+ showRequest = configuration.isVerbose();
+ client = new DefaultHttpClient();
+ clientContext = new BasicHttpContext();
+
+ int port = configuration.getUrl().getPort();
+ if (port == -1) {
+
+ // no port set
+ host = new HttpHost(configuration.getUrl().getHost());
+ } else {
+
+ // a specific port is asked
+ host = new HttpHost(configuration.getUrl().getHost(), port);
+ }
+
+ // set encoding (will then encode parameters fine)
+ client.getParams().setParameter(
+ CoreProtocolPNames.HTTP_CONTENT_CHARSET,
+ configuration.getEncoding());
+
+ requestFactory = new RedmineRequestFactory();
+ requestFactory.addDefaultRequests();
+ }
+
+ public RedmineRequestFactory getRequestFactory() {
+ return requestFactory;
+ }
+
+ public boolean isOpen() {
+ return open;
+ }
+
+ public void open() throws RestException, IOException {
+
+ if (!isOpen()) {
+
+ // first ping
+ ping();
+
+ if (!configuration.isAnonymous()) {
+
+ // log in
+ login();
+ }
+
+ open = true;
+ }
+ }
+
+ /**
+ * Ask some data from the server
+ *
+ * @param request request used for asking data
+ * @return the stream of the response
+ * @throws RestException if any pb while asking data
+ */
+ public InputStream executeRequest(RestRequest request) throws RestException {
+ 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);
+
+ StatusLine sl = response.getStatusLine();
+ int statusCode = sl.getStatusCode();
+
+ if (log.isDebugEnabled()) {
+ log.debug("status code " + statusCode + " for " + gm.getURI());
+ }
+
+ HttpEntity entity = response.getEntity();
+
+ if (statusCode == HttpStatus.SC_NOT_FOUND) {
+ String responseAsString = EntityUtils.toString(entity);
+ throw new RestDataNotFoundException(
+ "could not retreave some datas : " +
+ responseAsString);
+ }
+
+ 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);
+ }
+ }
+
+ public RedmineClientConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (open) {
+
+ try {
+
+ releaseConnection();
+
+ RestRequest request = getRequest(ModelHelper.LOGOUT_REQUEST_NAME);
+ HttpRequestBase httpRequest = prepareRequest(request);
+
+ HttpResponse response = executeRequest(httpRequest);
+ EntityUtils.consume(response.getEntity());
+ } catch (Exception e) {
+ throw new IOException(
+ "could not close client for reason " +
+ e.getMessage(), e);
+ } finally {
+
+ try {
+
+ client.getConnectionManager().shutdown();
+ } finally {
+
+ open = false;
+ }
+ }
+ }
+ }
+
+ protected HttpResponse executeRequest(HttpRequestBase gm) throws IOException {
+
+ // always release any previous connection
+ releaseConnection();
+
+ 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()));
+ }
+
+ HttpRequestBase gm;
+ switch (request.getMethod()) {
+
+ case GET:
+ gm = prepareGetRequest(request);
+ break;
+ case POST:
+ gm = preparePostRequest(request);
+ break;
+ case PUT:
+ gm = preparePutRequest(request);
+ break;
+ case DELETE:
+ gm = prepareDeleteRequest(request);
+ break;
+ case HEAD:
+ default:
+ throw new IllegalStateException(
+ "Can not deal with method " + request.getMethod());
+ }
+
+ if (getConfiguration().getAuthConfiguration().isUseApiKey()) {
+
+ gm.addHeader("X-Redmine-API-Key",
+ getConfiguration().getAuthConfiguration().getApiKey());
+ }
+// 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) {
+ String uri = host.toURI();
+ String result = request.toPath(uri);
+ return result;
+ }
+
+ protected HttpGet prepareGetRequest(RestRequest request) throws IOException {
+
+ String uri = getRequestUrl(request);
+ String[] parameters = request.getParameters();
+ Map<String, File> attachments = request.getAttachments();
+
+ if (attachments != null) {
+
+ // 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 {
+
+ String uri = getRequestUrl(request);
+ String[] parameters = request.getParameters();
+ Map<String, File> attachments = request.getAttachments();
+
+ if (attachments != null) {
+
+ // 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);
+
+ return gm;
+ }
+
+ protected HttpPost preparePostRequest(RestRequest request) throws IOException {
+
+ String uri = getRequestUrl(request);
+ String[] parameters = request.getParameters();
+ Map<String, File> attachments = request.getAttachments();
+
+ HttpPost gm = new HttpPost(uri);
+
+ if (attachments == null) {
+
+ // not a multi-part request
+ addParams(gm, parameters);
+ } else {
+
+ // multi-part request
+ prepareMultiPart(gm, attachments, parameters);
+ }
+ return gm;
+ }
+
+ protected HttpPut preparePutRequest(RestRequest request) throws IOException {
+
+ String uri = getRequestUrl(request);
+ String[] parameters = request.getParameters();
+ Map<String, File> attachments = request.getAttachments();
+
+ HttpPut gm = new HttpPut(uri);
+
+ if (attachments == null) {
+
+ // not a multi-part request
+ addParams(gm, parameters);
+
+ } else {
+
+ // multi-part request
+ prepareMultiPart(gm, attachments, parameters);
+ }
+ return gm;
+ }
+
+ protected void addParams(HttpRequestBase gm,
+ String... parameters) throws IOException {
+
+ if (parameters.length > 0) {
+
+ // 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];
+ if (value == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("skip null parameter " + key);
+ }
+ continue;
+ }
+ uriBuilder.addParameter(key, value);
+ }
+ try {
+ URI uri = uriBuilder.build();
+ gm.setURI(uri);
+ } catch (URISyntaxException e) {
+ throw new IOException("Could not build uri", e);
+ }
+ }
+ }
+
+ protected void prepareMultiPart(HttpEntityEnclosingRequestBase gm,
+ Map<String, File> attachments,
+ String... parameters) throws IOException {
+
+ MultipartEntity entity = new MultipartEntity();
+
+ if (parameters.length > 0) {
+
+ // 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];
+ if (value == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("skip null parameter " + key);
+ }
+ continue;
+ }
+ entity.addPart(key, new StringBody(value));
+ if (log.isDebugEnabled()) {
+ log.debug("add parameter [" + key + "]=" + value);
+ }
+ }
+ }
+
+ // add file parts
+ for (Map.Entry<String, File> entry : attachments.entrySet()) {
+ String key = entry.getKey();
+ File file = entry.getValue();
+ if (log.isDebugEnabled()) {
+ log.debug("add attachment " + key + "=" + file);
+ }
+ FileBody bin = new FileBody(file, file.getName(), "",
+ configuration.getEncoding());
+ entity.addPart(key, bin);
+
+ }
+ if (attachments.isEmpty()) {
+ log.warn("no attachment in a multi-part request!");
+ }
+
+ if (log.isDebugEnabled()) {
+ entity.writeTo(System.out);
+ }
+ gm.setEntity(entity);
+ gm.addHeader("content-type", entity.getContentType().getValue());
+ gm.addHeader("content-length", entity.getContentLength() + "");
+ if (showRequest) {
+ log.info("content-type : " + entity.getContentType() +
+ ", content-length : " + entity.getContentLength());
+ }
+ }
+
+ protected void ping() throws RestException, IOException {
+
+ RestRequest request = getRequest(ModelHelper.PING_REQUEST_NAME);
+
+ HttpRequestBase gm = prepareRequest(request);
+
+ HttpResponse response = executeRequest(gm);
+
+ try {
+ StatusLine sl = response.getStatusLine();
+ int statusCode = sl.getStatusCode();
+ if (log.isDebugEnabled()) {
+ log.debug("status code " + statusCode + " for " + gm.getURI());
+ }
+
+ if (statusCode != HttpStatus.SC_OK) {
+
+ throw new RestException(
+ "Could not ping to " + gm.getURI() +
+ " statusCode: " + statusCode + ", reason: " +
+ sl.getReasonPhrase());
+ }
+
+ String content = EntityUtils.toString(response.getEntity());
+
+ boolean ok = "ping".equals(content);
+ if (!ok) {
+ throw new IOException(
+ "can not connect to " + configuration.getUrl());
+ }
+ } 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) {
+
+ // 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());
+ }
+
+ HttpRequestBase gm = prepareRequest(request);
+
+ HttpResponse response = executeRequest(gm);
+
+ try {
+ StatusLine sl = response.getStatusLine();
+ int statusCode = sl.getStatusCode();
+ if (log.isDebugEnabled()) {
+ log.debug("status code " + statusCode + " for " + gm.getURI());
+ }
+
+ if (statusCode != HttpStatus.SC_OK) {
+ throw new RestException(
+ "Got error code <" + statusCode + ":" +
+ sl.getReasonPhrase() + "> on " + gm.getURI());
+ }
+
+ // ok session is logged in
+ } finally {
+ EntityUtils.consume(response.getEntity());
+ }
+ }
+
+ /**
+ * 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 void releaseConnection() {
+ client.getConnectionManager().closeExpiredConnections();
+ }
+}
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClient.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientAuthConfiguration.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientAuthConfiguration.java (rev 0)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientAuthConfiguration.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -0,0 +1,57 @@
+package org.nuiton.jredmine.client;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * Configuration of the authentication for the {@link RedmineClient}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public class RedmineClientAuthConfiguration {
+
+ public static RedmineClientAuthConfiguration newConf(String apiKey,
+ String username,
+ String password) {
+ RedmineClientAuthConfiguration result =
+ new RedmineClientAuthConfiguration();
+ result.setApiKey(apiKey);
+ result.setUsername(username);
+ result.setPassword(password);
+ return result;
+ }
+
+ protected String username;
+
+ protected String password;
+
+ protected String apiKey;
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getApiKey() {
+ return apiKey;
+ }
+
+ public void setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ }
+
+ public boolean isUseApiKey() {
+ return StringUtils.isNotBlank(apiKey);
+ }
+}
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientAuthConfiguration.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientConfiguration.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientConfiguration.java (rev 0)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientConfiguration.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -0,0 +1,66 @@
+/*
+ * #%L
+ * Maven helper plugin
+ *
+ * $Id$
+ * $HeadURL: http://svn.nuiton.org/svn/maven-helper-plugin/trunk/src/main/java/org/nuito… $
+ * %%
+ * Copyright (C) 2009 - 2010 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.client;
+
+import java.net.URL;
+
+/**
+ * Configuration for a {@link RedmineClient}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public interface RedmineClientConfiguration {
+
+ /** @return base url of server */
+ URL getUrl();
+
+ /** @return the encoding used to encode request to send */
+ String getEncoding();
+
+ /** @return {@code true} to make verbose client (show request and parameters) */
+ boolean isVerbose();
+
+ /** @return {@code true} if rest client does not need login */
+ boolean isAnonymous();
+
+ /** @param url the url of server to set */
+ void setUrl(URL url);
+
+ /** @param encoding the encodng used to encode request to set */
+ void setEncoding(String encoding);
+
+ /** @param verbose the flag verbose to set */
+ void setVerbose(boolean verbose);
+
+ /** @param anonymous the flag anonymous to set */
+ void setAnonymous(boolean anonymous);
+
+ RedmineClientAuthConfiguration getAuthConfiguration();
+
+ void setAuthConfiguration(RedmineClientAuthConfiguration authConfiguration);
+
+}
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineClientConfiguration.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java (rev 0)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -0,0 +1,450 @@
+package org.nuiton.jredmine.client;
+/*
+ * #%L
+ * JRedmine :: Client
+ * $Id$
+ * $HeadURL: http://svn.nuiton.org/svn/jredmine/branches/jredmine-1.x/jredmine-client/sr… $
+ * %%
+ * 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(a)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(a)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(a)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(a)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(a)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
+ };
+ }
+ }
+
+}
Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/client/RedmineRequestFactory.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRequestFactory.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRequestFactory.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRequestFactory.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -1,450 +0,0 @@
-package org.nuiton.jredmine.rest;
-/*
- * #%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(a)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 RedmineRestClient}.
- *
- * @author tchemit <chemit(a)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(a)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(a)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(a)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
- };
- }
- }
-
-}
Deleted: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRestClient.java
===================================================================
--- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRestClient.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRestClient.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -1,173 +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.rest;
-
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.StatusLine;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codehaus.plexus.util.StringUtils;
-import org.nuiton.io.rest.RequestFactory;
-import org.nuiton.io.rest.RestClient;
-import org.nuiton.io.rest.RestClientConfiguration;
-import org.nuiton.io.rest.RestRequest;
-import org.nuiton.io.rest.RestSession;
-import org.nuiton.jredmine.RedmineServiceConfiguration;
-import org.nuiton.jredmine.model.ModelHelper;
-
-import java.io.IOException;
-
-/**
- * Implementation of a {@link RestClient} to access a Redmine server via the
- * {@code redmine_rest} rails plugin.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @plexus.component role="org.nuiton.io.rest.RestClient" role-hint="redmine"
- * @since 1.0.0
- */
-public class RedmineRestClient extends RestClient {
-
- private static final Log log = LogFactory.getLog(RedmineRestClient.class);
-
- private final RequestFactory requestFactory;
-
- public RedmineRestClient() {
- requestFactory = new RedmineRequestFactory();
- requestFactory.addDefaultRequests();
- }
-
- public RedmineRestClient(RestClientConfiguration configuration) {
- super(configuration);
- requestFactory = new RedmineRequestFactory();
- requestFactory.addDefaultRequests();
- }
-
- @Override
- public RequestFactory getRequestFactory() {
- return requestFactory;
- }
-
- @Override
- protected void open(RestSession session) throws IOException {
-
- ping(session);
-
- if (!configuration.isAnonymous()) {
- login(session);
- }
- }
-
- @Override
- protected void close(RestSession session) throws IOException {
-
- if (session != null) {
- try {
- RestRequest request = getRequest(ModelHelper.LOGOUT_REQUEST_NAME);
- session.setOpen(false);
- session.doRequest(request);
- } finally {
- session.close();
- }
- }
- }
-
- protected void ping(RestSession session) throws IOException {
-
- try {
-
- RestRequest request = getRequest(ModelHelper.PING_REQUEST_NAME);
- HttpMethod gm = session.doRequest(request);
-
- StatusLine sl = gm.getStatusLine();
- int statusCode = sl.getStatusCode();
- if (log.isDebugEnabled()) {
- log.debug("status code " + statusCode + " for " + gm.getPath());
- }
-
- if (statusCode != HttpStatus.SC_OK) {
- gm.releaseConnection();
- throw new IOException(
- "Got error code <" + statusCode + ":" +
- sl.getReasonPhrase() + "> on " + gm.getPath());
- }
-
- String content = gm.getResponseBodyAsString();
-
- boolean ok = "ping".equals(content);
- if (!ok) {
- throw new IOException(
- "can not connect to " + configuration.getRestUrl());
- }
- } catch (IOException ex) {
- throw ex;
- } catch (Exception ex) {
- throw new IOException(
- "could not ping " + configuration.getRestUrl() +
- " for reason " + ex.getMessage(), ex);
- }
- }
-
- protected void login(RestSession session) throws IOException {
-
- RestRequest request;
- String apiKey = getConfiguration().getApiKey();
- boolean useApiKey = StringUtils.isNotBlank(apiKey);
- if (useApiKey) {
-
- // 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,
- configuration.getRestUsername(),
- configuration.getRestPassword());
- }
-
- HttpMethod gm = session.doRequest(request);
-
- StatusLine sl = gm.getStatusLine();
- int statusCode = sl.getStatusCode();
- if (log.isDebugEnabled()) {
- log.debug("status code " + statusCode + " for " + gm.getPath());
- }
-
- if (statusCode != HttpStatus.SC_OK) {
- gm.releaseConnection();
- throw new IOException(
- "Got error code <" + statusCode + ":" +
- sl.getReasonPhrase() + "> on " + gm.getPath());
- }
-
- // ok session is logged in
-
- }
-
- @Override
- public RedmineServiceConfiguration getConfiguration() {
- return (RedmineServiceConfiguration) super.getConfiguration();
- }
-}
Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineFixtures.java
===================================================================
--- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineFixtures.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineFixtures.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -66,469 +66,6 @@
return "1925";
}
-// public List<Attachment> getAttachments() {
-// return get(Attachment.class);
-// }
-//
-// public List<Issue> getIssues() {
-// return get(Issue.class);
-// }
-//
-// public List<Project> getProjects() {
-// return get(Project.class);
-// }
-//
-// public List<Tracker> getTrackers() {
-// return get(Tracker.class);
-// }
-//
-// public List<User> getUsers() {
-// return get(User.class);
-// }
-//
-// public List<Version> getVersions() {
-// return get(Version.class);
-// }
-//
-// public <T> List<T> get(Class<T> modelType) {
-// if (model == null) {
-// try {
-// loadModel();
-// } catch (Exception ex) {
-// throw new RuntimeException(ex);
-// }
-// }
-// return (List<T>) model.get(modelType);
-// }
-//
-// public <T> T get(Class<T> type, int pos) {
-// List<T> ts = get(type);
-// return ts.get(pos);
-// }
-//
-// private void loadModel()
-// throws Exception {
-// model = ArrayListMultimap.create();
-//
-// Attachment tempA;
-// tempA = new Attachment();
-// tempA.setAuthorId((Integer) RedmineDataConverter.Integer.convert("4"));
-// tempA.setContainerId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempA.setId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempA.setFilesize((Integer) RedmineDataConverter.Integer.convert("411"));
-// tempA.setDownloads((Integer) RedmineDataConverter.Integer.convert("0"));
-// tempA.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-05T12:56:41+02:00"));
-// tempA.setContainerType((String) RedmineDataConverter.Text.convert("Version"));
-// tempA.setContentType((String) RedmineDataConverter.Text.convert("application/json"));
-// tempA.setDigest((String) RedmineDataConverter.Text.convert("6ea84342c7475c05fb077b4aca832f9a"));
-// tempA.setDiskFilename((String) RedmineDataConverter.Text.convert("090905125641_get_issue.json"));
-// tempA.setFilename((String) RedmineDataConverter.Text.convert("get_issue.json"));
-// model.put(Attachment.class, tempA);
-// tempA = new Attachment();
-// tempA.setAuthorId((Integer) RedmineDataConverter.Integer.convert("4"));
-// tempA.setContainerId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempA.setId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempA.setFilesize((Integer) RedmineDataConverter.Integer.convert("411"));
-// tempA.setDownloads((Integer) RedmineDataConverter.Integer.convert("0"));
-// tempA.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-05T12:56:41+02:00"));
-// tempA.setContainerType((String) RedmineDataConverter.Text.convert("Version"));
-// tempA.setContentType((String) RedmineDataConverter.Text.convert("application/json"));
-// tempA.setDigest((String) RedmineDataConverter.Text.convert("6ea84342c7475c05fb077b4aca832f9a"));
-// tempA.setDiskFilename((String) RedmineDataConverter.Text.convert("090905125641_get_issue.json2"));
-// tempA.setFilename((String) RedmineDataConverter.Text.convert("get_issue.json2"));
-// model.put(Attachment.class, tempA);
-//
-// Issue tempI;
-// tempI = new Issue();
-// tempI.setAuthorId((Integer) RedmineDataConverter.Integer.convert("5"));
-// tempI.setCategoryId((Integer) RedmineDataConverter.Integer.convert("2"));
-// tempI.setDoneRatio((Integer) RedmineDataConverter.Integer.convert("0"));
-// tempI.setLockVersion((Integer) RedmineDataConverter.Integer.convert("7"));
-// tempI.setPriorityId((Integer) RedmineDataConverter.Integer.convert("4"));
-// tempI.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempI.setStatusId((Integer) RedmineDataConverter.Integer.convert("3"));
-// tempI.setTrackerId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempI.setFixedVersionId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempI.setId((Integer) RedmineDataConverter.Integer.convert("3"));
-// tempI.setParentId((Integer) RedmineDataConverter.Integer.convert("3"));
-// tempI.setRootId((Integer) RedmineDataConverter.Integer.convert("3"));
-// tempI.setLft((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempI.setRgt((Integer) RedmineDataConverter.Integer.convert("2"));
-// tempI.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-04T20:11:52+02:00"));
-// tempI.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T00:37:40+02:00"));
-// tempI.setStartDate((Date) RedmineDataConverter.Date.convert("2009-09-04"));
-// tempI.setDescription((String) RedmineDataConverter.Text.convert("avec une description !"));
-// tempI.setSubject((String) RedmineDataConverter.Text.convert("yes!"));
-// model.put(Issue.class, tempI);
-// tempI = new Issue();
-// tempI.setAuthorId((Integer) RedmineDataConverter.Integer.convert("5"));
-// tempI.setCategoryId((Integer) RedmineDataConverter.Integer.convert("2"));
-// tempI.setDoneRatio((Integer) RedmineDataConverter.Integer.convert("0"));
-// tempI.setLockVersion((Integer) RedmineDataConverter.Integer.convert("7"));
-// tempI.setPriorityId((Integer) RedmineDataConverter.Integer.convert("4"));
-// tempI.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempI.setStatusId((Integer) RedmineDataConverter.Integer.convert("3"));
-// tempI.setTrackerId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempI.setFixedVersionId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempI.setId((Integer) RedmineDataConverter.Integer.convert("4"));
-// tempI.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-04T20:11:52+02:00"));
-// tempI.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T00:37:40+02:00"));
-// tempI.setStartDate((Date) RedmineDataConverter.Date.convert("2009-09-04"));
-// tempI.setDescription((String) RedmineDataConverter.Text.convert("avec une description !2"));
-// tempI.setSubject((String) RedmineDataConverter.Text.convert("yes!2"));
-// model.put(Issue.class, tempI);
-//
-// Project tempP;
-// tempP = new Project();
-// tempP.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-04T18:11:54+02:00"));
-// tempP.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-04T18:11:54+02:00"));
-// tempP.setIdentifier((String) RedmineDataConverter.Text.convert("one"));
-// tempP.setName((String) RedmineDataConverter.Text.convert("one"));
-// tempP.setId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempP.setLft((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempP.setRgt((Integer) RedmineDataConverter.Integer.convert("2"));
-// tempP.setProjectsCount((Integer) RedmineDataConverter.Integer.convert("0"));
-// tempP.setStatus((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempP.setIsPublic((Boolean) RedmineDataConverter.Boolean.convert("true"));
-// model.put(Project.class, tempP);
-// tempP = new Project();
-// tempP.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-05T16:22:14+02:00"));
-// tempP.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-05T16:22:29+02:00"));
-// tempP.setIdentifier((String) RedmineDataConverter.Text.convert("two"));
-// tempP.setName((String) RedmineDataConverter.Text.convert("two"));
-// tempP.setId((Integer) RedmineDataConverter.Integer.convert("2"));
-// tempP.setProjectsCount((Integer) RedmineDataConverter.Integer.convert("0"));
-// tempP.setStatus((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempP.setIsPublic((Boolean) RedmineDataConverter.Boolean.convert("false"));
-// model.put(Project.class, tempP);
-//
-// Tracker tempT;
-// tempT = new Tracker();
-// tempT.setId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempT.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempT.setTrackerId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempT.setPosition((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempT.setIsInChlog((Boolean) RedmineDataConverter.Boolean.convert("true"));
-// tempT.setIsInRoadmap((Boolean) RedmineDataConverter.Boolean.convert("false"));
-// tempT.setName((String) RedmineDataConverter.Text.convert("Anomalie"));
-// model.put(Tracker.class, tempT);
-// tempT = new Tracker();
-// tempT.setId((Integer) RedmineDataConverter.Integer.convert("2"));
-// tempT.setIsInChlog((Boolean) RedmineDataConverter.Boolean.convert("true"));
-// tempT.setIsInRoadmap((Boolean) RedmineDataConverter.Boolean.convert("true"));
-// tempT.setName((String) RedmineDataConverter.Text.convert("Evolution"));
-// tempT.setPosition((Integer) RedmineDataConverter.Integer.convert("2"));
-// tempT.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempT.setTrackerId((Integer) RedmineDataConverter.Integer.convert("2"));
-// model.put(Tracker.class, tempT);
-// tempT = new Tracker();
-// tempT.setId((Integer) RedmineDataConverter.Integer.convert("3"));
-// tempT.setIsInChlog((Boolean) RedmineDataConverter.Boolean.convert("false"));
-// tempT.setIsInRoadmap((Boolean) RedmineDataConverter.Boolean.convert("false"));
-// tempT.setName((String) RedmineDataConverter.Text.convert("Assistance"));
-// tempT.setPosition((Integer) RedmineDataConverter.Integer.convert("3"));
-// tempT.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempT.setTrackerId((Integer) RedmineDataConverter.Integer.convert("3"));
-// model.put(Tracker.class, tempT);
-//
-// User tempU;
-// tempU = new User();
-// tempU.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-04T17:24:46+02:00"));
-// tempU.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T01:23:59+02:00"));
-// tempU.setLastLoginOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T01:23:59+02:00"));
-// tempU.setId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempU.setMemberId((Integer) RedmineDataConverter.Integer.convert("5"));
-// tempU.setRoleId((Integer) RedmineDataConverter.Integer.convert("3"));
-// tempU.setStatus((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempU.setAdmin((Boolean) RedmineDataConverter.Boolean.convert("true"));
-// tempU.setMailNotification((Boolean) RedmineDataConverter.Boolean.convert("true"));
-// tempU.setFirstname((String) RedmineDataConverter.Text.convert("Redmine"));
-// tempU.setHashedPassword(
-// (String) RedmineDataConverter.Text.convert("70c881d4a26984ddce795f6f71817c9cf4480e79"));
-// tempU.setLanguage((String) RedmineDataConverter.Text.convert("fr"));
-// tempU.setLastname((String) RedmineDataConverter.Text.convert("Admin"));
-// tempU.setLogin((String) RedmineDataConverter.Text.convert("admin"));
-// tempU.setMail((String) RedmineDataConverter.Text.convert("dummy(a)codelutin.com"));
-// tempU.setIdentityUrl((String) RedmineDataConverter.Text.convert("yo"));
-// model.put(User.class, tempU);
-// tempU = new User();
-// tempU.setAdmin((Boolean) RedmineDataConverter.Boolean.convert("true"));
-// tempU.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-04T19:49:02+02:00"));
-// tempU.setFirstname((String) RedmineDataConverter.Text.convert("tony"));
-// tempU.setHashedPassword(
-// (String) RedmineDataConverter.Text.convert("8aed1322e5450badb078e1fb60a817a1df25a2ca"));
-// tempU.setId((Integer) RedmineDataConverter.Integer.convert("5"));
-// tempU.setLanguage((String) RedmineDataConverter.Text.convert("fr"));
-// tempU.setLastLoginOn((Date) RedmineDataConverter.Datetime.convert("2009-09-04T19:49:38+02:00"));
-// tempU.setLastname((String) RedmineDataConverter.Text.convert("chemit2"));
-// tempU.setLogin((String) RedmineDataConverter.Text.convert("tchemit2"));
-// tempU.setMail((String) RedmineDataConverter.Text.convert("chemit(a)codelutin.com"));
-// tempU.setMailNotification((Boolean) RedmineDataConverter.Boolean.convert("false"));
-// tempU.setMemberId((Integer) RedmineDataConverter.Integer.convert("4"));
-// tempU.setRoleId((Integer) RedmineDataConverter.Integer.convert("3"));
-// tempU.setStatus((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempU.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-04T19:49:38+02:00"));
-// model.put(User.class, tempU);
-// tempU = new User();
-// tempU.setAdmin((Boolean) RedmineDataConverter.Boolean.convert("false"));
-// tempU.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-05T16:24:11+02:00"));
-// tempU.setFirstname((String) RedmineDataConverter.Text.convert("dev"));
-// tempU.setHashedPassword(
-// (String) RedmineDataConverter.Text.convert("70c881d4a26984ddce795f6f71817c9cf4480e79"));
-// tempU.setId((Integer) RedmineDataConverter.Integer.convert("7"));
-// tempU.setLanguage((String) RedmineDataConverter.Text.convert("fr"));
-// tempU.setLastLoginOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T16:34:39+02:00"));
-// tempU.setLastname((String) RedmineDataConverter.Text.convert("dev"));
-// tempU.setLogin((String) RedmineDataConverter.Text.convert("dev"));
-// tempU.setMail((String) RedmineDataConverter.Text.convert("dev3(a)ynot-home.info"));
-// tempU.setMailNotification((Boolean) RedmineDataConverter.Boolean.convert("false"));
-// tempU.setMemberId((Integer) RedmineDataConverter.Integer.convert("9"));
-// tempU.setRoleId((Integer) RedmineDataConverter.Integer.convert("4"));
-// tempU.setStatus((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempU.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T16:34:39+02:00"));
-// model.put(User.class, tempU);
-//
-// Version tempV;
-// tempV = new Version();
-// tempV.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T02:47:39+02:00"));
-// tempV.setDescription((String) RedmineDataConverter.Text.convert("yo"));
-// tempV.setId((Integer) RedmineDataConverter.Integer.convert("9"));
-// tempV.setName((String) RedmineDataConverter.Text.convert("yor"));
-// tempV.setSharing((String) RedmineDataConverter.Text.convert("none"));
-// tempV.setStatus((String) RedmineDataConverter.Text.convert("open"));
-// tempV.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempV.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T02:50:49+02:00"));
-// model.put(Version.class, tempV);
-// tempV = new Version();
-// tempV.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T03:05:09+02:00"));
-// tempV.setDescription((String) RedmineDataConverter.Text.convert("ysssoye"));
-// tempV.setId((Integer) RedmineDataConverter.Integer.convert("13"));
-// tempV.setName((String) RedmineDataConverter.Text.convert("rrrrrrrrrouuuuuua"));
-// tempV.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempV.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T03:05:09+02:00"));
-// model.put(Version.class, tempV);
-// tempV = new Version();
-// tempV.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T03:07:58+02:00"));
-// tempV.setDescription((String) RedmineDataConverter.Text.convert("ysssoye"));
-// tempV.setId((Integer) RedmineDataConverter.Integer.convert("15"));
-// tempV.setName((String) RedmineDataConverter.Text.convert("aaaauuuuuua"));
-// tempV.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempV.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T03:07:58+02:00"));
-// model.put(Version.class, tempV);
-// tempV = new Version();
-// tempV.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T04:12:25+02:00"));
-// tempV.setDescription((String) RedmineDataConverter.Text.convert("ysssoyeppppppppppppppppp"));
-// tempV.setId((Integer) RedmineDataConverter.Integer.convert("16"));
-// tempV.setName((String) RedmineDataConverter.Text.convert("aaaau"));
-// tempV.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempV.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T04:13:20+02:00"));
-// model.put(Version.class, tempV);
-// tempV = new Version();
-// tempV.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T03:05:40+02:00"));
-// tempV.setDescription((String) RedmineDataConverter.Text.convert("ysssoye"));
-// tempV.setId((Integer) RedmineDataConverter.Integer.convert("14"));
-// tempV.setName((String) RedmineDataConverter.Text.convert("aaaaaaaaaarrrrrrrrrouuuuuua"));
-// tempV.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempV.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T03:05:40+02:00"));
-// model.put(Version.class, tempV);
-// tempV = new Version();
-// tempV.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-05T00:39:15+02:00"));
-// tempV.setId((Integer) RedmineDataConverter.Integer.convert("5"));
-// tempV.setName((String) RedmineDataConverter.Text.convert("2"));
-// tempV.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempV.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-05T00:39:15+02:00"));
-// model.put(Version.class, tempV);
-// tempV = new Version();
-// tempV.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-04T18:13:05+02:00"));
-// tempV.setId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempV.setName((String) RedmineDataConverter.Text.convert("1.0.0"));
-// tempV.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempV.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-04T18:13:05+02:00"));
-// model.put(Version.class, tempV);
-// tempV = new Version();
-// tempV.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T03:00:12+02:00"));
-// tempV.setDescription((String) RedmineDataConverter.Text.convert("yoye"));
-// tempV.setEffectiveDate((Date) RedmineDataConverter.Date.convert("2009-09-06"));
-// tempV.setId((Integer) RedmineDataConverter.Integer.convert("11"));
-// tempV.setName((String) RedmineDataConverter.Text.convert("yaouuuuuua"));
-// tempV.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempV.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T03:00:12+02:00"));
-// model.put(Version.class, tempV);
-// tempV = new Version();
-// tempV.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T02:50:59+02:00"));
-// tempV.setDescription((String) RedmineDataConverter.Text.convert("yoye"));
-// tempV.setEffectiveDate((Date) RedmineDataConverter.Date.convert("2009-09-06"));
-// tempV.setId((Integer) RedmineDataConverter.Integer.convert("10"));
-// tempV.setName((String) RedmineDataConverter.Text.convert("ya"));
-// tempV.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempV.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T02:54:16+02:00"));
-// model.put(Version.class, tempV);
-// tempV = new Version();
-// tempV.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T03:00:37+02:00"));
-// tempV.setDescription((String) RedmineDataConverter.Text.convert("ysssoye"));
-// tempV.setEffectiveDate((Date) RedmineDataConverter.Date.convert("2009-09-06"));
-// tempV.setId((Integer) RedmineDataConverter.Integer.convert("12"));
-// tempV.setName((String) RedmineDataConverter.Text.convert("ouuuuuua"));
-// tempV.setProjectId((Integer) RedmineDataConverter.Integer.convert("1"));
-// tempV.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-06T03:00:42+02:00"));
-// model.put(Version.class, tempV);
-//
-// IssueStatus tempIS;
-// tempIS = new IssueStatus();
-// tempIS.setId(1);
-// tempIS.setName("Nouveau");
-// tempIS.setPosition(1);
-// tempIS.setDefaultDoneRatio(10);
-// tempIS.setIsClosed(false);
-// tempIS.setIsDefault(true);
-// model.put(IssueStatus.class, tempIS);
-// tempIS = new IssueStatus();
-// tempIS.setId(2);
-// tempIS.setName("Assigné");
-// tempIS.setPosition(2);
-// tempIS.setIsClosed(false);
-// tempIS.setIsDefault(false);
-// model.put(IssueStatus.class, tempIS);
-// tempIS = new IssueStatus();
-// tempIS.setId(3);
-// tempIS.setName("Résolu");
-// tempIS.setPosition(3);
-// tempIS.setIsClosed(false);
-// tempIS.setIsDefault(false);
-// model.put(IssueStatus.class, tempIS);
-// tempIS = new IssueStatus();
-// tempIS.setId(4);
-// tempIS.setName("Commentaire");
-// tempIS.setPosition(4);
-// tempIS.setIsClosed(false);
-// tempIS.setIsDefault(false);
-// model.put(IssueStatus.class, tempIS);
-// tempIS = new IssueStatus();
-// tempIS.setId(5);
-// tempIS.setName("Fermé");
-// tempIS.setPosition(5);
-// tempIS.setIsClosed(true);
-// tempIS.setIsDefault(false);
-// model.put(IssueStatus.class, tempIS);
-// tempIS = new IssueStatus();
-// tempIS.setId(6);
-// tempIS.setPosition(6);
-// tempIS.setName("Rejeté");
-// tempIS.setIsClosed(true);
-// tempIS.setIsDefault(false);
-// model.put(IssueStatus.class, tempIS);
-//
-// IssuePriority tempIP;
-// tempIP = new IssuePriority();
-// tempIP.setId(3);
-// tempIP.setParentId(1);
-// tempIP.setProjectId(2);
-// tempIP.setName("Bas");
-// tempIP.setPosition(1);
-// tempIP.setOpt("IPRI");
-// tempIP.setIsDefault(false);
-// tempIP.setActive(true);
-// model.put(IssuePriority.class, tempIP);
-// tempIP = new IssuePriority();
-// tempIP.setId(4);
-// tempIP.setName("Normal");
-// tempIP.setPosition(2);
-// tempIP.setOpt("IPRI");
-// tempIP.setIsDefault(true);
-// model.put(IssuePriority.class, tempIP);
-// tempIP = new IssuePriority();
-// tempIP.setId(5);
-// tempIP.setName("Haut");
-// tempIP.setPosition(3);
-// tempIP.setOpt("IPRI");
-// tempIP.setIsDefault(false);
-// model.put(IssuePriority.class, tempIP);
-// tempIP = new IssuePriority();
-// tempIP.setId(6);
-// tempIP.setName("Urgent");
-// tempIP.setPosition(4);
-// tempIP.setOpt("IPRI");
-// tempIP.setIsDefault(false);
-// model.put(IssuePriority.class, tempIP);
-// tempIP = new IssuePriority();
-// tempIP.setId(7);
-// tempIP.setName("Immédiat");
-// tempIP.setPosition(5);
-// tempIP.setOpt("IPRI");
-// tempIP.setIsDefault(false);
-// model.put(IssuePriority.class, tempIP);
-//
-// IssueCategory tempIC;
-// tempIC = new IssueCategory();
-// tempIC.setId(1);
-// tempIC.setName("categorie one");
-// tempIC.setProjectId(1);
-// model.put(IssueCategory.class, tempIC);
-// tempIC = new IssueCategory();
-// tempIC.setId(2);
-// tempIC.setName("categorie two");
-// tempIC.setProjectId(1);
-// model.put(IssueCategory.class, tempIC);
-//
-// News tempN;
-// tempN = new News();
-// tempN.setId(85);
-// tempN.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-17T21:50:26+02:00"));
-// tempN.setProjectId(1);
-// tempN.setAuthorId(4);
-// tempN.setCommentsCount(0);
-// tempN.setDescription("description");
-// tempN.setSummary("summary");
-// tempN.setTitle("title");
-// model.put(News.class, tempN);
-// tempN = new News();
-// tempN.setId(86);
-// tempN.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-09-17T21:55:26+02:00"));
-// tempN.setProjectId(1);
-// tempN.setAuthorId(4);
-// tempN.setCommentsCount(0);
-// tempN.setDescription("description2");
-// tempN.setSummary("summary2");
-// tempN.setTitle("title2");
-// model.put(News.class, tempN);
-//
-// TimeEntry tempE;
-//
-// tempE = new TimeEntry();
-// tempE.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-12-31T23:02:02+01:00"));
-// tempE.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-12-31T23:02:02+01:00"));
-// tempE.setSpentOn((Date) RedmineDataConverter.Date.convert("2009-12-31"));
-// tempE.setId(1);
-// tempE.setProjectId(1);
-// tempE.setUserId(4);
-// tempE.setIssueId(6);
-// tempE.setActivityId(8);
-//
-// tempE.setHours(1);
-// tempE.setTmonth(12);
-// tempE.setTyear(2009);
-// tempE.setTweek(53);
-// tempE.setComments("Test");
-// model.put(TimeEntry.class, tempE);
-//
-// tempE = new TimeEntry();
-// tempE.setCreatedOn((Date) RedmineDataConverter.Datetime.convert("2009-12-31T23:10:01+01:00"));
-// tempE.setUpdatedOn((Date) RedmineDataConverter.Datetime.convert("2009-12-31T23:10:01+01:00"));
-// tempE.setSpentOn((Date) RedmineDataConverter.Date.convert("2009-12-31"));
-// tempE.setId(2);
-// tempE.setProjectId(1);
-// tempE.setUserId(4);
-// tempE.setIssueId(6);
-// tempE.setActivityId(9);
-//
-// tempE.setHours(2);
-// tempE.setTmonth(12);
-// tempE.setTyear(2009);
-// tempE.setTweek(53);
-// tempE.setComments("deuxième temps");
-// model.put(TimeEntry.class, tempE);
-// }
-
public Version versionToAdd() {
Version version = new Version();
version.setId(TIMESTAMP);
Added: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java
===================================================================
--- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java (rev 0)
+++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -0,0 +1,278 @@
+/*
+ * #%L
+ * JRedmine :: Client
+ *
+ * $Id$
+ * $HeadURL: http://svn.nuiton.org/svn/jredmine/branches/jredmine-1.x/jredmine-client/sr… $
+ * %%
+ * 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.client;
+
+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.test.RedmineFixtureClassRule;
+
+import java.io.InputStream;
+
+/**
+ * Tests the {@link RedmineClient}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.5
+ */
+public class RedmineClientTest {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(RedmineClientTest.class);
+
+ @ClassRule
+ public static final RedmineFixtureClassRule<RedmineFixtures> checkConfigRule =
+ RedmineFixtureClassRule.newFixtures(RedmineFixtures.class);
+
+ protected RedmineFixtures getFixtures() {
+ return checkConfigRule.getFixtures();
+ }
+
+ protected RedmineClient client;
+
+ protected String projectName;
+
+ protected String versionName;
+
+ protected String issueId;
+
+ @Before
+ public void setUp() throws Exception {
+
+ RedmineFixtures fixtures = checkConfigRule.getFixtures();
+
+ client = new RedmineClient(getConfiguration());
+ client.open();
+
+ projectName = fixtures.projectName();
+ versionName = fixtures.versionName();
+ issueId = fixtures.issueId();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+
+ if (client != null) {
+ client.close();
+ }
+ }
+
+ @Test
+ public void isOpen() throws Exception {
+ Assert.assertTrue(client.isOpen());
+ }
+
+ @Test
+ public void isClose() throws Exception {
+ Assert.assertTrue(client.isOpen());
+ client.close();
+ Assert.assertFalse(client.isOpen());
+ }
+
+ @Test
+ public void getProjects() throws Exception {
+
+ askData(ModelHelper.GET_ALL_PROJECT_REQUEST_NAME);
+ }
+
+ @Test
+ public void getIssuePriorities() throws Exception {
+
+ askData(ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME);
+ }
+
+ @Test
+ public void getIssueStatuses() throws Exception {
+
+ askData(ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME);
+ }
+
+ @Test
+ public void getProject() throws Exception {
+
+ askData(ModelHelper.GET_PROJECT_REQUEST_NAME, projectName);
+ }
+
+ @Test
+ public void getIssueCategories() throws Exception {
+
+ askData(ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME, projectName);
+ }
+
+ @Test
+ public void getTrackers() throws Exception {
+
+ askData(ModelHelper.GET_ALL_TRACKER_REQUEST_NAME, projectName);
+ }
+
+ @Test
+ public void getNews() throws Exception {
+
+ askData(ModelHelper.GET_ALL_NEWS_REQUEST_NAME, projectName);
+ }
+
+ @Test
+ public void getProjectMembers() throws Exception {
+
+ askData(ModelHelper.GET_ALL_USER_REQUEST_NAME, projectName);
+ }
+
+ @Test
+ public void getProjectIssues() throws Exception {
+
+ askData(ModelHelper.GET_ALL_PROJECT_ISSUES_REQUEST_NAME, projectName);
+ }
+
+ @Test
+ public void getVersions() throws Exception {
+
+ askData(ModelHelper.GET_ALL_VERSION_REQUEST_NAME, projectName);
+ }
+
+ @Test
+ public void getVersion() throws Exception {
+
+ askData(ModelHelper.GET_VERSION_REQUEST_NAME, projectName, versionName);
+ }
+
+ @Test
+ public void getVersionIssues() throws Exception {
+
+ askData(ModelHelper.GET_ALL_ISSUES_REQUEST_NAME, projectName, versionName);
+ }
+
+ @Test
+ public void getOpenedIssues() throws Exception {
+
+ askData(ModelHelper.GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME, projectName);
+ }
+
+ @Test
+ public void getClosedIssues() throws Exception {
+
+ askData(ModelHelper.GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME, projectName);
+ }
+
+ @Test
+ public void getIssueTimeEntries() throws Exception {
+
+ askData(ModelHelper.GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME, projectName, issueId);
+ }
+
+ @Test
+ public void getAttachments() throws Exception {
+
+ askData(ModelHelper.GET_ALL_ATTACHMENTS_REQUEST_NAME, projectName, versionName);
+ }
+
+ @Test
+ public void login() throws Exception {
+
+ Assume.assumeTrue(!getConfiguration().isAnonymous());
+ //Assume.assumeTrue(StringUtils.isBlank(getConfiguration().getApiKey()));
+ client.open();
+ }
+
+ @Test
+ public void loginByApiKey() throws Exception {
+
+ Assume.assumeTrue(!getConfiguration().isAnonymous());
+ //Assume.assumeTrue(StringUtils.isNotBlank(getConfiguration().getAuthConfiguration().getApiKey()));
+ client.open();
+ }
+
+ @Test
+ public void getUserProjects() throws Exception {
+
+ Assume.assumeTrue(!getConfiguration().isAnonymous());
+ askData(ModelHelper.GET_USER_PROJECTS_REQUEST_NAME);
+ }
+
+ @Test
+ public void addVersion() throws Exception {
+ Assume.assumeTrue(!getConfiguration().isAnonymous());
+ //TODO
+ }
+
+ @Test
+ public void addAttachment() throws Exception {
+ Assume.assumeTrue(!getConfiguration().isAnonymous());
+ //TODO
+ }
+
+ @Test
+ public void addNews() throws Exception {
+ Assume.assumeTrue(!getConfiguration().isAnonymous());
+ //TODO
+ }
+
+ @Test
+ public void updateVersion() throws Exception {
+ Assume.assumeTrue(!getConfiguration().isAnonymous());
+ //TODO
+ }
+
+ @Test
+ public void nextVersion() throws Exception {
+ Assume.assumeTrue(!getConfiguration().isAnonymous());
+ //TODO
+ }
+
+ @Test
+ public void addIssueTime() throws Exception {
+ Assume.assumeTrue(!getConfiguration().isAnonymous());
+ //TODO
+ }
+
+ protected void askData(String requestId, Object... params) throws Exception {
+
+ 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);
+ }
+ askData.close();
+ } finally {
+ IOUtil.close(askData);
+ }
+ }
+
+ protected RedmineServiceConfiguration getConfiguration() {
+ return checkConfigRule.getConf();
+ }
+}
Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineClientTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java
===================================================================
--- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java (rev 0)
+++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -0,0 +1,244 @@
+package org.nuiton.jredmine.client;
+/*
+ * #%L
+ * JRedmine :: Client
+ * $Id$
+ * $HeadURL: http://svn.nuiton.org/svn/jredmine/branches/jredmine-1.x/jredmine-client/sr… $
+ * %%
+ * 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(a)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);
+ }
+}
Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/client/RedmineRequestFactoryTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Deleted: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRequestFactoryTest.java
===================================================================
--- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRequestFactoryTest.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRequestFactoryTest.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -1,243 +0,0 @@
-package org.nuiton.jredmine.rest;
-/*
- * #%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 java.util.Arrays;
-
-/**
- * Tests the {@link RedmineRequestFactory}.
- *
- * @author tchemit <chemit(a)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);
- }
-}
Deleted: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java
===================================================================
--- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -1,272 +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.rest;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.StringUtils;
-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.test.RedmineAnonymousFixtureClassRule;
-
-import java.io.InputStream;
-
-/**
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.0.0
- */
-public class RedmineRestClientTest {
-
- /** Logger. */
- private static final Log log =
- LogFactory.getLog(RedmineRestClientTest.class);
-
- @ClassRule
- public static final RedmineAnonymousFixtureClassRule<RedmineFixtures> checkConfigRule =
- RedmineAnonymousFixtureClassRule.newFixtures(RedmineFixtures.class);
-
- protected RedmineFixtures getFixtures() {
- return checkConfigRule.getFixtures();
- }
-
- protected RedmineRestClient client;
-
- protected String projectName;
-
- protected String versionName;
-
- protected String issueId;
-
- @Before
- public void setUp() throws Exception {
-
- RedmineFixtures fixtures = checkConfigRule.getFixtures();
-
- client = new RedmineRestClient(getConfiguration());
- client.open();
-
- projectName = fixtures.projectName();
- versionName = fixtures.versionName();
- issueId = fixtures.issueId();
- }
-
- @After
- public void tearDown() throws Exception {
-
- if (client != null) {
- client.close();
- }
- }
-
- @Test
- public void isOpen() throws Exception {
- Assert.assertTrue(client.isOpen());
- }
-
- @Test
- public void isClose() throws Exception {
- Assert.assertTrue(client.isOpen());
- client.close();
- Assert.assertFalse(client.isOpen());
- }
-
- @Test
- public void getProjects() throws Exception {
-
- askData(ModelHelper.GET_ALL_PROJECT_REQUEST_NAME);
- }
-
- @Test
- public void getIssuePriorities() throws Exception {
-
- askData(ModelHelper.GET_ALL_ISSUE_PRIORITY_REQUEST_NAME);
- }
-
- @Test
- public void getIssueStatuses() throws Exception {
-
- askData(ModelHelper.GET_ALL_ISSUE_STATUS_REQUEST_NAME);
- }
-
- @Test
- public void getProject() throws Exception {
-
- askData(ModelHelper.GET_PROJECT_REQUEST_NAME, projectName);
- }
-
- @Test
- public void getIssueCategories() throws Exception {
-
- askData(ModelHelper.GET_ALL_ISSUE_CATEGORY_REQUEST_NAME, projectName);
- }
-
- @Test
- public void getTrackers() throws Exception {
-
- askData(ModelHelper.GET_ALL_TRACKER_REQUEST_NAME, projectName);
- }
-
- @Test
- public void getNews() throws Exception {
-
- askData(ModelHelper.GET_ALL_NEWS_REQUEST_NAME, projectName);
- }
-
- @Test
- public void getProjectMembers() throws Exception {
-
- askData(ModelHelper.GET_ALL_USER_REQUEST_NAME, projectName);
- }
-
- @Test
- public void getProjectIssues() throws Exception {
-
- askData(ModelHelper.GET_ALL_PROJECT_ISSUES_REQUEST_NAME, projectName);
- }
-
- @Test
- public void getVersions() throws Exception {
-
- askData(ModelHelper.GET_ALL_VERSION_REQUEST_NAME, projectName);
- }
-
- @Test
- public void getVersion() throws Exception {
-
- askData(ModelHelper.GET_VERSION_REQUEST_NAME, projectName, versionName);
- }
-
- @Test
- public void getVersionIssues() throws Exception {
-
- askData(ModelHelper.GET_ALL_ISSUES_REQUEST_NAME, projectName, versionName);
- }
-
- @Test
- public void getOpenedIssues() throws Exception {
-
- askData(ModelHelper.GET_ALL_PROJECT_OPENED_ISSUES_REQUEST_NAME, projectName);
- }
-
- @Test
- public void getClosedIssues() throws Exception {
-
- askData(ModelHelper.GET_ALL_PROJECT_CLOSED_ISSUES_REQUEST_NAME, projectName);
- }
-
- @Test
- public void getIssueTimeEntries() throws Exception {
-
- askData(ModelHelper.GET_ALL_ISSUE_TIME_ENTRY_REQUEST_NAME, projectName, issueId);
- }
-
- @Test
- public void getAttachments() throws Exception {
-
- askData(ModelHelper.GET_ALL_ATTACHMENTS_REQUEST_NAME, projectName, versionName);
- }
-
- @Test
- public void login() throws Exception {
-
- Assume.assumeTrue(!getConfiguration().isAnonymous());
- Assume.assumeTrue(StringUtils.isBlank(getConfiguration().getApiKey()));
- client.open();
- }
-
- @Test
- public void loginByApiKey() throws Exception {
-
- Assume.assumeTrue(!getConfiguration().isAnonymous());
- Assume.assumeTrue(StringUtils.isNotBlank(getConfiguration().getApiKey()));
- client.open();
- }
-
- @Test
- public void getUserProjects() throws Exception {
-
- Assume.assumeTrue(!getConfiguration().isAnonymous());
- askData(ModelHelper.GET_USER_PROJECTS_REQUEST_NAME);
- }
-
- @Test
- public void addVersion() throws Exception {
- Assume.assumeTrue(!getConfiguration().isAnonymous());
- //TODO
- }
-
- @Test
- public void addAttachment() throws Exception {
- Assume.assumeTrue(!getConfiguration().isAnonymous());
- //TODO
- }
-
- @Test
- public void addNews() throws Exception {
- Assume.assumeTrue(!getConfiguration().isAnonymous());
- //TODO
- }
-
- @Test
- public void updateVersion() throws Exception {
- Assume.assumeTrue(!getConfiguration().isAnonymous());
- //TODO
- }
-
- @Test
- public void nextVersion() throws Exception {
- Assume.assumeTrue(!getConfiguration().isAnonymous());
- //TODO
- }
-
- @Test
- public void addIssueTime() throws Exception {
- Assume.assumeTrue(!getConfiguration().isAnonymous());
- //TODO
- }
-
- protected void askData(String requestId, Object... params) throws Exception {
-
- RestRequest request = client.getRequest(requestId, params);
- InputStream askData = client.askData(request);
- String toString = IOUtil.toString(askData);
- if (getConfiguration().isVerbose() && log.isInfoEnabled()) {
- log.info(toString);
- }
- }
-
- protected RedmineServiceConfiguration getConfiguration() {
- return checkConfigRule.getConf();
- }
-}
Modified: trunk/jredmine-maven-plugin/pom.xml
===================================================================
--- trunk/jredmine-maven-plugin/pom.xml 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/pom.xml 2012-10-13 21:50:04 UTC (rev 364)
@@ -64,6 +64,11 @@
</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-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -32,6 +32,7 @@
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.plugin.AbstractPlugin;
import java.net.URL;
@@ -64,16 +65,16 @@
@Parameter(property = "redmine.url")
protected URL url;
-// /**
-// * The redmine's server login apiKey.
-// * <p/>
-// * <b>Note:</b> This parameter (or username/password) is mandatory if you
-// * not use a {@code anonymous} service.
-// *
-// * @since 2.0
-// */
-// @Parameter(property = "redmine.apiKey")
-// protected String apiKey;
+ /**
+ * The redmine's server login apiKey.
+ * <p/>
+ * <b>Note:</b> This parameter (or username/password) is mandatory if you
+ * not use a {@code anonymous} service.
+ *
+ * @since 1.5
+ */
+ @Parameter(property = "redmine.apiKey")
+ protected String apiKey;
/**
* The redmine's server login.
@@ -167,6 +168,8 @@
protected boolean initOk = true;
+ private RedmineClientAuthConfiguration authConfiguration;
+
///////////////////////////////////////////////////////////////////////////
/// Plugin
///////////////////////////////////////////////////////////////////////////
@@ -206,62 +209,29 @@
}
///////////////////////////////////////////////////////////////////////////
- /// RestClientConfiguration
+ /// RedmineClientConfiguration
///////////////////////////////////////////////////////////////////////////
@Override
- public String getRestPassword() {
- return password;
+ public RedmineClientAuthConfiguration getAuthConfiguration() {
+ return authConfiguration;
}
@Override
- public URL getRestUrl() {
- return url;
+ public void setAuthConfiguration(RedmineClientAuthConfiguration authConfiguration) {
+ this.authConfiguration = authConfiguration;
}
@Override
- public String getRestUsername() {
- return username;
+ public URL getUrl() {
+ return url;
}
@Override
- public void setRestPassword(String restPassword) {
- password = restPassword;
+ public void setUrl(URL url) {
+ this.url = url;
}
- @Override
- public void setRestUrl(URL restUrl) {
- url = restUrl;
- }
-
- @Override
- public void setRestUsername(String restUsername) {
- username = restUsername;
- }
-
- /**
- * <strong>Note:</strong> Still not used (will be in version 2.0)
- *
- * @return the api key
- * @since 2.0
- */
- @Override
- public String getApiKey() {
- return null;
-// return apiKey;
- }
-
- /**
- * <strong>Note:</strong> Still not used (will be in version 2.0)
- *
- * @param apiKey the niew api key to set
- * @since 2.0
- */
- @Override
- public void setApiKey(String apiKey) {
-// this.apiKey = apiKey;
- }
-
///////////////////////////////////////////////////////////////////////////
/// AbstractRedmineMojo
///////////////////////////////////////////////////////////////////////////
@@ -290,10 +260,9 @@
} else if (issueManagement.getSystem() != null && !issueManagement.getSystem().equalsIgnoreCase(REDMINE_SYSTEM)) {
throw new MojoExecutionException("Redmine's Plugin only supports 'redmine' Issue Management system.");
}
+
// prepare Redmine service configuration
- URL url = getRestUrl();
-
if (url == null || url.toString().isEmpty()) {
// no redmine url specified, guess it from issueManagement
@@ -307,22 +276,27 @@
// apply configuration
- setRestUrl(url);
+ setUrl(url);
+ authConfiguration = RedmineClientAuthConfiguration.newConf(
+ apiKey, username, password
+ );
+
if (verbose) {
if (isAnonymous()) {
getLog().info("Redmine anonymous configuration :\n>> host : " +
- getRestUrl());
+ getUrl());
} else {
-// if (StringUtils.isNotBlank(apiKey)) {
-// getLog().info("Redmine configuration :\n>> host : " +
-// getRestUrl() + "\n>> apiKey: " +
-// getApiKey());
-// } else {
- getLog().info("Redmine configuration :\n>> host : " +
- getRestUrl() + "\n>> username : " +
- getRestUsername());
-// }
+
+ if (authConfiguration.isUseApiKey()) {
+ getLog().info("Redmine configuration :\n>> host : " +
+ getUrl() + "\n>> apiKey: " +
+ apiKey);
+ } else {
+ getLog().info("Redmine configuration :\n>> host : " +
+ getUrl() + "\n>> username : " +
+ username);
+ }
}
}
@@ -338,7 +312,7 @@
}
serviceInit = false;
initOk = false;
- getLog().error("could not init Redmine service [" + getRestUrl() + "] with user '" + getRestUsername() + "'", e);
+ getLog().error("could not init Redmine service [" + getUrl() + "]", e);
}
}
@@ -355,7 +329,7 @@
}
if (!serviceInit) {
- getLog().error("could not init Redmine service [" + getRestUrl() + "] with user '" + getRestUsername() + "'");
+ getLog().error("could not init Redmine service [" + getUrl() + "]");
return false;
}
@@ -379,6 +353,18 @@
/// Others
///////////////////////////////////////////////////////////////////////////
+ public void setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
protected void closeService() {
if (service != null) {
try {
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-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/DisplayDataMojo.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -44,7 +44,7 @@
import org.nuiton.jredmine.model.Tracker;
import org.nuiton.jredmine.model.User;
import org.nuiton.jredmine.model.Version;
-import org.nuiton.jredmine.rest.RedmineRequestFactory;
+import org.nuiton.jredmine.client.RedmineRequestFactory;
import org.nuiton.plugin.PluginHelper;
import java.util.Arrays;
@@ -159,7 +159,7 @@
}
///////////////////////////////////////////////////////////////////////////
- /// RestClientConfiguration
+ /// RedmineClientConfiguration
///////////////////////////////////////////////////////////////////////////
@Override
@@ -350,7 +350,7 @@
protected String getDataScope(Class<?> type) {
RequestFactory requestFactory =
- service.getDelegateImplementor().getSession().getRequestFactory();
+ service.getDelegateImplementor().getClient().getRequestFactory();
String requestName = typesToRequestName.get(type);
RestRequestBuilder requestBuilder =
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-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/GenerateChangesMojo.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -69,7 +69,6 @@
/** The actions understood by the changes.xml format. */
enum Actions {
-
add,
fix,
update,
@@ -209,7 +208,7 @@
}
///////////////////////////////////////////////////////////////////////////
- /// RestClientConfiguration
+ /// RedmineClientConfiguration
///////////////////////////////////////////////////////////////////////////
@Override
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-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/LoginMojo.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -35,10 +35,12 @@
import org.nuiton.jredmine.RedmineService;
import org.nuiton.jredmine.RedmineServiceConfiguration;
import org.nuiton.jredmine.RedmineServiceImplementor;
+import org.nuiton.jredmine.client.RedmineClientAuthConfiguration;
import org.nuiton.plugin.AbstractPlugin;
import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
import java.net.URL;
+import java.util.Properties;
/**
* Obtain login for the redmine server to use.
@@ -97,15 +99,15 @@
@Parameter(property = "redmine.serverId", required = true)
protected String serverId;
-// /**
-// * Un flag pour utiliser le clef API pluto que le login/password.
-// * <p/>
-// * Il faut alors que le serveur contienne en username le clef API (encrypté ou non).
-// *
-// * @since 2.0
-// */
-// @Parameter(property = "redmine.useApiKey", defaultValue = "false")
-// private boolean useApiKey;
+ /**
+ * Un flag pour utiliser le clef API pluto que le login/password.
+ * <p/>
+ * Il faut alors que le serveur contienne en username le clef API (encrypté ou non).
+ *
+ * @since 2.0
+ */
+ @Parameter(property = "redmine.useApiKey", defaultValue = "false")
+ private boolean useApiKey;
///////////////////////////////////////////////////////////////////////////
/// Mojo components
@@ -155,6 +157,9 @@
*/
protected static ShareServerSecretPlugin plugin;
+
+ private RedmineClientAuthConfiguration authConfiguration;
+
private static final String REDMINE_USERNAME = "redmine.username";
private static final String REDMINE_PASSWORD = "redmine.password";
@@ -199,7 +204,7 @@
}
///////////////////////////////////////////////////////////////////////////
- /// RestClientConfiguration
+ /// RedmineClientConfiguration
///////////////////////////////////////////////////////////////////////////
@Override
@@ -211,47 +216,26 @@
public void setAnonymous(boolean anonymous) {
}
- ///////////////////////////////////////////////////////////////////////////
- /// RestClientConfiguration
- ///////////////////////////////////////////////////////////////////////////
-
@Override
- public String getRestPassword() {
- return project.getProperties().getProperty(REDMINE_PASSWORD);
- }
-
- @Override
- public URL getRestUrl() {
+ public URL getUrl() {
return url;
}
@Override
- public String getRestUsername() {
- return project.getProperties().getProperty(REDMINE_USERNAME);
+ public void setUrl(URL url) {
+ this.url = url;
}
@Override
- public void setRestPassword(String restPassword) {
+ public RedmineClientAuthConfiguration getAuthConfiguration() {
+ return authConfiguration;
}
@Override
- public void setRestUrl(URL restUrl) {
- url = restUrl;
+ public void setAuthConfiguration(RedmineClientAuthConfiguration authConfiguration) {
+ this.authConfiguration = authConfiguration;
}
- @Override
- public void setRestUsername(String restUsername) {
- }
-
- @Override
- public String getApiKey() {
- return project.getProperties().getProperty(REDMINE_API_KEY);
- }
-
- @Override
- public void setApiKey(String apiKey) {
- }
-
///////////////////////////////////////////////////////////////////////////
/// AbstractPlugin
///////////////////////////////////////////////////////////////////////////
@@ -261,12 +245,12 @@
if (plugin == null) {
plugin = new ShareServerSecretPlugin();
plugin.setServerId(serverId);
-// if (useApiKey) {
-// plugin.setUsernameOut(REDMINE_API_KEY);
-// } else {
- plugin.setUsernameOut(REDMINE_USERNAME);
- plugin.setPasswordOut(REDMINE_PASSWORD);
-// }
+ if (useApiKey) {
+ plugin.setUsernameOut(REDMINE_API_KEY);
+ } else {
+ plugin.setUsernameOut(REDMINE_USERNAME);
+ plugin.setPasswordOut(REDMINE_PASSWORD);
+ }
plugin.setRunOnce(true);
plugin.setProject(project);
@@ -297,8 +281,6 @@
// prepare Redmine service configuration
- URL url = getRestUrl();
-
if (url == null || url.toString().isEmpty()) {
// no redmine url specified, guess it from issueManagement
@@ -312,7 +294,7 @@
// apply configuration
- setRestUrl(url);
+ setUrl(url);
}
@Override
@@ -337,6 +319,13 @@
return;
}
+ Properties properties = project.getProperties();
+ authConfiguration = RedmineClientAuthConfiguration.newConf(
+ properties.getProperty(REDMINE_API_KEY),
+ properties.getProperty(REDMINE_USERNAME),
+ properties.getProperty(REDMINE_PASSWORD)
+ );
+
// init Redmine service
try {
@@ -351,7 +340,7 @@
throw e;
}
// if (verbose) {
- getLog().error("could not init Redmine service [" + getRestUrl() + "] with user '" + getRestUsername() + "'", e);
+ getLog().error("could not init Redmine service [" + getUrl() + "]", e);
// }
// return false;
}
Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/NextVersionMojo.java
===================================================================
--- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/NextVersionMojo.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/NextVersionMojo.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -132,7 +132,7 @@
}
///////////////////////////////////////////////////////////////////////////
- /// RestClientConfiguration
+ /// RedmineClientConfiguration
///////////////////////////////////////////////////////////////////////////
@Override
Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishAttachmentsMojo.java
===================================================================
--- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishAttachmentsMojo.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishAttachmentsMojo.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -123,7 +123,7 @@
}
///////////////////////////////////////////////////////////////////////////
- /// RestClientConfiguration
+ /// RedmineClientConfiguration
///////////////////////////////////////////////////////////////////////////
@Override
Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishNewsMojo.java
===================================================================
--- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishNewsMojo.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/PublishNewsMojo.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -112,7 +112,7 @@
}
///////////////////////////////////////////////////////////////////////////
- /// RestClientConfiguration
+ /// RedmineClientConfiguration
///////////////////////////////////////////////////////////////////////////
@Override
Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/UpdateVersionMojo.java
===================================================================
--- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/UpdateVersionMojo.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/UpdateVersionMojo.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -149,7 +149,7 @@
}
///////////////////////////////////////////////////////////////////////////
- /// RestClientConfiguration
+ /// RedmineClientConfiguration
///////////////////////////////////////////////////////////////////////////
@Override
Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AbstractAnnouncementMojo.java
===================================================================
--- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AbstractAnnouncementMojo.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AbstractAnnouncementMojo.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -268,10 +268,10 @@
return attachmentLinkTemplate;
}
- @Override
- public String getUrl() {
- return url.toString();
- }
+// @Override
+// public String getUrl() {
+// return url.toString();
+// }
@Override
public String getArtifactId() {
Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AnnouncementGenerator.java
===================================================================
--- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AnnouncementGenerator.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AnnouncementGenerator.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -81,7 +81,7 @@
}
public String getUrl() {
- return configuration.getUrl();
+ return configuration.getUrl().toString();
}
public Map<Attachment, String> getAttachmentsUrls(Attachment[] attachments) {
Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AnnouncementGeneratorConfiguration.java
===================================================================
--- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AnnouncementGeneratorConfiguration.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/announcement/AnnouncementGeneratorConfiguration.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -29,6 +29,7 @@
import org.nuiton.jredmine.model.Attachment;
import java.io.File;
+import java.net.URL;
import java.util.Map;
/**
@@ -41,7 +42,7 @@
public interface AnnouncementGeneratorConfiguration {
/** @return the redmine url */
- String getUrl();
+ URL getUrl();
/** @return the redmine attachment url template */
String getAttachmentLinkTemplate();
Modified: trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractRedmineReport.java
===================================================================
--- trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractRedmineReport.java 2012-10-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/main/java/org/nuiton/jredmine/plugin/report/AbstractRedmineReport.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -196,7 +196,7 @@
}
///////////////////////////////////////////////////////////////////////////
- /// RestClientConfiguration
+ /// RedmineClientConfiguration
///////////////////////////////////////////////////////////////////////////
@Override
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-13 21:48:33 UTC (rev 363)
+++ trunk/jredmine-maven-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoTest.java 2012-10-13 21:50:04 UTC (rev 364)
@@ -33,6 +33,7 @@
import org.nuiton.jredmine.RedmineConfigurationUtil;
import org.nuiton.jredmine.RedmineFixtures;
import org.nuiton.jredmine.RedmineServiceConfiguration;
+import org.nuiton.jredmine.client.RedmineClientAuthConfiguration;
import org.nuiton.plugin.AbstractMojoTest;
import java.io.File;
@@ -62,9 +63,15 @@
// add a issue management
IssueManagement i = new IssueManagement();
i.setSystem(AbstractRedmineMojo.REDMINE_SYSTEM);
- i.setUrl(mojo.getRestUrl().toString());
+ i.setUrl(mojo.getUrl().toString());
mojo.getProject().setIssueManagement(i);
+ RedmineClientAuthConfiguration authConfiguration =
+ getConfiguration().getAuthConfiguration();
+ mojo.setUsername(authConfiguration.getUsername());
+ mojo.setPassword(authConfiguration.getPassword());
+ mojo.setApiKey(authConfiguration.getApiKey());
+
if (mojo instanceof RedmineProjectAware) {
// fill projectId if none is given from pom.xml
@@ -110,6 +117,8 @@
try {
mojo.init();
+
+
canContinue = mojo.checkSkip();
if (!canContinue) {
if (log.isInfoEnabled()) {
1
0
Author: tchemit
Date: 2012-10-13 23:48:33 +0200 (Sat, 13 Oct 2012)
New Revision: 363
Url: http://nuiton.org/repositories/revision/jredmine/363
Log:
refs #2200: Updates to helper-m-p 1.6
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-10-13 10:50:38 UTC (rev 362)
+++ trunk/pom.xml 2012-10-13 21:48:33 UTC (rev 363)
@@ -60,6 +60,7 @@
<!-- must be on a fixed version, not on the snapshot to make possible release -->
<jredminePluginVersion>1.4</jredminePluginVersion>
+ <helperPluginVersion>1.6-SNAPSHOT</helperPluginVersion>
<doxiaVersion>1.3</doxiaVersion>
@@ -91,7 +92,26 @@
<dependencyManagement>
<dependencies>
+
<dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.2.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpmime</artifactId>
+ <version>4.2.1</version>
+ </dependency>
+
+ <dependency>
<groupId>org.nuiton</groupId>
<artifactId>helper-maven-plugin</artifactId>
<version>${helperPluginVersion}</version>
@@ -533,10 +553,15 @@
<configuration>
<environmentVariables>
<jredmine-test.url>${jredmine-test.url}</jredmine-test.url>
- <jredmine-test.login>${jredmine-test.login}</jredmine-test.login>
+ <jredmine-test.username>
+ ${jredmine-test.username}
+ </jredmine-test.username>
<jredmine-test.password>
${jredmine-test.password}
</jredmine-test.password>
+ <jredmine-test.apiKey>
+ ${jredmine-test.apiKey}
+ </jredmine-test.apiKey>
<jredmine-test.verbose>
${jredmine-test.verbose}
</jredmine-test.verbose>
@@ -730,8 +755,10 @@
<phase>initialize</phase>
<configuration>
<serverId>jredmine-test</serverId>
- <usernameOut>jredmine-test.login</usernameOut>
+ <usernameOut>jredmine-test.username</usernameOut>
<passwordOut>jredmine-test.password</passwordOut>
+ <privateKeyOut>jredmine-test.apiKey</privateKeyOut>
+ <skipNullValues>true</skipNullValues>
</configuration>
</execution>
</executions>
1
0