[coselmar] branch feature/6009-create-document updated (c07e607 -> d0da34f)
This is an automated email from the git hooks/post-receive script. New change to branch feature/6009-create-document in repository coselmar. See http://git.codelutin.com/coselmar.git from c07e607 first step of document creation : document metadata new d0da34f improve document metadata save The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit d0da34fa914ccb153fb66a91ee6bf62e7b7d73fd Author: Yannick Martel <martel@©odelutin.com> Date: Tue Nov 4 18:01:52 2014 +0100 improve document metadata save Summary of changes: coselmar-persistence/pom.xml | 8 ++++-- coselmar-rest/pom.xml | 13 +++++++++ .../fr/ifremer/coselmar/beans/DocumentBean.java | 22 +++++++++++---- .../services/CoselmarWebServiceSupport.java | 23 ++++++++++++---- .../coselmar/services/v1/DocumentsWebService.java | 13 +++++---- .../src/main/webapp/js/coselmar-controllers.js | 2 -- .../src/main/webapp/js/coselmar-services.js | 17 +++++++----- pom.xml | 32 +++++++++++++++++++++- 8 files changed, 101 insertions(+), 29 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/6009-create-document in repository coselmar. See http://git.codelutin.com/coselmar.git commit d0da34fa914ccb153fb66a91ee6bf62e7b7d73fd Author: Yannick Martel <martel@©odelutin.com> Date: Tue Nov 4 18:01:52 2014 +0100 improve document metadata save --- coselmar-persistence/pom.xml | 8 ++++-- coselmar-rest/pom.xml | 13 +++++++++ .../fr/ifremer/coselmar/beans/DocumentBean.java | 22 +++++++++++---- .../services/CoselmarWebServiceSupport.java | 23 ++++++++++++---- .../coselmar/services/v1/DocumentsWebService.java | 13 +++++---- .../src/main/webapp/js/coselmar-controllers.js | 2 -- .../src/main/webapp/js/coselmar-services.js | 17 +++++++----- pom.xml | 32 +++++++++++++++++++++- 8 files changed, 101 insertions(+), 29 deletions(-) diff --git a/coselmar-persistence/pom.xml b/coselmar-persistence/pom.xml index 0932629..8fe4fee 100644 --- a/coselmar-persistence/pom.xml +++ b/coselmar-persistence/pom.xml @@ -64,6 +64,11 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> <artifactId>nuiton-converter</artifactId> </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + </dependency> + <!-- Tests --> <dependency> <groupId>junit</groupId> @@ -137,8 +142,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> fr.ifremer.coselmar.persistence </defaultPackage> <templates> - org.nuiton.topia.templates.TopiaMetaTransformer, - org.nuiton.eugene.java.JavaEnumerationTransformer, + org.nuiton.topia.templates.TopiaMetaTransformer </templates> <failIfUnsafe>true</failIfUnsafe> </configuration> diff --git a/coselmar-rest/pom.xml b/coselmar-rest/pom.xml index 53b3817..fbae26e 100644 --- a/coselmar-rest/pom.xml +++ b/coselmar-rest/pom.xml @@ -109,6 +109,18 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> <scope>provided</scope> </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>postgresql</groupId> + <artifactId>postgresql</artifactId> + <scope>runtime</scope> + </dependency> + <!-- Tests --> <dependency> <groupId>junit</groupId> @@ -136,6 +148,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <path>/services</path> + <port>8081</port> <uriEncoding>UTF-8</uriEncoding> <systemProperties> <!--<coselmar.logConfigurationFile>${basedir}/target</coselmar.logConfigurationFile>--> 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 cc785a8..2b1a4ff 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 @@ -1,8 +1,10 @@ package fr.ifremer.coselmar.beans; import java.io.Serializable; +import java.util.Collection; import java.util.Date; -import java.util.List; +import java.util.HashSet; +import java.util.Set; /** * @author ymartel <martel@codelutin.com> @@ -13,15 +15,16 @@ public class DocumentBean implements Serializable { protected String name; protected String ownerName; protected String privacy; - protected List<String> keywords; + protected Set<String> keywords; protected Date depositDate; - public DocumentBean(String id, String name, String ownerName, String privacy, Date depositDate) { + public DocumentBean(String id, String name, String ownerName, String privacy, Date depositDate, Collection<String> keywords) { this.id = id; this.name = name; this.ownerName = ownerName; this.privacy = privacy; this.depositDate = depositDate; + this.keywords = new HashSet<>(keywords); } public String getId() { @@ -64,11 +67,18 @@ public class DocumentBean implements Serializable { this.depositDate = depositDate; } - public List<String> getKeywords() { + public Set<String> getKeywords() { return keywords; } - public void setKeywords(List<String> keywords) { - this.keywords = keywords; + public void setKeywords(Collection<String> keywords) { + this.keywords = new HashSet<>(keywords); + } + + public void addKeywords(Collection<String> keywords) { + if (this.keywords == null) { + this.keywords = new HashSet<>(keywords); + } + this.keywords.addAll(keywords); } } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarWebServiceSupport.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarWebServiceSupport.java index ebd0a07..5732aba 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarWebServiceSupport.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarWebServiceSupport.java @@ -9,35 +9,46 @@ import fr.ifremer.coselmar.persistence.entity.UserTopiaDao; import fr.ifremer.coselmar.services.config.CoselmarServicesConfig; import fr.ifremer.coselmar.services.v1.DocumentsWebService; import org.debux.webmotion.server.WebMotionController; +import org.debux.webmotion.server.call.HttpContext; /** * @author ymartel <martel@codelutin.com> */ public abstract class CoselmarWebServiceSupport extends WebMotionController implements CoselmarService { - protected CoselmarServicesContext servicesContext; + private CoselmarServicesContext servicesContext; @Override public void setServicesContext(CoselmarServicesContext servicesContext) { this.servicesContext = servicesContext; } + protected CoselmarServicesContext getServicesContext() { + //try to get it from Request context + HttpContext context = getContext(); + if (context != null) { + CoselmarRestRequestContext requestContext = CoselmarRestRequestContext.getRequestContext(context); + this.servicesContext = requestContext.getServicesContext(); + } + return this.servicesContext; + } + // Delegate serviceContext // protected Date getNow() { - return servicesContext.getNow(); + return getServicesContext().getNow(); } protected String getCleanMail(String email) { - return servicesContext.getCleanMail(email); + return getServicesContext().getCleanMail(email); } protected CoselmarPersistenceContext getPersistenceContext() { - return servicesContext.getPersistenceContext(); + return getServicesContext().getPersistenceContext(); } protected CoselmarServicesConfig getCoselmarServicesConfig() { - return servicesContext.getCoselmarServicesConfig(); + return getServicesContext().getCoselmarServicesConfig(); } protected Locale getLocale() { @@ -51,7 +62,7 @@ public abstract class CoselmarWebServiceSupport extends WebMotionController impl } protected <E extends CoselmarService> E newService(Class<E> serviceClass) { - return servicesContext.newService(serviceClass); + return getServicesContext().newService(serviceClass); } // Persistence // 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 0220344..56381ca 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 @@ -17,20 +17,23 @@ import fr.ifremer.coselmar.services.CoselmarWebServiceSupport; public class DocumentsWebService extends CoselmarWebServiceSupport { public DocumentBean getDocument(String documentId) { - //TODO load from bdd - Date now = new Date(); - DocumentBean result = new DocumentBean("1", "fakeDocument", "no owner", "public", now); - return result; + + Document document = getDocumentDao().forTopiaIdEquals(documentId).findUnique(); + Date depositDate = new Date(document.getDepositDate().getTime()); + //TODO ymartel 20141103 : manage file ? + DocumentBean documentBean = new DocumentBean(document.getTopiaId(), document.getName(), "N/A", document.getPrivacy().name(), depositDate, document.getKeywords()); + return documentBean; } public List<DocumentBean> getDocuments() { + List<Document> documentList = getDocumentDao().findAll(); List<DocumentBean> result = new ArrayList<>(documentList.size()); for (Document document : documentList) { Date depositDate = new Date(document.getDepositDate().getTime()); //TODO ymartel 20141103 : manage file ? - DocumentBean documentBean = new DocumentBean(document.getTopiaId(), document.getName(), "N/A", document.getPrivacy().name(), depositDate); + DocumentBean documentBean = new DocumentBean(document.getTopiaId(), document.getName(), "N/A", document.getPrivacy().name(), depositDate, document.getKeywords()); result.add(documentBean); } diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index 68316a6..b7dd9e1 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -17,8 +17,6 @@ coselmarControllers.controller("NewDocumentCtrl", ['$scope', 'documentService', $scope.createNewDocument = function(){ var newdocument = {'name':$scope.name, 'file':$scope.file, 'privacy':$scope.privacy, 'keywords':$scope.keywords}; - console.log("document to create"); - console.log(newdocument); // Call service to create a new document documentService.createDocument(newdocument, $scope); diff --git a/coselmar-ui/src/main/webapp/js/coselmar-services.js b/coselmar-ui/src/main/webapp/js/coselmar-services.js index 972d60e..fe40926 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-services.js @@ -9,17 +9,20 @@ function Document(resource){ this.resource = resource; this.createDocument = function(document, scope){ + + console.log("document to create"); + console.log(document); + // Save the document - var docResource = resource('v1/documents/new'); - console.log("new document saved"); -// docResource.save(document, function(response){ -// scope.message = response.message; -// }); + var docResource = resource('http://localhost:8081/services/v1/documents', {'documentBean':document}); + docResource.save(document, function(response){ + scope.message = response.message; + }); } this.getDocument = function(id, scope){ // Load the document - var docResource = resource('v1/documents/:documentId', {documentId:'@documentId'}); + var docResource = resource('http://localhost:8081/services/v1/documents/:documentId', {documentId:'@documentId'}); docResource.get({documentId:id}, function(document){ scope.document = document; }); @@ -28,7 +31,7 @@ function Document(resource){ this.getDocuments = function(scope){ // Load all documents console.log("loading all documents"); - var docResource = resource('v1/documents'); + var docResource = resource('http://localhost:8081/services/v1/documents'); docResource.query(function(documents){ scope.documents = documents; }, function(errorResult) { diff --git a/pom.xml b/pom.xml index bd315aa..9fbaf04 100644 --- a/pom.xml +++ b/pom.xml @@ -120,7 +120,7 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> <nuitonI18nVersion>3.3</nuitonI18nVersion> <eugenePluginVersion>2.13</eugenePluginVersion> - <topiaVersion>3.0-beta-12</topiaVersion> + <topiaVersion>3.0-beta-14</topiaVersion> <nuitonWebVersion>1.17</nuitonWebVersion> <nuitonUtilsVersion>3.0-rc-7</nuitonUtilsVersion> @@ -129,6 +129,10 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> <nuitonValidatorVersion>3.0-rc-1</nuitonValidatorVersion> <nuitonConvertorVersion>1.0</nuitonConvertorVersion> + <hibernateVersion>4.3.5.Final</hibernateVersion> + <postgresqlVersion>9.1-901-1.jdbc4</postgresqlVersion> + <h2Version>1.4.178</h2Version> + </properties> @@ -208,6 +212,32 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> <scope>compile</scope> </dependency> + <!-- persistence --> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + <version>${hibernateVersion}</version> + <scope>runtime</scope> + <exclusions> + <exclusion> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.0-api</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>${postgresqlVersion}</version> + </dependency> + + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>${h2Version}</version> + </dependency> + <!-- Commons --> <dependency> <groupId>org.apache.commons</groupId> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm