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 989a41533a830efb8a61817a3609650ffbb96ccd Author: Yannick Martel <martel@©odelutin.com> Date: Mon Dec 7 18:22:18 2015 +0100 refs-40 #7648 First draft for projects export --- coselmar-rest/pom.xml | 4 ++ .../fr/ifremer/coselmar/beans/QuestionBean.java | 10 ++++ .../coselmar/beans/QuestionExportModel.java | 55 ++++++++++++++++++++++ .../coselmar/services/v1/QuestionsWebService.java | 28 +++++++++++ coselmar-rest/src/main/resources/mapping | 6 ++- pom.xml | 5 ++ 6 files changed, 107 insertions(+), 1 deletion(-) diff --git a/coselmar-rest/pom.xml b/coselmar-rest/pom.xml index bd084cb..c9bcc0a 100644 --- a/coselmar-rest/pom.xml +++ b/coselmar-rest/pom.xml @@ -98,6 +98,10 @@ <artifactId>nuiton-utils</artifactId> </dependency> <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-csv</artifactId> + </dependency> + <dependency> <groupId>org.nuiton.i18n</groupId> <artifactId>nuiton-i18n</artifactId> </dependency> diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionBean.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionBean.java index 18ccc77..98d84b6 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionBean.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionBean.java @@ -33,12 +33,18 @@ public class QuestionBean implements Serializable { protected String id; + + public static final String PROPERTY_TITLE = "title"; protected String title; + public static final String PROPERTY_SUBMISSION_DATE = "submissionDate"; protected Date submissionDate; + + public static final String PROPERTY_DEADLINE = "deadline"; protected Date deadline; + public static final String PROPERTY_THEMES = "themes"; protected Set<String> themes; protected String summary; @@ -47,12 +53,14 @@ public class QuestionBean implements Serializable { protected String type; + public static final String PROPERTY_PARTICIPANTS = "participants"; protected Set<UserBean> participants; protected Set<UserBean> supervisors; protected Set<UserBean> contributors; + public static final String PROPERTY_CLIENTS = "clients"; protected Set<UserBean> clients; protected Set<QuestionBean> parents; @@ -60,8 +68,10 @@ public class QuestionBean implements Serializable { protected String privacy; + public static final String PROPERTY_RELATED_DOCUMENTS = "relatedDocuments"; protected Set<DocumentBean> relatedDocuments; + public static final String PROPERTY_STATUS = "status"; protected String status; protected Set<String> externalExperts; diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionExportModel.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionExportModel.java new file mode 100644 index 0000000..7b986e8 --- /dev/null +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/beans/QuestionExportModel.java @@ -0,0 +1,55 @@ +package fr.ifremer.coselmar.beans; + +import com.google.common.base.Joiner; +import fr.ifremer.coselmar.persistence.entity.Question; +import fr.ifremer.coselmar.persistence.entity.Status; +import org.nuiton.csv.Common; +import org.nuiton.csv.ExportModel; +import org.nuiton.csv.ExportableColumn; +import org.nuiton.csv.ValueFormatter; +import org.nuiton.csv.ext.AbstractExportModel; +import org.nuiton.util.DateUtil; + +import java.util.List; + +import static org.nuiton.i18n.I18n.t; + +/** + * @author ymartel (martel@codelutin.com) + */ +public class QuestionExportModel extends AbstractExportModel<QuestionBean> { + + protected static final ValueFormatter<List<String>> LIST_STRING_FORMATTER = new ValueFormatter<List<String>>() { + @Override + public String format(List<String> value) { + return Joiner.on(",").join(value); + } + }; + + protected static final ValueFormatter<List<Object>> LIST_COUNTER_VALUE_FORMATTER = new ValueFormatter<List<Object>>() { + @Override + public String format(List<Object> value) { + String result = "0"; + if (value != null) { + result = String.valueOf(value.size()); + } + return result; + } + }; + + protected static final Common.DateValue dateFormatter = new Common.DateValue(DateUtil.DEFAULT_PATTERN); + + public QuestionExportModel() { + super(';'); + + modelBuilder.newColumnForExport(t("question.metadata.title"), QuestionBean.PROPERTY_TITLE); + modelBuilder.newColumnForExport(t("question.metadata.submissionDate"), QuestionBean.PROPERTY_SUBMISSION_DATE, dateFormatter); + modelBuilder.newColumnForExport(t("question.metadata.status"), QuestionBean.PROPERTY_STATUS, new Common.EnumByNameParserFormatter(Status.class)); + modelBuilder.newColumnForExport(t("question.metadata.themes"), QuestionBean.PROPERTY_THEMES, LIST_STRING_FORMATTER); + modelBuilder.newColumnForExport(t("question.metadata.deadline"), QuestionBean.PROPERTY_DEADLINE, dateFormatter); + modelBuilder.newColumnForExport(t("question.metadata.participants"), QuestionBean.PROPERTY_PARTICIPANTS, LIST_COUNTER_VALUE_FORMATTER); + modelBuilder.newColumnForExport(t("question.metadata.clients"), QuestionBean.PROPERTY_CLIENTS, LIST_COUNTER_VALUE_FORMATTER); + modelBuilder.newColumnForExport(t("question.metadata.relatedDocuments"), QuestionBean.PROPERTY_RELATED_DOCUMENTS, LIST_COUNTER_VALUE_FORMATTER); + } + +} 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 64d3488..e5106aa 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 @@ -25,6 +25,9 @@ package fr.ifremer.coselmar.services.v1; */ import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.io.Writer; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -38,10 +41,12 @@ import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import fr.ifremer.coselmar.beans.DocumentBean; import fr.ifremer.coselmar.beans.QuestionBean; +import fr.ifremer.coselmar.beans.QuestionExportModel; import fr.ifremer.coselmar.beans.QuestionSearchBean; import fr.ifremer.coselmar.beans.UserBean; import fr.ifremer.coselmar.beans.UserWebToken; import fr.ifremer.coselmar.converter.BeanEntityConverter; +import fr.ifremer.coselmar.exceptions.CoselmarTechnicalException; import fr.ifremer.coselmar.persistence.entity.CoselmarUser; import fr.ifremer.coselmar.persistence.entity.CoselmarUserGroup; import fr.ifremer.coselmar.persistence.entity.CoselmarUserRole; @@ -53,14 +58,20 @@ import fr.ifremer.coselmar.services.CoselmarWebServiceSupport; import fr.ifremer.coselmar.services.errors.InvalidCredentialException; import fr.ifremer.coselmar.services.errors.UnauthorizedException; import fr.ifremer.coselmar.services.indexation.QuestionsIndexationService; +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.output.WriterOutputStream; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.lucene.queryparser.classic.ParseException; +import org.debux.webmotion.server.render.Render; +import org.nuiton.csv.Export; import org.nuiton.topia.persistence.TopiaIdFactory; import org.nuiton.topia.persistence.TopiaNoResultException; import org.nuiton.util.pagination.PaginationParameter; +import javax.activation.MimeType; + /** * @author ymartel <martel@codelutin.com> */ @@ -816,6 +827,23 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { return types; } + public Render exportQuestions(QuestionSearchBean searchOption) throws InvalidCredentialException, UnauthorizedException { + + List<QuestionBean> questions = getQuestions(searchOption); + + QuestionExportModel exportModel = new QuestionExportModel(); + + String exportData; + try { + exportData = Export.exportToString(exportModel, questions); + } catch (Exception e) { + throw new CoselmarTechnicalException("Unable to export datas"); + } + + return renderDownload(IOUtils.toInputStream(exportData), "export-projects", "text/csv"); + + } + //////////////////////////////////////////////////////////////////////////// /////////////////////// Internal Parts ///////////////////////////// diff --git a/coselmar-rest/src/main/resources/mapping b/coselmar-rest/src/main/resources/mapping index b933d17..e31d444 100644 --- a/coselmar-rest/src/main/resources/mapping +++ b/coselmar-rest/src/main/resources/mapping @@ -65,4 +65,8 @@ POST /v1/questions QuestionsWebService.addQuestion DELETE /v1/questions/{questionId} QuestionsWebService.deleteQuestion # Admin API -POST /v1/admin/lucene/index AdminWebService.refreshLuceneIndex \ No newline at end of file +POST /v1/admin/lucene/index AdminWebService.refreshLuceneIndex + +# Export + +GET /v1/export/questions QuestionsWebService.exportQuestions \ No newline at end of file diff --git a/pom.xml b/pom.xml index 611b532..99aef73 100644 --- a/pom.xml +++ b/pom.xml @@ -221,6 +221,11 @@ </dependency> <dependency> <groupId>org.nuiton</groupId> + <artifactId>nuiton-csv</artifactId> + <version>${nuitonCsvVersion}</version> + </dependency> + <dependency> + <groupId>org.nuiton</groupId> <artifactId>nuiton-decorator</artifactId> <version>${nuitonDecoratorVersion}</version> </dependency> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.