This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit b0a9c2844cf0fb97a679f554e56b464269ba1ea8 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Jan 21 18:16:03 2015 +0100 cannot edit document used by questions --- .../java/fr/ifremer/coselmar/beans/DocumentBean.java | 16 ++++++++++++++++ .../coselmar/services/v1/DocumentsWebService.java | 10 ++++++++++ coselmar-ui/src/main/webapp/js/coselmar-controllers.js | 3 +-- .../src/main/webapp/views/documents/viewDocument.html | 4 ++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/DocumentBean.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/DocumentBean.java index 2b60237..6726a35 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/DocumentBean.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/DocumentBean.java @@ -56,6 +56,7 @@ public class DocumentBean implements Serializable { protected boolean withFile; protected String mimeType; protected String externalUrl; + protected Set<QuestionBean> relatedQuestions; public DocumentBean(String id, String name, String ownerName, String privacy, Date depositDate, Collection<String> keywords, @@ -246,4 +247,19 @@ public class DocumentBean implements Serializable { public void setComment(String comment) { this.comment = comment; } + + public Set<QuestionBean> getRelatedQuestions() { + return relatedQuestions; + } + + public void setRelatedQuestions(Set<QuestionBean> relatedQuestions) { + this.relatedQuestions = relatedQuestions; + } + + public void addRelatedQuestion(QuestionBean relatedQuestion) { + if (this.relatedQuestions == null) { + this.relatedQuestions = new HashSet<>(); + } + this.relatedQuestions.add(relatedQuestion); + } } 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 6305cf8..53def42 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 @@ -37,12 +37,14 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import fr.ifremer.coselmar.beans.DocumentBean; +import fr.ifremer.coselmar.beans.QuestionBean; import fr.ifremer.coselmar.beans.UserWebToken; import fr.ifremer.coselmar.converter.BeanEntityConverter; import fr.ifremer.coselmar.persistence.entity.CoselmarUser; import fr.ifremer.coselmar.persistence.entity.CoselmarUserRole; import fr.ifremer.coselmar.persistence.entity.Document; import fr.ifremer.coselmar.persistence.entity.Privacy; +import fr.ifremer.coselmar.persistence.entity.Question; import fr.ifremer.coselmar.services.CoselmarTechnicalException; import fr.ifremer.coselmar.services.CoselmarWebServiceSupport; import fr.ifremer.coselmar.services.errors.InvalidCredentialException; @@ -103,6 +105,14 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { } DocumentBean documentBean = BeanEntityConverter.toBean(documentId, document); + + // Manage related Question + List<Question> relatedQuestions = getQuestionDao().forRelatedDocumentsContains(document).findAll(); + for (Question relatedQuestion : relatedQuestions) { + QuestionBean questionBean = BeanEntityConverter.toLightBean(getPersistenceContext().getTopiaIdFactory(), relatedQuestion); + documentBean.addRelatedQuestion(questionBean); + } + return documentBean; } diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 83eba95..935beec 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -171,6 +171,7 @@ coselmarControllers.controller("DocumentViewCtrl", documentService.getDocument($routeParams.documentId, function(document) { $scope.document = document; + $scope.canEdit = !(document.relatedQuestions && document.relatedQuestions.length > 0); }); $scope.deleteDocument = function(documentId){ @@ -185,8 +186,6 @@ coselmarControllers.controller("DocumentViewCtrl", // edit part - $scope.canEdit = true; - //to enter in edit mode from view $scope.edit = function() { $location.search("edit"); diff --git a/coselmar-ui/src/main/webapp/views/documents/viewDocument.html b/coselmar-ui/src/main/webapp/views/documents/viewDocument.html index e604b4f..62899cc 100644 --- a/coselmar-ui/src/main/webapp/views/documents/viewDocument.html +++ b/coselmar-ui/src/main/webapp/views/documents/viewDocument.html @@ -68,6 +68,10 @@ <td>Comment</td> <td>{{document.comment}}</td> </tr> + <tr> + <td>Questions with the document</td> + <td>{{document.relatedQuestions.length || 0}}</td> + </tr> </table> <div class="float-right"> <a class="btn btn-action btn-edit" ng-click="edit()" ng-if="editSession != true && canEdit"> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.