This is an automated email from the git hooks/post-receive script. New commit to branch refonte-rest in repository coselmar. See https://gitlab.nuiton.org/codelutin/coselmar.git commit 353f7534fb225b2750a2261c44145ff85a5db0cb Author: Yannick Martel <martel@©odelutin.com> Date: Wed Jun 5 11:50:11 2019 +0200 some api fixes --- .../coselmar/services/v1/DocumentsWebService.java | 34 +++++++++++++++------- .../coselmar/services/v1/QuestionsWebService.java | 9 ++++-- .../coselmar/services/v1/UsersWebService.java | 3 +- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java index 4ea5141..f5afc27 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java @@ -70,6 +70,7 @@ import org.nuiton.util.pagination.PaginationResult; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; +import javax.ws.rs.FormParam; import javax.ws.rs.GET; import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; @@ -83,6 +84,7 @@ import javax.ws.rs.core.Response; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; @@ -388,11 +390,10 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { @POST @Path("/v1/documents") - @Consumes(MediaType.MULTIPART_FORM_DATA) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public DocumentBean addDocument(@Context CoselmarServicesContext servicesContext, @HeaderParam(AUTHORIZATION_HEADER) String authorization, - DocumentBean document, - MultipartFormDataInput uploadFile) throws InvalidCredentialException, UnauthorizedException { + @FormParam("document") DocumentBean document) throws InvalidCredentialException, UnauthorizedException { // Check authentication CoselmarUser userWebToken = checkUserAuthentication(servicesContext, authorization); @@ -428,11 +429,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { throw new InvalidCredentialException(message); } - FileInfos fileInfos = null; - if (uploadFile != null) { - fileInfos = manageDocumentFile(servicesContext, uploadFile, owner); - } - DocumentBean result = createDocument(servicesContext, document, fileInfos, owner); + DocumentBean result = createDocument(servicesContext, document, null, owner); persistenceContext.commit(); @@ -542,9 +539,10 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { @POST @Path("/v1/documents/{documentId}") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public void saveDocument(@Context CoselmarServicesContext servicesContext, @HeaderParam(AUTHORIZATION_HEADER) String authorization, - DocumentBean document) throws InvalidCredentialException, UnauthorizedException { + @FormParam("document") DocumentBean document) throws InvalidCredentialException, UnauthorizedException { Preconditions.checkNotNull(document); Preconditions.checkNotNull(document.getId()); @@ -915,7 +913,11 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { // put the document in the good directory String filePath = getDocumentFileDestPath(servicesContext, owner, fileName); File uploadedFile = new File(filePath); - Files.copy(in, uploadedFile.toPath()); + java.nio.file.Path pathToFile = uploadedFile.toPath(); + if (Files.notExists(pathToFile)) { + Files.createFile(pathToFile); + } + Files.copy(in, pathToFile, StandardCopyOption.REPLACE_EXISTING); FileInfos fileInfos = new FileInfos(); fileInfos.setFileName(fileName); @@ -950,6 +952,18 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { String absolutePath = dataDirectory.getAbsolutePath(); String userFolder = StringUtils.replaceChars(user.getFirstname() + "-" + user.getName(), " ", "_"); String userPath = absolutePath + File.separator + userFolder; + + // Make sure path exist + // java.nio.file.Path userDirPath = new java.nio.file.Path.of(userPath); // After J8 + java.nio.file.Path userDirPath = Paths.get(userPath); + if (Files.notExists(userDirPath)) { + try { + Files.createDirectory(userDirPath); + } catch (IOException e) { + throw new CoselmarTechnicalException("Cannot create user file directory"); + } + } + return userPath; } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java index d039474..724464b 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/QuestionsWebService.java @@ -598,9 +598,10 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { @POST @Path("/v1/questions/{questionId}") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public void saveQuestion(@Context CoselmarServicesContext servicesContext, @HeaderParam(AUTHORIZATION_HEADER) String authorization, - QuestionBean question) throws InvalidCredentialException, UnauthorizedException { + @FormParam("question") QuestionBean question) throws InvalidCredentialException, UnauthorizedException { // Check authentication CoselmarUser supervisor = checkUserAuthentication(servicesContext, authorization); @@ -1016,7 +1017,8 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { @Path("/v1/questions/{questionId}/ancestors") public List<QuestionTreeNode> getAncestors(@Context CoselmarServicesContext servicesContext, @HeaderParam(AUTHORIZATION_HEADER) String authorization, - @PathParam("questionId") String questionId, int depth) throws InvalidCredentialException, UnauthorizedException { + @PathParam("questionId") String questionId, + @QueryParam("depth") int depth) throws InvalidCredentialException, UnauthorizedException { // Check authentication CoselmarUser currentUser = checkUserAuthentication(servicesContext, authorization); @@ -1061,7 +1063,8 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { @Path("/v1/questions/{questionId}/descendants") public List<QuestionTreeNode> getDescendants(@Context CoselmarServicesContext servicesContext, @HeaderParam(AUTHORIZATION_HEADER) String authorization, - @PathParam("questionId") String questionId, int depth) throws InvalidCredentialException, UnauthorizedException { + @PathParam("questionId") String questionId, + @QueryParam("depth") int depth) throws InvalidCredentialException, UnauthorizedException { // Check authentication CoselmarUser currentUser = checkUserAuthentication(servicesContext, authorization); diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java index bfa26b3..35156a2 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/UsersWebService.java @@ -314,10 +314,11 @@ public class UsersWebService extends CoselmarWebServiceSupport { @POST @Path("/v1/users/{userId}") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public void modifyUser(@Context CoselmarServicesContext servicesContext, @HeaderParam(AUTHORIZATION_HEADER) String authorization, @PathParam("userId") String userId, - UserBean user) throws InvalidCredentialException, UnauthorizedException, InvalidParameterException, TopiaNoResultException, MailAlreadyExistingException { + @FormParam("user") UserBean user) throws InvalidCredentialException, UnauthorizedException, InvalidParameterException, TopiaNoResultException, MailAlreadyExistingException { // Check authentication CoselmarUser userWebToken = checkUserAuthentication(servicesContext, authorization); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.