r66 - in trunk: jredmine-client/src/main/java/org/nuiton/jredmine jredmine-client/src/main/java/org/nuiton/jredmine/model jredmine-client/src/main/java/org/nuiton/jredmine/rest jredmine-client/src/main/redmine/jredmine/app/controllers jredmine-client/src/test/java/org/nuiton/jredmine jredmine-client/src/test/java/org/nuiton/jredmine/rest jredmine-client/src/test/resources maven-jredmine-plugin/src/main/java/org/nuiton/jredmine/plugin maven-jredmine-plugin/src/test/java/org/nuiton/jredmine
Author: tchemit Date: 2010-01-03 11:49:37 +0100 (Sun, 03 Jan 2010) New Revision: 66 Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.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/RedmineLogguedService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceLoginException.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineAnonymousServiceTest.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceAsAnonymousTest.java trunk/maven-jredmine-plugin/src/test/resources/log4j.properties trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayProjects.xml trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayVersions.xml Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineService.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/RedmineModelEnum.java trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRestClient.java trunk/jredmine-client/src/main/redmine/jredmine/app/controllers/jredmine_controller.rb trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceTest.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineTestContract.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/TestHelper.java trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java trunk/jredmine-client/src/test/resources/log4j.properties trunk/maven-jredmine-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java trunk/maven-jredmine-plugin/src/main/java/org/nuiton/jredmine/plugin/DisplayDataMojo.java trunk/maven-jredmine-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoTest.java trunk/maven-jredmine-plugin/src/test/java/org/nuiton/jredmine/plugin/DisplayDataMojoTest.java trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayAll.xml Log: Evolution #127: Pouvoir acc?\195?\169der a certains services sans ?\195?\170tre connect?\195?\169 : - creation de deux contracts pour separer l'api publique et privee - amelioration du design des services Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineAnonymousService.java 2010-01-03 10:49:37 UTC (rev 66) @@ -0,0 +1,197 @@ +package org.nuiton.jredmine; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.io.rest.RestClient; +import org.nuiton.io.rest.RestClientConfiguration; +import org.nuiton.jredmine.model.*; +import org.nuiton.jredmine.rest.RedmineRestClient; + +/** + * Default implementation of {@link RedmineAnonymousService}. + * <p/> + * This implementation just make sure that the rest client is anonnymous. + * <p/> + * Created: 2 janv. 2010 + * + * @author chemit + * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @version $Revision: $ + * <p/> + * Mise a jour: $Date: $ par : + * $Author: tchemit $ + * @plexus.component role="org.nuiton.jredmine.RedmineAnonymousService" role-hint="default" + * @see org.nuiton.io.rest.RestClientConfiguration#isAnonymous() + * @since 1.0.3 + */ +public class DefaultRedmineAnonymousService implements RedmineServiceImplementor, RedmineAnonymousService { + /** + * Logger + */ + private static final Log log = LogFactory.getLog(DefaultRedmineAnonymousService.class); + //FIXME Make this works again (there is a bad internal state somewhere...) +// /** +// * @plexus.requirement role="org.nuiton.jredmine.RedmineServiceImplementor" role-hint="default" +// */ + protected RedmineServiceImplementor delegateImplementor; + + public DefaultRedmineAnonymousService() { + delegateImplementor = new DefaultRedmineServiceImplementor(); + } + + /////////////////////////////////////////////////////////////////////////// + /// RedmineAnonymousService implementation + /////////////////////////////////////////////////////////////////////////// + + @Override + public IssueStatus[] getIssueStatuses() throws RedmineServiceException { + return getDatas(RedmineRestClient.GET_ISSUE_STATUS_LIST, IssueStatus.class); + } + + @Override + public IssuePriority[] getIssuePriorities() throws RedmineServiceException { + return getDatas(RedmineRestClient.GET_ISSUE_PRIORITY_LIST, IssuePriority.class); + } + + @Override + public Project[] getProjects() throws RedmineServiceException { + return getDatas(RedmineRestClient.GET_PROJECT_LIST, Project.class); + } + + @Override + public IssueCategory[] getIssueCategories(String projectName) throws RedmineServiceException { + return getDatas(RedmineRestClient.GET_ISSUE_CATEGORY_LIST, IssueCategory.class, projectName); + } + + @Override + public Project getProject(String projectName) throws RedmineServiceException { + return getData(RedmineRestClient.GET_PROJECT, Project.class, projectName); + } + + @Override + public Tracker[] getTrackers(String projectName) throws RedmineServiceException { + return getDatas(RedmineRestClient.GET_TRACKER_LIST, Tracker.class, projectName); + } + + @Override + public News[] getNews(String projectName) throws RedmineServiceException { + return getDatas(RedmineRestClient.GET_NEWS_LIST, News.class, projectName); + } + + @Override + public User[] getUsers(String projectName) throws RedmineServiceException { + return getProjectMembers(projectName); + } + + @Override + public User[] getProjectMembers(String projectName) throws RedmineServiceException { + return getDatas(RedmineRestClient.GET_USER_LIST, User.class, projectName); + } + + @Override + public Version[] getVersions(String projectName) throws RedmineServiceException { + return getDatas(RedmineRestClient.GET_VERSION_LIST, Version.class, projectName); + } + + @Override + public Version getVersion(String projectName, String versionName) throws RedmineServiceException { + return getData(RedmineRestClient.GET_VERSION, Version.class, projectName, versionName); + } + + @Override + public Attachment[] getAttachments(String projectName, String versionName) throws RedmineServiceException { + return getDatas(RedmineRestClient.GET_ATTACHMENTS_LIST, Attachment.class, projectName, versionName); + } + + @Override + public Issue[] getIssues(String projectName, String versionName) throws RedmineServiceException { + return getDatas(RedmineRestClient.GET_ISSUE_LIST, Issue.class, projectName, versionName); + } + + @Override + public TimeEntry[] getIssueTimeEntries(String projectName, String issueId) throws RedmineServiceException { + return getDatas(RedmineRestClient.GET_ISSUE_TIME_ENTRY_LIST, TimeEntry.class, projectName, issueId); + } + + @Override + public Issue[] getIssues(String projectName) throws RedmineServiceException { + Issue[] result = getDatas(RedmineRestClient.GET_PROJECT_ISSUES, Issue.class, projectName); + return result; + } + + @Override + public Issue[] getOpenedIssues(String projectName) throws RedmineServiceException { + Issue[] result = getDatas(RedmineRestClient.GET_PROJECT_OPENED_ISSUES, Issue.class, projectName); + return result; + } + + @Override + public Issue[] getClosedIssues(String projectName) throws RedmineServiceException { + Issue[] result = getDatas(RedmineRestClient.GET_PROJECT_CLOSED_ISSUES, Issue.class, projectName); + return result; + } + + /////////////////////////////////////////////////////////////////////////// + /// RedmineServiceImplementor implementation + /////////////////////////////////////////////////////////////////////////// + @Override + public RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException { + // Force to not be loggued + configuration.setAnonymous(true); + if (log.isDebugEnabled()) { + log.debug("init configuration for " + this); + } + RedmineServiceImplementor result = delegateImplementor.init(configuration); + return result; + } + + @Override + public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { + if (log.isDebugEnabled()) { + log.debug("init session for " + this); + } + checkNotLoggued(session); + return delegateImplementor.init(session); + } + + @Override + public <T> T getData(String requestName, Class<T> type, Object... args) throws RedmineServiceException { + return delegateImplementor.getData(requestName, type, args); + } + + @Override + public <T> T[] getDatas(String requestName, Class<T> type, Object... args) throws RedmineServiceException { + return delegateImplementor.getDatas(requestName, type, args); + } + + @Override + public <T> T sendData(String requestName, Class<T> klazz, Object... args) throws RedmineServiceException { + return delegateImplementor.sendData(requestName, klazz, args); + } + + @Override + public <T> T[] sendDatas(String requestName, Class<T> klazz, Object... args) throws RedmineServiceException { + return delegateImplementor.sendDatas(requestName, klazz, args); + } + + @Override + public boolean isInit() { + return delegateImplementor.isInit(); + } + + @Override + public void destroy() throws RedmineServiceException { + delegateImplementor.destroy(); + } + + @Override + public void checkNotLoggued(RestClient session) throws IllegalStateException, RedmineServiceLoginException, NullPointerException { + delegateImplementor.checkNotLoggued(session); + } + + @Override + public void checkLoggued() throws IllegalStateException, RedmineServiceLoginException, NullPointerException { + delegateImplementor.checkLoggued(); + } + +} Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineService.java 2010-01-03 10:49:37 UTC (rev 66) @@ -22,18 +22,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.nuiton.io.rest.RestClient; import org.nuiton.io.rest.RestClientConfiguration; -import org.nuiton.io.rest.RestException; -import org.nuiton.io.rest.RestRequest; import org.nuiton.jredmine.model.*; -import org.nuiton.jredmine.model.io.xpp3.RedmineXpp3Helper; import org.nuiton.jredmine.rest.RedmineRestClient; -import java.io.IOException; -import java.io.InputStream; - /** * Default {@link RedmineService} implementation based on a {@link RestClient} * @@ -41,437 +34,74 @@ * @plexus.component role="org.nuiton.jredmine.RedmineService" role-hint="default" * @since 1.0.0 */ -public class DefaultRedmineService implements RedmineService, RedmineServiceImplementor { +public class DefaultRedmineService extends DefaultRedmineAnonymousService implements RedmineService { protected static final Log log = LogFactory.getLog(DefaultRedmineService.class); - /** - * client Rest - * - * @plexus.requirement role="org.nuiton.io.rest.RestClient" - * role-hint="redmine" - */ - protected RestClient session; - /** - * xpp3 xpp3Helper to transform xml stream to pojo - */ - protected final RedmineXpp3Helper xpp3Helper; - /** - * internal state to known if service was init - */ - protected boolean init; - public DefaultRedmineService() { - this.xpp3Helper = new RedmineXpp3Helper(); - if (log.isDebugEnabled()) { - log.debug("new " + this); - } - } - /////////////////////////////////////////////////////////////////////////// - /// RedmineService implementation + /// RedmineServiceImplementor implementation /////////////////////////////////////////////////////////////////////////// @Override - public Version addVersion(String projectName, Version version) throws RedmineServiceException { - checkInit(); - RestRequest r = getRequest(RedmineRestClient.ADD_VERSION, projectName, version); - - // send data and obtain created version - try { - - InputStream stream = session.sendData(r); - Version v = getDataFromStream(Version.class, stream); - return v; - } catch (Exception e) { - throw new RedmineServiceException("could not send for reason " + e.getMessage(), e); - } + public RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException { + RedmineServiceImplementor result = delegateImplementor.init(configuration); + return result; } @Override - public Attachment addAttachment(String projectName, String versionName, Attachment attachement) throws RedmineServiceException { - checkInit(); - RestRequest r = getRequest(RedmineRestClient.ADD_ATTACHMENT, projectName, versionName, attachement); + public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { + return delegateImplementor.init(session); + } - // send data and obtain created attachment - try { + /////////////////////////////////////////////////////////////////////////// + /// RedmineLogguedService implementation + /////////////////////////////////////////////////////////////////////////// - InputStream stream = session.sendData(r); - Attachment v = getDataFromStream(Attachment.class, stream); - return v; - } catch (Exception e) { - throw new RedmineServiceException("could not send for reason " + e.getMessage(), e); - } + @Override + public Project[] getUserProjects() throws RedmineServiceException { + checkLoggued(); + Project[] result = getDatas(RedmineRestClient.GET_USER_PROJECTS, Project.class); + return result; } @Override - public News addNews(String projectName, News news) throws RedmineServiceException { - checkInit(); - RestRequest r = getRequest(RedmineRestClient.ADD_NEWS, projectName, news); - - // send data and obtain created news - try { - - InputStream stream = session.sendData(r); - News v = getDataFromStream(News.class, stream); - return v; - } catch (Exception e) { - throw new RedmineServiceException("could not send for reason " + e.getMessage(), e); - } + public Version addVersion(String projectName, Version version) throws RedmineServiceException { + // send data and obtain created version + Version result = sendData(RedmineRestClient.ADD_VERSION, Version.class, projectName, version); + return result; } @Override public Version updateVersion(String projectName, Version version) throws RedmineServiceException { - checkInit(); - RestRequest r = getRequest(RedmineRestClient.UPDATE_VERSION, projectName, version); - // send data and obtain updated version - try { - - InputStream stream = session.sendData(r); - Version v = getDataFromStream(Version.class, stream); - return v; - } catch (Exception e) { - throw new RedmineServiceException("could not send for reason " + e.getMessage(), e); - } + Version result = sendData(RedmineRestClient.UPDATE_VERSION, Version.class, projectName, version); + return result; } @Override public Version nextVersion(String projectName, String oldVersionName, Version newVersion) throws RedmineServiceException { - checkInit(); - RestRequest r = getRequest(RedmineRestClient.NEXT_VERSION, projectName, oldVersionName, newVersion); // send data and obtain updated version - try { - - InputStream stream = session.sendData(r); - Version v = getDataFromStream(Version.class, stream); - return v; - } catch (Exception e) { - throw new RedmineServiceException("could not send for reason " + e.getMessage(), e); - } + Version result = sendData(RedmineRestClient.NEXT_VERSION, Version.class, projectName, oldVersionName, newVersion); + return result; } @Override - public TimeEntry addIssueTimeEntry(String projectName, String issueId, TimeEntry entry) throws RedmineServiceException { - checkInit(); - RestRequest r = getRequest(RedmineRestClient.ADD_ISSUE_TIME_ENTRY, projectName, issueId, entry); - - // send data and obtain updated version - try { - - InputStream stream = session.sendData(r); - TimeEntry timeEntry = getDataFromStream(TimeEntry.class, stream); - return timeEntry; - } catch (Exception e) { - throw new RedmineServiceException("could not send for reason " + e.getMessage(), e); - } - } - - @Override - public IssueStatus[] getIssueStatuses() throws RedmineServiceException { - return getDatas(IssueStatus.class); - } - - @Override - public IssuePriority[] getIssuePriorities() throws RedmineServiceException { - return getDatas(IssuePriority.class); - } - - @Override - public Project[] getProjects() throws RedmineServiceException { - return getDatas(Project.class); - } - - @Override - public IssueCategory[] getIssueCategories(String projectName) throws RedmineServiceException { - return getDatas(IssueCategory.class, projectName); - } - - @Override - public Project getProject(String projectName) throws RedmineServiceException { - return getData(Project.class, projectName); - } - - @Override - public Tracker[] getTrackers(String projectName) throws RedmineServiceException { - return getDatas(Tracker.class, projectName); - } - - @Override - public News[] getNews(String projectName) throws RedmineServiceException { - return getDatas(News.class, projectName); - } - - @Override - public User[] getUsers(String projectName) throws RedmineServiceException { - return getDatas(User.class, projectName); - } - - @Override - public Version[] getVersions(String projectName) throws RedmineServiceException { - return getDatas(Version.class, projectName); - } - - @Override - public Version getVersion(String projectName, String versionName) throws RedmineServiceException { - return getData(Version.class, projectName, versionName); - } - - @Override - public Attachment[] getAttachments(String projectName, String versionName) throws RedmineServiceException { - return getDatas(Attachment.class, projectName, versionName); - } - - @Override - public Issue[] getIssues(String projectName, String versionName) throws RedmineServiceException { - return getDatas(Issue.class, projectName, versionName); - } - - @Override - public TimeEntry[] getIssueTimeEntries(String projectName, String issueId) throws RedmineServiceException { - return getDatas(TimeEntry.class, projectName, issueId); - } - - @Override - public Project[] getUserProjects() throws RedmineServiceException { - - Class<Project> type = Project.class; - RestRequest r = getRequest(RedmineRestClient.GET_USER_PROJECTS); - - // obtain data from rest client - InputStream stream; - try { - - stream = session.askData(r); - - } catch (Exception e) { - throw new RedmineServiceException("could not obtain data stream for type " + type.getName() + "forUser for reason " + e.getMessage(), e); - } - - if (stream == null) { - return null; - } - Project[] projects = getDatasFromStream(type, stream); - return projects; - } - - @Override - public Issue[] getIssues(String projectName) throws RedmineServiceException { - Class<Issue> type = Issue.class; - RestRequest r = getRequest(RedmineRestClient.GET_PROJECT_ISSUES, projectName); - - // obtain data from rest client - InputStream stream; - try { - - stream = session.askData(r); - - } catch (Exception e) { - throw new RedmineServiceException("could not obtain data stream for type " + r + " for reason " + e.getMessage(), e); - } - - if (stream == null) { - return null; - } - Issue[] issues = getDatasFromStream(type, stream); - return issues; - } - - @Override - public Issue[] getOpenedIssues(String projectName) throws RedmineServiceException { - Class<Issue> type = Issue.class; - RestRequest r = getRequest(RedmineRestClient.GET_PROJECT_OPENED_ISSUES, projectName); - - // obtain data from rest client - InputStream stream; - try { - - stream = session.askData(r); - - } catch (Exception e) { - throw new RedmineServiceException("could not obtain data stream for type " + type.getName() + "forUser for reason " + e.getMessage(), e); - } - - if (stream == null) { - return null; - } - Issue[] issues = getDatasFromStream(type, stream); - return issues; - } - - @Override - public Issue[] getClosedIssues(String projectName) throws RedmineServiceException { - Class<Issue> type = Issue.class; - RestRequest r = getRequest(RedmineRestClient.GET_PROJECT_CLOSED_ISSUES, projectName); - - // obtain data from rest client - InputStream stream; - try { - - stream = session.askData(r); - - } catch (Exception e) { - throw new RedmineServiceException("could not obtain data stream for type " + type.getName() + "forUser for reason " + e.getMessage(), e); - } - - if (stream == null) { - return null; - } - Issue[] issues = getDatasFromStream(type, stream); - return issues; - } - - /////////////////////////////////////////////////////////////////////////// - /// RedmineServiceImplementor implementation - /////////////////////////////////////////////////////////////////////////// - @Override - public boolean isInit() { - return init; - } - - @Override - public RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException { - session.setConfiguration(configuration); - RedmineServiceImplementor result = init(session); + public Attachment addAttachment(String projectName, String versionName, Attachment attachement) throws RedmineServiceException { + // send data and obtain created attachment + Attachment result = sendData(RedmineRestClient.ADD_ATTACHMENT, Attachment.class, projectName, versionName, attachement); return result; } @Override - public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { - if (init) { - throw new IllegalStateException("the client " + this + " was already init!"); - } - try { - this.session = session; - - if (!session.isOpen()) { - session.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 { - checkInit(); - try { - if (session.isOpen()) { - try { - session.close(); - } catch (RestException ex) { - throw new RedmineServiceException("has problem while closing Rest client " + ex.getMessage(), ex); - } - } - } finally { - if (session != null) { - session = null; - } - init = false; - } - } - - @Override - public <T> T getData(Class<T> type, Object... args) throws RedmineServiceException { - checkInit(); - - InputStream stream = getDataStream(type, args); - - if (stream == null) { - return null; - } - - T result = getDataFromStream(type, stream); + public News addNews(String projectName, News news) throws RedmineServiceException { + // send data and obtain created news + News result = sendData(RedmineRestClient.ADD_NEWS, News.class, projectName, news); return result; } @Override - public <T> T[] getDatas(Class<T> type, Object... args) throws RedmineServiceException { - checkInit(); - - InputStream stream = getDatasStream(type, args); - - if (stream == null) { - return null; - } - - T[] result = getDatasFromStream(type, stream); + public TimeEntry addIssueTimeEntry(String projectName, String issueId, TimeEntry entry) throws RedmineServiceException { + // send data and obtain updated version + TimeEntry result = sendData(RedmineRestClient.ADD_ISSUE_TIME_ENTRY, TimeEntry.class, projectName, issueId, entry); return result; } - - @Override - public <T> InputStream getDataStream(Class<T> type, Object... args) throws RedmineServiceException { - - InputStream stream = getDataStream(type, false, args); - return stream; - } - - @Override - public <T> InputStream getDatasStream(Class<T> type, Object... args) throws RedmineServiceException { - - InputStream stream = getDataStream(type, true, args); - return stream; - } - - /////////////////////////////////////////////////////////////////////////// - /// Internal methods - /////////////////////////////////////////////////////////////////////////// - protected <T> InputStream getDataStream(Class<T> type, boolean array, Object... args) throws RedmineServiceException { - - String requestName = type.getName() + (array ? "list" : "detail"); - RestRequest r = getRequest(requestName, args); - - // obtain data from rest client - try { - - InputStream stream = session.askData(r); - return stream; - } catch (Exception e) { - throw new RedmineServiceException("could not botain data stream for type " + type + " for reason " + e.getMessage(), e); - } - } - - protected RestRequest getRequest(String requestName, Object... args) throws RedmineServiceException { - RestRequest r; - try { - r = session.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 = xpp3Helper.readObject(type, stream); - return result; - } catch (IOException ex) { - throw new RedmineServiceException("could not obtain datas of type " + type + " for reason " + ex.getMessage(), ex); - } catch (XmlPullParserException 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 = xpp3Helper.readObjects(type, stream); - return result; - } catch (IOException ex) { - throw new RedmineServiceException("could not obtain datas of type " + type + " for reason " + ex.getMessage(), ex); - } catch (XmlPullParserException 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!"); - } - } -} +} \ No newline at end of file Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java 2010-01-03 10:49:37 UTC (rev 66) @@ -0,0 +1,249 @@ +package org.nuiton.jredmine; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.nuiton.io.rest.RestClient; +import org.nuiton.io.rest.RestClientConfiguration; +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 java.io.IOException; +import java.io.InputStream; + +/** + * Created: 2 janv. 2010 + * + * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author: tchemit $ + * @plexus.component role="org.nuiton.jredmine.RedmineServiceImplementor" role-hint="default" + * @since 1.0.3 + */ +public class DefaultRedmineServiceImplementor implements RedmineServiceImplementor { + /** + * Logger + */ + private static final Log log = LogFactory.getLog(DefaultRedmineServiceImplementor.class); + //FIXME Make this works again (there is a bad internal state somewhere...) +// /** +// * client Rest +// * +// * @plexus.requirement role="org.nuiton.io.rest.RestClient" role-hint="redmine" +// */ + protected RestClient session; + /** + * 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() { + this.xpp3Helper = new RedmineXpp3Helper(); + if (log.isDebugEnabled()) { + log.debug("new " + this); + } + this.session = new RedmineRestClient(); + } + + /////////////////////////////////////////////////////////////////////////// + /// RedmineServiceImplementor implementation + /////////////////////////////////////////////////////////////////////////// + + @Override + public boolean isInit() { + return init; + } + + @Override + public RedmineServiceImplementor init(RestClientConfiguration configuration) throws RedmineServiceException { + session.setConfiguration(configuration); + RedmineServiceImplementor result = init(session); + return result; + } + + @Override + public RedmineServiceImplementor init(RestClient session) throws RedmineServiceException { + if (init) { + throw new IllegalStateException("the client " + this + " was already init!"); + } + try { + this.session = session; + + if (!session.isOpen()) { + session.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 { + checkInit(); + try { + if (session.isOpen()) { + try { + session.close(); + } catch (RestException ex) { + throw new RedmineServiceException("has problem while closing Rest client " + ex.getMessage(), ex); + } + } + } finally { +// if (session != null) { +// session = null; +// } + init = false; + } + } + + @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(session); + checkSessionConfigurationNotNull(session); + if (session.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 { + + RestRequest r = getRequest(requestName, args); + + // obtain data from rest client + try { + + InputStream stream = session.askData(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 = session.sendData(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 = session.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 { + if (stream == null) { + return null; + } + + try { + T result = xpp3Helper.readObject(type, stream); + return result; + } catch (IOException ex) { + throw new RedmineServiceException("could not obtain datas of type " + type + " for reason " + ex.getMessage(), ex); + } catch (XmlPullParserException 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 { + if (stream == null) { + return null; + } + try { + T[] result = xpp3Helper.readObjects(type, stream); + return result; + } catch (IOException ex) { + throw new RedmineServiceException("could not obtain datas of type " + type + " for reason " + ex.getMessage(), ex); + } catch (XmlPullParserException 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(RestClient session) { + if (session == null) { + throw new NullPointerException("session can not be null"); + } + } + + protected void checkSessionConfigurationNotNull(RestClient session) { + if (session.getConfiguration() == null) { + throw new NullPointerException("session configuration can not be null"); + } + } +} Property changes on: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/DefaultRedmineServiceImplementor.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineAnonymousService.java 2010-01-03 10:49:37 UTC (rev 66) @@ -0,0 +1,202 @@ +package org.nuiton.jredmine; + +import org.nuiton.jredmine.model.*; + +/** + * Contract of all redmine operations which do not requires any login to server. + * <p/> + * A default implementation is offered in + * {@link org.nuiton.jredmine.DefaultRedmineAnonymousService}. + * <p/> + * Created: 2 janv. 2010 + * + * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author: tchemit $ + * @see org.nuiton.jredmine.DefaultRedmineAnonymousService + * @since 1.0.3 + */ +public interface RedmineAnonymousService { + + /** + * Obtain all accessible projets. + * + * @return all the projects + * @throws RedmineServiceException if any pb while retriving datas + * @see org.nuiton.jredmine.model.Project + */ + Project[] getProjects() throws RedmineServiceException; + + /** + * Obtain all the priorities defined on a {@link org.nuiton.jredmine.model.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 org.nuiton.jredmine.model.IssuePriority + */ + IssuePriority[] getIssuePriorities() throws RedmineServiceException; + + /** + * Obtain all the statuses defined on a {@link org.nuiton.jredmine.model.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 org.nuiton.jredmine.model.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 org.nuiton.jredmine.model.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 org.nuiton.jredmine.model.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 + * @deprecated since 1.0.3, use now {@link #getProjectMembers(String)}. + */ + @Deprecated + User[] getUsers(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/RedmineAnonymousService.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineLogguedService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineLogguedService.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineLogguedService.java 2010-01-03 10:49:37 UTC (rev 66) @@ -0,0 +1,123 @@ +package org.nuiton.jredmine; + +import org.nuiton.jredmine.model.*; + + +/** + * Contract of all redmine operations that needs a login to be performed. + * <p/> + * A default implementation is offered in + * {@link org.nuiton.jredmine.DefaultRedmineService}. + * <p/> + * Created: 2 janv. 2010 + * + * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author: tchemit $ + * @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 org.nuiton.jredmine.model.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/RedmineLogguedService.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineService.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineService.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineService.java 2010-01-03 10:49:37 UTC (rev 66) @@ -20,275 +20,21 @@ */ package org.nuiton.jredmine; -import org.nuiton.jredmine.model.*; - /** - * The service that mirrors the rails {@code jredmine} plugin. + * The full service with anonymous methods and loggued ones. + * <p/> + * <b>Note:</b> A default implementation is offered : + * {@link DefaultRedmineService} * * @author chemit + * @see DefaultRedmineService * @since 1.0.0 */ -public interface RedmineService { +public interface RedmineService extends RedmineAnonymousService, RedmineLogguedService { /** * Plexus lookup name */ String ROLE = RedmineService.class.getName(); - /** - * Obtain all accessible projets for the loggued user. - * - * @return all the projects - * @throws RedmineServiceException if any pb while retriving datas - * @see Project - */ - Project[] getProjects() throws RedmineServiceException; - - /** - * Obtain for the loggued user, all projets where he belongs. - * <p/> - * <b>Note:</b> this method could return less projects than the method - * {@link #getProjects()} since here the user must belongs to the project - * and not just can access it. - * - * @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; - - /** - * 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[] getUsers(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 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; - - /** - * Add a version for a given project. - * - * @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. - * - * @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. - * - * @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. - * - * @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. - * - * @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; - - /** - * 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; - - /** - * Add a new time entry to the given issue for the given project and - * return the updated time entry. - * - * @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; } Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceImplementor.java 2010-01-03 10:49:37 UTC (rev 66) @@ -24,15 +24,16 @@ import org.nuiton.io.rest.RestClientConfiguration; import org.nuiton.jredmine.rest.RedmineRestClient; -import java.io.InputStream; - /** - * Technical contrat te be implemented in a {@link RedmineService}. + * Technical contract to implements a redmine service which wrap the + * {@link org.nuiton.jredmine.rest.RedmineRestClient}. * <p/> - * Any concrete implentation of a {@link RedmineService} should (must ?) also - * implements this contract. + * A default implementation is offered in {@link org.nuiton.jredmine.DefaultRedmineServiceImplementor}. + * <p/> + * Any concrete implentation of a redmine service should implements this.. * * @author chemit + * @see org.nuiton.jredmine.DefaultRedmineServiceImplementor * @since 1.0.0 */ public interface RedmineServiceImplementor { @@ -48,12 +49,12 @@ /** * Initialize the service given a redmine client already initialized. * - * @param client the redmine client to be used by the service + * @param session the redmine client to be used by the service * @return the initialized service * @throws RedmineServiceException if any pb * @see RedmineRestClient */ - RedmineServiceImplementor init(RestClient client) throws RedmineServiceException; + RedmineServiceImplementor init(RestClient session) throws RedmineServiceException; /** * Initialize the service given a client configuration. @@ -74,44 +75,69 @@ /** * Generic method to obtain a single data from a redmine server. * - * @param <T> the type of data to obtain - * @param type the type of data to obtain - * @param args the parameters to obtain the data + * @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(Class<T> type, Object... args) throws RedmineServiceException; + <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 type the type of data to obtain - * @param args the parameters to obtain the datas + * @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(Class<T> type, Object... args) throws RedmineServiceException; + <T> T[] getDatas(String requestName, Class<T> type, Object... args) throws RedmineServiceException; /** - * Generic method to obtain an input stream of a data from a redmine server. + * Generic method to send a data to a redmine server and return the single + * data updated from the redmine server. * - * @param <T> the type of data to obtain - * @param type the type of data to obtain - * @param args the parameters to obtain the data - * @return the input stream containing the data + * @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> InputStream getDataStream(Class<T> type, Object... args) throws RedmineServiceException; + <T> T sendData(String requestName, Class<T> klazz, Object... args) throws RedmineServiceException; + /** - * Generic method to obtain an input stream of an array of data from a redmine server. + * Generic method to send a data (or more ) to a redmine server and + * return the array of data from the redmine server. * - * @param <T> the type of data to obtain - * @param type the type of data to obtain - * @param args the parameters to obtain the datas - * @return the input stream containing the datas + * @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> InputStream getDatasStream(Class<T> type, Object... args) throws RedmineServiceException; + <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; + + /** + * 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/RedmineServiceLoginException.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceLoginException.java (rev 0) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/RedmineServiceLoginException.java 2010-01-03 10:49:37 UTC (rev 66) @@ -0,0 +1,34 @@ +package org.nuiton.jredmine; + +/** + * An exception to be thrown when a problem with authentication state in a + * {@link org.nuiton.jredmine.RedmineService}. + * <p/> + * Created: 2 janv. 2010 + * + * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author: tchemit $ + * @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/RedmineServiceLoginException.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/RedmineModelEnum.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/RedmineModelEnum.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/model/RedmineModelEnum.java 2010-01-03 10:49:37 UTC (rev 66) @@ -20,6 +20,8 @@ */ package org.nuiton.jredmine.model; +import org.nuiton.jredmine.rest.RedmineRestClient; + /** * Un énumération pour connaitre l'ensemble des classes du modèle. * @@ -28,26 +30,29 @@ */ public enum RedmineModelEnum { - issueStatus(IssueStatus.class, RedmineModelScope.none), - issuePriority(IssuePriority.class, RedmineModelScope.none), - project(Project.class, RedmineModelScope.none), - issueCategory(IssueCategory.class, RedmineModelScope.project), - tracker(Tracker.class, RedmineModelScope.project), - user(User.class, RedmineModelScope.project), - news(News.class, RedmineModelScope.project), - version(Version.class, RedmineModelScope.project), - issue(Issue.class, RedmineModelScope.version), - timeEntry(TimeEntry.class, RedmineModelScope.issue), - attachment(Attachment.class, RedmineModelScope.version); - + issueStatus(IssueStatus.class, RedmineModelScope.none, RedmineRestClient.GET_ISSUE_STATUS_LIST), + issuePriority(IssuePriority.class, RedmineModelScope.none, RedmineRestClient.GET_ISSUE_PRIORITY_LIST), + project(Project.class, RedmineModelScope.none, RedmineRestClient.GET_PROJECT_LIST), + issueCategory(IssueCategory.class, RedmineModelScope.project, RedmineRestClient.GET_ISSUE_CATEGORY_LIST), + tracker(Tracker.class, RedmineModelScope.project, RedmineRestClient.GET_TRACKER_LIST), + user(User.class, RedmineModelScope.project, RedmineRestClient.GET_USER_LIST), + news(News.class, RedmineModelScope.project, RedmineRestClient.GET_NEWS_LIST), + version(Version.class, RedmineModelScope.project, RedmineRestClient.GET_VERSION_LIST), + issue(Issue.class, RedmineModelScope.version, RedmineRestClient.GET_ISSUE_LIST), + timeEntry(TimeEntry.class, RedmineModelScope.issue, RedmineRestClient.GET_ISSUE_TIME_ENTRY_LIST), + attachment(Attachment.class, RedmineModelScope.version, RedmineRestClient.GET_ATTACHMENTS_LIST); + private final Class<?> modelType; private final RedmineModelScope scope; + private final String requestAll; - private RedmineModelEnum(Class<?> modelType, RedmineModelScope scope) { + private RedmineModelEnum(Class<?> modelType, RedmineModelScope scope, String requestAll) { this.modelType = modelType; this.scope = scope; + this.requestAll = requestAll; } + public Class<?> getModelType() { return modelType; } @@ -56,6 +61,10 @@ return scope; } + public String getRequestAll() { + return requestAll; + } + public static RedmineModelEnum valueOf(Class<?> type) { for (RedmineModelEnum e : values()) { if (type == e.getModelType()) { Modified: trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRestClient.java =================================================================== --- trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRestClient.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/jredmine-client/src/main/java/org/nuiton/jredmine/rest/RedmineRestClient.java 2010-01-03 10:49:37 UTC (rev 66) @@ -239,7 +239,9 @@ ping(session); - login(session); + if (!configuration.isAnonymous()) { + login(session); + } } @Override Modified: trunk/jredmine-client/src/main/redmine/jredmine/app/controllers/jredmine_controller.rb =================================================================== --- trunk/jredmine-client/src/main/redmine/jredmine/app/controllers/jredmine_controller.rb 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/jredmine-client/src/main/redmine/jredmine/app/controllers/jredmine_controller.rb 2010-01-03 10:49:37 UTC (rev 66) @@ -1,7 +1,8 @@ class JredmineController < ActionController::Base # find user (after login) - before_filter :find_user, :except => [:ping, :login] + before_filter :find_user, :only => [:get_user_projects, :add_version, :update_version, :add_news, :add_attachment, :add_version_attachment, :add_issue_time, :update_issue_time] + #before_filter :find_user, :except => [:ping, :login, :get_projects, :get_project_versions] # find project and check permission before_filter :find_project, :except => [:ping, :login, :logout, :get_projects, :get_user_projects, :get_issue_statuses, :get_issue_priorities] Added: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java (rev 0) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java 2010-01-03 10:49:37 UTC (rev 66) @@ -0,0 +1,240 @@ +package org.nuiton.jredmine; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.*; +import org.nuiton.io.rest.RestClientConfiguration; +import static org.nuiton.jredmine.TestHelper.getTestConfiguration; +import org.nuiton.jredmine.model.*; +import org.nuiton.jredmine.rest.RedmineRestClient; + +/** + * Created: 2 janv. 2010 + * + * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author: tchemit $ + */ +public abstract class AbstractRedmineServiceTest<S extends RedmineAnonymousService> implements RedmineTestContract { + /** + * Logger + */ + private static final Log log = LogFactory.getLog(AbstractRedmineServiceTest.class); + + /** + * shared rest client (open only one session for all the test) + */ + static RedmineRestClient client; + /** + * service to test + */ + private S service; + + protected Project[] projects; + protected Project project; + protected Version[] versions; + protected Version version; + protected User[] users; + protected Issue[] issues; + protected IssuePriority[] issuePriorities; + protected IssueStatus[] issueStatuses; + protected IssueCategory[] issueCategories; + protected Tracker[] trackers; + protected News newz; + protected News[] news; + protected Attachment attachment; + protected Attachment[] attachments; + protected TimeEntry timeEntry; + protected TimeEntry[] timeEntries; + + private final Class<S> serviceType; + + public AbstractRedmineServiceTest(Class<S> serviceType) { + this.serviceType = serviceType; + } + + protected S getService() { + return service; + } + + @BeforeClass + public static void setUpClass() throws Exception { + // make sure client is null before starting the test + + client = null; + } + + @AfterClass + public static void tearDownClass() throws Exception { + if (client != null) { + client.close(); + client = null; + } + } + + protected final S newService() throws Exception { + return serviceType.newInstance(); + } + + protected RedmineRestClient newClient(RestClientConfiguration configuration) { + RedmineRestClient client; + try { + client = new RedmineRestClient(configuration); + + client.open(); + } catch (Exception e) { + + // could not log + if (log.isErrorEnabled()) { + log.error("can not connect to server " + configuration.getRestUrl() + ", will skip test " + DefaultRedmineServiceTest.class.getName()); + } +// System.out.println("can not connect to server " + configuration.getRestUrl() + ", will skip test " + DefaultRedmineServiceTest.class.getName()); + client = null; + } + return client; + } + + @Before + public void setUp() throws Exception { + + if (client == null) { + + RestClientConfiguration configuration = getTestConfiguration(); + try { + client = newClient(configuration); + } finally { + Assume.assumeTrue(client != null && client.isOpen()); + } + } + + service = newService(); + + ((RedmineServiceImplementor) service).init(client); + } + + @After + public void tearDown() throws Exception { + service = null; + project = null; + projects = null; + version = null; + versions = null; + users = null; + issues = null; + issueCategories = null; + issuePriorities = null; + issueStatuses = null; + trackers = null; + newz = null; + news = null; + attachment = null; + attachments = null; + timeEntry = null; + timeEntries = null; + } + + + @Test + public void isInit() throws Exception { + + Assert.assertFalse(((RedmineServiceImplementor) newService()).isInit()); + } + + @Test + @Override + public void getProjects() throws Exception { + projects = getService().getProjects(); + } + + @Test + @Override + public void getIssuePriorities() throws Exception { + issuePriorities = getService().getIssuePriorities(); + } + + @Test + @Override + public void getIssueStatuses() throws Exception { + issueStatuses = getService().getIssueStatuses(); + } + + @Test + @Override + public void getProject() throws Exception { + project = getService().getProject(PROJECT_NAME); + } + + @Test + @Override + public void getIssueCategories() throws Exception { + issueCategories = getService().getIssueCategories(PROJECT_NAME); + } + + @Test + @Override + public void getTrackers() throws Exception { + trackers = getService().getTrackers(PROJECT_NAME); + } + + @Test + @Override + public void getNews() throws Exception { + news = getService().getNews(PROJECT_NAME); + } + + @Test + @Override + public void getProjectMembers() throws Exception { + users = getService().getProjectMembers(PROJECT_NAME); + } + + @Test + @Override + public void getProjectIssues() throws Exception { + issues = getService().getIssues(PROJECT_NAME); + } + + @Test + @Override + public void getVersions() throws Exception { + versions = getService().getVersions(PROJECT_NAME); + } + + @Test + @Override + public void getVersion() throws Exception { + version = getService().getVersion(PROJECT_NAME, VERSION_NAME); + } + + @Test + @Override + public void getVersionIssues() throws Exception { + issues = getService().getIssues(PROJECT_NAME, VERSION_NAME); + } + + @Test + @Override + public void getOpenedIssues() throws Exception { + issues = getService().getOpenedIssues(PROJECT_NAME); + } + + @Test + @Override + public void getClosedIssues() throws Exception { + issues = getService().getClosedIssues(PROJECT_NAME); + } + + @Test + @Override + public void getIssueTimeEntries() throws Exception { + timeEntries = getService().getIssueTimeEntries(PROJECT_NAME, ISSUE_ID); + } + + @Test + @Override + public void getAttachments() throws Exception { + attachments = getService().getAttachments(PROJECT_NAME, VERSION_NAME); + } +} Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/AbstractRedmineServiceTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineAnonymousServiceTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineAnonymousServiceTest.java (rev 0) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineAnonymousServiceTest.java 2010-01-03 10:49:37 UTC (rev 66) @@ -0,0 +1,71 @@ +package org.nuiton.jredmine; + +import org.junit.Test; +import org.nuiton.io.rest.RestClientConfiguration; +import org.nuiton.jredmine.rest.RedmineRestClient; + +/** + * Created: 2 janv. 2010 + * + * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author: tchemit $ + */ +public class DefaultRedmineAnonymousServiceTest extends AbstractRedmineServiceTest<DefaultRedmineAnonymousService> { + + public DefaultRedmineAnonymousServiceTest() { + super(DefaultRedmineAnonymousService.class); + } + + @Override + protected RedmineRestClient newClient(RestClientConfiguration configuration) { + configuration.setAnonymous(true); + return super.newClient(configuration); + } + + @Test + @Override + public void getUserProjects() throws Exception { + // not for anonymous service + } + + @Test + @Override + public void addVersion() throws Exception { + // not for anonymous service + } + + @Test + @Override + public void addAttachment() throws Exception { + // not for anonymous service + } + + @Test + @Override + public void addNews() throws Exception { + // not for anonymous service + } + + @Test + @Override + public void updateVersion() throws Exception { + // not for anonymous service + } + + @Test + @Override + public void nextVersion() throws Exception { + // not for anonymous service + } + + @Test + @Override + public void addIssueTime() throws Exception { + // not for anonymous service + } + + +} Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineAnonymousServiceTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceAsAnonymousTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceAsAnonymousTest.java (rev 0) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceAsAnonymousTest.java 2010-01-03 10:49:37 UTC (rev 66) @@ -0,0 +1,81 @@ +package org.nuiton.jredmine; + +import org.junit.Test; +import org.nuiton.io.rest.RestClientConfiguration; +import org.nuiton.jredmine.model.Attachment; +import org.nuiton.jredmine.model.News; +import org.nuiton.jredmine.model.TimeEntry; +import org.nuiton.jredmine.model.Version; +import org.nuiton.jredmine.rest.RedmineRestClient; + +/** + * Created: 2 janv. 2010 + * + * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author: tchemit $ + */ +public class DefaultRedmineServiceAsAnonymousTest extends AbstractRedmineServiceTest<DefaultRedmineService> { + + public DefaultRedmineServiceAsAnonymousTest() { + super(DefaultRedmineService.class); + } + + @Override + protected RedmineRestClient newClient(RestClientConfiguration configuration) { + configuration.setAnonymous(true); + return super.newClient(configuration); + } + + @Test(expected = RedmineServiceLoginException.class) + @Override + public void getUserProjects() throws Exception { + projects = getService().getUserProjects(); + } + + @Test(expected = RedmineServiceLoginException.class) + @Override + public void addVersion() throws Exception { + version = new Version(); + getService().addVersion(PROJECT_NAME, version); + } + + @Test(expected = RedmineServiceLoginException.class) + @Override + public void addAttachment() throws Exception { + attachment = new Attachment(); + getService().addAttachment(PROJECT_NAME, VERSION_NAME, attachment); + } + + @Test(expected = RedmineServiceLoginException.class) + @Override + public void addNews() throws Exception { + newz = new News(); + getService().addNews(PROJECT_NAME, newz); + } + + @Test(expected = RedmineServiceLoginException.class) + @Override + public void updateVersion() throws Exception { + version = new Version(); + getService().updateVersion(PROJECT_NAME, version); + } + + @Test(expected = RedmineServiceLoginException.class) + @Override + public void nextVersion() throws Exception { + + version = new Version(); + getService().nextVersion(PROJECT_NAME, VERSION_NAME, version); + } + + @Test(expected = RedmineServiceLoginException.class) + @Override + public void addIssueTime() throws Exception { + timeEntry = new TimeEntry(); + getService().addIssueTimeEntry(PROJECT_NAME, ISSUE_ID, timeEntry); + } + +} \ No newline at end of file Property changes on: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceAsAnonymousTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceTest.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/DefaultRedmineServiceTest.java 2010-01-03 10:49:37 UTC (rev 66) @@ -20,222 +20,61 @@ */ package org.nuiton.jredmine; -import org.junit.*; -import org.nuiton.io.rest.RestClientConfiguration; -import static org.nuiton.jredmine.TestHelper.getTestConfiguration; -import org.nuiton.jredmine.model.*; -import org.nuiton.jredmine.rest.RedmineRestClient; +import org.junit.Test; /** * @author chemit */ -public class DefaultRedmineServiceTest implements RedmineTestContract { +public class DefaultRedmineServiceTest extends AbstractRedmineServiceTest<DefaultRedmineService> { - /** - * shared rest client (open only one session for all the test) - */ - static RedmineRestClient client; - /** - * service to test - */ - RedmineService service; - - Project[] projects; - Project project; - Version[] versions; - Version version; - User[] users; - Issue[] issues; - IssuePriority[] issuePriorities; - IssueStatus[] issueStatuses; - IssueCategory[] issueCategories; - Tracker[] trackers; - News[] news; - Attachment[] attachments; - TimeEntry[] timeEntries; - - - @BeforeClass - public static void setUpClass() throws Exception { - RestClientConfiguration configuration = getTestConfiguration(); - - client = new RedmineRestClient(configuration); - try { - - client.open(); - } catch (Exception e) { - - // could not log - System.out.println("can not connect to server " + configuration.getRestUrl() + ", will skip test " + DefaultRedmineServiceTest.class.getName()); - } finally { - Assume.assumeTrue(client != null && client.isOpen()); - } + public DefaultRedmineServiceTest() { + super(DefaultRedmineService.class); } - @AfterClass - public static void tearDownClass() throws Exception { - if (client != null) { - client.close(); - } - } - - @Before - public void setUp() throws Exception { - service = new DefaultRedmineService(); - - ((RedmineServiceImplementor) service).init(client); - } - - @After - public void tearDown() throws Exception { - - service = null; - } - - @Test - public void isInit() throws Exception { - - Assert.assertFalse(new DefaultRedmineService().isInit()); - } - - - @Test @Override - public void getProjects() throws Exception { - projects = service.getProjects(); + public void getUserProjects() throws Exception { + projects = getService().getUserProjects(); } @Test @Override - public void getIssuePriorities() throws Exception { - issuePriorities = service.getIssuePriorities(); - } - - @Test - @Override - public void getIssueStatuses() throws Exception { - issueStatuses = service.getIssueStatuses(); - } - - @Test - @Override - public void getProject() throws Exception { - project = service.getProject(PROJECT_NAME); - } - - @Test - @Override - public void getIssueCategories() throws Exception { - issueCategories = service.getIssueCategories(PROJECT_NAME); - } - - @Test - @Override - public void getTrackers() throws Exception { - trackers = service.getTrackers(PROJECT_NAME); - } - - @Test - @Override - public void getNews() throws Exception { - news = service.getNews(PROJECT_NAME); - } - - @Test - @Override - public void getUsers() throws Exception { - users = service.getUsers(PROJECT_NAME); - } - - @Test - @Override - public void getProjectIssues() throws Exception { - issues = service.getIssues(PROJECT_NAME); - } - - @Test - @Override - public void getVersions() throws Exception { - versions = service.getVersions(PROJECT_NAME); - } - - @Test - @Override - public void getVersion() throws Exception { - version = service.getVersion(PROJECT_NAME, VERSION_NAME); - } - - @Test - @Override - public void getVersionIssues() throws Exception { - issues = service.getIssues(PROJECT_NAME, VERSION_NAME); - } - - @Test - @Override - public void getOpenedIssues() throws Exception { - issues = service.getOpenedIssues(PROJECT_NAME); - } - - @Test - @Override - public void getClosedIssues() throws Exception { - issues = service.getClosedIssues(PROJECT_NAME); - } - - @Test - @Override - public void getIssueTimeEntries() throws Exception { - timeEntries = service.getIssueTimeEntries(PROJECT_NAME, ISSUE_ID); - } - - - @Test - @Override - public void getAttachments() throws Exception { - attachments = service.getAttachments(PROJECT_NAME, VERSION_NAME); - } - - @Test - @Override public void addVersion() throws Exception { - //TODO + // TODO } @Test @Override public void addAttachment() throws Exception { - //TODO + // TODO } @Test @Override public void addNews() throws Exception { - //TODO + // TODO } @Test @Override public void updateVersion() throws Exception { - //TODO + // TODO } @Test @Override public void nextVersion() throws Exception { - //TODO + // TODO } @Test @Override public void addIssueTime() throws Exception { - TimeEntry timeEntry = new TimeEntry(); - timeEntry.setActivityId(9); - timeEntry.setComments("ajout time"); - timeEntry.setHours(3.5f); -// timeEntry.setSpentOn(new Date()); - service.addIssueTimeEntry(PROJECT_NAME, ISSUE_ID, timeEntry); - //TODO +// TimeEntry timeEntry = new TimeEntry(); +// timeEntry.setActivityId(9); +// timeEntry.setComments("ajout time"); +// timeEntry.setHours(3.5f); +//// timeEntry.setSpentOn(new Date()); +// getService().addIssueTimeEntry(PROJECT_NAME, ISSUE_ID, timeEntry); } } Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineTestContract.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineTestContract.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/RedmineTestContract.java 2010-01-03 10:49:37 UTC (rev 66) @@ -32,8 +32,10 @@ void getNews() throws Exception; - void getUsers() throws Exception; + void getUserProjects() throws Exception; + void getProjectMembers() throws Exception; + void getProjectIssues() throws Exception; void getVersions() throws Exception; Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/TestHelper.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/TestHelper.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/TestHelper.java 2010-01-03 10:49:37 UTC (rev 66) @@ -46,7 +46,7 @@ protected static Properties defaultConfig; protected static Properties userConfig; protected static EnumMap<RedmineModelEnum, List<?>> memoryModel; - + public static void initDefaultConfiguration() throws IOException { if (DEFAULT_CONFIGURATION != null) { Modified: trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java =================================================================== --- trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/jredmine-client/src/test/java/org/nuiton/jredmine/rest/RedmineRestClientTest.java 2010-01-03 10:49:37 UTC (rev 66) @@ -142,9 +142,14 @@ } @Override - @Test - public void getUsers() throws Exception { + public void getUserProjects() throws Exception { + + doRequest(RedmineRestClient.GET_USER_PROJECTS, PROJECT_NAME); + } + @Override + public void getProjectMembers() throws Exception { + doRequest(RedmineRestClient.GET_USER_LIST, PROJECT_NAME); } Modified: trunk/jredmine-client/src/test/resources/log4j.properties =================================================================== --- trunk/jredmine-client/src/test/resources/log4j.properties 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/jredmine-client/src/test/resources/log4j.properties 2010-01-03 10:49:37 UTC (rev 66) @@ -23,4 +23,5 @@ log4j.logger.org.nuiton.jredmine=INFO log4j.logger.org.nuiton.io.rest=INFO +#log4j.logger.org.nuiton.io.xpp3.Xpp3Helper=DEBUG log4j.logger.org.apache.commons.httpclient.HttpClient=INFO Modified: trunk/maven-jredmine-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java =================================================================== --- trunk/maven-jredmine-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/maven-jredmine-plugin/src/main/java/org/nuiton/jredmine/plugin/AbstractRedmineMojo.java 2010-01-03 10:49:37 UTC (rev 66) @@ -173,12 +173,15 @@ protected boolean serviceInit; protected boolean initOk = true; + private boolean anonymous; public AbstractRedmineMojo(boolean requireProject, boolean requireVersion, boolean requireUser) { super(); this.requireProject = requireProject; this.requireVersion = requireVersion; this.requireUser = requireUser; + // by default, requires to be loggued + this.anonymous = false; } /////////////////////////////////////////////////////////////////////////// @@ -246,7 +249,7 @@ serviceInit = false; initOk = false; // if (verbose) { - getLog().error("could not init Redmine service [" + getRestUrl() + "] with user '" + getRestUsername() + "'", e); + getLog().error("could not init Redmine service [" + getRestUrl() + "] with user '" + getRestUsername() + "'", e); // } // return false; } @@ -315,7 +318,7 @@ getLog().info("skip goal, runOnce flag is on, and was already executed."); return false; } - + if (!serviceInit) { getLog().error("could not init Redmine service [" + getRestUrl() + "] with user '" + getRestUsername() + "'"); return false; @@ -501,6 +504,16 @@ this.encoding = encoding; } + @Override + public boolean isAnonymous() { + return anonymous; + } + + @Override + public void setAnonymous(boolean anonymous) { + this.anonymous = true; + } + /////////////////////////////////////////////////////////////////////////// /// Others /////////////////////////////////////////////////////////////////////////// @@ -557,7 +570,7 @@ protected boolean initReleaseUser() { try { - users = service.getUsers(projectId); + users = service.getProjectMembers(projectId); User user = ModelHelper.byLogin(username, users); Modified: trunk/maven-jredmine-plugin/src/main/java/org/nuiton/jredmine/plugin/DisplayDataMojo.java =================================================================== --- trunk/maven-jredmine-plugin/src/main/java/org/nuiton/jredmine/plugin/DisplayDataMojo.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/maven-jredmine-plugin/src/main/java/org/nuiton/jredmine/plugin/DisplayDataMojo.java 2010-01-03 10:49:37 UTC (rev 66) @@ -65,6 +65,8 @@ public DisplayDataMojo() { super(false, false, false); + // no need to be loggued to obtain informations from redmine + setAnonymous(true); } @Override @@ -94,6 +96,8 @@ return; } actions = getDownloadActions(types, + RedmineModelEnum.project, + RedmineModelEnum.version, RedmineModelEnum.issueStatus, RedmineModelEnum.issuePriority, RedmineModelEnum.issueCategory, @@ -131,7 +135,8 @@ RedmineModelScope scope = entry.getScope(); - Object[] datas = ((RedmineServiceImplementor) service).getDatas(entry.getModelType(), projectId, versionId); + String requestName = entry.getRequestAll(); + Object[] datas = ((RedmineServiceImplementor) service).getDatas(requestName, entry.getModelType(), projectId, versionId); buffer.append("\nValues of '").append(entry).append('\''); if (scope == RedmineModelScope.project || scope == RedmineModelScope.version) { buffer.append(" for project ").append(projectId); Modified: trunk/maven-jredmine-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoTest.java =================================================================== --- trunk/maven-jredmine-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoTest.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/maven-jredmine-plugin/src/test/java/org/nuiton/jredmine/plugin/AbstractRedmineMojoTest.java 2010-01-03 10:49:37 UTC (rev 66) @@ -20,7 +20,10 @@ */ package org.nuiton.jredmine.plugin; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.maven.model.IssueManagement; +import org.junit.After; import org.junit.Assert; import org.junit.BeforeClass; import org.nuiton.jredmine.TestHelper; @@ -36,6 +39,11 @@ */ public abstract class AbstractRedmineMojoTest<P extends AbstractRedmineMojo> extends AbstractMojoTest<P> { + /** + * Logger + */ + private static final Log log = LogFactory.getLog(AbstractRedmineMojoTest.class); + @BeforeClass public static void atTheBegining() throws IOException { @@ -53,7 +61,6 @@ i.setSystem(AbstractRedmineMojo.REDMINE_SYSTEM); i.setUrl(mojo.getRestUrl() + "/projects/one/issues"); mojo.getProject().setIssueManagement(i); - } @Override @@ -68,7 +75,14 @@ try { mojo.init(); canContinue = mojo.checkSkip(); + if (!canContinue) { + if (log.isInfoEnabled()) { + log.info("The goal was marked as to be skip, the test is done."); + } + return; + } } catch (Exception e) { + log.error(e); canContinue = false; } if (canContinue) { @@ -80,6 +94,14 @@ } } + @After + public void tearDown() throws Exception { + P mojo = getMojo(); + if (mojo != null) { + mojo.closeService(); + } + } + protected void mojoDoAction() throws Exception { if (!canContinue) { return; Modified: trunk/maven-jredmine-plugin/src/test/java/org/nuiton/jredmine/plugin/DisplayDataMojoTest.java =================================================================== --- trunk/maven-jredmine-plugin/src/test/java/org/nuiton/jredmine/plugin/DisplayDataMojoTest.java 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/maven-jredmine-plugin/src/test/java/org/nuiton/jredmine/plugin/DisplayDataMojoTest.java 2010-01-03 10:49:37 UTC (rev 66) @@ -34,6 +34,16 @@ } @Test + public void displayProjects() throws Exception { + mojoDoAction(); + } + + @Test + public void displayVersions() throws Exception { + mojoDoAction(); + } + + @Test public void displayProjectTrackers() throws Exception { mojoDoAction(); } Copied: trunk/maven-jredmine-plugin/src/test/resources/log4j.properties (from rev 65, trunk/maven-jredmine-plugin/src/main/resources/log4j.properties) =================================================================== --- trunk/maven-jredmine-plugin/src/test/resources/log4j.properties (rev 0) +++ trunk/maven-jredmine-plugin/src/test/resources/log4j.properties 2010-01-03 10:49:37 UTC (rev 66) @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +log4j.rootCategory=WARN, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%p] (%c{1}:%L) - %m%n + +log4j.logger.org.nuiton.jredmine=INFO +log4j.logger.org.nuiton.io.rest=INFO +log4j.logger.org.nuiton.plugin.AbstractMojoTest=INFO +log4j.logger.org.apache.commons.httpclient.HttpClient=INFO Modified: trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayAll.xml =================================================================== --- trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayAll.xml 2010-01-01 20:45:06 UTC (rev 65) +++ trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayAll.xml 2010-01-03 10:49:37 UTC (rev 66) @@ -19,7 +19,7 @@ <configuration> <projectId>one</projectId> <versionId>1.0.0</versionId> - <types>tracker,user,issueStatus,issueCategory,issuePriority,tracker</types> + <types>project,version,tracker,user,issueStatus,issueCategory,issuePriority,tracker</types> </configuration> <executions> <execution> Added: trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayProjects.xml =================================================================== --- trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayProjects.xml (rev 0) +++ trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayProjects.xml 2010-01-03 10:49:37 UTC (rev 66) @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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"> + + <groupId>org.nuiton.maven-redmine-plugin</groupId> + <artifactId>test-generate-changes</artifactId> + <version>0</version> + <modelVersion>4.0.0</modelVersion> + + <name>generate-changes</name> + + <build> + + <plugins> + <plugin> + <groupId>org.nuiton.jredmine</groupId> + <artifactId>maven-jredmine-plugin</artifactId> + <configuration> + <!--<projectId>one</projectId>--> + <!--<versionId>1.0.0</versionId>--> + <types>project</types> + </configuration> + <executions> + <execution> + <goals> + <goal>display-data</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Added: trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayVersions.xml =================================================================== --- trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayVersions.xml (rev 0) +++ trunk/maven-jredmine-plugin/src/test/resources/org/nuiton/jredmine/plugin/displayDataMojoTest/displayVersions.xml 2010-01-03 10:49:37 UTC (rev 66) @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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"> + + <groupId>org.nuiton.maven-redmine-plugin</groupId> + <artifactId>test-generate-changes</artifactId> + <version>0</version> + <modelVersion>4.0.0</modelVersion> + + <name>generate-changes</name> + + <build> + + <plugins> + <plugin> + <groupId>org.nuiton.jredmine</groupId> + <artifactId>maven-jredmine-plugin</artifactId> + <configuration> + <projectId>one</projectId> + <!--<versionId>1.0.0</versionId>--> + <types>version</types> + </configuration> + <executions> + <execution> + <goals> + <goal>display-data</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file
participants (1)
-
tchemit@users.nuiton.org