This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See https://gitlab.nuiton.org/codelutin/coselmar.git commit 68243fa5ec7d031009d7d0ec8c194bd0a75e0fce Author: Yannick Martel <martel@©odelutin.com> Date: Thu Jun 15 14:39:51 2017 +0200 Some code quality --- .../coselmar/beans/DocumentSearchExample.java | 32 ++++++++++++++++------ .../coselmar/beans/QuestionSearchExample.java | 32 ++++++++++++++++------ .../persistence/entity/QuestionTopiaDao.java | 12 ++++---- .../coselmar/converter/BeanEntityConverter.java | 2 +- .../coselmar/services/CoselmarRestUtil.java | 2 +- .../services/CoselmarWebServiceSupport.java | 9 ++++++ .../services/DefaultCoselmarServicesContext.java | 2 +- .../indexation/DocumentsIndexationService.java | 27 ++++++++---------- .../coselmar/services/indexation/LuceneUtils.java | 7 ++--- .../indexation/QuestionsIndexationService.java | 22 +++++++-------- .../coselmar/services/indexation/TikaUtils.java | 14 ++++++---- .../indexation/TransverseIndexationService.java | 20 +++++++++----- .../coselmar/services/v1/DocumentsWebService.java | 22 +++++++-------- .../coselmar/services/v1/GeneralWebService.java | 2 +- .../coselmar/services/v1/QuestionsWebService.java | 22 +++++++-------- .../coselmar/services/v1/UsersWebService.java | 4 +-- 16 files changed, 138 insertions(+), 93 deletions(-) diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchExample.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchExample.java index 1e9860b..c313314 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchExample.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/DocumentSearchExample.java @@ -55,35 +55,51 @@ public class DocumentSearchExample extends SearchExample<Document> { protected boolean orderDesc; public Date getPublicationAfterDate() { - return publicationAfterDate; + return publicationAfterDate != null ? new Date(publicationAfterDate.getTime()): null; } public void setPublicationAfterDate(Date publicationAfterDate) { - this.publicationAfterDate = publicationAfterDate; + if (publicationAfterDate != null) { + this.publicationAfterDate = new Date(publicationAfterDate.getTime()); + } else { + this.publicationAfterDate = null; + } } public Date getPublicationBeforeDate() { - return publicationBeforeDate; + return publicationBeforeDate != null ? new Date(publicationBeforeDate.getTime()) : null; } public void setPublicationBeforeDate(Date publicationBeforeDate) { - this.publicationBeforeDate = publicationBeforeDate; + if (publicationBeforeDate != null) { + this.publicationBeforeDate = new Date(publicationBeforeDate.getTime()); + } else { + this.publicationBeforeDate = null; + } } public Date getDepositAfterDate() { - return depositAfterDate; + return depositAfterDate != null ? new Date(depositAfterDate.getTime()) : null; } public void setDepositAfterDate(Date depositAfterDate) { - this.depositAfterDate = depositAfterDate; + if (depositAfterDate != null) { + this.depositAfterDate = new Date(depositAfterDate.getTime()); + } else { + this.depositAfterDate = null; + } } public Date getDepositBeforeDate() { - return depositBeforeDate; + return depositBeforeDate != null ? new Date(depositBeforeDate.getTime()) : null; } public void setDepositBeforeDate(Date depositBeforeDate) { - this.depositBeforeDate = depositBeforeDate; + if (depositBeforeDate != null) { + this.depositBeforeDate = new Date(depositBeforeDate.getTime()); + } else { + this.depositBeforeDate = null; + } } public String getOwnerName() { diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/QuestionSearchExample.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/QuestionSearchExample.java index 5ff9672..dc22e83 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/QuestionSearchExample.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/beans/QuestionSearchExample.java @@ -60,35 +60,51 @@ public class QuestionSearchExample extends SearchExample<Question> { protected CoselmarUser participant; public Date getSubmissionAfterDate() { - return submissionAfterDate; + return submissionAfterDate != null ? new Date(submissionAfterDate.getTime()) : null; } public void setSubmissionAfterDate(Date submissionAfterDate) { - this.submissionAfterDate = submissionAfterDate; + if (submissionAfterDate != null) { + this.submissionAfterDate = new Date(submissionAfterDate.getTime()); + } else { + this.submissionAfterDate = null; + } } public Date getSubmissionBeforeDate() { - return submissionBeforeDate; + return submissionBeforeDate != null ? new Date(submissionBeforeDate.getTime()) : null; } public void setSubmissionBeforeDate(Date submissionBeforeDate) { - this.submissionBeforeDate = submissionBeforeDate; + if (submissionBeforeDate != null) { + this.submissionBeforeDate = new Date(submissionBeforeDate.getTime()); + } else { + this.submissionBeforeDate = null; + } } public Date getDeadlineAfterDate() { - return deadlineAfterDate; + return deadlineAfterDate != null ? new Date(deadlineAfterDate.getTime()) : null; } public void setDeadlineAfterDate(Date deadlineAfterDate) { - this.deadlineAfterDate = deadlineAfterDate; + if (deadlineAfterDate != null) { + this.deadlineAfterDate = new Date(deadlineAfterDate.getTime()); + } else { + this.deadlineAfterDate = null; + } } public Date getDeadlineBeforeDate() { - return deadlineBeforeDate; + return deadlineBeforeDate != null ? new Date(deadlineBeforeDate.getTime()) : null; } public void setDeadlineBeforeDate(Date deadlineBeforeDate) { - this.deadlineBeforeDate = deadlineBeforeDate; + if (deadlineBeforeDate != null) { + this.deadlineBeforeDate = new Date(deadlineBeforeDate.getTime()); + } else { + this.deadlineBeforeDate = null; + } } @Override diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java index 4b6d4ac..37738b4 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/QuestionTopiaDao.java @@ -48,28 +48,28 @@ public class QuestionTopiaDao extends AbstractQuestionTopiaDao<Question> { public PaginationResult<Question> findForExpert(CoselmarUser expert, QuestionSearchExample questionSearchExample, PaginationParameter page) { - StringBuilder hqlWithoutSelectBuilder = new StringBuilder(" FROM " + Question.class.getName() + " Q " - + " INNER JOIN Q." + Question.PROPERTY_PARTICIPANTS + " CUG "); + StringBuilder hqlWithoutSelectBuilder = new StringBuilder(" FROM ").append(Question.class.getName()).append(" Q ") + .append(" INNER JOIN Q.").append(Question.PROPERTY_PARTICIPANTS).append(" CUG "); Map<String, Object> args = new HashMap<>(); String publicCondition = DaoUtils.getQueryForAttributeEquals("Q", Question.PROPERTY_PRIVACY, args, Privacy.PUBLIC, ""); - hqlWithoutSelectBuilder.append(" WHERE ( (" + publicCondition + " ) "); + hqlWithoutSelectBuilder.append(" WHERE ( (").append(publicCondition).append(" ) "); String privateCondition = DaoUtils.getQueryForAttributeEquals("Q", Question.PROPERTY_PRIVACY, args, Privacy.PRIVATE, ""); - hqlWithoutSelectBuilder.append(" OR (" + privateCondition); + hqlWithoutSelectBuilder.append(" OR (").append(privateCondition); String participantCondition = DaoUtils.andAttributeContains("CUG", CoselmarUserGroup.PROPERTY_MEMBERS, args, expert); hqlWithoutSelectBuilder.append(participantCondition); String clientCondition = DaoUtils.andAttributeContains("Q", Question.PROPERTY_CLIENTS, args, expert); - hqlWithoutSelectBuilder.append(clientCondition + ") )"); + hqlWithoutSelectBuilder.append(clientCondition).append(") )"); String finerHql = refineSearch(questionSearchExample, "Q", args); - hqlWithoutSelectBuilder.append(" AND (" + finerHql + ")" ); + hqlWithoutSelectBuilder.append(" AND (").append(finerHql).append(")" ); StringBuilder hqlBuilder = new StringBuilder("SELECT Q ").append(hqlWithoutSelectBuilder); 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 b470a39..bba3e64 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 @@ -54,7 +54,7 @@ import java.util.Set; /** * @author ymartel <martel@codelutin.com> */ -public class BeanEntityConverter { +public final class BeanEntityConverter { private BeanEntityConverter() { throw new IllegalAccessError("Utility class"); diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarRestUtil.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarRestUtil.java index 152ed50..005fc6e 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarRestUtil.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/CoselmarRestUtil.java @@ -32,7 +32,7 @@ import javax.servlet.http.HttpServletResponse; /** * @author ymartel <martel@codelutin.com> */ -public class CoselmarRestUtil { +public final class CoselmarRestUtil { public static final String HEADER_ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers"; 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 a63266a..8bbcf8c 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 @@ -58,6 +58,7 @@ import java.util.Map; public abstract class CoselmarWebServiceSupport extends WebMotionController implements CoselmarService { private static final Log log = LogFactory.getLog(CoselmarWebServiceSupport.class); + protected static final String AUTHORIZATION_HEADER = "Authorization"; private CoselmarServicesContext servicesContext; @@ -140,6 +141,14 @@ public abstract class CoselmarWebServiceSupport extends WebMotionController impl } /** + * Just get the Authorization header from context + * @return + */ + protected String getAuthorizationHeader() { + return getContext().getHeader(AUTHORIZATION_HEADER); + } + + /** * Check the authorization code. * Get the token from the authorization and reconstitute JWT user token. * diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/DefaultCoselmarServicesContext.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/DefaultCoselmarServicesContext.java index 70faf28..0924ffb 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/DefaultCoselmarServicesContext.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/DefaultCoselmarServicesContext.java @@ -200,7 +200,7 @@ public class DefaultCoselmarServicesContext implements CoselmarServicesContext { if (log.isErrorEnabled()) { log.error(errorMessage, e); } - throw new CoselmarTechnicalException(errorMessage); + throw new CoselmarTechnicalException(errorMessage, e); } return generatedPassword; diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/DocumentsIndexationService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/DocumentsIndexationService.java index ba46886..d3c914b 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/DocumentsIndexationService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/DocumentsIndexationService.java @@ -78,8 +78,7 @@ public class DocumentsIndexationService extends CoselmarSimpleServiceSupport { protected static final String DOCUMENT_NAME_CLOUD_TAG_PROPERTY = "documentCloudTagName"; protected static final String DOCUMENT_KEYWORD_CLOUD_TAG_PROPERTY = "documentCloudTagKeyword"; protected static final String DOCUMENT_FILE_CONTENT_INDEX_PROPERTY = "documentFileContent"; - protected static final String DOCUMENT_TYPE = "documentindextype"; - protected static final int MAGICAL_SEARCH_SIZE = 1000; + protected static final String INDEXATION_DOCUMENT_TYPE = "documentindextype"; public void indexDocument(DocumentBean document, String fileContent) throws IOException { @@ -94,7 +93,7 @@ public class DocumentsIndexationService extends CoselmarSimpleServiceSupport { doc.add(new TextField(DOCUMENT_AUTHORS_INDEX_PROPERTY, document.getAuthors(), Field.Store.YES)); } doc.add(new Field(DOCUMENT_SUMMARY_INDEX_PROPERTY, documentSummary, LuceneUtils.TYPE_STORED)); - doc.add(new Field("type", DOCUMENT_TYPE, TextField.TYPE_STORED)); + doc.add(new Field(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE, TextField.TYPE_STORED)); // Cloud Tag management if (documentName.length() >= CloudWordUtils.CLOUD_TAG_WORD_MIN_SIZE) { @@ -158,9 +157,9 @@ public class DocumentsIndexationService extends CoselmarSimpleServiceSupport { // Combine that with the type BooleanQuery.Builder fullQueryBuilder = new BooleanQuery.Builder(); fullQueryBuilder.add(queryBuilder.build(), BooleanClause.Occur.MUST); - fullQueryBuilder.add(new TermQuery(new Term("type", DOCUMENT_TYPE)), BooleanClause.Occur.MUST); + fullQueryBuilder.add(new TermQuery(new Term(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.MUST); - ScoreDoc[] hits = isearcher.search(fullQueryBuilder.build(), MAGICAL_SEARCH_SIZE).scoreDocs; + ScoreDoc[] hits = isearcher.search(fullQueryBuilder.build(), TransverseIndexationService.MAGICAL_SEARCH_SIZE).scoreDocs; List<String> documentIds = new ArrayList(hits.length); @@ -215,9 +214,9 @@ public class DocumentsIndexationService extends CoselmarSimpleServiceSupport { BooleanQuery.Builder fullQueryBuilder = new BooleanQuery.Builder(); fullQueryBuilder.add(keywordsQueryBuilder.build(), BooleanClause.Occur.MUST); - fullQueryBuilder.add(new TermQuery(new Term("type", DOCUMENT_TYPE)), BooleanClause.Occur.MUST); + fullQueryBuilder.add(new TermQuery(new Term(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.MUST); - ScoreDoc[] hits = isearcher.search(fullQueryBuilder.build(), MAGICAL_SEARCH_SIZE).scoreDocs; + ScoreDoc[] hits = isearcher.search(fullQueryBuilder.build(), TransverseIndexationService.MAGICAL_SEARCH_SIZE).scoreDocs; List<String> documentIds = new ArrayList(hits.length); @@ -238,9 +237,9 @@ public class DocumentsIndexationService extends CoselmarSimpleServiceSupport { // Retrieve document BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); queryBuilder.add(new TermQuery(new Term(DOCUMENT_ID_INDEX_PROPERTY, document.getId())), BooleanClause.Occur.MUST); - queryBuilder.add(new TermQuery(new Term("type", DOCUMENT_TYPE)), BooleanClause.Occur.MUST); + queryBuilder.add(new TermQuery(new Term(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.MUST); - ScoreDoc[] hits = isearcher.search(queryBuilder.build(), MAGICAL_SEARCH_SIZE).scoreDocs; + ScoreDoc[] hits = isearcher.search(queryBuilder.build(), TransverseIndexationService.MAGICAL_SEARCH_SIZE).scoreDocs; if (hits.length > 0) { Document doc = new Document(); doc.add(new StringField(DOCUMENT_ID_INDEX_PROPERTY, document.getId(), Field.Store.YES)); @@ -273,7 +272,7 @@ public class DocumentsIndexationService extends CoselmarSimpleServiceSupport { } } - doc.add(new Field("type", DOCUMENT_TYPE, TextField.TYPE_STORED)); + doc.add(new Field(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE, TextField.TYPE_STORED)); if (StringUtils.isNotBlank(fileContent)) { doc.add(new Field(DOCUMENT_FILE_CONTENT_INDEX_PROPERTY, fileContent, LuceneUtils.TYPE_STORED)); @@ -291,7 +290,7 @@ public class DocumentsIndexationService extends CoselmarSimpleServiceSupport { // Retrieve document BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); queryBuilder.add(new TermQuery(new Term(DOCUMENT_ID_INDEX_PROPERTY, documentId)), BooleanClause.Occur.MUST); - queryBuilder.add(new TermQuery(new Term("type", DOCUMENT_TYPE)), BooleanClause.Occur.MUST); + queryBuilder.add(new TermQuery(new Term(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.MUST); getLuceneUtils().getIndexWriter().deleteDocuments(queryBuilder.build()); getLuceneUtils().getIndexWriter().commit(); @@ -300,9 +299,7 @@ public class DocumentsIndexationService extends CoselmarSimpleServiceSupport { public void cleanIndex() throws IOException { BooleanQuery query = new BooleanQuery.Builder() - .add(new TermQuery(new Term("type", DOCUMENT_TYPE)), BooleanClause.Occur.MUST) - //XXX ymartel 20151215 : Clean older DOCUMENT_TYPE value too (less or equals V1.0.1), should be removed after V2.0 - .add(new TermQuery(new Term("type", "document")), BooleanClause.Occur.SHOULD) + .add(new TermQuery(new Term(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.MUST) .build(); getLuceneUtils().getIndexWriter().deleteDocuments(query); getLuceneUtils().getIndexWriter().commit(); @@ -316,7 +313,7 @@ public class DocumentsIndexationService extends CoselmarSimpleServiceSupport { // Combine that with the type BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); - queryBuilder.add(new TermQuery(new Term("type", DOCUMENT_TYPE)), BooleanClause.Occur.MUST); + queryBuilder.add(new TermQuery(new Term(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.MUST); BooleanQuery.Builder questionIdBuilder = new BooleanQuery.Builder(); for (String documentId : documentIds) { diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/LuceneUtils.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/LuceneUtils.java index 0c537c6..7910246 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/LuceneUtils.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/LuceneUtils.java @@ -48,10 +48,9 @@ public class LuceneUtils { private static final Log log = LogFactory.getLog(LuceneUtils.class); - public Analyzer analyzer; - public final IndexWriterConfig indexationConfig = new IndexWriterConfig(getAnalyzer()); - public IndexWriter indexWriter; - protected Tika tika; + protected Analyzer analyzer; + protected final IndexWriterConfig indexationConfig = new IndexWriterConfig(getAnalyzer()); + protected IndexWriter indexWriter; public static final FieldType TYPE_STORED = new FieldType(); static { diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java index 1528f37..028fe33 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/QuestionsIndexationService.java @@ -83,7 +83,7 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { protected static final String QUESTION_TITLE_CLOUD_TAG_PROPERTY = "questionCloudTagTitle"; protected static final String QUESTION_SUMMARY_CLOUD_TAG_PROPERTY = "questionCloudTagSummary"; protected static final String QUESTION_THEME_CLOUD_TAG_PROPERTY = "questionCloudTagTheme"; - protected static final String DOCUMENT_TYPE = "questionindextype"; + protected static final String INDEXATION_DOCUMENT_TYPE = "questionindextype"; public void indexQuestion(QuestionBean question) throws IOException { @@ -94,10 +94,10 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { // Retrieve document BooleanQuery query = new BooleanQuery.Builder() .add(new TermQuery(new Term(QUESTION_ID_INDEX_PROPERTY, question.getId())), BooleanClause.Occur.MUST) - .add(new TermQuery(new Term("type", DOCUMENT_TYPE)), BooleanClause.Occur.MUST) + .add(new TermQuery(new Term(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.MUST) .build(); - ScoreDoc[] hits = isearcher.search(query, 1000).scoreDocs; + ScoreDoc[] hits = isearcher.search(query, TransverseIndexationService.MAGICAL_SEARCH_SIZE).scoreDocs; String questionTitle = question.getTitle(); String questionSummary = question.getSummary(); if (hits.length > 0) { @@ -132,7 +132,7 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { doc.add(new TextField(QUESTION_PRIVACY_INDEX_PROPERTY, question.getPrivacy(), Field.Store.YES)); - doc.add(new Field("type", DOCUMENT_TYPE, TextField.TYPE_STORED)); + doc.add(new Field(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE, TextField.TYPE_STORED)); getLuceneUtils().getIndexWriter().updateDocument(new Term(QUESTION_ID_INDEX_PROPERTY, question.getId()), doc); @@ -168,7 +168,7 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { } } - doc.add(new Field("type", DOCUMENT_TYPE, TextField.TYPE_STORED)); + doc.add(new Field(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE, TextField.TYPE_STORED)); getLuceneUtils().getIndexWriter().addDocument(doc); @@ -186,7 +186,7 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { // Combine that with the type BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); - queryBuilder.add(new TermQuery(new Term("type", DOCUMENT_TYPE)), BooleanClause.Occur.MUST); + queryBuilder.add(new TermQuery(new Term(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.MUST); String searchPrivacy = searchBean.getPrivacy(); if(StringUtils.isNotBlank(searchPrivacy)) { @@ -237,7 +237,7 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { } BooleanQuery fullQuery = queryBuilder.build(); - ScoreDoc[] hits = isearcher.search(fullQuery, 1000).scoreDocs; + ScoreDoc[] hits = isearcher.search(fullQuery, TransverseIndexationService.MAGICAL_SEARCH_SIZE).scoreDocs; List<String> documentIds = new ArrayList(hits.length); @@ -256,7 +256,7 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { // Retrieve document BooleanQuery query = new BooleanQuery.Builder() .add(new TermQuery(new Term(QUESTION_ID_INDEX_PROPERTY, documentId)), BooleanClause.Occur.MUST) - .add(new TermQuery(new Term("type", DOCUMENT_TYPE)), BooleanClause.Occur.MUST) + .add(new TermQuery(new Term(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.MUST) .build(); getLuceneUtils().getIndexWriter().deleteDocuments(query); @@ -266,9 +266,7 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { protected void cleanIndex() throws IOException { BooleanQuery query = new BooleanQuery.Builder() - .add(new TermQuery(new Term("type", DOCUMENT_TYPE)), BooleanClause.Occur.SHOULD) - //XXX ymartel 20151215 : Clean older DOCUMENT_TYPE value too (less or equals V1.0.1), should be removed after V2.0 - .add(new TermQuery(new Term("type", "question")), BooleanClause.Occur.SHOULD) + .add(new TermQuery(new Term(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.SHOULD) .build(); getLuceneUtils().getIndexWriter().deleteDocuments(query); getLuceneUtils().getIndexWriter().commit(); @@ -308,7 +306,7 @@ public class QuestionsIndexationService extends CoselmarSimpleServiceSupport { // Combine that with the type BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); - queryBuilder.add(new TermQuery(new Term("type", DOCUMENT_TYPE)), BooleanClause.Occur.MUST); + queryBuilder.add(new TermQuery(new Term(TransverseIndexationService.INDEXATION_FIELD_TYPE, INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.MUST); BooleanQuery.Builder questionIdBuilder = new BooleanQuery.Builder(); for (String questionId : questionIds) { diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TikaUtils.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TikaUtils.java index c88f143..be5ee7b 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TikaUtils.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TikaUtils.java @@ -38,7 +38,7 @@ import java.util.List; /** * @author ymartel (martel@codelutin.com) */ -public class TikaUtils { +public final class TikaUtils { private static final Log log = LogFactory.getLog(TikaUtils.class); @@ -53,16 +53,20 @@ public class TikaUtils { "text/html" ); - private static final Tika tika = new Tika(); + private static final Tika TIKA = new Tika(); + + private TikaUtils() { + throw new IllegalAccessError("Utility class"); + } public static String getFileContent(String filePath) { String fileContent = ""; File file = new File(filePath); try { - String mimeType = tika.detect(file); + String mimeType = TIKA.detect(file); // Can we read it ? if (StringUtils.isNotBlank(mimeType) && READABLE_TEXT_MIMETYPES.contains(mimeType.toLowerCase())) { - fileContent = tika.parseToString(file); + fileContent = TIKA.parseToString(file); } } catch (IOException e) { if (log.isErrorEnabled()) { @@ -77,7 +81,7 @@ public class TikaUtils { } public static String getFileMimeType(String filePath) { - String mimeType = tika.detect(filePath); + String mimeType = TIKA.detect(filePath); return mimeType; } } diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TransverseIndexationService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TransverseIndexationService.java index b3dac78..e196056 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TransverseIndexationService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/indexation/TransverseIndexationService.java @@ -28,6 +28,8 @@ import fr.ifremer.coselmar.beans.QuestionBean; import fr.ifremer.coselmar.config.CloudWordUtils; import fr.ifremer.coselmar.services.CoselmarSimpleServiceSupport; import fr.ifremer.coselmar.services.StringLongMapValueComparator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.Term; import org.apache.lucene.misc.HighFreqTerms; @@ -57,13 +59,15 @@ import java.util.TreeMap; */ public class TransverseIndexationService extends CoselmarSimpleServiceSupport { + private static final Log log = LogFactory.getLog(TransverseIndexationService.class); + + public static final int MAGICAL_SEARCH_SIZE = 1000; + public static final String INDEXATION_FIELD_TYPE = "type"; + protected void cleanAllIndex() throws IOException { BooleanQuery query = new BooleanQuery.Builder() - .add(new TermQuery(new Term("type", QuestionsIndexationService.DOCUMENT_TYPE)), BooleanClause.Occur.SHOULD) - .add(new TermQuery(new Term("type", DocumentsIndexationService.DOCUMENT_TYPE)), BooleanClause.Occur.SHOULD) - //XXX ymartel 20151215 : Clean older DOCUMENT_TYPE value too (less or equals V1.0.1), should be removed after V2.0 - .add(new TermQuery(new Term("type", "question")), BooleanClause.Occur.SHOULD) - .add(new TermQuery(new Term("type", "document")), BooleanClause.Occur.SHOULD) + .add(new TermQuery(new Term(INDEXATION_FIELD_TYPE, QuestionsIndexationService.INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.SHOULD) + .add(new TermQuery(new Term(INDEXATION_FIELD_TYPE, DocumentsIndexationService.INDEXATION_DOCUMENT_TYPE)), BooleanClause.Occur.SHOULD) .build(); getLuceneUtils().getIndexWriter().deleteDocuments(query); getLuceneUtils().getIndexWriter().commit(); @@ -82,7 +86,7 @@ public class TransverseIndexationService extends CoselmarSimpleServiceSupport { DocumentsIndexationService.DOCUMENT_KEYWORD_CLOUD_TAG_PROPERTY, DocumentsIndexationService.DOCUMENT_FILE_CONTENT_INDEX_PROPERTY, }; - TermStats[] highFreqTerms = HighFreqTermsMultiFields.getHighFreqTermsMultiFields(indexReader, 60, searchedFields, new HighFreqTerms.TotalTermFreqComparator()); + TermStats[] highFreqTerms = HighFreqTermsMultiFields.getHighFreqTermsMultiFields(indexReader, MAGICAL_SEARCH_SIZE, searchedFields, new HighFreqTerms.TotalTermFreqComparator()); for (TermStats termStats : highFreqTerms) { long totalTermFreq = termStats.totalTermFreq; @@ -99,7 +103,9 @@ public class TransverseIndexationService extends CoselmarSimpleServiceSupport { } } catch (Exception e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Erreur during topWords search", e); + } } indexReader.close(); 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 46c6237..bac184f 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 @@ -111,7 +111,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { public DocumentBean getDocument(String documentId) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); // reconstitute full id @@ -176,7 +176,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { public PaginationResult<DocumentBean> getPaginatedDocuments(DocumentSearchBean searchBean) throws InvalidCredentialException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); CoselmarUserRole currentUserRole = currentUser.getRole(); @@ -273,7 +273,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { public List<String> getSearchBibliography(DocumentSearchBean searchBean) throws InvalidCredentialException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); CoselmarUserRole currentUserRole = currentUser.getRole(); @@ -355,7 +355,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { public DocumentBean addDocument(DocumentBean document, UploadFile uploadFile) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); UserWebToken userWebToken = checkAuthentication(authorization); // Only Expert or Supervisor can add document @@ -381,7 +381,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { // 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(message); + log.error(message, tnre); } throw new InvalidCredentialException(message); } @@ -405,7 +405,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { Preconditions.checkNotNull(uploadFile); // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); String documentFullId = getFullIdFromShort(Document.class, documentId); @@ -487,7 +487,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { } catch (FileNotFoundException e) { if (log.isErrorEnabled()) { String message = String.format("Unable to retrieve file %s", fileName); - log.error(message); + log.error(message, e); } throw new NoResultException("File does not exist"); } @@ -499,7 +499,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { Preconditions.checkNotNull(document.getId()); // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); String documentId = getDocumentFullId(document.getId()); @@ -627,7 +627,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { public void deleteDocument(String documentId) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); // reconstitute full id @@ -688,7 +688,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { Preconditions.checkNotNull(uploadFile); // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); // Only Supervisor/Admin can add Zip documents @@ -846,7 +846,7 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { if (log.isErrorEnabled()) { log.error("error during File transfer", e); } - throw new CoselmarTechnicalException("Internal error during file transfer"); + throw new CoselmarTechnicalException("Internal error during file transfer", e); } FileInfos fileInfos = new FileInfos(); diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/GeneralWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/GeneralWebService.java index 090c15b..cb9bb07 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/GeneralWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/GeneralWebService.java @@ -58,8 +58,8 @@ public class GeneralWebService extends CoselmarWebServiceSupport { } catch (IOException|ParseException e) { if (log.isErrorEnabled()) { log.error("Unable to search by lucene, make search directly in database", e); - throw new CoselmarTechnicalException("Unable to get most frequecy words"); } + throw new CoselmarTechnicalException("Unable to get most frequecy words", e); } List<CloudWord> cloudWords = new ArrayList<>(topTerms.size()); 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 55ecfe4..8597f5a 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 @@ -95,7 +95,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { public void addQuestion(QuestionBean question) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); UserWebToken userWebToken = checkAuthentication(authorization); // Only Supervisor can add question @@ -278,7 +278,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { public List<QuestionBean> getQuestions(QuestionSearchBean searchOption) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); List<Question> questionList; @@ -298,7 +298,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { public PaginationResult<QuestionBean> getPaginatedQuestions(QuestionSearchBean searchOption) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); PaginationResult<Question> paginatedQuestions; @@ -347,7 +347,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { public void deleteQuestion(String questionId) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); UserWebToken userWebToken = checkAuthentication(authorization); // Only Supervisor can delete question @@ -417,7 +417,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { public QuestionBean getQuestion(String questionId) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); // Supervisor can get all the question elements @@ -488,7 +488,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { public void addDocuments(String questionId, DocumentBean[] documents) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); UserWebToken userWebToken = checkAuthentication(authorization); // Only Supervisor can add documents @@ -551,7 +551,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { public void saveQuestion(QuestionBean question) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser supervisor = checkUserAuthentication(authorization); // Only Supervisor can save question @@ -946,7 +946,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { public List<QuestionTreeNode> getAncestors(String questionId, int depth) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); // Supervisor can get all the question elements @@ -987,7 +987,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { public List<QuestionTreeNode> getDescendants(String questionId, int depth) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); // Supervisor can get all the question elements @@ -1028,7 +1028,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { public List<QuestionBean> getUserQuestions(String userId, QuestionUserRole userRole) throws InvalidCredentialException, UnauthorizedException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); CoselmarUser currentUser = checkUserAuthentication(authorization); // Member cannot access to list of questions @@ -1072,7 +1072,7 @@ public class QuestionsWebService extends CoselmarWebServiceSupport { public List<CloudWord> getTopWords(String questionId) throws InvalidCredentialException, UnauthorizedException, NoResultException { // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); checkUserAuthentication(authorization); // Retrieve Question 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 5d1613d..7732715 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 @@ -195,7 +195,7 @@ public class UsersWebService extends CoselmarWebServiceSupport { Preconditions.checkNotNull(user); // Check authentication - String authorization = getContext().getHeader("Authorization"); + String authorization = getAuthorizationHeader(); UserWebToken userWebToken = checkAuthentication(authorization); // Who is allowed here ? Admin and Superviseur @@ -487,7 +487,7 @@ public class UsersWebService extends CoselmarWebServiceSupport { if (log.isErrorEnabled()) { log.error("Error during export", e); } - throw new CoselmarTechnicalException("Unable to export datas"); + throw new CoselmarTechnicalException("Unable to export datas", e); } return renderDownload(IOUtils.toInputStream(exportData), "export-users-result.csv", "text/csv"); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.