branch develop updated (166496f -> 3c42708)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git from 166496f Merge branch 'feature/6014-modify-user' into develop new cf38c8d #6140 add new metadata in document entity new 1c77d64 #6140 manager document metadata in webservice new 673e11b #6140 add new metadata in document views new 3c42708 Merge branch 'feature/6140-update-document-metadata' into develop The 4 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 3c427089cc3e372a8036f43489eee22f2b79db8a Merge: 166496f 673e11b Author: Yannick Martel <martel@©odelutin.com> Date: Wed Nov 26 16:55:42 2014 +0100 Merge branch 'feature/6140-update-document-metadata' into develop commit 673e11b82b16207ef885f3bbb611391d7cbbf532 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Nov 26 16:53:30 2014 +0100 #6140 add new metadata in document views commit 1c77d64152f9b87c42155ddd19830b726bb56d38 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Nov 26 11:23:09 2014 +0100 #6140 manager document metadata in webservice commit cf38c8d9b10d0ffce7853b414efd46dcb7e9fd40 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Nov 26 10:17:13 2014 +0100 #6140 add new metadata in document entity Summary of changes: .../src/main/xmi/coselmar-model.properties | 5 +- .../src/main/xmi/coselmar-model.zargo | Bin 6029 -> 6490 bytes .../fr/ifremer/coselmar/beans/DocumentBean.java | 127 +++++++++++++++- .../coselmar/converter/BeanEntityConverter.java | 40 +++-- .../coselmar/services/v1/DocumentsWebService.java | 162 +++++++++++++++++---- .../coselmar/services/v1/UsersWebService.java | 7 +- .../src/main/webapp/js/coselmar-controllers.js | 23 ++- .../src/main/webapp/js/coselmar-services.js | 11 +- .../src/main/webapp/views/documents/document.html | 34 ++++- .../src/main/webapp/views/documents/documents.html | 6 +- .../main/webapp/views/documents/newdocument.html | 105 +++++++++++-- 11 files changed, 447 insertions(+), 73 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 develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit cf38c8d9b10d0ffce7853b414efd46dcb7e9fd40 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Nov 26 10:17:13 2014 +0100 #6140 add new metadata in document entity --- .../src/main/xmi/coselmar-model.properties | 5 +- .../src/main/xmi/coselmar-model.zargo | Bin 6029 -> 6487 bytes .../fr/ifremer/coselmar/beans/DocumentBean.java | 127 ++++++++++++++++++++- .../coselmar/converter/BeanEntityConverter.java | 30 ++++- 4 files changed, 155 insertions(+), 7 deletions(-) diff --git a/coselmar-persistence/src/main/xmi/coselmar-model.properties b/coselmar-persistence/src/main/xmi/coselmar-model.properties index a91b2b0..1835e8e 100644 --- a/coselmar-persistence/src/main/xmi/coselmar-model.properties +++ b/coselmar-persistence/src/main/xmi/coselmar-model.properties @@ -24,4 +24,7 @@ model.tagvalue.version=1.0 package.fr.ifremer.coselmar.persistence.entity.stereotype=entity -model.tagvalue.useEnumerationName=true \ No newline at end of file +model.tagvalue.useEnumerationName=true + +# Text +fr.ifremer.coselmar.persistence.entity.Document.attribute.summary.tagValue.hibernateAttributeType=text \ No newline at end of file diff --git a/coselmar-persistence/src/main/xmi/coselmar-model.zargo b/coselmar-persistence/src/main/xmi/coselmar-model.zargo index 11e04de..b07f229 100644 Binary files a/coselmar-persistence/src/main/xmi/coselmar-model.zargo and b/coselmar-persistence/src/main/xmi/coselmar-model.zargo differ 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 85445e4..93528a0 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 @@ -35,22 +35,59 @@ import java.util.Set; */ public class DocumentBean implements Serializable { + // Standard Data protected String id; protected String name; protected String ownerName; protected String privacy; protected Set<String> keywords; protected Date depositDate; + protected String authors; + protected String license; + protected String copyright; + protected String type; + protected String language; + protected String summary; + protected Date publicationDate; + + // Document could be internal file or external link + protected boolean isFile; protected String mimeType; + protected String externalUrl; - public DocumentBean(String id, String name, String ownerName, String privacy, Date depositDate, Collection<String> keywords, String mimeType) { + public DocumentBean(String id, String name, String ownerName, String privacy, + Date depositDate, Collection<String> keywords, + String type, String summary, String language, Date publicationDate, + String authors, String license, String copyright, + boolean isFile, String mimeType, String externalUrl) { this.id = id; this.name = name; this.ownerName = ownerName; this.privacy = privacy; - this.depositDate = depositDate; + if (depositDate != null) { + this.depositDate = new Date(depositDate.getTime()); + } this.keywords = new HashSet<>(keywords); this.mimeType = mimeType; + + this.type = type; + this.summary = summary; + this.language = language; + if (publicationDate != null) { + this.publicationDate = new Date(publicationDate.getTime()); + } + + this.authors = authors; + this.license = license; + this.copyright = copyright; + + if (isFile) { + this.isFile = true; + this.mimeType = mimeType; + } else { + this.isFile = false; + this.externalUrl = externalUrl; + } } public String getId() { @@ -90,7 +127,9 @@ public class DocumentBean implements Serializable { } public void setDepositDate(Date depositDate) { - this.depositDate = depositDate; + if (depositDate != null) { + this.depositDate = new Date(depositDate.getTime()); + } } public Set<String> getKeywords() { @@ -107,4 +146,86 @@ public class DocumentBean implements Serializable { } this.keywords.addAll(keywords); } + + public String getAuthors() { + return authors; + } + + public void setAuthors(String authors) { + this.authors = authors; + } + + public String getLicense() { + return license; + } + + public void setLicense(String license) { + this.license = license; + } + + public String getCopyright() { + return copyright; + } + + public void setCopyright(String copyright) { + this.copyright = copyright; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public String getSummary() { + return summary; + } + + public void setSummary(String summary) { + this.summary = summary; + } + + public Date getPublicationDate() { + return publicationDate; + } + + public void setPublicationDate(Date publicationDate) { + if (publicationDate != null) { + this.publicationDate = new Date(publicationDate.getTime()); + } + } + + public boolean isFile() { + return isFile; + } + + public void setFile(boolean isFile) { + this.isFile = isFile; + } + + public String getExternalUrl() { + return externalUrl; + } + + public void setExternalUrl(String externalUrl) { + this.externalUrl = externalUrl; + } + + public String getMimeType() { + return mimeType; + } + + public void setMimeType(String mimeType) { + this.mimeType = mimeType; + } } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java index f024037..26ea92a 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java @@ -30,6 +30,7 @@ import fr.ifremer.coselmar.beans.DocumentBean; import fr.ifremer.coselmar.beans.UserBean; import fr.ifremer.coselmar.persistence.entity.CoselmarUser; import fr.ifremer.coselmar.persistence.entity.Document; +import org.apache.commons.lang3.StringUtils; /** * @author ymartel <martel@codelutin.com> @@ -38,14 +39,37 @@ public class BeanEntityConverter { public static DocumentBean toBean(Document document) { String documentLightId = document.getTopiaId().replace(Document.class.getCanonicalName() + "_", ""); - Date depositeDate = new Date(document.getDepositDate().getTime()); + Date depositeDate = document.getDepositDate(); + Date publicationDate = document.getPublicationDate(); + CoselmarUser documentOwner = document.getOwner(); + String owner = "N/A"; + if (documentOwner != null) { + String firstname = documentOwner.getFirstname(); + String lastname = documentOwner.getName(); + owner = StringUtils.defaultString(firstname) + StringUtils.defaultString(lastname); + } + + return new DocumentBean(documentLightId, document.getName(), - "N/A", + owner, document.getPrivacy().name(), depositeDate, document.getKeywords(), - document.getMimeType()); + + document.getType(), + document.getSummary(), + document.getLanguage(), + publicationDate, + + document.getAuthors(), + document.getLicense(), + document.getCopyright(), + + document.isIsFile(), + document.getMimeType(), + document.getExternalUrl() + ); } public static UserBean toBean(CoselmarUser user) { -- 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 develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit 1c77d64152f9b87c42155ddd19830b726bb56d38 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Nov 26 11:23:09 2014 +0100 #6140 manager document metadata in webservice --- .../coselmar/converter/BeanEntityConverter.java | 10 +- .../coselmar/services/v1/DocumentsWebService.java | 144 +++++++++++++++++---- .../coselmar/services/v1/UsersWebService.java | 7 +- 3 files changed, 124 insertions(+), 37 deletions(-) diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java index 26ea92a..61be990 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java @@ -37,8 +37,7 @@ import org.apache.commons.lang3.StringUtils; */ public class BeanEntityConverter { - public static DocumentBean toBean(Document document) { - String documentLightId = document.getTopiaId().replace(Document.class.getCanonicalName() + "_", ""); + public static DocumentBean toBean(String lightId, Document document) { Date depositeDate = document.getDepositDate(); Date publicationDate = document.getPublicationDate(); CoselmarUser documentOwner = document.getOwner(); @@ -50,7 +49,7 @@ public class BeanEntityConverter { } - return new DocumentBean(documentLightId, + return new DocumentBean(lightId, document.getName(), owner, document.getPrivacy().name(), @@ -72,9 +71,8 @@ public class BeanEntityConverter { ); } - public static UserBean toBean(CoselmarUser user) { - String userLightId = user.getTopiaId().replace(CoselmarUser.class.getCanonicalName() + "_", ""); - return new UserBean(userLightId, + public static UserBean toBean(String lightId ,CoselmarUser user) { + return new UserBean(lightId, user.getFirstname(), user.getName(), user.getMail(), 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 55eabec..d4dbb70 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 @@ -34,16 +34,22 @@ import java.util.Date; import java.util.List; import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import fr.ifremer.coselmar.beans.DocumentBean; +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.Document; import fr.ifremer.coselmar.persistence.entity.DocumentPrivacy; import fr.ifremer.coselmar.services.CoselmarTechnicalException; import fr.ifremer.coselmar.services.CoselmarWebServiceSupport; +import fr.ifremer.coselmar.services.errors.InvalidCredentialException; +import fr.ifremer.coselmar.services.errors.UnauthorizedException; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.debux.webmotion.server.call.UploadFile; import org.debux.webmotion.server.render.Render; +import org.nuiton.topia.persistence.TopiaNoResultException; import org.nuiton.util.DateUtil; import static org.apache.commons.logging.LogFactory.getLog; @@ -58,11 +64,10 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { public DocumentBean getDocument(String documentId) { // reconstitute full id - String fullId = Document.class.getCanonicalName() + "_" + documentId; + String fullId = Document.class.getCanonicalName() + getPersistenceContext().getTopiaIdFactory().getSeparator() + documentId; Document document = getDocumentDao().forTopiaIdEquals(fullId).findUnique(); - //TODO ymartel 20141103 : manage file ? - DocumentBean documentBean = BeanEntityConverter.toBean(document); + DocumentBean documentBean = BeanEntityConverter.toBean(documentId, document); return documentBean; } @@ -78,51 +83,66 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { for (Document document : documentList) { //TODO ymartel 20141103 : manage file ? - DocumentBean documentBean = BeanEntityConverter.toBean(document); + String lightId = getPersistenceContext().getTopiaIdFactory().getRandomPart(document.getTopiaId()); + DocumentBean documentBean = BeanEntityConverter.toBean(lightId, document); result.add(documentBean); } return result; } - public void addDocument(DocumentBean document, UploadFile uploadFile) { - Preconditions.checkNotNull(document); - Preconditions.checkNotNull(uploadFile); + public void addDocument(DocumentBean document, UploadFile uploadFile) throws InvalidCredentialException, UnauthorizedException { - // Document File - String fileName = uploadFile.getName(); - File uploadedFile = uploadFile.getFile(); - String contentType = uploadFile.getContentType(); + // Check authentication + String authorization = getContext().getHeader("Authorization"); + UserWebToken userWebToken = checkAuthentication(authorization); - if (log.isInfoEnabled()) { - String message = String.format("File name : %s, content-type : %s", fileName, contentType); - log.info(message); + // Only Expert or Supervisor can add document + String userRole = userWebToken.getRole(); + if (!Lists.newArrayList().contains(userRole.toUpperCase())) { + String message = String.format("User %s %s ('%s') is not allowed to add document", + userWebToken.getFirstName(), userWebToken.getLastName(), userWebToken.getUserId()); + if (log.isWarnEnabled()) { + log.warn(message); + } + throw new UnauthorizedException(message); } - // put the document in the good directory - // TODO ymartel 20141105 : with user management, put the document in a user specifique folder - File dataDirectory = getCoselmarServicesConfig().getDataDirectory(); - String absolutePath = dataDirectory.getAbsolutePath(); - Date now = getNow(); - String formatedDay = DateUtil.formatDate(now, "yyyymmdd"); - String prefix = formatedDay + "-"; - File destFile = new File(absolutePath + "/" + prefix + fileName); + Preconditions.checkNotNull(document); + + // retrieve user who will be assigned as document owner + String fullId = CoselmarUser.class.getCanonicalName() + + getPersistenceContext().getTopiaIdFactory().getSeparator() + userWebToken.getUserId(); + + CoselmarUser owner; try { - FileUtils.moveFile(uploadedFile, destFile); - } catch (IOException e) { + owner = getCoselmarUserDao().forTopiaIdEquals(fullId).findUnique(); + } catch (TopiaNoResultException tnre) { + // Should not happened, cause user are not really deleted + String message = String.format("Seems that logged user ('%s') does not exist anymore.", fullId); if (log.isErrorEnabled()) { - log.error("error during File transfer", e); + log.equals(message); } - throw new CoselmarTechnicalException("Internal error during file transfer"); + throw new CoselmarTechnicalException(message); + } + + String documentName = document.getName(); + String contentType = null; + + // If document has a file, manager it ! + if (document.isFile()) { + contentType = managerDocumentFile(uploadFile, owner); + } // Document Metadata Document documentEntity = getDocumentDao().create(); - documentEntity.setName(fileName); + documentEntity.setOwner(owner); + + documentEntity.setName(documentName); documentEntity.setPrivacy(DocumentPrivacy.valueOf(document.getPrivacy().toUpperCase())); documentEntity.addAllKeywords(document.getKeywords()); - documentEntity.setMimeType(contentType); Date depositDate = document.getDepositDate(); if (depositDate != null) { @@ -131,6 +151,26 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { documentEntity.setDepositDate(new Date()); } + documentEntity.setType(document.getType()); + documentEntity.setSummary(document.getSummary()); + documentEntity.setLanguage(document.getLanguage()); + documentEntity.setPublicationDate(document.getPublicationDate()); + + + // Legal / copyright part + documentEntity.setAuthors(document.getAuthors()); + documentEntity.setCopyright(document.getCopyright()); + documentEntity.setLicense(document.getLicense()); + + // Document resource part + if (document.isFile()) { + documentEntity.setIsFile(true); + documentEntity.setMimeType(contentType); + } else { + documentEntity.setIsFile(false); + documentEntity.setExternalUrl(document.getExternalUrl()); + } + commit(); } @@ -184,4 +224,52 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { commit(); } + + //////////////////////////////////////////////////////////////////////////// + /////////////////////// Internal Parts ///////////////////////////// + //////////////////////////////////////////////////////////////////////////// + + /** + * When a Document is sent, it could have a File part : this manage the + * upload file. The file is stored in the user specific directory, and the + * contentType of document is returned, cause need in Document Metadata. + * + * @return the upload file Metadata + */ + protected String managerDocumentFile(UploadFile uploadFile, CoselmarUser owner) { + Preconditions.checkNotNull(uploadFile); + + // Document File + String fileName = uploadFile.getName(); + File uploadedFile = uploadFile.getFile(); + String contentType = uploadFile.getContentType(); + + if (log.isInfoEnabled()) { + String message = String.format("File name : %s, content-type : %s", fileName, contentType); + log.info(message); + } + + // put the document in the good directory + // TODO ymartel 20141105 : with user management, put the document in a user specifique folder + File dataDirectory = getCoselmarServicesConfig().getDataDirectory(); + String absolutePath = dataDirectory.getAbsolutePath(); + String userPath = absolutePath + File.separator + owner.getFirstname() + "-" + owner.getName(); + + Date now = getNow(); + String formattedDay = DateUtil.formatDate(now, "yyyymmdd"); + String prefix = formattedDay + "-"; + + File destFile = new File(userPath + File.separator + prefix + fileName); + try { + FileUtils.moveFile(uploadedFile, destFile); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("error during File transfer", e); + } + throw new CoselmarTechnicalException("Internal error during file transfer"); + } + return contentType; + } + + } 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 ecd02d2..ebb6f42 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 @@ -60,10 +60,10 @@ public class UsersWebService extends CoselmarWebServiceSupport { } // reconstitute full id - String fullId = CoselmarUser.class.getCanonicalName() + "_" + userId; + String fullId = CoselmarUser.class.getCanonicalName() + getPersistenceContext().getTopiaIdFactory().getSeparator() + userId; CoselmarUser user = getCoselmarUserDao().forTopiaIdEquals(fullId).findUnique(); - UserBean userBean = BeanEntityConverter.toBean(user); + UserBean userBean = BeanEntityConverter.toBean(userId, user); return userBean; } @@ -79,7 +79,8 @@ public class UsersWebService extends CoselmarWebServiceSupport { List<UserBean> result = new ArrayList<>(userList.size()); for (CoselmarUser user : userList) { - UserBean userBean = BeanEntityConverter.toBean(user); + String userLightId = getPersistenceContext().getTopiaIdFactory().getRandomPart(user.getTopiaId()); + UserBean userBean = BeanEntityConverter.toBean(userLightId, user); result.add(userBean); } -- 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 develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit 673e11b82b16207ef885f3bbb611391d7cbbf532 Author: Yannick Martel <martel@©odelutin.com> Date: Wed Nov 26 16:53:30 2014 +0100 #6140 add new metadata in document views --- .../src/main/xmi/coselmar-model.zargo | Bin 6487 -> 6490 bytes .../fr/ifremer/coselmar/beans/DocumentBean.java | 18 ++-- .../coselmar/converter/BeanEntityConverter.java | 2 +- .../coselmar/services/v1/DocumentsWebService.java | 36 ++++--- .../src/main/webapp/js/coselmar-controllers.js | 23 +++-- .../src/main/webapp/js/coselmar-services.js | 11 ++- .../src/main/webapp/views/documents/document.html | 34 ++++++- .../src/main/webapp/views/documents/documents.html | 6 +- .../main/webapp/views/documents/newdocument.html | 105 ++++++++++++++++++--- 9 files changed, 187 insertions(+), 48 deletions(-) diff --git a/coselmar-persistence/src/main/xmi/coselmar-model.zargo b/coselmar-persistence/src/main/xmi/coselmar-model.zargo index b07f229..9036e41 100644 Binary files a/coselmar-persistence/src/main/xmi/coselmar-model.zargo and b/coselmar-persistence/src/main/xmi/coselmar-model.zargo differ 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 93528a0..6984fff 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 @@ -51,7 +51,7 @@ public class DocumentBean implements Serializable { protected Date publicationDate; // Document could be internal file or external link - protected boolean isFile; + protected boolean withFile; protected String mimeType; protected String externalUrl; @@ -59,7 +59,7 @@ public class DocumentBean implements Serializable { Date depositDate, Collection<String> keywords, String type, String summary, String language, Date publicationDate, String authors, String license, String copyright, - boolean isFile, String mimeType, String externalUrl) { + boolean withFile, String mimeType, String externalUrl) { this.id = id; this.name = name; this.ownerName = ownerName; @@ -81,11 +81,11 @@ public class DocumentBean implements Serializable { this.license = license; this.copyright = copyright; - if (isFile) { - this.isFile = true; + if (withFile) { + this.withFile = true; this.mimeType = mimeType; } else { - this.isFile = false; + this.withFile = false; this.externalUrl = externalUrl; } } @@ -205,12 +205,12 @@ public class DocumentBean implements Serializable { } } - public boolean isFile() { - return isFile; + public boolean isWithFile() { + return withFile; } - public void setFile(boolean isFile) { - this.isFile = isFile; + public void setWithFile(boolean isFile) { + this.withFile = isFile; } public String getExternalUrl() { diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java index 61be990..bed5346 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/converter/BeanEntityConverter.java @@ -65,7 +65,7 @@ public class BeanEntityConverter { document.getLicense(), document.getCopyright(), - document.isIsFile(), + document.isWithFile(), document.getMimeType(), document.getExternalUrl() ); 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 d4dbb70..e3380b8 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 @@ -39,6 +39,7 @@ import fr.ifremer.coselmar.beans.DocumentBean; 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.DocumentPrivacy; import fr.ifremer.coselmar.services.CoselmarTechnicalException; @@ -46,6 +47,7 @@ import fr.ifremer.coselmar.services.CoselmarWebServiceSupport; import fr.ifremer.coselmar.services.errors.InvalidCredentialException; import fr.ifremer.coselmar.services.errors.UnauthorizedException; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.debux.webmotion.server.call.UploadFile; import org.debux.webmotion.server.render.Render; @@ -61,6 +63,9 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { private static final Log log = getLog(DocumentsWebService.class); + public static final List<String> DOCUMENT_ALLOWED_USER_ROLES = + Lists.newArrayList(CoselmarUserRole.EXPERT.name()); + public DocumentBean getDocument(String documentId) { // reconstitute full id @@ -99,7 +104,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { // Only Expert or Supervisor can add document String userRole = userWebToken.getRole(); - if (!Lists.newArrayList().contains(userRole.toUpperCase())) { + if (!DOCUMENT_ALLOWED_USER_ROLES.contains(userRole.toUpperCase())) { String message = String.format("User %s %s ('%s') is not allowed to add document", userWebToken.getFirstName(), userWebToken.getLastName(), userWebToken.getUserId()); if (log.isWarnEnabled()) { @@ -130,7 +135,8 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { String contentType = null; // If document has a file, manager it ! - if (document.isFile()) { + if (document.isWithFile()) { + documentName = uploadFile.getName(); contentType = managerDocumentFile(uploadFile, owner); } @@ -163,11 +169,11 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { documentEntity.setLicense(document.getLicense()); // Document resource part - if (document.isFile()) { - documentEntity.setIsFile(true); + if (document.isWithFile()) { + documentEntity.setWithFile(true); documentEntity.setMimeType(contentType); } else { - documentEntity.setIsFile(false); + documentEntity.setWithFile(false); documentEntity.setExternalUrl(document.getExternalUrl()); } @@ -186,12 +192,11 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { String fileName = document.getName(); Date depositeDate = document.getDepositDate(); - File dataDirectory = getCoselmarServicesConfig().getDataDirectory(); - String absolutePath = dataDirectory.getAbsolutePath(); + String userDocumentPath = getUserDocumentPath(document.getOwner()); String formatedDay = DateUtil.formatDate(depositeDate, "yyyymmdd"); String prefix = formatedDay + "-"; - File documentFile = new File(absolutePath + "/" + prefix + fileName); + File documentFile = new File(userDocumentPath + "/" + prefix + fileName); String fileMimeType = document.getMimeType(); try { @@ -221,6 +226,9 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { Document document = getDocumentDao().forTopiaIdEquals(fullId).findUnique(); getDocumentDao().delete(document); + //TODO ymartel 20141126 : delete file + + commit(); } @@ -250,10 +258,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { } // put the document in the good directory - // TODO ymartel 20141105 : with user management, put the document in a user specifique folder - File dataDirectory = getCoselmarServicesConfig().getDataDirectory(); - String absolutePath = dataDirectory.getAbsolutePath(); - String userPath = absolutePath + File.separator + owner.getFirstname() + "-" + owner.getName(); + String userPath = getUserDocumentPath(owner); Date now = getNow(); String formattedDay = DateUtil.formatDate(now, "yyyymmdd"); @@ -271,5 +276,12 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { return contentType; } + protected String getUserDocumentPath(CoselmarUser user) { + File dataDirectory = getCoselmarServicesConfig().getDataDirectory(); + String absolutePath = dataDirectory.getAbsolutePath(); + String userFolder = StringUtils.replaceChars(user.getFirstname() + "-" + user.getName(), " ", "_"); + String userPath = absolutePath + File.separator + userFolder; + return userPath; + } } diff --git a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js index e31d174..2be62f7 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-controllers.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-controllers.js @@ -96,22 +96,33 @@ coselmarControllers.controller("DocumentsCtrl", ['$scope', '$route', '$routePara // Controller for new document View -coselmarControllers.controller("NewDocumentCtrl", ['$scope', '$route', 'documentService', function($scope, $route, documentService){ +coselmarControllers.controller("NewDocumentCtrl", ['$scope', '$location', 'documentService', function($scope, $location, documentService){ + + $scope.document = {'privacy': 'PUBLIC'}; + $scope.upload = {}; $scope.createNewDocument = function(){ - var documentMetadata = {'privacy':$scope.privacy, 'keywords':$scope.keywords}; // Call service to create a new document - documentService.createDocument(documentMetadata, $scope.documentFile, $scope); + documentService.createDocument( + $scope.document, $scope.upload.file, function() { + $location.path("/documents"); + + },function(error) { + //TODO ymartel 20141118 : deal with error.status or statusText + console.log("error occurs"); + console.log(error.s); + }); - // Reload the page - $route.reload(); }; }]); // Controller for single document View coselmarControllers.controller("DocumentViewCtrl", - ['$scope', '$route', '$location', 'documentService', '$routeParams', function($scope, $route, $location, documentService, $routeParams) { + ['$scope', '$route', '$location', 'documentService', '$routeParams', 'coselmar-config', + function($scope, $route, $location, documentService, $routeParams, coselmarConfig) { + + $scope.container = {baseUrl : coselmarConfig.BASE_URL}; documentService.getDocument($routeParams.documentId, $scope); diff --git a/coselmar-ui/src/main/webapp/js/coselmar-services.js b/coselmar-ui/src/main/webapp/js/coselmar-services.js index 5b4d262..2d236b3 100644 --- a/coselmar-ui/src/main/webapp/js/coselmar-services.js +++ b/coselmar-ui/src/main/webapp/js/coselmar-services.js @@ -33,11 +33,14 @@ function Document(resource, config){ var baseURL = config.BASE_URL + "/documents"; - this.createDocument = function(metadata, file, scope){ + this.createDocument = function(metadata, file, successFunction, failFunction) { var formData = new FormData(); - formData.append("uploadFile", file); + if (file) { + formData.append("uploadFile", file); + } formData.append("document", JSON.stringify(metadata)); + // Save the document var docResource = resource(baseURL, null, { 'upload': { @@ -48,9 +51,7 @@ function Document(resource, config){ } } }); - docResource.upload(formData, function(response){ - //manage result - }); + docResource.upload(null, formData, successFunction, failFunction); } this.getDocument = function(id, scope){ diff --git a/coselmar-ui/src/main/webapp/views/documents/document.html b/coselmar-ui/src/main/webapp/views/documents/document.html index 44b7690..d40c006 100644 --- a/coselmar-ui/src/main/webapp/views/documents/document.html +++ b/coselmar-ui/src/main/webapp/views/documents/document.html @@ -40,7 +40,7 @@ </tr> <tr> <td>Type</td> - <td>{{document.mimeType}}</td> + <td>{{document.type}}</td> </tr> <tr> <td>Keywords</td> @@ -54,9 +54,39 @@ <td>Deposite Date</td> <td>{{document.depositDate | date:'mediumDate'}}</td> </tr> + <tr> + <td>Summary</td> + <td>{{document.summary}}</td> + </tr> + <tr> + <td>Authors</td> + <td>{{document.authors}}</td> + </tr> + <tr> + <td>Copyright</td> + <td>{{document.copyright}}</td> + </tr> + <tr> + <td>License</td> + <td>{{document.lincese}}</td> + </tr> + <tr> + <td>Language</td> + <td>{{document.language}}</td> + </tr> + <tr> + <td>PublicationDate</td> + <td>{{document.publicationDate | date:'mediumDate'}}</td> + </tr> + <tr> + <td>Document type</td> + <td ng-if="document.withFile">{{document.mimeType}}</td> + <td ng-if="!document.withFile">External Link</td> + </tr> </table> <div style="padding-left: 200px"> - <a href="/v1/documents/{{document.id}}/file" class="btn btn-primary">Download</a> + <a href="{{container.baseUrl}}/documents/{{document.id}}/file" class="btn btn-primary" ng-if="document.withFile">Download</a> + <a href="{{document.externalUrl}}" target="_blank" class="btn btn-primary" ng-if="!document.withFile">Open Link</a> <a class="btn btn-danger" ng-click="deleteDocument(document.id)">Delete</a> </div> </div> diff --git a/coselmar-ui/src/main/webapp/views/documents/documents.html b/coselmar-ui/src/main/webapp/views/documents/documents.html index 9eed5c5..4c089ef 100644 --- a/coselmar-ui/src/main/webapp/views/documents/documents.html +++ b/coselmar-ui/src/main/webapp/views/documents/documents.html @@ -51,14 +51,16 @@ <th>Privacy</th> <th>Keywords</th> <th>Deposit Date</th> + <th>Related Question</th> <th></th> </tr> <tr ng-repeat="document in documents"> <td><a href="#/documents/{{document.id}}">{{document.name}}</a></td> <td>{{document.ownerName}}</td> <td>{{document.privacy}}</td> - <td>{{document.keywords}}</td> - <td>{{document.depositDate}}</td> + <td><span ng-repeat="keyword in document.keywords">{{keyword}} ,</span></td> + <td>{{document.depositDate | date:'mediumDate'}}</td> + <td>N/A</td> <td><a class="btn btn-danger" ng-click="deleteDocument(document.id)">Delete</a></td> </tr> </table> diff --git a/coselmar-ui/src/main/webapp/views/documents/newdocument.html b/coselmar-ui/src/main/webapp/views/documents/newdocument.html index 7465bdb..d619818 100644 --- a/coselmar-ui/src/main/webapp/views/documents/newdocument.html +++ b/coselmar-ui/src/main/webapp/views/documents/newdocument.html @@ -28,7 +28,7 @@ <div style="padding-top: 15px"> <!-- Summary goes here --> - Here you can upload a new document in the repository. For each document, + Here you can add a new document in the repository. For each document, some keywords are needed to make easier search of the document, and you can specify a privacy : <ul> @@ -41,21 +41,56 @@ <div class=""> - <form class="form-horizontal" role="form" ng-submit="createNewDocument()"> + <form class="form-horizontal" name="documentForm" role="form" ng-submit="createNewDocument()"> <div class="form-group"> + <label class="col-md-4 control-label">Name</label> + + <div class="col-md-5"> + <input type="text" class="form-control" name="name" ng-model="document.name" required/> + </div> + </div> + + <div class="form-group"> + <label class="col-md-4 control-label">Type</label> + + <div class="col-md-5"> + <input type="text" class="form-control" name="type" ng-model="document.type" required/> + </div> + </div> + + <div class="form-group"> + <label class="col-md-4 control-label">Attach File ?</label> + + <div class="col-md-5"> + <input type="checkbox" ng-model="document.withFile" ng-init="document.withFile = false" /> + </div> + </div> + + <div class="form-group" ng-if="document.withFile"> <label class="col-md-4 control-label">File</label> <div class="col-md-5"> - <input type="file" class="form-control" name="file" ng-file-model="documentFile" required/> + <input type="file" class="form-control" name="uploadFile" ng-file-model="upload.file" required /> </div> </div> + <div class="form-group" ng-if="!document.withFile"> + <label class="col-md-4 control-label">External URL</label> + + <div class="col-md-5"> + <input type="input" class="form-control" name="externalUrl" + ng-model="document.externalUrl" required /> + </div> + </div> + <div class="form-group"> - <label class="col-md-4 control-label">keyword</label> + <label class="col-md-4 control-label">keywords</label> <div class="col-md-5"> - <input type="text" class="form-control" name="keyword" ng-model="keywords" ng-list required/> + <input type="text" class="form-control" name="keyword" + ng-model="document.keywords" ng-list required + placeholder="keyword 1, keyword2" /> </div> </div> @@ -63,12 +98,12 @@ <label class="col-md-4 control-label">Privacy</label> <div class="col-md-5"> - <select class="form-control" name="privacy" ng-model="privacy"> - <option value="private">private</option> - <option value="public">public</option> - <option value="restricted">restricted</option> + <select class="form-control" name="privacy" ng-model="document.privacy"> + <option value="PRIVATE">private</option> + <option value="PUBLIC">public</option> + <option value="RESTRICTED">restricted</option> </select> - <div ng-if="privacy == 'restricted'"> + <div ng-if="privacy == 'RESTRICTED'"> Not Yet available </div> </div> @@ -76,8 +111,56 @@ </div> <div class="form-group"> + <label class="col-md-4 control-label">Authors</label> + + <div class="col-md-5"> + <input type="text" class="form-control" name="authors" ng-model="document.authors" required/> + </div> + </div> + + <div class="form-group"> + <label class="col-md-4 control-label">Copyright</label> + + <div class="col-md-5"> + <input type="text" class="form-control" name="copyright" ng-model="document.copyright" required/> + </div> + </div> + + <div class="form-group"> + <label class="col-md-4 control-label">Licence</label> + + <div class="col-md-5"> + <input type="text" class="form-control" name="licence" ng-model="document.licence" /> + </div> + </div> + + <div class="form-group"> + <label class="col-md-4 control-label">Language</label> + + <div class="col-md-5"> + <input type="text" class="form-control" name="language" ng-model="document.language" /> + </div> + </div> + + <div class="form-group"> + <label class="col-md-4 control-label">Publication date</label> + + <div class="col-md-5"> + <input type="date" class="form-control" name="publicationDate" ng-model="document.publicationDate" /> + </div> + </div> + + <div class="form-group"> + <label class="col-md-4 control-label">Summary</label> + + <div class="col-md-5"> + <textarea type="text" class="form-control" name="summary" ng-model="document.summary" required /> + </div> + </div> + + <div class="form-group"> <div style="padding-left: 200px"> - <input type="submit" value="Submit" class="btn btn-primary" ng-if="privacy != 'restricted'"/> + <input type="submit" value="Submit" class="btn btn-primary" ng-if="documentForm.$valid && privacy != 'RESTRICTED'"/> </div> </div> </form> -- 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 develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit 3c427089cc3e372a8036f43489eee22f2b79db8a Merge: 166496f 673e11b Author: Yannick Martel <martel@©odelutin.com> Date: Wed Nov 26 16:55:42 2014 +0100 Merge branch 'feature/6140-update-document-metadata' into develop .../src/main/xmi/coselmar-model.properties | 5 +- .../src/main/xmi/coselmar-model.zargo | Bin 6029 -> 6490 bytes .../fr/ifremer/coselmar/beans/DocumentBean.java | 127 +++++++++++++++- .../coselmar/converter/BeanEntityConverter.java | 40 +++-- .../coselmar/services/v1/DocumentsWebService.java | 162 +++++++++++++++++---- .../coselmar/services/v1/UsersWebService.java | 7 +- .../src/main/webapp/js/coselmar-controllers.js | 23 ++- .../src/main/webapp/js/coselmar-services.js | 11 +- .../src/main/webapp/views/documents/document.html | 34 ++++- .../src/main/webapp/views/documents/documents.html | 6 +- .../main/webapp/views/documents/newdocument.html | 105 +++++++++++-- 11 files changed, 447 insertions(+), 73 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm