diff --git a/.gitignore b/.gitignore
index 13bbe5b911..6677fea66a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,15 @@
-.idea/
-
+.DS_Store
+.idea
+*.iml
+rebel.xml
+private.properties
+target/
+dist/
+private/
+classes/
+build/
+node_modules/
+bower_components/
+derby.log
+gcm.properties
+npm-debug.log
\ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index b83ade6962..0000000000
--- a/.gitmodules
+++ /dev/null
@@ -1,28 +0,0 @@
-[submodule "docdoku-plm-server"]
- path = docdoku-plm-server
- url = https://github.com/docdoku/docdoku-plm-server.git
- branch = master
-[submodule "docdoku-plm-front"]
- path = docdoku-plm-front
- url = https://github.com/docdoku/docdoku-plm-front.git
- branch = master
-[submodule "docdoku-plm-sample-data"]
- path = docdoku-plm-sample-data
- url = https://github.com/docdoku/docdoku-plm-sample-data.git
- branch = master
-[submodule "docdoku-plm-doc"]
- path = docdoku-plm-doc
- url = https://github.com/docdoku/docdoku-plm-doc.git
- branch = master
-[submodule "docdoku-plm-docker"]
- path = docdoku-plm-docker
- url = https://github.com/docdoku/docdoku-plm-docker.git
- branch = master
-[submodule "docdoku-plm-conversion-service"]
- path = docdoku-plm-conversion-service
- url = https://github.com/docdoku/docdoku-plm-conversion-service.git
- branch = master
-[submodule "docdoku-plm-api"]
- path = docdoku-plm-api
- url = https://github.com/docdoku/docdoku-plm-api.git
- branch = master
diff --git a/NOTICE.txt b/NOTICE.txt
new file mode 100644
index 0000000000..7c8f131725
--- /dev/null
+++ b/NOTICE.txt
@@ -0,0 +1,44 @@
+Args4j - The MIT License - http://opensource.org/licenses/mit-license.php
+Elasticsearch - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+Commons IO - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+Commons Codec - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+Lucene - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+Apache POI - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+JODConverter - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+mustache.js - The MIT License - http://opensource.org/licenses/mit-license.php
+LESSCSS - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+Modernizr - The MIT License - http://opensource.org/licenses/mit-license.php
+jQuery - The MIT License - http://opensource.org/licenses/mit-license.php
+Three.js - The MIT License - http://opensource.org/licenses/mit-license.php
+Underscore.js - The MIT License - http://opensource.org/licenses/mit-license.php
+Buzz - The MIT License - http://opensource.org/licenses/mit-license.php
+RequireJS - The MIT License - http://opensource.org/licenses/mit-license.php
+Backbone.js - The MIT License - http://opensource.org/licenses/mit-license.php
+bootstrap-switch - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+dataTables - BSD license 3-Clause http://opensource.org/licenses/BSD-3-Clause
+OkHttp - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+mustache.java - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+Guava - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+artofsolving - LGPL Version 2.1, http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
+java3d vecmath - Java Distribution License (JDL), https://java3d.java.net/jdl-java3d.pdf
+ITextPDF - AGPL Version 3, https://www.gnu.org/licenses/agpl-3.0.txt
+Dozer - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+Joda-Time - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+Bouncy Castle - The MIT License - http://opensource.org/licenses/mit-license.php
+Glassfish - COMMON DEVELOPMENT AND DISTRIBUTION (CDDL) Version 1.0, https://glassfish.java.net/public/CDDL+GPL.html
+Jackson FasterXML - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+Swagger - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+Brsanthu MigBase64 - BSD license 3-Clause http://opensource.org/licenses/BSD-3-Clause
+Underscore - The MIT License - http://opensource.org/licenses/mit-license.php
+Moment - The MIT License - http://opensource.org/licenses/mit-license.php
+Lodash - The MIT License - http://opensource.org/licenses/mit-license.php
+Fontawesome - SIL OFL 1.1 - http://scripts.sil.org/OFL
+Bootbox - The MIT License - http://opensource.org/licenses/mit-license.php
+Tweenjs - The MIT License - http://opensource.org/licenses/mit-license.php
+Unorm - The MIT License - http://opensource.org/licenses/mit-license.php
+BuzzJS - The MIT License - http://opensource.org/licenses/mit-license.php
+AsyncJS - The MIT License - http://opensource.org/licenses/mit-license.php
+SelectizeJS - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
+Datatables - The MIT License - http://opensource.org/licenses/mit-license.php
+dateformat - The MIT License - http://opensource.org/licenses/mit-license.php
+dat.gui - Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/
\ No newline at end of file
diff --git a/README.md b/README.md
index 632ad28d54..89d7507e6a 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Welcome to the DocDokuPLM project
+
Welcome to the DocDokuPLM project
## What is DocDokuPLM?
@@ -16,15 +16,15 @@ DocDokuPLM is a high end Open Source PLM solution.
## Project support
-The Project is lead by the DocDoku team.
+The Project is lead by the DocDoku team and is part of the [OW2 Consortium](http://ow2.org/).
## Setting Up
You have a full description of the [Installation Guide](https://github.com/docdoku/docdoku-plm/wiki/Installation-Guide).
-To know how to use the PLM, you can look at the [Quick Starter Guide](https://github.com/docdoku/docdoku-plm/wiki/Quick-Starter-Guide) or at the [User Guide](http://docdokuplm.com/docdoku-plm/user-guide/en/2.5/).
+To know how to use the PLM, you can look at the [Quick Starter Guide](https://github.com/docdoku/docdoku-plm/wiki/Quick-Starter-Guide) or at the [User Guide](http://docdokuplm.com/docdoku-plm/user-guide/en/2.0/).
-## Coding
+## Coding
You may fork or just clone the code on [GitHub](https://github.com/docdoku/docdoku-plm) and then compile and package it with Maven.
@@ -34,4 +34,4 @@ You have more information in the [Development Guide](https://github.com/docdoku/
AGPL version 3
-## [Cloud Hosting](https://docdokuplm.net)
+## [Cloud Hosting](http://docdokuplm.net)
diff --git a/docdoku-api-java/README.md b/docdoku-api-java/README.md
new file mode 100644
index 0000000000..f6184f8400
--- /dev/null
+++ b/docdoku-api-java/README.md
@@ -0,0 +1,23 @@
+# Docdoku API Java
+
+Generates a jar that could be used in other projects to consume DocdokuPLM web services
+
+## Documentation
+
+Create a client, then use http services, example :
+
+ ApiClient client = new DocdokuPLMBasicClient("http://localhost:8080/api", login, password).getClient();
+ AccountDTO myAccount = new AccountsApi(client).getAccount();
+
+See all classes under `src/test/java` for api usage
+
+## Development guide
+
+Build
+
+* Run `mvn clean install` docdoku-api module
+* Run `mvn clean install` this module
+
+Tests
+
+Tests needs a running server and are skipped from build, they validate the build from generated sources. Edit TestConfig.java if needed.
diff --git a/docdoku-api-java/pom.xml b/docdoku-api-java/pom.xml
new file mode 100644
index 0000000000..51db425588
--- /dev/null
+++ b/docdoku-api-java/pom.xml
@@ -0,0 +1,234 @@
+
+
+
+ docdoku-plm
+ com.docdoku
+ 2.5-SNAPSHOT
+
+ jar
+ 4.0.0
+ docdoku-api-java
+
+
+
+ io.swagger
+ swagger-annotations
+ ${swagger-annotations-version}
+
+
+ commons-codec
+ commons-codec
+ 1.5
+
+
+
+ org.glassfish.jersey.core
+ jersey-client
+ ${jersey-version}
+
+
+ org.glassfish.jersey.media
+ jersey-media-multipart
+ ${jersey-version}
+
+
+ org.glassfish.jersey.media
+ jersey-media-json-jackson
+ 2.22.1
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-core
+ ${jackson-version}
+
+
+ com.fasterxml.jackson.core
+ jackson-annotations
+ ${jackson-version}
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson-version}
+
+
+ com.fasterxml.jackson.datatype
+ jackson-datatype-joda
+ 2.1.5
+
+
+ joda-time
+ joda-time
+ ${jodatime-version}
+
+
+
+ com.squareup.okhttp3
+ okhttp
+ 3.2.0
+
+
+
+
+ com.brsanthu
+ migbase64
+ 2.2
+
+
+
+
+ junit
+ junit
+ ${junit-version}
+ test
+
+
+ commons-io
+ commons-io
+ 2.4
+ test
+
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ 1.10
+
+
+ generate-sources
+ add-source
+
+
+ ${project.basedir}/src/main/java
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.1
+
+ 1.8
+ 1.8
+ ${project.build.sourceEncoding}
+
+
+
+
+
+ io.swagger
+ swagger-codegen-maven-plugin
+ 2.1.5
+
+
+ generate-sources
+
+ generate
+
+
+ ${project.parent.basedir}/docdoku-api/target/swagger/swagger.json
+ java
+
+ com.docdoku.api.services
+ com.docdoku.api.client
+ com.docdoku.api.models
+ jersey2
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy-dependencies
+ prepare-package
+
+ copy-dependencies
+
+
+ ${project.build.directory}/lib
+ false
+ false
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+ jar-with-dependencies
+
+
+
+
+ make-assembly
+ package
+
+ single
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.16
+
+ true
+
+ ${env.URL}
+ ${env.LOGIN}
+ ${env.PASSWORD}
+ ${env.WORKSPACE}
+ ${env.DEBUG}
+
+
+
+
+
+
+
+ running-instance
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.16
+
+ false
+
+
+
+
+
+
+
+
+ 1.5.8
+ 2.12
+ 2.4.2
+ 2.3
+ 1.0.0
+ 4.8.1
+
+
+
\ No newline at end of file
diff --git a/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMBasicClient.java b/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMBasicClient.java
new file mode 100644
index 0000000000..85e49e5935
--- /dev/null
+++ b/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMBasicClient.java
@@ -0,0 +1,45 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiClient;
+import okhttp3.Credentials;
+
+/**
+ * This class helps to create the swagger client.
+ * @author Morgan Guimard
+ */
+public class DocdokuPLMBasicClient extends DocdokuPLMClient{
+
+ public DocdokuPLMBasicClient(String host, String login, String password) {
+ this(host,login,password,false);
+ }
+
+ public DocdokuPLMBasicClient(String host, String login, String password, boolean debug) {
+ super(host,debug);
+ client.addDefaultHeader("Authorization", Credentials.basic(login, password));
+ }
+
+ public ApiClient getClient(){
+ return client;
+ }
+
+}
diff --git a/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMClient.java b/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMClient.java
new file mode 100644
index 0000000000..34d64d4014
--- /dev/null
+++ b/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMClient.java
@@ -0,0 +1,55 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiClient;
+
+import java.text.SimpleDateFormat;
+
+/**
+ * This class helps to create the swagger client.
+ * @author Morgan Guimard
+ */
+public class DocdokuPLMClient {
+
+ protected ApiClient client;
+ protected String host;
+ protected boolean debug;
+
+ public DocdokuPLMClient(String host, boolean debug) {
+ this.host = host;
+ this.debug = debug;
+ createClient();
+ }
+
+ public void connect(String login, String password){}
+
+ protected void createClient() {
+ client = new ApiClient();
+ client.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
+ client.setBasePath(host);
+ client.setDebugging(debug);
+ }
+
+ public ApiClient getClient() {
+ return client;
+ }
+}
diff --git a/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMCookieClient.java b/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMCookieClient.java
new file mode 100644
index 0000000000..6d063411a1
--- /dev/null
+++ b/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMCookieClient.java
@@ -0,0 +1,80 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiClient;
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.AccountDTO;
+import com.docdoku.api.services.AccountsApi;
+import okhttp3.Credentials;
+
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class helps to create the swagger client.
+ * @author Morgan Guimard
+ */
+public class DocdokuPLMCookieClient extends DocdokuPLMClient{
+
+ private String cookie;
+
+ private static final Logger LOGGER = Logger.getLogger(DocdokuPLMCookieClient.class.getName());
+
+ public DocdokuPLMCookieClient(String host, String login, String password) {
+ this(host,login,password,false);
+ }
+
+ public DocdokuPLMCookieClient(String host, String login, String password, boolean debug) {
+ super(host,debug);
+ connect(login, password);
+ }
+
+
+ public void connect(String login, String password){
+
+ client.addDefaultHeader("Authorization", Credentials.basic(login, password));
+
+ try {
+ AccountDTO account = new AccountsApi(client).getAccount();
+ LOGGER.log(Level.INFO,"Connected as " + account.getName());
+ Map> responseHeaders = client.getResponseHeaders();
+ System.out.println(responseHeaders);
+ List strings = responseHeaders.get("Set-Cookie");
+ if(strings != null && !strings.isEmpty()){
+ this.cookie = strings.get(0);
+ createClient();
+ client.addDefaultHeader("Cookie", this.cookie);
+ } else {
+ LOGGER.log(Level.WARNING,"Cannot fetch cookie");
+ }
+
+ } catch (ApiException e) {
+ LOGGER.log(Level.SEVERE,"Cannot connect to docdoku plm server http response code = " + client.getStatusCode()); }
+ }
+
+ public ApiClient getClient(){
+ return client;
+ }
+
+}
diff --git a/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMJWTClient.java b/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMJWTClient.java
new file mode 100644
index 0000000000..46af1f0d4a
--- /dev/null
+++ b/docdoku-api-java/src/main/java/com/docdoku/api/DocdokuPLMJWTClient.java
@@ -0,0 +1,79 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.AccountDTO;
+import com.docdoku.api.models.LoginRequestDTO;
+import com.docdoku.api.services.AuthApi;
+
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class helps to create the swagger client.
+ * @author Morgan Guimard
+ */
+public class DocdokuPLMJWTClient extends DocdokuPLMClient{
+
+ private String token;
+
+ private static final Logger LOGGER = Logger.getLogger(DocdokuPLMJWTClient.class.getName());
+
+ public DocdokuPLMJWTClient(String host, String login, String password) {
+ this(host,login,password,false);
+ }
+
+ public DocdokuPLMJWTClient(String host, String login, String password, boolean debug) {
+ super(host,debug);
+ connect(login, password);
+ }
+
+ @Override
+ public void connect(String login, String password){
+
+ LoginRequestDTO loginRequestDTO = new LoginRequestDTO();
+ loginRequestDTO.setLogin(login);
+ loginRequestDTO.setPassword(password);
+
+ try {
+ AccountDTO account = new AuthApi(client).login(loginRequestDTO);
+ LOGGER.log(Level.INFO,"Connected as " + account.getName());
+ Map> responseHeaders = client.getResponseHeaders();
+ System.out.println(responseHeaders);
+ List strings = responseHeaders.get("jwt");
+ if(strings != null && !strings.isEmpty()){
+ this.token = strings.get(0);
+ createClient();
+ client.addDefaultHeader("Authorization", "Bearer " + this.token);
+ } else {
+ LOGGER.log(Level.WARNING,"Cannot fetch token");
+ }
+
+ } catch (ApiException e) {
+ LOGGER.log(Level.SEVERE,"Cannot connect to docdoku plm server http response code = " + client.getStatusCode());
+ }
+
+ }
+
+}
diff --git a/docdoku-api-java/src/main/java/com/docdoku/api/models/utils/LastIterationHelper.java b/docdoku-api-java/src/main/java/com/docdoku/api/models/utils/LastIterationHelper.java
new file mode 100644
index 0000000000..878511f7cd
--- /dev/null
+++ b/docdoku-api-java/src/main/java/com/docdoku/api/models/utils/LastIterationHelper.java
@@ -0,0 +1,43 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api.models.utils;
+
+import com.docdoku.api.models.DocumentIterationDTO;
+import com.docdoku.api.models.DocumentRevisionDTO;
+import com.docdoku.api.models.PartIterationDTO;
+import com.docdoku.api.models.PartRevisionDTO;
+/**
+ * This class helps to get last iteration from documents or parts
+ * @Author Morgan Guimard
+ */
+public class LastIterationHelper {
+
+ public static DocumentIterationDTO getLastIteration(DocumentRevisionDTO documentRevisionDTO){
+ int iterations = documentRevisionDTO.getDocumentIterations().size();
+ return documentRevisionDTO.getDocumentIterations().get(iterations - 1);
+ }
+
+ public static PartIterationDTO getLastIteration(PartRevisionDTO partRevisionDTO){
+ int iterations = partRevisionDTO.getPartIterations().size();
+ return partRevisionDTO.getPartIterations().get(iterations - 1);
+ }
+
+}
diff --git a/docdoku-api-java/src/main/java/com/docdoku/api/models/utils/UploadDownloadHelper.java b/docdoku-api-java/src/main/java/com/docdoku/api/models/utils/UploadDownloadHelper.java
new file mode 100644
index 0000000000..60fdc3eb57
--- /dev/null
+++ b/docdoku-api-java/src/main/java/com/docdoku/api/models/utils/UploadDownloadHelper.java
@@ -0,0 +1,130 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api.models.utils;
+
+import com.docdoku.api.client.ApiClient;
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.client.Pair;
+import com.docdoku.api.models.DocumentIterationDTO;
+import com.docdoku.api.models.PartIterationDTO;
+
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * This class helps to upload and download files on documents and parts
+ *
+ * @implNote : This is a temporary class and will be removed as soon as fix generated upload and download
+ * methods with swagger-codegen
+ *
+ * @author Morgan Guimard
+ */
+public class UploadDownloadHelper {
+
+ private static final int CHUNK_SIZE = 1024 * 8;
+
+ public static void uploadAttachedFile(PartIterationDTO partIterationDTO, ApiClient client, File file) throws ApiException {
+ String path = "/files/{workspaceId}/parts/{number}/{version}/{iteration}/attachedfiles".replaceAll("\\{format\\}", "json")
+ .replaceAll("\\{" + "workspaceId" + "\\}", client.escapeString(partIterationDTO.getWorkspaceId()))
+ .replaceAll("\\{" + "number" + "\\}", client.escapeString(partIterationDTO.getNumber()))
+ .replaceAll("\\{" + "version" + "\\}", client.escapeString(partIterationDTO.getVersion()))
+ .replaceAll("\\{" + "iteration" + "\\}", String.valueOf(partIterationDTO.getIteration()));
+
+ upload(path, file, client);
+ }
+
+ public static void uploadAttachedFile(DocumentIterationDTO documentIterationDTO, ApiClient client, File file) throws ApiException {
+
+ String path = "/files/{workspaceId}/documents/{documentId}/{version}/{iteration}".replaceAll("\\{format\\}", "json")
+ .replaceAll("\\{" + "workspaceId" + "\\}", client.escapeString(documentIterationDTO.getWorkspaceId()))
+ .replaceAll("\\{" + "documentId" + "\\}", client.escapeString(documentIterationDTO.getDocumentMasterId()))
+ .replaceAll("\\{" + "version" + "\\}", client.escapeString(documentIterationDTO.getVersion()))
+ .replaceAll("\\{" + "iteration" + "\\}", String.valueOf(documentIterationDTO.getIteration()));
+
+ upload(path,file,client);
+
+ }
+
+ public static void uploadNativeCADFile(PartIterationDTO partIterationDTO, ApiClient client, File file) throws ApiException {
+ String path = "/files/{workspaceId}/parts/{number}/{version}/{iteration}/nativecad".replaceAll("\\{format\\}", "json")
+ .replaceAll("\\{" + "workspaceId" + "\\}", client.escapeString(partIterationDTO.getWorkspaceId()))
+ .replaceAll("\\{" + "number" + "\\}", client.escapeString(partIterationDTO.getNumber()))
+ .replaceAll("\\{" + "version" + "\\}", client.escapeString(partIterationDTO.getVersion()))
+ .replaceAll("\\{" + "iteration" + "\\}", String.valueOf(partIterationDTO.getIteration()));
+
+ upload(path,file,client);
+ }
+
+ private static void upload(String path, File file, ApiClient client) throws ApiException {
+ List queryParams = new ArrayList();
+ Map headerParams = new HashMap();
+ Map formParams = new HashMap();
+ formParams.put("upload", file);
+ final String[] accepts = {};
+ final String accept = client.selectHeaderAccept(accepts);
+ final String[] contentTypes = {MediaType.MULTIPART_FORM_DATA};
+ final String contentType = client.selectHeaderContentType(contentTypes);
+ String[] authNames = new String[]{};
+ client.invokeAPI(path, "POST", queryParams, file, headerParams, formParams, accept, contentType, authNames, null);
+ }
+
+ public static File downloadFile(String fileName, ApiClient client) throws ApiException {
+ String path = "/files/" + fileName;
+ List queryParams = new ArrayList();
+ Map headerParams = new HashMap();
+ Map formParams = new HashMap();
+ final String[] accepts = {"application/octet-stream"};
+ final String accept = client.selectHeaderAccept(accepts);
+ final String[] contentTypes = {};
+ final String contentType = client.selectHeaderContentType(contentTypes);
+ String[] authNames = new String[]{};
+ GenericType returnType = new GenericType() {
+ };
+ File file = client.invokeAPI(path, "GET", queryParams, null, headerParams, formParams, accept, contentType, authNames, returnType);
+ Map> responseHeaders = client.getResponseHeaders();
+ List encoding = responseHeaders.get("Content-Encoding");
+
+ return encoding != null && "gzip".equals(encoding.get(0)) ? uncompress(file) : file;
+ }
+
+
+ private static File uncompress(File file) {
+ File out = new File(file.getAbsolutePath() + ".unzip");
+ int length;
+ byte[] data = new byte[CHUNK_SIZE];
+ try (GZIPInputStream is = new GZIPInputStream(new FileInputStream(file)); OutputStream os = new FileOutputStream(out)) {
+ while ((length = is.read(data)) != -1) {
+ os.write(data, 0, length);
+ }
+ os.flush();
+ return out;
+ } catch (IOException e) {
+ return file;
+ }
+ }
+
+}
diff --git a/docdoku-api-java/src/main/java/com/docdoku/api/models/utils/WorkflowHelper.java b/docdoku-api-java/src/main/java/com/docdoku/api/models/utils/WorkflowHelper.java
new file mode 100644
index 0000000000..965ec1bf1f
--- /dev/null
+++ b/docdoku-api-java/src/main/java/com/docdoku/api/models/utils/WorkflowHelper.java
@@ -0,0 +1,85 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api.models.utils;
+
+import com.docdoku.api.models.*;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * This class helps to manipulate workflow objects
+ * @Author Morgan Guimard
+ */
+public class WorkflowHelper {
+
+ public static ActivityDTO getCurrentActivity(WorkflowDTO workflow){
+
+ List activities = workflow.getActivities();
+ int currentStep = getCurrentStep(workflow);
+ if (currentStep < activities.size()) {
+ return activities.get(currentStep);
+ } else {
+ return null;
+ }
+
+ }
+
+ public static int getCurrentStep(WorkflowDTO workflow){
+ List activities = workflow.getActivities();
+ int i = 0;
+ for (ActivityDTO activity : activities) {
+ if (activity.getComplete()) {
+ i++;
+ } else {
+ break;
+ }
+ }
+ return i;
+ }
+
+
+ public static List getRunningTasks(WorkflowDTO workflowDTO) {
+ return getRunningTasks(getCurrentActivity(workflowDTO));
+ }
+
+ public static List getRunningTasks(ActivityDTO currentActivity) {
+ List tasks = new ArrayList<>();
+ for(TaskDTO task : currentActivity.getTasks()){
+ if(TaskDTO.StatusEnum.IN_PROGRESS.equals(task.getStatus())){
+ tasks.add(task);
+ }
+ }
+ return tasks;
+ }
+
+ public static Set getRolesInvolved(WorkflowModelDTO workflowModel) {
+ Set roles = new HashSet<>();
+ for(ActivityModelDTO activityModelDTO:workflowModel.getActivityModels()){
+ for(TaskModelDTO taskModelDTO : activityModelDTO.getTaskModels()){
+ roles.add(taskModelDTO.getRole());
+ }
+ }
+ return roles;
+ }
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/AccountsApiTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/AccountsApiTest.java
new file mode 100644
index 0000000000..0cff478e86
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/AccountsApiTest.java
@@ -0,0 +1,71 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.AccountDTO;
+import com.docdoku.api.services.AccountsApi;
+import junit.framework.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.util.UUID;
+
+@RunWith(JUnit4.class)
+public class AccountsApiTest {
+
+ @Test
+ public void createAccountTest() throws ApiException {
+ String login = "USER-"+ UUID.randomUUID().toString().substring(0,6);
+ AccountDTO accountDTO = new AccountDTO();
+ accountDTO.setLogin(login);
+ accountDTO.setEmail("my@email.com");
+ accountDTO.setNewPassword("password");
+ accountDTO.setLanguage("en");
+ accountDTO.setName("Mr " + login);
+ accountDTO.setTimeZone("CET");
+ AccountDTO account = new AccountsApi(TestConfig.GUEST_CLIENT).createAccount(accountDTO);
+ Assert.assertEquals(account.getLogin(), login);
+ }
+
+ @Test
+ public void getAccountTest() throws ApiException {
+ AccountDTO account = new AccountsApi(TestConfig.BASIC_CLIENT).getAccount();
+ Assert.assertEquals(account.getLogin(), TestConfig.LOGIN);
+ }
+
+ @Test
+ public void updateAccountTest() throws ApiException {
+
+ String newName = UUID.randomUUID().toString().substring(0,6);
+
+ AccountsApi accountsApi = new AccountsApi(TestConfig.BASIC_CLIENT);
+ AccountDTO account = accountsApi.getAccount();
+ account.setName(newName);
+
+ AccountDTO updatedAccount = accountsApi.updateAccount(account);
+ Assert.assertEquals(updatedAccount.getName(), newName);
+ Assert.assertEquals(updatedAccount,account);
+
+ }
+
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/DocdokuPLMClientTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/DocdokuPLMClientTest.java
new file mode 100644
index 0000000000..81a45530f7
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/DocdokuPLMClientTest.java
@@ -0,0 +1,80 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiClient;
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.AccountDTO;
+import com.docdoku.api.models.WorkspaceDTO;
+import com.docdoku.api.models.WorkspaceListDTO;
+import com.docdoku.api.services.AccountsApi;
+import com.docdoku.api.services.WorkspacesApi;
+import junit.framework.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.util.UUID;
+
+/**
+ * This class tests DocdokuPLMClient class
+ * @Author Morgan Guimard
+ */
+
+@RunWith(JUnit4.class)
+public class DocdokuPLMClientTest {
+ @Test
+ public void basicTests() throws ApiException {
+ runTest(TestConfig.BASIC_CLIENT);
+ }
+
+ @Test
+ public void cookieTests() throws ApiException {
+ runTest(TestConfig.COOKIE_CLIENT);
+ }
+
+ @Test
+ @Ignore
+ public void jwtTests() throws ApiException {
+ runTest(TestConfig.JWT_CLIENT);
+ }
+
+
+ private void runTest(ApiClient client) throws ApiException {
+ WorkspacesApi workspacesApi = new WorkspacesApi(client);
+ AccountsApi accountsApi = new AccountsApi(client);
+
+ AccountDTO account = accountsApi.getAccount();
+ Assert.assertEquals(TestConfig.LOGIN, account.getLogin());
+
+ WorkspaceDTO workspace = new WorkspaceDTO();
+ workspace.setId(UUID.randomUUID().toString());
+
+ workspacesApi.createWorkspace(workspace, TestConfig.LOGIN);
+
+ WorkspaceListDTO workspacesForConnectedUser = workspacesApi.getWorkspacesForConnectedUser();
+ Assert.assertNotNull(workspacesForConnectedUser);
+ Assert.assertTrue("Should contain created workspace", workspacesForConnectedUser.getAllWorkspaces().contains(workspace));
+ workspacesApi.deleteWorkspace(workspace.getId());
+ }
+
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/DocumentApiTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/DocumentApiTest.java
new file mode 100644
index 0000000000..4ac9afa467
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/DocumentApiTest.java
@@ -0,0 +1,126 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.*;
+import com.docdoku.api.models.utils.LastIterationHelper;
+import com.docdoku.api.models.utils.UploadDownloadHelper;
+import com.docdoku.api.services.DocumentApi;
+import com.docdoku.api.services.FoldersApi;
+import org.apache.commons.io.FileUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.UUID;
+
+@RunWith(JUnit4.class)
+public class DocumentApiTest {
+
+ private DocumentApi documentApi = new DocumentApi(TestConfig.BASIC_CLIENT);
+ private FoldersApi foldersApi = new FoldersApi(TestConfig.BASIC_CLIENT);
+
+ @Test
+ public void documentApiUsageTests() throws ApiException {
+
+ // Create a document
+ DocumentCreationDTO document = new DocumentCreationDTO();
+ document.setReference(UUID.randomUUID().toString().substring(0,6));
+ document.setTitle("GeneratedDoc");
+
+ DocumentRevisionDTO createdDocument = foldersApi.createDocumentMasterInFolder(TestConfig.WORKSPACE, document, TestConfig.WORKSPACE);
+ Assert.assertEquals(createdDocument.getDocumentMasterId(),document.getReference());
+
+ // Check in
+ DocumentRevisionDTO checkedInDocument = documentApi.checkInDocument(TestConfig.WORKSPACE, createdDocument.getDocumentMasterId(), createdDocument.getVersion(), "");
+ Assert.assertEquals(checkedInDocument.getDocumentMasterId(),document.getReference());
+ Assert.assertEquals(LastIterationHelper.getLastIteration(checkedInDocument).getIteration(), Integer.valueOf("1"));
+
+ // Check out
+ DocumentRevisionDTO checkedOutDocument = documentApi.checkOutDocument(TestConfig.WORKSPACE, createdDocument.getDocumentMasterId(), createdDocument.getVersion(), "");
+ Assert.assertEquals(checkedOutDocument.getDocumentMasterId(),document.getReference());
+ Assert.assertEquals(LastIterationHelper.getLastIteration(checkedOutDocument).getIteration(),Integer.valueOf("2"));
+
+ // Undo check out
+ DocumentRevisionDTO undoCheckOutDocument= documentApi.undoCheckOutDocument(TestConfig.WORKSPACE, createdDocument.getDocumentMasterId(), createdDocument.getVersion(), "");
+ Assert.assertEquals(undoCheckOutDocument,checkedInDocument);
+
+ // Check out
+ checkedOutDocument = documentApi.checkOutDocument(TestConfig.WORKSPACE, createdDocument.getDocumentMasterId(), createdDocument.getVersion(), "");
+
+ // Edit
+ DocumentIterationDTO lastIteration = LastIterationHelper.getLastIteration(checkedOutDocument);
+ Assert.assertNull(lastIteration.getModificationDate());
+ lastIteration.setRevisionNote("Something modified");
+
+ DocumentIterationDTO updatedIteration = documentApi.updateDocumentIteration(TestConfig.WORKSPACE, checkedOutDocument.getDocumentMasterId(), checkedOutDocument.getVersion(), "2", lastIteration);
+
+ Assert.assertNotNull(updatedIteration.getModificationDate());
+ lastIteration.setModificationDate(updatedIteration.getModificationDate());
+ Assert.assertEquals(lastIteration,updatedIteration);
+
+ // Check in
+ checkedInDocument = documentApi.checkInDocument(TestConfig.WORKSPACE, createdDocument.getDocumentMasterId(), createdDocument.getVersion(), "");
+ Assert.assertNull(checkedInDocument.getCheckOutUser());
+
+ // Release
+ DocumentRevisionDTO releasedDocument = documentApi.releaseDocumentRevision(TestConfig.WORKSPACE, checkedInDocument.getDocumentMasterId(), checkedInDocument.getVersion(), "");
+ Assert.assertEquals(releasedDocument.getStatus(), DocumentRevisionDTO.StatusEnum.RELEASED);
+
+ // Mark as obsolete
+ DocumentRevisionDTO obsoleteDocument = documentApi.markDocumentRevisionAsObsolete(TestConfig.WORKSPACE, releasedDocument.getDocumentMasterId(), releasedDocument.getVersion(), "");
+ Assert.assertEquals(obsoleteDocument.getStatus(), DocumentRevisionDTO.StatusEnum.OBSOLETE);
+
+ }
+
+ @Test
+ public void uploadDownloadAttachedFilesToDocumentTest() throws ApiException, IOException {
+
+ // Create a document
+ DocumentCreationDTO documentCreation = new DocumentCreationDTO();
+ documentCreation.setReference(UUID.randomUUID().toString().substring(0, 6));
+ documentCreation.setTitle("GeneratedDoc");
+
+ DocumentRevisionDTO document = foldersApi.createDocumentMasterInFolder(TestConfig.WORKSPACE, documentCreation, TestConfig.WORKSPACE);
+
+ URL fileURL = DocumentApiTest.class.getClassLoader().getResource("com/docdoku/api/attached-file.md");
+ File file = new File(fileURL.getPath());
+
+ DocumentIterationDTO lastIteration = LastIterationHelper.getLastIteration(document);
+ UploadDownloadHelper.uploadAttachedFile(lastIteration, TestConfig.BASIC_CLIENT, file);
+
+ document = documentApi.getDocumentRevision(TestConfig.WORKSPACE, document.getDocumentMasterId(), document.getVersion(), null);
+
+ lastIteration = LastIterationHelper.getLastIteration(document);
+ Assert.assertFalse(lastIteration.getAttachedFiles().isEmpty());
+
+ File downloadedFile = UploadDownloadHelper.downloadFile(lastIteration.getAttachedFiles().get(0), TestConfig.BASIC_CLIENT);
+ Assert.assertTrue(FileUtils.contentEquals(file, downloadedFile));
+
+ }
+
+
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/FoldersApiTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/FoldersApiTest.java
new file mode 100644
index 0000000000..4dc76818d9
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/FoldersApiTest.java
@@ -0,0 +1,56 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.FolderDTO;
+import com.docdoku.api.services.FoldersApi;
+import junit.framework.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.util.List;
+import java.util.UUID;
+
+@RunWith(JUnit4.class)
+public class FoldersApiTest {
+
+ @Test
+ public void getRootFoldersTest() throws ApiException {
+ FoldersApi foldersApi = new FoldersApi(TestConfig.BASIC_CLIENT);
+ List rootFolders = foldersApi.getRootFolders(TestConfig.WORKSPACE, null);
+ Assert.assertNotNull(rootFolders);
+ }
+
+ @Test
+ public void createRootFoldersTest() throws ApiException {
+ String folderName = "Folder-"+UUID.randomUUID().toString().substring(0,6);
+ FolderDTO folder = new FolderDTO();
+ folder.setName(folderName);
+ FoldersApi foldersApi = new FoldersApi(TestConfig.BASIC_CLIENT);
+ foldersApi.createSubFolder(TestConfig.WORKSPACE,TestConfig.WORKSPACE, folder);
+ List rootFolders = foldersApi.getRootFolders(TestConfig.WORKSPACE, null);
+ Assert.assertEquals(rootFolders.stream()
+ .filter(folderDTO -> folderName.equals(folderDTO.getName()))
+ .count(),1);
+ }
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/LanguagesApiTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/LanguagesApiTest.java
new file mode 100644
index 0000000000..5169b242b1
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/LanguagesApiTest.java
@@ -0,0 +1,42 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.services.LanguagesApi;
+import junit.framework.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.util.List;
+
+@RunWith(JUnit4.class)
+public class LanguagesApiTest {
+
+ @Test
+ public void getLanguagesTest() throws ApiException {
+ LanguagesApi languagesApi = new LanguagesApi(TestConfig.GUEST_CLIENT);
+ List languages = languagesApi.getLanguages();
+ Assert.assertTrue(languages.contains("en"));
+ Assert.assertTrue(languages.contains("fr"));
+ }
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/PartApiTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/PartApiTest.java
new file mode 100644
index 0000000000..ddbda7d719
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/PartApiTest.java
@@ -0,0 +1,151 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.PartCreationDTO;
+import com.docdoku.api.models.PartIterationDTO;
+import com.docdoku.api.models.PartRevisionDTO;
+import com.docdoku.api.models.utils.LastIterationHelper;
+import com.docdoku.api.models.utils.UploadDownloadHelper;
+import com.docdoku.api.services.PartApi;
+import com.docdoku.api.services.PartbinaryApi;
+import com.docdoku.api.services.PartsApi;
+import org.apache.commons.io.FileUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.UUID;
+
+@RunWith(JUnit4.class)
+public class PartApiTest {
+
+ private PartApi partApi = new PartApi(TestConfig.BASIC_CLIENT);
+ private PartbinaryApi partbinaryApi = new PartbinaryApi(TestConfig.BASIC_CLIENT);
+ private PartsApi partsApi = new PartsApi(TestConfig.BASIC_CLIENT);
+
+ @Test
+ public void partApiUsageTests() throws ApiException {
+
+ // Create a part
+ PartCreationDTO part = new PartCreationDTO();
+ part.setNumber(UUID.randomUUID().toString().substring(0, 6));
+ part.setName("GeneratedPart");
+
+ PartRevisionDTO createdPart = partsApi.createNewPart(TestConfig.WORKSPACE, part);
+ Assert.assertEquals(createdPart.getNumber(), part.getNumber());
+
+ // Check in
+ PartRevisionDTO checkedInPart = partApi.checkIn(TestConfig.WORKSPACE, createdPart.getNumber(), createdPart.getVersion(), "");
+ Assert.assertEquals(checkedInPart.getNumber(),part.getNumber());
+ Assert.assertEquals(LastIterationHelper.getLastIteration(checkedInPart).getIteration(), Integer.valueOf("1"));
+
+ // Check out
+ PartRevisionDTO checkedOutPart = partApi.checkOut(TestConfig.WORKSPACE, createdPart.getNumber(), createdPart.getVersion(), "");
+ Assert.assertEquals(checkedOutPart.getNumber(),part.getNumber());
+ Assert.assertEquals(LastIterationHelper.getLastIteration(checkedOutPart).getIteration(),Integer.valueOf("2"));
+
+ // Undo check out
+ PartRevisionDTO undoCheckOutPart= partApi.undoCheckOut(TestConfig.WORKSPACE, createdPart.getNumber(), createdPart.getVersion(), "");
+ Assert.assertEquals(undoCheckOutPart,checkedInPart);
+
+ // Check out
+ checkedOutPart = partApi.checkOut(TestConfig.WORKSPACE, createdPart.getNumber(), createdPart.getVersion(), "");
+
+ // Edit
+ PartIterationDTO lastIteration = LastIterationHelper.getLastIteration(checkedOutPart);
+ Assert.assertNull(lastIteration.getModificationDate());
+ lastIteration.setIterationNote("Something modified");
+
+ PartRevisionDTO updatedPartRevision = partApi.updatePartIteration(TestConfig.WORKSPACE, checkedOutPart.getNumber(), checkedOutPart.getVersion(), 2, lastIteration);
+
+ PartIterationDTO updatedIteration = LastIterationHelper.getLastIteration(updatedPartRevision);
+ Assert.assertNotNull(updatedIteration.getModificationDate());
+ lastIteration.setModificationDate(updatedIteration.getModificationDate());
+ Assert.assertEquals(lastIteration,updatedIteration);
+
+ // Check in
+ checkedInPart = partApi.checkIn(TestConfig.WORKSPACE, createdPart.getNumber(), createdPart.getVersion(), "");
+ Assert.assertNull(checkedInPart.getCheckOutUser());
+
+ // Release
+ PartRevisionDTO releasedPart = partApi.releasePartRevision(TestConfig.WORKSPACE, checkedInPart.getNumber(), checkedInPart.getVersion(), "");
+ Assert.assertEquals(releasedPart.getStatus(), PartRevisionDTO.StatusEnum.RELEASED);
+
+ // Mark as obsolete
+ PartRevisionDTO obsoletePart = partApi.markPartRevisionAsObsolete(TestConfig.WORKSPACE, releasedPart.getNumber(), releasedPart.getVersion(), "");
+ Assert.assertEquals(obsoletePart.getStatus(), PartRevisionDTO.StatusEnum.OBSOLETE);
+
+ }
+
+
+ @Test
+ public void uploadDownloadAttachedFilesToPartTest() throws ApiException, IOException {
+
+ // Create a part
+ PartCreationDTO partCreation = new PartCreationDTO();
+ partCreation.setNumber(UUID.randomUUID().toString().substring(0, 6));
+ partCreation.setName("GeneratedPart");
+
+ PartRevisionDTO part = partsApi.createNewPart(TestConfig.WORKSPACE, partCreation);
+ URL fileURL = PartApiTest.class.getClassLoader().getResource("com/docdoku/api/attached-file.md");
+ File file = new File(fileURL.getPath());
+
+ PartIterationDTO lastIteration = LastIterationHelper.getLastIteration(part);
+ UploadDownloadHelper.uploadAttachedFile(lastIteration,TestConfig.BASIC_CLIENT,file);
+ part = partsApi.getPartRevision(TestConfig.WORKSPACE, part.getNumber(), part.getVersion());
+ lastIteration = LastIterationHelper.getLastIteration(part);
+ Assert.assertFalse(lastIteration.getAttachedFiles().isEmpty());
+
+ File downloadedFile = UploadDownloadHelper.downloadFile(lastIteration.getAttachedFiles().get(0), TestConfig.BASIC_CLIENT);
+ Assert.assertTrue(FileUtils.contentEquals(file, downloadedFile));
+
+ }
+
+
+ @Test
+ public void uploadDownloadNativeCADFileToPartTest() throws ApiException, IOException {
+
+ // Create a part
+ PartCreationDTO partCreation = new PartCreationDTO();
+ partCreation.setNumber(UUID.randomUUID().toString().substring(0, 6));
+ partCreation.setName("GeneratedPart");
+
+ PartRevisionDTO part = partsApi.createNewPart(TestConfig.WORKSPACE, partCreation);
+ URL fileURL = PartApiTest.class.getClassLoader().getResource("com/docdoku/api/native-cad.json");
+ File file = new File(fileURL.getPath());
+
+ PartIterationDTO lastIteration = LastIterationHelper.getLastIteration(part);
+ UploadDownloadHelper.uploadNativeCADFile(lastIteration,TestConfig.BASIC_CLIENT,file);
+ part = partsApi.getPartRevision(TestConfig.WORKSPACE, part.getNumber(), part.getVersion());
+ lastIteration = LastIterationHelper.getLastIteration(part);
+ Assert.assertFalse(lastIteration.getNativeCADFile().isEmpty());
+
+ File downloadedFile = UploadDownloadHelper.downloadFile(lastIteration.getNativeCADFile(), TestConfig.BASIC_CLIENT);
+ Assert.assertTrue(FileUtils.contentEquals(file, downloadedFile));
+
+ }
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/TaskApiTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/TaskApiTest.java
new file mode 100644
index 0000000000..e4b5654a6e
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/TaskApiTest.java
@@ -0,0 +1,144 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.*;
+import com.docdoku.api.models.utils.WorkflowHelper;
+import com.docdoku.api.services.*;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+@RunWith(JUnit4.class)
+public class TaskApiTest {
+
+ private WorkspacesApi workspacesApi = new WorkspacesApi(TestConfig.BASIC_CLIENT);
+ private RolesApi rolesApi = new RolesApi(TestConfig.BASIC_CLIENT);
+ private UsersApi usersApi = new UsersApi(TestConfig.BASIC_CLIENT);
+ private WorkflowModelsApi workflowModelsApi = new WorkflowModelsApi(TestConfig.BASIC_CLIENT);
+ private WorkspaceWorkflowsApi workspaceWorkflowsApi = new WorkspaceWorkflowsApi(TestConfig.BASIC_CLIENT);
+ private TasksApi tasksApi = new TasksApi(TestConfig.BASIC_CLIENT);
+
+ @Test
+ public void tests() throws ApiException {
+
+ String workflowModelReference = "W_MODEL-" + UUID.randomUUID().toString().substring(0, 6);
+ String roleName = "ROLE-" + UUID.randomUUID().toString().substring(0, 6);
+ String groupId = "GROUP-" + UUID.randomUUID().toString().substring(0, 6);
+
+ // Get current user to create a role with default assignee
+ UserDTO user = usersApi.whoami(TestConfig.WORKSPACE);
+
+
+ UserGroupDTO userGroup = new UserGroupDTO();
+ userGroup.setWorkspaceId(TestConfig.WORKSPACE);
+ userGroup.setId(groupId);
+
+ workspacesApi.createGroup(TestConfig.WORKSPACE,userGroup);
+ workspacesApi.addUser(TestConfig.WORKSPACE,user, userGroup.getId());
+
+ RoleDTO role = new RoleDTO();
+ role.setWorkspaceId(TestConfig.WORKSPACE);
+ role.setName(roleName);
+ // Assign default assigned users
+ role.getDefaultAssignedUsers().add(user);
+
+
+ RoleDTO createdRole = rolesApi.createRole(TestConfig.WORKSPACE, role);
+
+ // Create a task model
+ TaskModelDTO taskModelDTO = new TaskModelDTO();
+ taskModelDTO.setTitle("TASK_1");
+ taskModelDTO.setInstructions("Do something please");
+ taskModelDTO.setNum(0);
+ taskModelDTO.setRole(createdRole);
+
+ List tasks = new ArrayList<>();
+ tasks.add(taskModelDTO);
+
+ // Create an activity model
+ ActivityModelDTO activityModelDTO = new ActivityModelDTO();
+ activityModelDTO.setLifeCycleState("ACTIVITY_1");
+ activityModelDTO.setStep(0);
+ activityModelDTO.setType(ActivityModelDTO.TypeEnum.SEQUENTIAL);
+ activityModelDTO.setTaskModels(tasks);
+
+ List activityModels = new ArrayList<>();
+ activityModels.add(activityModelDTO);
+
+ // Create a workflow model
+ WorkflowModelDTO workflowModelDTO = new WorkflowModelDTO();
+ workflowModelDTO.setReference(workflowModelReference);
+ workflowModelDTO.setFinalLifeCycleState("FINAL_STATE");
+ workflowModelDTO.setActivityModels(activityModels);
+
+
+ WorkflowModelDTO workflowModel = workflowModelsApi.createWorkflowModel(TestConfig.WORKSPACE, workflowModelDTO);
+ Assert.assertEquals(workflowModel.getId(), workflowModelReference);
+
+ // Use this model to create a workflow
+
+ // We need to assigned users and or groups
+ List roleMapping = new ArrayList<>();
+ RoleMappingDTO roleMappingDTO = new RoleMappingDTO();
+ roleMappingDTO.setRoleName(role.getName());
+ roleMappingDTO.getGroupIds().add(groupId);
+ roleMapping.add(roleMappingDTO);
+
+ // Create a workflow container
+ WorkspaceWorkflowCreationDTO workspaceWorkflowCreationDTO = new WorkspaceWorkflowCreationDTO();
+ workspaceWorkflowCreationDTO.setId(UUID.randomUUID().toString().substring(0, 6));
+ workspaceWorkflowCreationDTO.setRoleMapping(roleMapping);
+ workspaceWorkflowCreationDTO.setWorkflowModelId(workflowModel.getId());
+
+ WorkspaceWorkflowDTO workspaceWorkflow = workspaceWorkflowsApi.createWorkspaceWorkflow(TestConfig.WORKSPACE, workspaceWorkflowCreationDTO);
+ List assignedTasks = tasksApi.getAssignedTasksForGivenUser(TestConfig.WORKSPACE, TestConfig.LOGIN);
+ Assert.assertEquals(1,
+ assignedTasks.stream()
+ .filter(taskDTO -> taskDTO.getWorkflowId() != null &&
+ taskDTO.getWorkflowId().equals(workspaceWorkflow.getWorkflow().getId()))
+ .count());
+
+ ActivityDTO currentActivity = WorkflowHelper.getCurrentActivity(workspaceWorkflow.getWorkflow());
+ List runningTasks = WorkflowHelper.getRunningTasks(currentActivity);
+ TaskDTO firstRunningTasks = runningTasks.get(0);
+ Assert.assertNotNull(firstRunningTasks);
+
+ String taskId = workspaceWorkflow.getWorkflow().getId() + "-" + currentActivity.getStep() + "-" + firstRunningTasks.getNum();
+
+
+ TaskProcessDTO taskProcessDTO = new TaskProcessDTO();
+ taskProcessDTO.setAction(TaskProcessDTO.ActionEnum.APPROVE);
+ taskProcessDTO.setComment("Test are passing !");
+ tasksApi.processTask(TestConfig.WORKSPACE, taskId, taskProcessDTO);
+
+
+ }
+
+
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/TestConfig.java b/docdoku-api-java/src/test/java/com/docdoku/api/TestConfig.java
new file mode 100644
index 0000000000..79e488fc67
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/TestConfig.java
@@ -0,0 +1,48 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiClient;
+
+public class TestConfig {
+
+ public static String URL;
+ public static String LOGIN;
+ public static String PASSWORD;
+ public static String WORKSPACE;
+ public static boolean DEBUG;
+ public static ApiClient GUEST_CLIENT;
+ public static ApiClient BASIC_CLIENT;
+ public static ApiClient JWT_CLIENT;
+ public static ApiClient COOKIE_CLIENT;
+
+ static{
+ URL = System.getProperty("url") != null ? System.getProperty("url") : "http://localhost:8080/api";
+ LOGIN = System.getProperty("login") != null ? System.getProperty("login") : "test";
+ PASSWORD = System.getProperty("password") != null ? System.getProperty("password") : "test";
+ WORKSPACE = System.getProperty("workspace") != null ? System.getProperty("workspace") : "test";
+ DEBUG = System.getProperty("debug") != null ? Boolean.parseBoolean(System.getProperty("debug")) : false;
+ GUEST_CLIENT = new DocdokuPLMClient(URL,DEBUG).getClient();
+ BASIC_CLIENT = new DocdokuPLMBasicClient(URL,LOGIN, PASSWORD, DEBUG).getClient();
+ JWT_CLIENT = new DocdokuPLMBasicClient(URL, LOGIN, PASSWORD, DEBUG).getClient();
+ COOKIE_CLIENT = new DocdokuPLMCookieClient(URL, LOGIN, PASSWORD, DEBUG).getClient();
+ }
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/TimezonesApiTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/TimezonesApiTest.java
new file mode 100644
index 0000000000..26a4040379
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/TimezonesApiTest.java
@@ -0,0 +1,42 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.services.TimezoneApi;
+import junit.framework.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.util.List;
+
+@RunWith(JUnit4.class)
+public class TimezonesApiTest {
+
+ @Test
+ public void getTimezonesTest() throws ApiException {
+ TimezoneApi timezoneApi = new TimezoneApi(TestConfig.GUEST_CLIENT);
+ List timeZones = timezoneApi.getTimeZones();
+ Assert.assertTrue(timeZones.contains("CET"));
+ }
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/UploadDownloadConsistencyTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/UploadDownloadConsistencyTest.java
new file mode 100644
index 0000000000..512baaca14
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/UploadDownloadConsistencyTest.java
@@ -0,0 +1,93 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.DocumentCreationDTO;
+import com.docdoku.api.models.DocumentIterationDTO;
+import com.docdoku.api.models.DocumentRevisionDTO;
+import com.docdoku.api.models.utils.LastIterationHelper;
+import com.docdoku.api.models.utils.UploadDownloadHelper;
+import com.docdoku.api.services.DocumentApi;
+import com.docdoku.api.services.FoldersApi;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+@RunWith(JUnit4.class)
+public class UploadDownloadConsistencyTest {
+
+ private DocumentApi documentApi = new DocumentApi(TestConfig.BASIC_CLIENT);
+ private FoldersApi foldersApi = new FoldersApi(TestConfig.BASIC_CLIENT);
+
+
+ @Test
+ public void uploadZipTest() throws ApiException, IOException {
+
+ // Create a document
+ DocumentCreationDTO documentCreation = new DocumentCreationDTO();
+ documentCreation.setReference(UUID.randomUUID().toString().substring(0, 6));
+ documentCreation.setTitle("GeneratedDoc");
+
+ DocumentRevisionDTO document = foldersApi.createDocumentMasterInFolder(TestConfig.WORKSPACE, documentCreation, TestConfig.WORKSPACE);
+
+ URL fileURL = UploadDownloadConsistencyTest.class.getClassLoader().getResource("com/docdoku/api/attached-file.zip");
+ File file = new File(fileURL.getPath());
+
+ List originalEntries = getEntries(file);
+ Assert.assertEquals(1,originalEntries.size());
+
+ DocumentIterationDTO lastIteration = LastIterationHelper.getLastIteration(document);
+ UploadDownloadHelper.uploadAttachedFile(lastIteration, TestConfig.BASIC_CLIENT, file);
+ document = documentApi.getDocumentRevision(TestConfig.WORKSPACE, document.getDocumentMasterId(), document.getVersion(), null);
+ lastIteration = LastIterationHelper.getLastIteration(document);
+ File downloadedFile = UploadDownloadHelper.downloadFile(lastIteration.getAttachedFiles().get(0), TestConfig.BASIC_CLIENT);
+
+ List downloadedEntries = getEntries(downloadedFile);
+ Assert.assertTrue(new HashSet<>(originalEntries).equals(new HashSet<>(downloadedEntries)));
+
+
+ }
+
+ private List getEntries(File file){
+ List fileNames = new ArrayList<>();
+ try (ZipFile zipFile = new ZipFile(file)) {
+ Enumeration zipEntries = zipFile.entries();
+ while (zipEntries.hasMoreElements()) {
+ String fileName = ((ZipEntry) zipEntries.nextElement()).getName();
+ fileNames.add(fileName);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return fileNames;
+ }
+
+
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/UserApiTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/UserApiTest.java
new file mode 100644
index 0000000000..dc36d08900
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/UserApiTest.java
@@ -0,0 +1,60 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.UserDTO;
+import com.docdoku.api.services.UsersApi;
+import junit.framework.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.util.List;
+
+@RunWith(JUnit4.class)
+public class UserApiTest {
+
+ private UsersApi usersApi = new UsersApi(TestConfig.BASIC_CLIENT);
+
+ @Test
+ public void whoamiTest() throws ApiException {
+ UserDTO currentUser = usersApi.whoami(TestConfig.WORKSPACE);
+ Assert.assertEquals(currentUser.getLogin(),TestConfig.LOGIN);
+ Assert.assertEquals(currentUser.getWorkspaceId(),TestConfig.WORKSPACE);
+ }
+
+ @Test
+ public void getAdminInWorkspaceTest() throws ApiException {
+ UserDTO admin = usersApi.getAdminInWorkspace(TestConfig.WORKSPACE);
+ Assert.assertEquals(admin.getWorkspaceId(),TestConfig.WORKSPACE);
+ }
+
+ @Test
+ public void getUsersInWorkspaceTest() throws ApiException {
+ List users = usersApi.getUsersInWorkspace(TestConfig.WORKSPACE);
+ Assert.assertEquals(users.stream()
+ .filter(user -> TestConfig.LOGIN.equals(user.getLogin()))
+ .count(),1);
+ }
+
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/WorkflowApiTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/WorkflowApiTest.java
new file mode 100644
index 0000000000..ad9c1a4719
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/WorkflowApiTest.java
@@ -0,0 +1,269 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.*;
+import com.docdoku.api.models.utils.WorkflowHelper;
+import com.docdoku.api.services.*;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+@RunWith(JUnit4.class)
+public class WorkflowApiTest {
+
+ private WorkspacesApi workspacesApi = new WorkspacesApi(TestConfig.BASIC_CLIENT);
+ private RolesApi rolesApi = new RolesApi(TestConfig.BASIC_CLIENT);
+ private UsersApi usersApi = new UsersApi(TestConfig.BASIC_CLIENT);
+ private WorkflowModelsApi workflowModelsApi = new WorkflowModelsApi(TestConfig.BASIC_CLIENT);
+ private WorkspaceWorkflowsApi workspaceWorkflowsApi = new WorkspaceWorkflowsApi(TestConfig.BASIC_CLIENT);
+ private WorkflowsApi workflowsApi = new WorkflowsApi(TestConfig.BASIC_CLIENT);
+ private TasksApi tasksApi = new TasksApi(TestConfig.BASIC_CLIENT);
+ private PartsApi partsApi = new PartsApi(TestConfig.BASIC_CLIENT);
+ private DocumentApi documentApi = new DocumentApi(TestConfig.BASIC_CLIENT);
+ private FoldersApi foldersApi = new FoldersApi(TestConfig.BASIC_CLIENT);
+
+
+ @Test
+ public void testWorkflowOnWorkspacesWorkflow() throws ApiException {
+
+ // Create a workflow model
+ String workflowModelReference = "W_MODEL-" + UUID.randomUUID().toString().substring(0, 6);
+ WorkflowModelDTO workflowModel = createModel(workflowModelReference);
+ Assert.assertEquals(workflowModel.getId(), workflowModelReference);
+
+ List roleMapping = resolveDefaultRoles(workflowModel);
+
+ // Create a workflow container
+ WorkspaceWorkflowCreationDTO workspaceWorkflowCreationDTO = new WorkspaceWorkflowCreationDTO();
+ workspaceWorkflowCreationDTO.setId(UUID.randomUUID().toString().substring(0, 6));
+ workspaceWorkflowCreationDTO.setRoleMapping(roleMapping);
+ workspaceWorkflowCreationDTO.setWorkflowModelId(workflowModel.getId());
+
+ WorkspaceWorkflowDTO workspaceWorkflow = workspaceWorkflowsApi.createWorkspaceWorkflow(TestConfig.WORKSPACE, workspaceWorkflowCreationDTO);
+ Assert.assertEquals(workspaceWorkflow.getId(),workspaceWorkflowCreationDTO.getId());
+ Assert.assertEquals(workspaceWorkflow.getWorkspaceId(),TestConfig.WORKSPACE);
+ runAsserts(workspaceWorkflow.getWorkflow(), workflowModel);
+ processTask(workspaceWorkflow.getWorkflow(), workflowModel);
+
+ workspaceWorkflowsApi.deleteWorkspaceWorkflow(TestConfig.WORKSPACE, workspaceWorkflow.getId());
+ }
+
+ @Test
+ public void testWorkflowOnPart() throws ApiException {
+
+ // Create a workflow model
+ String workflowModelReference = "W_MODEL-" + UUID.randomUUID().toString().substring(0, 6);
+ WorkflowModelDTO workflowModel = createModel(workflowModelReference);
+ Assert.assertEquals(workflowModel.getId(), workflowModelReference);
+
+ List roleMapping = resolveDefaultRoles(workflowModel);
+
+ // Create a part
+
+ // Create a part
+ PartCreationDTO part = new PartCreationDTO();
+ part.setNumber(UUID.randomUUID().toString().substring(0, 6));
+ part.setWorkflowModelId(workflowModelReference);
+ part.setRoleMapping(roleMapping);
+ PartRevisionDTO newPart = partsApi.createNewPart(TestConfig.WORKSPACE, part);
+ partsApi.checkIn(TestConfig.WORKSPACE, newPart.getNumber(),newPart.getVersion(), "");
+
+ WorkflowDTO workflow = workflowsApi.getWorkflowInstance(TestConfig.WORKSPACE, newPart.getWorkflow().getId());
+ Assert.assertEquals(workflow,newPart.getWorkflow());
+ runAsserts(newPart.getWorkflow(), workflowModel);
+
+ processTask(newPart.getWorkflow(), workflowModel);
+
+
+ }
+
+ @Test
+ public void testWorkflowOnDocument() throws ApiException {
+
+ // Create a workflow model
+ String workflowModelReference = "W_MODEL-" + UUID.randomUUID().toString().substring(0, 6);
+ WorkflowModelDTO workflowModel = createModel(workflowModelReference);
+ Assert.assertEquals(workflowModel.getId(), workflowModelReference);
+
+ List roleMapping = resolveDefaultRoles(workflowModel);
+
+ // Create a document
+ DocumentCreationDTO document = new DocumentCreationDTO();
+ document.setReference(UUID.randomUUID().toString().substring(0,6));
+ document.setWorkflowModelId(workflowModelReference);
+ document.setRoleMapping(roleMapping);
+
+ DocumentRevisionDTO createdDocument = foldersApi.createDocumentMasterInFolder(TestConfig.WORKSPACE, document, TestConfig.WORKSPACE);
+ // TODO : upload file to doc, then download, then checkin
+ documentApi.checkInDocument(TestConfig.WORKSPACE, createdDocument.getDocumentMasterId(), createdDocument.getVersion(), "");
+
+ WorkflowDTO workflow = workflowsApi.getWorkflowInstance(TestConfig.WORKSPACE, createdDocument.getWorkflow().getId());
+ Assert.assertEquals(workflow,createdDocument.getWorkflow());
+
+ runAsserts(createdDocument.getWorkflow(), workflowModel);
+
+ try {
+ processTask(createdDocument.getWorkflow(), workflowModel);
+ } catch (ApiException e){
+ Assert.assertEquals("Before marking a task as done or rejecting it on a document you must have downloaded and opened it at least one time",e.getMessage());
+ }
+
+ }
+
+ private void runAsserts(WorkflowDTO workflowDTO, WorkflowModelDTO workflowModel) {
+ Assert.assertNotNull(workflowDTO);
+ Assert.assertEquals(workflowDTO.getFinalLifeCycleState(),workflowModel.getFinalLifeCycleState());
+ Assert.assertNotNull(workflowDTO.getActivities());
+ Assert.assertEquals(workflowDTO.getActivities().size(), workflowModel.getActivityModels().size());
+ Assert.assertEquals(workflowDTO.getActivities().get(0).getLifeCycleState(), workflowModel.getActivityModels().get(0).getLifeCycleState());
+ Assert.assertEquals(workflowDTO.getActivities().get(0).getTasks().size(), workflowModel.getActivityModels().get(0).getTaskModels().size());
+ Assert.assertEquals(workflowDTO.getActivities().get(0).getTasks().get(0).getTitle(), workflowModel.getActivityModels().get(0).getTaskModels().get(0).getTitle());
+ Assert.assertEquals(workflowDTO.getActivities().get(0).getTasks().get(1).getTitle(), workflowModel.getActivityModels().get(0).getTaskModels().get(1).getTitle());
+ }
+
+ private void processTask(WorkflowDTO createdWorkflow, WorkflowModelDTO createdFrom) throws ApiException {
+
+ UserDTO me = usersApi.whoami(TestConfig.WORKSPACE);
+
+ // Retrieve workflow by it's id
+ WorkflowDTO workflow = workflowsApi.getWorkflowInstance(TestConfig.WORKSPACE, createdWorkflow.getId());
+ Assert.assertEquals(workflow,createdWorkflow);
+
+ // Get first running task, assert our user is in assigned users
+ ActivityDTO currentActivity = WorkflowHelper.getCurrentActivity(workflow);
+ List runningTasks = WorkflowHelper.getRunningTasks(workflow);
+ TaskDTO firstTask = runningTasks.get(0);
+
+ Assert.assertTrue(firstTask.getAssignedUsers().contains(me));
+ Assert.assertEquals(firstTask.getStatus(), TaskDTO.StatusEnum.IN_PROGRESS);
+
+ // Approve the first task
+ TaskProcessDTO taskProcessDTO = new TaskProcessDTO();
+ taskProcessDTO.setComment("Okay");
+ taskProcessDTO.setSignature("data:image/gif;base64,R0lGODlhAQABAAAAACw=");
+ taskProcessDTO.setAction(TaskProcessDTO.ActionEnum.APPROVE);
+
+ String taskId = workflow.getId() + "-" + currentActivity.getStep() + "-" + firstTask.getNum();
+
+ tasksApi.processTask(TestConfig.WORKSPACE, taskId, taskProcessDTO);
+
+ TaskDTO task = tasksApi.getTask(TestConfig.WORKSPACE, taskId);
+ Assert.assertEquals(TaskDTO.StatusEnum.APPROVED, task.getStatus());
+
+ workflow = workflowsApi.getWorkflowInstance(TestConfig.WORKSPACE, workflow.getId());
+
+ currentActivity = WorkflowHelper.getCurrentActivity(workflow);
+ TaskDTO nextTask = WorkflowHelper.getRunningTasks(currentActivity).get(0);
+ Assert.assertEquals(createdFrom.getActivityModels().get(0).getTaskModels().get(1).getTitle(),nextTask.getTitle());
+
+ }
+
+ private List resolveDefaultRoles(WorkflowModelDTO workflowModel) {
+ Set rolesInvolved = WorkflowHelper.getRolesInvolved(workflowModel);
+ List roleMapping = new ArrayList<>();
+
+ // we need to resolve the roles (use defaults assignments)
+ for(RoleDTO role:rolesInvolved){
+
+ RoleMappingDTO roleMappingDTO = new RoleMappingDTO();
+ roleMappingDTO.setRoleName(role.getName());
+
+ for(UserGroupDTO group :role.getDefaultAssignedGroups()){
+ roleMappingDTO.getGroupIds().add(group.getId());
+ }
+ for(UserDTO user:role.getDefaultAssignedUsers()){
+ roleMappingDTO.getUserLogins().add(user.getLogin());
+ }
+ roleMapping.add(roleMappingDTO);
+ }
+
+ return roleMapping;
+ }
+
+ public WorkflowModelDTO createModel(String workflowModelReference) throws ApiException {
+
+ String roleName = "ROLE-" + UUID.randomUUID().toString().substring(0, 6);
+
+ // Get current user to create a role with default assignee
+ UserDTO user = usersApi.whoami(TestConfig.WORKSPACE);
+ List userGroups = workspacesApi.getUserGroups(TestConfig.WORKSPACE);
+
+ RoleDTO role = new RoleDTO();
+ role.setWorkspaceId(TestConfig.WORKSPACE);
+ role.setName(roleName);
+
+ // Assign default assigned users
+ role.getDefaultAssignedUsers().add(user);
+
+ // Assign default assigned groups
+ if(!userGroups.isEmpty()) {
+ role.getDefaultAssignedGroups().add(userGroups.get(0));
+ }
+
+ RoleDTO createdRole = rolesApi.createRole(TestConfig.WORKSPACE, role);
+
+ // Create a task model
+ TaskModelDTO taskModelDTO_1 = new TaskModelDTO();
+ taskModelDTO_1.setTitle("TASK_1");
+ taskModelDTO_1.setInstructions("Do something please");
+ taskModelDTO_1.setNum(0);
+ taskModelDTO_1.setRole(createdRole);
+
+ TaskModelDTO taskModelDTO_2 = new TaskModelDTO();
+ taskModelDTO_2.setTitle("TASK_2");
+ taskModelDTO_2.setInstructions("Do something else");
+ taskModelDTO_2.setNum(1);
+ taskModelDTO_2.setRole(createdRole);
+
+ List tasks = new ArrayList<>();
+ tasks.add(taskModelDTO_1);
+ tasks.add(taskModelDTO_2);
+
+ // Create an activity model
+ ActivityModelDTO activityModelDTO = new ActivityModelDTO();
+ activityModelDTO.setLifeCycleState("ACTIVITY_1");
+ activityModelDTO.setStep(0);
+ activityModelDTO.setType(ActivityModelDTO.TypeEnum.SEQUENTIAL);
+ activityModelDTO.setTaskModels(tasks);
+
+ List activityModels = new ArrayList<>();
+ activityModels.add(activityModelDTO);
+
+ // Create a workflow model
+ WorkflowModelDTO workflowModelDTO = new WorkflowModelDTO();
+ workflowModelDTO.setReference(workflowModelReference);
+ workflowModelDTO.setFinalLifeCycleState("FINAL_STATE");
+ workflowModelDTO.setActivityModels(activityModels);
+
+ WorkflowModelDTO workflowModel = workflowModelsApi.createWorkflowModel(TestConfig.WORKSPACE, workflowModelDTO);
+ return workflowModel;
+ }
+
+}
diff --git a/docdoku-api-java/src/test/java/com/docdoku/api/WorkspacesApiTest.java b/docdoku-api-java/src/test/java/com/docdoku/api/WorkspacesApiTest.java
new file mode 100644
index 0000000000..5ffda26121
--- /dev/null
+++ b/docdoku-api-java/src/test/java/com/docdoku/api/WorkspacesApiTest.java
@@ -0,0 +1,127 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api;
+
+
+import com.docdoku.api.client.ApiException;
+import com.docdoku.api.models.*;
+import com.docdoku.api.services.AccountsApi;
+import com.docdoku.api.services.WorkspacesApi;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.util.List;
+import java.util.UUID;
+
+@RunWith(JUnit4.class)
+public class WorkspacesApiTest {
+
+ @Test
+ public void createWorkspaceTest() throws ApiException {
+ WorkspaceDTO workspace = new WorkspaceDTO();
+ String workspaceId = UUID.randomUUID().toString().substring(0,6);
+ workspace.setId(workspaceId);
+ workspace.setDescription("Generated by tests");
+ workspace.setFolderLocked(false);
+ WorkspacesApi workspacesApi = new WorkspacesApi(TestConfig.BASIC_CLIENT);
+ WorkspaceDTO createdWorkspace = workspacesApi.createWorkspace(workspace, TestConfig.LOGIN);
+ Assert.assertEquals(workspace,createdWorkspace);
+ workspacesApi.deleteWorkspace(workspaceId);
+ }
+
+ @Test
+ public void getWorkspaceList() throws ApiException {
+ WorkspaceDTO workspace = new WorkspaceDTO();
+ String workspaceId = UUID.randomUUID().toString().substring(0,6);
+ workspace.setId(workspaceId);
+ workspace.setDescription("Generated by tests");
+ workspace.setFolderLocked(false);
+ WorkspacesApi workspacesApi = new WorkspacesApi(TestConfig.BASIC_CLIENT);
+ WorkspaceDTO createdWorkspace = workspacesApi.createWorkspace(workspace, TestConfig.LOGIN);
+ WorkspaceListDTO workspacesForConnectedUser = workspacesApi.getWorkspacesForConnectedUser();
+ Assert.assertTrue(workspacesForConnectedUser.getAllWorkspaces().contains(createdWorkspace));
+ workspacesApi.deleteWorkspace(workspaceId);
+ }
+
+ @Test
+ public void updateWorkspace() throws ApiException {
+ WorkspaceDTO workspace = new WorkspaceDTO();
+ String workspaceId = UUID.randomUUID().toString().substring(0,6);
+ workspace.setId(workspaceId);
+ workspace.setDescription("Generated by tests");
+ workspace.setFolderLocked(false);
+ WorkspacesApi workspacesApi = new WorkspacesApi(TestConfig.BASIC_CLIENT);
+ WorkspaceDTO createdWorkspace = workspacesApi.createWorkspace(workspace, TestConfig.LOGIN);
+ String newDescription = "Updated by tests";
+ createdWorkspace.setDescription(newDescription);
+ WorkspaceDTO updatedWorkspace = workspacesApi.updateWorkspace(workspaceId, createdWorkspace);
+ Assert.assertEquals(updatedWorkspace.getDescription(),newDescription);
+ Assert.assertEquals(updatedWorkspace,createdWorkspace);
+ workspacesApi.deleteWorkspace(workspaceId);
+ }
+
+ @Test
+ public void addUserInWorkspace() throws ApiException {
+ AccountDTO newAccount = createAccount();
+ UserDTO userToAdd = new UserDTO();
+ userToAdd.setLogin(newAccount.getLogin());
+ WorkspacesApi workspacesApi = new WorkspacesApi(TestConfig.BASIC_CLIENT);
+ workspacesApi.addUser(TestConfig.WORKSPACE, userToAdd, null);
+ List usersInWorkspace = workspacesApi.getUsersInWorkspace(TestConfig.WORKSPACE);
+ Assert.assertEquals(usersInWorkspace.stream().filter(userDTO -> userDTO.getLogin().equals(userToAdd.getLogin())).count(), 1);
+ }
+
+ @Test
+ public void addUserInGroup() throws ApiException {
+ AccountDTO newAccount = createAccount();
+ UserDTO userToAdd = new UserDTO();
+ userToAdd.setLogin(newAccount.getLogin());
+ UserGroupDTO group = createGroup();
+ WorkspacesApi workspacesApi = new WorkspacesApi(TestConfig.BASIC_CLIENT);
+ workspacesApi.addUser(TestConfig.WORKSPACE, userToAdd, group.getId());
+ List usersInGroup = workspacesApi.getUsersInGroup(TestConfig.WORKSPACE, group.getId());
+ Assert.assertEquals(usersInGroup.stream().filter(userDTO -> userDTO.getLogin().equals(userToAdd.getLogin())).count(),1);
+ }
+
+ private UserGroupDTO createGroup() throws ApiException {
+ String groupId = UUID.randomUUID().toString().substring(0,6);
+ UserGroupDTO group = new UserGroupDTO();
+ group.setWorkspaceId(TestConfig.WORKSPACE);
+ group.setId(groupId);
+ return new WorkspacesApi(TestConfig.BASIC_CLIENT).createGroup(TestConfig.WORKSPACE, group);
+ }
+
+
+ private AccountDTO createAccount() throws ApiException {
+ String login = "USER-"+ UUID.randomUUID().toString().substring(0,6);
+ AccountDTO accountDTO = new AccountDTO();
+ accountDTO.setLogin(login);
+ accountDTO.setEmail("my@email.com");
+ accountDTO.setNewPassword("password");
+ accountDTO.setLanguage("en");
+ accountDTO.setName("Mr " + login);
+ accountDTO.setTimeZone("CET");
+ return new AccountsApi(TestConfig.GUEST_CLIENT).createAccount(accountDTO);
+ }
+
+}
diff --git a/docdoku-api-java/src/test/resources/com/docdoku/api/attached-file.md b/docdoku-api-java/src/test/resources/com/docdoku/api/attached-file.md
new file mode 100644
index 0000000000..d00fb07231
--- /dev/null
+++ b/docdoku-api-java/src/test/resources/com/docdoku/api/attached-file.md
@@ -0,0 +1 @@
+Hey, some data inside !
\ No newline at end of file
diff --git a/docdoku-api-java/src/test/resources/com/docdoku/api/attached-file.zip b/docdoku-api-java/src/test/resources/com/docdoku/api/attached-file.zip
new file mode 100644
index 0000000000..b50d2114a6
Binary files /dev/null and b/docdoku-api-java/src/test/resources/com/docdoku/api/attached-file.zip differ
diff --git a/docdoku-api-java/src/test/resources/com/docdoku/api/native-cad.json b/docdoku-api-java/src/test/resources/com/docdoku/api/native-cad.json
new file mode 100644
index 0000000000..08a133b487
--- /dev/null
+++ b/docdoku-api-java/src/test/resources/com/docdoku/api/native-cad.json
@@ -0,0 +1 @@
+{"some":"3D data"}
\ No newline at end of file
diff --git a/docdoku-api-js/.gitignore b/docdoku-api-js/.gitignore
new file mode 100644
index 0000000000..d88b002282
--- /dev/null
+++ b/docdoku-api-js/.gitignore
@@ -0,0 +1,3 @@
+node_modules
+dist
+lib/spec.json
\ No newline at end of file
diff --git a/docdoku-api-js/Gruntfile.js b/docdoku-api-js/Gruntfile.js
new file mode 100644
index 0000000000..f91e75739a
--- /dev/null
+++ b/docdoku-api-js/Gruntfile.js
@@ -0,0 +1,41 @@
+'use strict';
+
+module.exports = function (grunt) {
+
+ require('load-grunt-tasks')(grunt);
+
+ grunt.initConfig({
+ copy:{
+ spec:{
+ files : {
+ 'lib/spec.json':'../docdoku-api/target/swagger/swagger.json'
+ }
+ },
+ browser:{
+ files : {
+ 'dist/index.html':'example/browser.html'
+ }
+ }
+ },
+ clean: {
+ options: {
+ force: true
+ },
+ files:['lib/spec.json', 'dist']
+ },
+
+ browserify: {
+ options:{
+ standalone:true
+ },
+ dist: {
+ files: {
+ 'dist/docdoku-api.js': ['lib/*.js']
+ }
+ }
+ }
+
+ });
+
+ grunt.registerTask('build',['clean', 'copy:spec','browserify:dist', 'copy:browser']);
+};
diff --git a/docdoku-api-js/README.md b/docdoku-api-js/README.md
new file mode 100644
index 0000000000..3f81158f1d
--- /dev/null
+++ b/docdoku-api-js/README.md
@@ -0,0 +1,61 @@
+# Docdoku API JS
+
+Generate a node module to integrate in your nodejs and/or browser application
+
+## Documentation
+
+This module is designed to work in a nodejs or a browser application
+
+### Browser
+
+Add the script to your page, then it's available from the window object
+
+
+
+
+
+### Node Js
+
+Install package, then in your app
+
+ var DocdokuPlmClient = require('../lib/docdoku-api');
+
+ var client = new DocdokuPlmClient({url:'http://localhost:8080/api'});
+
+ client.getApi().then(function(api){
+ api.languages.getLanguages().then(function(response){
+ console.log(response.obj);
+ });
+ });
+
+
+## Development guide
+
+Package folders description
+
+* `lib` : main module sources
+* `test` : test sources. Uses mocha (command : `mocha run test`)
+
+Build
+
+* Run `mvn clean install` in docdoku-api module
+* Run `npm run build` in this module directory
+
+Tests
+
+* Run `npm install` before. Change with your credentials (needs a running server).
+
+ mocha test/*.test.js --url=http://localhost:8080/api --login=foo --password=bar --workspace=foo
+
+* Browser testing : run `npm run build`, then launch a static server in dist folder `http-server -p 8086` to see results in browser
diff --git a/docdoku-api-js/example/browser.html b/docdoku-api-js/example/browser.html
new file mode 100644
index 0000000000..3ae6ed3a7c
--- /dev/null
+++ b/docdoku-api-js/example/browser.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docdoku-api-js/example/node-module.js b/docdoku-api-js/example/node-module.js
new file mode 100644
index 0000000000..6eaab1e93b
--- /dev/null
+++ b/docdoku-api-js/example/node-module.js
@@ -0,0 +1,12 @@
+// Use this lib as a node module
+
+var DocdokuPlmClient = require('../lib/docdoku-api');
+
+var client = new DocdokuPlmClient({url:'http://localhost:8080/api'});
+
+client.getApi().then(function(api){
+ api.languages.getLanguages().then(function(response){
+ console.log(response.obj);
+ });
+});
+
diff --git a/docdoku-api-js/lib/docdoku-api.js b/docdoku-api-js/lib/docdoku-api.js
new file mode 100644
index 0000000000..0439538ff3
--- /dev/null
+++ b/docdoku-api-js/lib/docdoku-api.js
@@ -0,0 +1,37 @@
+var SwaggerClient = require('swagger-client');
+var auth = require('swagger-client/lib/auth');
+var spec = require('./spec');
+
+var DocdokuPLMClient = module.exports = function(options){
+ this.setOptions(options);
+};
+
+DocdokuPLMClient.prototype.setOptions = function(options){
+
+ this.options = options || {};
+ this.authorizations = this.options.authorizations || {};
+
+ if(this.options.basicAuth){
+ this.authorizations.basicAuth = new SwaggerClient.PasswordAuthorization(this.options.login,this.options.password);
+ }
+
+ if(this.options.cookie){
+ this.authorizations.cookieAuth = new SwaggerClient.ApiKeyAuthorization('Cookie', this.options.cookie, 'header');
+ }
+
+ if(this.options.jwt){
+ this.authorizations.jwtAuth = new SwaggerClient.ApiKeyAuthorization('Authorization', 'Bearer ' + this.options.jwt, 'header');
+ }
+
+ return this;
+};
+
+DocdokuPLMClient.prototype.getApi = function(){
+ this.client = new SwaggerClient({
+ url: this.options.url,
+ spec:spec,
+ usePromise:true,
+ authorizations:this.authorizations
+ });
+ return this.client;
+};
diff --git a/docdoku-api-js/lib/exports.js b/docdoku-api-js/lib/exports.js
new file mode 100644
index 0000000000..6253d2cc74
--- /dev/null
+++ b/docdoku-api-js/lib/exports.js
@@ -0,0 +1,3 @@
+if(typeof window !== 'undefined'){
+ window.DocdokuPlmClient = require('./docdoku-api');
+}
diff --git a/docdoku-api-js/package.json b/docdoku-api-js/package.json
new file mode 100644
index 0000000000..59f6d928b5
--- /dev/null
+++ b/docdoku-api-js/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "docdoku-api-js",
+ "version": "1.0.0",
+ "description": "",
+ "author": "",
+ "directories": {
+ "example": "example"
+ },
+ "scripts": {
+ "clean": "npm install && grunt clean",
+ "build": "npm install && grunt build"
+ },
+ "devDependencies": {
+ "chai": "^3.5.0",
+ "grunt": "~0.4.1",
+ "grunt-browserify": "^5.0.0",
+ "grunt-contrib-clean": "~0.5.0",
+ "grunt-contrib-copy": "~0.5.0",
+ "load-grunt-tasks": "~0.3.0",
+ "swagger-client": "^2.1.15",
+ "yargs": "^4.7.1"
+ }
+}
diff --git a/docdoku-api-js/pom.xml b/docdoku-api-js/pom.xml
new file mode 100644
index 0000000000..6ccbc064ed
--- /dev/null
+++ b/docdoku-api-js/pom.xml
@@ -0,0 +1,62 @@
+
+
+
+ docdoku-plm
+ com.docdoku
+ 2.5-SNAPSHOT
+
+
+ pom
+ 4.0.0
+ docdoku-api-js
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.2.1
+
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.3.2
+
+
+ clean-dist
+ clean
+
+ exec
+
+
+ npm
+
+ run
+ clean
+
+
+
+
+ build-dist
+ generate-resources
+
+ exec
+
+
+ npm
+
+ run
+ build
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docdoku-api-js/test/accounts-api.test.js b/docdoku-api-js/test/accounts-api.test.js
new file mode 100644
index 0000000000..510355d2f7
--- /dev/null
+++ b/docdoku-api-js/test/accounts-api.test.js
@@ -0,0 +1,52 @@
+var chai = require('chai');
+var expect = chai.expect;
+var DocdokuPlmClient = require('../lib/docdoku-api');
+var config = require('yargs').argv;
+
+describe('Accounts api tests', function() {
+
+ it('Should create an account', function(done){
+
+ var client = new DocdokuPlmClient({url:config.url});
+
+ client.getApi().then(function(api){
+
+ expect(api.apis.accounts).to.be.defined;
+ expect(api.apis.accounts.createAccount).to.be.a.function;
+
+ api.apis.accounts.createAccount({
+ body:{
+ login:'USER-'+Date.now(),
+ email:'foo@foo.bar',
+ timeZone:'CET',
+ language:'en',
+ name:'Generated',
+ newPassword:'password'
+ }
+ }).then(function(response){
+ var accountCreated = response.obj;
+ expect(accountCreated).to.be.an.object;
+ done();
+ });
+
+ });
+ });
+
+ it('Should get current user account', function(done){
+
+ var client = new DocdokuPlmClient({
+ url:config.url,
+ login:config.login,
+ password:config.password,
+ basicAuth:true
+ });
+
+ client.getApi().then(function(api){
+ api.apis.accounts.getAccount().then(function(response){
+ expect(response.obj.login).to.equal(config.login);
+ done();
+ });
+ });
+ });
+
+});
diff --git a/docdoku-api-js/test/auth.test.js b/docdoku-api-js/test/auth.test.js
new file mode 100644
index 0000000000..65c6556fed
--- /dev/null
+++ b/docdoku-api-js/test/auth.test.js
@@ -0,0 +1,61 @@
+var chai = require('chai');
+var expect = chai.expect;
+var DocdokuPlmClient = require('../lib/docdoku-api');
+var config = require('yargs').argv;
+
+
+describe('Api auth tests', function() {
+
+ var jwt, cookie;
+
+ it('Should login and get session id and jwt', function(done) {
+
+ var client = new DocdokuPlmClient({url:config.url});
+ client.getApi().then(function(api){
+ api.auth.login({body:{login:config.login,password:config.password}}).then(function(response){
+ var headers = response.headers;
+ jwt = headers.jwt;
+ cookie = headers['set-cookie'][0];
+ expect(jwt).to.be.defined;
+ expect(cookie).to.be.defined;
+ done();
+ });
+ });
+ });
+/*
+
+ it('Should be able tu use basic auth', function(done) {
+
+ var client = new DocdokuPlmClient({
+ url:config.url,
+ login:config.login,
+ password:config.password,
+ basicAuth:true
+ });
+
+ client.getApi().then(function(api){
+ api.accounts.getAccount().then(function(response){
+ expect(response.status,200);
+ done();
+ });
+ });
+ });*/
+
+ it('Should be able tu use cookie', function(done) {
+
+ var client = new DocdokuPlmClient({
+ url:config.url,
+ cookie:cookie
+ });
+
+ client.getApi().then(function(api){
+ api.accounts.getAccount().then(function(response){
+ expect(response.status,200);
+ done();
+ });
+ });
+ });
+
+
+
+});
diff --git a/docdoku-api-js/test/client.test.js b/docdoku-api-js/test/client.test.js
new file mode 100644
index 0000000000..4c09148594
--- /dev/null
+++ b/docdoku-api-js/test/client.test.js
@@ -0,0 +1,29 @@
+var chai = require('chai');
+var expect = chai.expect;
+var DocdokuPlmClient = require('../lib/docdoku-api');
+var config = require('yargs').argv;
+
+describe('Api client creation', function() {
+ it('Should affect options to client when using constructor', function() {
+ var client = new DocdokuPlmClient({url:config.url});
+ expect(client.options.url).to.be.defined;
+ expect(client.options.url).to.equal(config.url);
+ });
+
+ it('Should modify options with setter', function() {
+ var client = new DocdokuPlmClient();
+ client.setOptions({url:config.url});
+ expect(client.options.url).to.be.defined;
+ expect(client.options.url).to.equal(config.url);
+ });
+
+ it('Should load the spec and give an api object', function(done) {
+ var client = new DocdokuPlmClient({url:config.url});
+ client.getApi().then(function(api){
+ expect(api).to.be.defined;
+ expect(api).to.be.an.object;
+ done();
+ });
+ });
+
+});
diff --git a/docdoku-api-js/test/document-api.test.js b/docdoku-api-js/test/document-api.test.js
new file mode 100644
index 0000000000..b92214f7de
--- /dev/null
+++ b/docdoku-api-js/test/document-api.test.js
@@ -0,0 +1,100 @@
+var chai = require('chai');
+var expect = chai.expect;
+var DocdokuPlmClient = require('../lib/docdoku-api');
+var config = require('yargs').argv;
+
+describe('Document api tests', function() {
+
+ it('Should create a document', function(done){
+
+ var client = new DocdokuPlmClient({
+ url:config.url,
+ login:config.login,
+ password:config.password,
+ basicAuth:true
+ });
+
+ client.getApi().then(function(api){
+
+ expect(api.apis.folders).to.be.defined;
+ expect(api.apis.folders.createAccount).to.be.a.function;
+ var documentReference = 'DOC-'+Date.now();
+ api.apis.folders.createDocumentMasterInFolder({
+ workspaceId:config.workspace,
+ body:{
+ reference:documentReference,
+ title:'GeneratedDoc'
+ },
+ folderId:config.workspace
+ }).then(function(response){
+ var documentCreated = response.obj;
+ expect(documentCreated).to.be.an.object;
+ expect(documentCreated.documentMasterId).to.equal(documentReference);
+ done();
+ });
+
+ });
+ });
+
+ it('Should list documents', function(done){
+
+ var client = new DocdokuPlmClient({
+ url:config.url,
+ login:config.login,
+ password:config.password,
+ basicAuth:true
+ });
+
+ client.getApi().then(function(api){
+
+ api.apis.documents.getDocumentsInWorkspace({
+ workspaceId:config.workspace,
+ start:0,
+ configSpecType:null
+ }).then(function(response){
+ var documents = response.obj;
+ expect(documents).to.be.an.array;
+ expect(documents.length).not.to.be.empty;
+ done();
+ });
+
+ });
+ });
+
+ it('Should list checkin a document', function(done){
+
+ var client = new DocdokuPlmClient({
+ url:config.url,
+ login:config.login,
+ password:config.password,
+ basicAuth:true
+ });
+
+ client.getApi().then(function(api){
+
+ var documentReference = 'DOCCHECKIN-'+Date.now();
+ api.apis.folders.createDocumentMasterInFolder({
+ workspaceId:config.workspace,
+ body:{
+ reference:documentReference,
+ title:'GeneratedDoc'
+ },
+ folderId:config.workspace
+ }).then(function(response){
+
+ var documentCreated = response.obj;
+
+ api.apis.document.checkInDocument({
+ workspaceId:config.workspace,
+ documentId:documentCreated.documentMasterId,
+ documentVersion:documentCreated.version
+ }).then(function(response){
+ expect(response.status).to.equal(200);
+ done();
+ });
+
+ });
+
+ });
+ });
+});
diff --git a/docdoku-api-js/test/language-api.test.js b/docdoku-api-js/test/language-api.test.js
new file mode 100644
index 0000000000..c52b8df9e1
--- /dev/null
+++ b/docdoku-api-js/test/language-api.test.js
@@ -0,0 +1,26 @@
+var chai = require('chai');
+var expect = chai.expect;
+var DocdokuPlmClient = require('../lib/docdoku-api');
+var config = require('yargs').argv;
+
+describe('Languages API tests', function() {
+
+ it('Should get language list', function(done) {
+
+ var client = new DocdokuPlmClient({url:config.url});
+
+ client.getApi().then(function(api){
+
+ expect(api.apis.languages).to.be.defined;
+ expect(api.apis.languages.getLanguages).to.be.a.function;
+
+ api.apis.languages.getLanguages().then(function(response){
+ expect(response.obj).to.be.an.array;
+ done();
+ });
+ });
+
+ });
+
+});
+
diff --git a/docdoku-api-js/test/timezones-api.test.js b/docdoku-api-js/test/timezones-api.test.js
new file mode 100644
index 0000000000..b8492d4ec9
--- /dev/null
+++ b/docdoku-api-js/test/timezones-api.test.js
@@ -0,0 +1,28 @@
+var chai = require('chai');
+var expect = chai.expect;
+var DocdokuPlmClient = require('../lib/docdoku-api');
+var config = require('yargs').argv;
+
+describe('Timezones API tests', function() {
+
+ it('Should get timezone list', function(done) {
+
+ var client = new DocdokuPlmClient({url:config.url});
+ client.getApi().then(function(api){
+
+ expect(api.apis.timezone).to.be.defined;
+ expect(api.apis.timezone.getTimeZones).to.be.a.function;
+
+ api.apis.timezone.getTimeZones().then(function(response){
+ var timezone = response.obj;
+ expect(timezone).to.be.an.array;
+ done();
+ });
+
+ });
+ });
+
+
+
+});
+
diff --git a/docdoku-api/README.md b/docdoku-api/README.md
new file mode 100644
index 0000000000..84474bb3b9
--- /dev/null
+++ b/docdoku-api/README.md
@@ -0,0 +1,7 @@
+# Docdoku API
+
+Generates a json file to describe web services.
+
+## Documentation
+
+TODO
\ No newline at end of file
diff --git a/docdoku-api/pom.xml b/docdoku-api/pom.xml
new file mode 100644
index 0000000000..ec7e1faf95
--- /dev/null
+++ b/docdoku-api/pom.xml
@@ -0,0 +1,174 @@
+
+
+
+
+ docdoku-plm
+ com.docdoku
+ 2.5-SNAPSHOT
+
+
+ 4.0.0
+ docdoku-api
+ jar
+
+
+
+
+
+ javax
+ javaee-api
+ 7.0
+ provided
+
+
+
+ com.docdoku
+ docdoku-common
+ 2.5-SNAPSHOT
+ provided
+
+
+
+ com.github.kongchen
+ swagger-maven-plugin
+ 3.1.3
+
+
+ io.swagger
+ swagger-jersey-jaxrs
+
+
+
+
+
+ com.google.guava
+ guava
+ 16.0
+
+
+ net.sf.dozer
+ dozer
+ 5.4.0
+
+
+ java3d
+ vecmath
+ 1.3.1
+
+
+ org.apache.poi
+ poi
+ 3.9
+
+
+ org.apache.poi
+ poi-ooxml
+ 3.9
+
+
+ org.bitbucket.b_c
+ jose4j
+ 0.5.1
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.2.1
+
+
+
+
+
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ 1.10
+
+
+ generate-sources
+ add-source
+
+
+ ${project.parent.basedir}/docdoku-server/docdoku-server-rest/src/main/java
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.1
+
+ 1.8
+ 1.8
+ ${project.build.sourceEncoding}
+
+
+
+
+
+ com.github.kongchen
+ swagger-maven-plugin
+ 3.1.3
+
+
+ compile
+
+ generate
+
+
+
+
+
+
+ /api
+ com.docdoku.server.rest
+ http,https
+
+ DocdokuPLM API
+ v2.5
+
+
+
+ basicAuth
+ basic
+
+
+ com.docdoku.api.swagger.JaxrsReader
+ ${project.build.directory}/swagger
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy-dependencies
+ prepare-package
+
+ copy-dependencies
+
+
+ ${project.build.directory}/lib
+ false
+ false
+ true
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docdoku-api/src/main/java/com/docdoku/api/swagger/JaxrsReader.java b/docdoku-api/src/main/java/com/docdoku/api/swagger/JaxrsReader.java
new file mode 100644
index 0000000000..af529954e0
--- /dev/null
+++ b/docdoku-api/src/main/java/com/docdoku/api/swagger/JaxrsReader.java
@@ -0,0 +1,426 @@
+/*
+ * DocDoku, Professional Open Source
+ * Copyright 2006 - 2015 DocDoku SARL
+ *
+ * This file is part of DocDokuPLM.
+ *
+ * DocDokuPLM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DocDokuPLM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with DocDokuPLM. If not, see .
+ */
+
+package com.docdoku.api.swagger;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.kongchen.swagger.docgen.LogAdapter;
+import com.github.kongchen.swagger.docgen.reader.AbstractReader;
+import com.github.kongchen.swagger.docgen.reader.ClassSwaggerReader;
+import io.swagger.annotations.*;
+import io.swagger.converter.ModelConverters;
+import io.swagger.jaxrs.ext.SwaggerExtension;
+import io.swagger.jaxrs.ext.SwaggerExtensions;
+import io.swagger.models.*;
+import io.swagger.models.Tag;
+import io.swagger.models.parameters.Parameter;
+import io.swagger.models.properties.ArrayProperty;
+import io.swagger.models.properties.MapProperty;
+import io.swagger.models.properties.Property;
+import io.swagger.models.properties.RefProperty;
+import io.swagger.util.Json;
+import org.springframework.core.annotation.AnnotationUtils;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.Produces;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The JaxrsReader class is used to generate the spec from docdoku-server-rest classes and annotations.
+ *
+ * The original reader has been taken from github and modified to fit our configuration.
+ * See https://github.com/kongchen/swagger-maven-plugin for more details
+ *
+ * @author Morgan Guimard
+ */
+public class JaxrsReader extends AbstractReader implements ClassSwaggerReader {
+
+ private static final Logger LOGGER = Logger.getLogger(JaxrsReader.class.getName());
+ static ObjectMapper m = Json.mapper();
+
+ public JaxrsReader(Swagger swagger, LogAdapter LOG) {
+ super(swagger, LOG);
+ }
+
+ public Swagger read(Set> classes) {
+ for (Class cls : classes)
+ read(cls);
+ return swagger;
+ }
+
+ public Swagger getSwagger() {
+ return this.swagger;
+ }
+
+ public Swagger read(Class cls) {
+ return read(cls, "", null, false, new String[0], new String[0], new HashMap(), new ArrayList());
+ }
+
+ protected Swagger read(Class> cls, String parentPath, String parentMethod, boolean readHidden, String[] parentConsumes, String[] parentProduces, Map parentTags, List parentParameters) {
+ if (swagger == null) {
+ swagger = new Swagger();
+ }
+
+ Api api = AnnotationUtils.findAnnotation(cls, Api.class);
+ javax.ws.rs.Path apiPath = AnnotationUtils.findAnnotation(cls, javax.ws.rs.Path.class);
+
+ if (!canReadApi(readHidden, api)) {
+ return swagger;
+ }
+
+ Map tags = updateTagsForApi(parentTags, api);
+ List securities = getSecurityRequirements(api);
+
+ Method methods[] = cls.getMethods();
+
+ for (Method method : methods) {
+ ApiOperation apiOperation = AnnotationUtils.findAnnotation(method, ApiOperation.class);
+ if (apiOperation == null || apiOperation.hidden()) {
+ continue;
+ }
+ javax.ws.rs.Path methodPath = AnnotationUtils.findAnnotation(method, javax.ws.rs.Path.class);
+
+ String operationPath = getPath(apiPath, methodPath, parentPath);
+ operationPath = cleanRegexPath(operationPath);
+
+ if (operationPath != null && apiOperation != null) {
+ Map regexMap = new HashMap();
+ operationPath = parseOperationPath(operationPath, regexMap);
+
+ String httpMethod = extractOperationMethod(apiOperation, method, SwaggerExtensions.chain());
+
+ Operation operation = parseMethod(method);
+
+ updateOperationParameters(parentParameters, regexMap, operation);
+
+ updateOperationProtocols(apiOperation, operation);
+
+ String[] apiConsumes = new String[0];
+ String[] apiProduces = new String[0];
+
+ Annotation annotation = AnnotationUtils.getAnnotation(cls, Consumes.class);
+ if (annotation != null)
+ apiConsumes = ((Consumes) annotation).value();
+ annotation = AnnotationUtils.getAnnotation(cls, Produces.class);
+ if (annotation != null)
+ apiProduces = ((Produces) annotation).value();
+
+ apiConsumes = updateOperationConsumes(parentConsumes, apiConsumes, operation);
+ apiProduces = updateOperationProduces(parentProduces, apiProduces, operation);
+
+ handleSubResource(apiConsumes, httpMethod, apiProduces, tags, method, operationPath, operation);
+
+ httpMethod = httpMethod == null ? parentMethod : httpMethod;
+ updateTagsForOperation(operation, apiOperation);
+ updateOperation(apiConsumes, apiProduces, tags, securities, operation);
+ updatePath(operationPath, httpMethod, operation);
+ }
+ }
+
+ return swagger;
+ }
+
+
+ private void handleSubResource(String[] apiConsumes, String httpMethod, String[] apiProduces, Map tags, Method method, String operationPath, Operation operation) {
+ if (isSubResource(method)) {
+ Type t = method.getGenericReturnType();
+ Class> responseClass = method.getReturnType();
+ Swagger subSwagger = read(responseClass, operationPath, httpMethod, true, apiConsumes, apiProduces, tags, operation.getParameters());
+ }
+ }
+
+ protected boolean isSubResource(Method method) {
+ Type t = method.getGenericReturnType();
+ Class> responseClass = method.getReturnType();
+ if (responseClass != null && AnnotationUtils.findAnnotation(responseClass, Api.class) != null) {
+ return true;
+ }
+ return false;
+ }
+
+ String getPath(javax.ws.rs.Path classLevelPath, javax.ws.rs.Path methodLevelPath, String parentPath) {
+ // Fix for empty path in sub resources. Should be fixed in a cleaner way ...
+ if (classLevelPath == null && methodLevelPath == null) {
+ return parentPath;
+ }
+ StringBuilder b = new StringBuilder();
+ if (parentPath != null && !"".equals(parentPath) && !"/".equals(parentPath)) {
+ if (!parentPath.startsWith("/"))
+ parentPath = "/" + parentPath;
+ if (parentPath.endsWith("/"))
+ parentPath = parentPath.substring(0, parentPath.length() - 1);
+
+ b.append(parentPath);
+ }
+ if (classLevelPath != null) {
+ b.append(classLevelPath.value());
+ }
+ if (methodLevelPath != null && !"/".equals(methodLevelPath.value())) {
+ String methodPath = methodLevelPath.value();
+ if (!methodPath.startsWith("/") && !b.toString().endsWith("/")) {
+ b.append("/");
+ }
+ if (methodPath.endsWith("/")) {
+ methodPath = methodPath.substring(0, methodPath.length() - 1);
+ }
+ b.append(methodPath);
+ }
+ String output = b.toString();
+ if (!output.startsWith("/"))
+ output = "/" + output;
+ if (output.endsWith("/") && output.length() > 1)
+ return output.substring(0, output.length() - 1);
+ else
+ return output;
+ }
+
+
+ public Operation parseMethod(Method method) {
+ Operation operation = new Operation();
+
+ ApiOperation apiOperation = (ApiOperation) AnnotationUtils.findAnnotation(method, ApiOperation.class);
+
+
+ String operationId = method.getName();
+ String responseContainer = null;
+
+ Class> responseClass = null;
+ Map defaultResponseHeaders = null;
+ Set