diff --git a/src/main/java/org/codelibs/fess/entity/BoostDocumentRule.java b/src/main/java/org/codelibs/fess/entity/BoostDocumentRule.java new file mode 100644 index 000000000..454aed322 --- /dev/null +++ b/src/main/java/org/codelibs/fess/entity/BoostDocumentRule.java @@ -0,0 +1,115 @@ +/* + * Copyright 2009-2015 the CodeLibs Project and the Others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +package org.codelibs.fess.entity; + +public class BoostDocumentRule { + + private String id; + + /** URL_EXPR: {NotNull, VARCHAR(4000)} */ + private String urlExpr; + + /** BOOST_EXPR: {NotNull, VARCHAR(4000)} */ + private String boostExpr; + + /** SORT_ORDER: {NotNull, INTEGER(10)} */ + private Integer sortOrder; + + /** CREATED_BY: {NotNull, VARCHAR(255)} */ + private String createdBy; + + private Long createdTime; + + /** UPDATED_BY: {VARCHAR(255)} */ + private String updatedBy; + + private Long updatedTime; + + private Long version; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getUrlExpr() { + return urlExpr; + } + + public void setUrlExpr(String urlExpr) { + this.urlExpr = urlExpr; + } + + public String getBoostExpr() { + return boostExpr; + } + + public void setBoostExpr(String boostExpr) { + this.boostExpr = boostExpr; + } + + public Integer getSortOrder() { + return sortOrder; + } + + public void setSortOrder(Integer sortOrder) { + this.sortOrder = sortOrder; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public Long getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(Long createdTime) { + this.createdTime = createdTime; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public Long getUpdatedTime() { + return updatedTime; + } + + public void setUpdatedTime(Long updatedTime) { + this.updatedTime = updatedTime; + } + + public Long getVersion() { + return version; + } + + public void setVersion(Long version) { + this.version = version; + } +} diff --git a/src/main/java/org/codelibs/fess/service/BoostDocumentRuleService.java b/src/main/java/org/codelibs/fess/service/BoostDocumentRuleService.java index 38dfc0d6c..0322130e5 100644 --- a/src/main/java/org/codelibs/fess/service/BoostDocumentRuleService.java +++ b/src/main/java/org/codelibs/fess/service/BoostDocumentRuleService.java @@ -18,17 +18,23 @@ package org.codelibs.fess.service; import java.io.Serializable; import java.util.List; -import java.util.Map; import javax.annotation.Resource; +import org.codelibs.core.beans.util.BeanUtil; +import org.codelibs.fess.client.FessEsClient; import org.codelibs.fess.crud.CommonConstants; import org.codelibs.fess.crud.CrudMessageException; -import org.codelibs.fess.db.cbean.BoostDocumentRuleCB; -import org.codelibs.fess.db.exbhv.BoostDocumentRuleBhv; -import org.codelibs.fess.db.exentity.BoostDocumentRule; +import org.codelibs.fess.entity.BoostDocumentRule; +import org.codelibs.fess.helper.FieldHelper; import org.codelibs.fess.pager.BoostDocumentRulePager; import org.dbflute.cbean.result.PagingResultBean; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.SearchHits; +import org.elasticsearch.search.sort.SortBuilders; +import org.elasticsearch.search.sort.SortOrder; import org.seasar.framework.beans.util.Beans; public class BoostDocumentRuleService implements Serializable { @@ -36,18 +42,47 @@ public class BoostDocumentRuleService implements Serializable { private static final long serialVersionUID = 1L; @Resource - protected BoostDocumentRuleBhv boostDocumentRuleBhv; + protected FessEsClient fessEsClient; - public BoostDocumentRuleService() { - super(); - } + @Resource + protected FieldHelper fieldHelper; public List getBoostDocumentRuleList(final BoostDocumentRulePager boostDocumentRulePager) { + final PagingResultBean boostDocumentRuleList = + fessEsClient.search(getIndex(), getType(), searchRequestBuilder -> { + if (boostDocumentRulePager.id != null) { + searchRequestBuilder.setQuery(QueryBuilders.idsQuery(getType()).addIds(boostDocumentRulePager.id)); + } + searchRequestBuilder.addSort(SortBuilders.fieldSort("sortOrder").order(SortOrder.ASC)); + searchRequestBuilder.setVersion(true); - final PagingResultBean boostDocumentRuleList = boostDocumentRuleBhv.selectPage(cb -> { - cb.paging(boostDocumentRulePager.getPageSize(), boostDocumentRulePager.getCurrentPageNumber()); - setupListCondition(cb, boostDocumentRulePager); - }); + final int size = boostDocumentRulePager.getPageSize(); + final int pageNum = boostDocumentRulePager.getCurrentPageNumber(); + // TODO modify size/pageNum + searchRequestBuilder.setFrom(size * (pageNum - 1)); + searchRequestBuilder.setSize(size); + return true; + }, (searchRequestBuilder, execTime, searchResponse) -> { + return searchResponse.map(response -> { + final PagingResultBean list = new PagingResultBean<>(); + list.setTableDbName(getType()); + final SearchHits searchHits = response.getHits(); + searchHits.forEach(hit -> { + list.add(createEntity(response, hit)); + }); + list.setAllRecordCount((int) searchHits.totalHits()); + list.setPageSize(boostDocumentRulePager.getPageSize()); + list.setCurrentPageNumber(boostDocumentRulePager.getCurrentPageNumber()); + return list; + }).orElseGet(() -> { + final PagingResultBean emptyList = new PagingResultBean<>(); + emptyList.setTableDbName(getType()); + emptyList.setAllRecordCount(0); + emptyList.setPageSize(boostDocumentRulePager.getPageSize()); + emptyList.setCurrentPageNumber(1); + return emptyList; + }); + }); // update pager Beans.copy(boostDocumentRuleList, boostDocumentRulePager).includes(CommonConstants.PAGER_CONVERSION_RULE).execute(); @@ -58,70 +93,41 @@ public class BoostDocumentRuleService implements Serializable { return boostDocumentRuleList; } - public BoostDocumentRule getBoostDocumentRule(final Map keys) { - final BoostDocumentRule boostDocumentRule = boostDocumentRuleBhv.selectEntity(cb -> { - cb.query().setId_Equal(Long.parseLong(keys.get("id"))); - setupEntityCondition(cb, keys); - }).orElse(null);//TODO - if (boostDocumentRule == null) { - // TODO exception? - return null; - } + public BoostDocumentRule getBoostDocumentRule(final String id) { + return fessEsClient.getDocument(getIndex(), getType(), searchRequestBuilder -> { + searchRequestBuilder.setQuery(QueryBuilders.idsQuery(getType()).addIds(id)); + searchRequestBuilder.setVersion(true); + return true; + }, this::createEntity).get(); + } - return boostDocumentRule; + protected String getType() { + return fieldHelper.boostDocumentRuleType; + } + + protected String getIndex() { + return fieldHelper.configIndex; } public void store(final BoostDocumentRule boostDocumentRule) throws CrudMessageException { - setupStoreCondition(boostDocumentRule); - - boostDocumentRuleBhv.insertOrUpdate(boostDocumentRule); - + fessEsClient.store(getIndex(), getType(), boostDocumentRule); } public void delete(final BoostDocumentRule boostDocumentRule) throws CrudMessageException { - setupDeleteCondition(boostDocumentRule); - - boostDocumentRuleBhv.delete(boostDocumentRule); - - } - - protected void setupListCondition(final BoostDocumentRuleCB cb, final BoostDocumentRulePager boostDocumentRulePager) { - if (boostDocumentRulePager.id != null) { - cb.query().setId_Equal(Long.parseLong(boostDocumentRulePager.id)); - } - // TODO Long, Integer, String supported only. - - // setup condition - cb.query().setDeletedBy_IsNull(); - cb.query().addOrderBy_SortOrder_Asc(); - - // search - - } - - protected void setupEntityCondition(final BoostDocumentRuleCB cb, final Map keys) { - - // setup condition - - } - - protected void setupStoreCondition(final BoostDocumentRule boostDocumentRule) { - - // setup condition - - } - - protected void setupDeleteCondition(final BoostDocumentRule boostDocumentRule) { - - // setup condition - + fessEsClient.delete(getIndex(), getType(), boostDocumentRule.getId(), boostDocumentRule.getVersion()); } public List getAvailableBoostDocumentRuleList() { - return boostDocumentRuleBhv.selectList(cb -> { - cb.query().setDeletedBy_IsNull(); - cb.query().addOrderBy_SortOrder_Asc(); - }); + return fessEsClient.getDocumentList(getIndex(), getType(), searchRequestBuilder -> { + return true; + }, this::createEntity); + } + + protected BoostDocumentRule createEntity(SearchResponse response, SearchHit hit) { + final BoostDocumentRule boostDocumentRule = BeanUtil.copyMapToNewBean(hit.getSource(), BoostDocumentRule.class); + boostDocumentRule.setId(hit.getId()); + boostDocumentRule.setVersion(hit.getVersion()); + return boostDocumentRule; } } diff --git a/src/main/java/org/codelibs/fess/solr/BoostDocumentRule.java b/src/main/java/org/codelibs/fess/solr/BoostDocumentRule.java index 52cf843c8..5a358a295 100644 --- a/src/main/java/org/codelibs/fess/solr/BoostDocumentRule.java +++ b/src/main/java/org/codelibs/fess/solr/BoostDocumentRule.java @@ -33,7 +33,7 @@ public class BoostDocumentRule { // nothing } - public BoostDocumentRule(final org.codelibs.fess.db.exentity.BoostDocumentRule rule) { + public BoostDocumentRule(final org.codelibs.fess.entity.BoostDocumentRule rule) { matchExpression = rule.getUrlExpr(); boostExpression = rule.getBoostExpr(); } diff --git a/src/main/java/org/codelibs/fess/web/admin/BoostDocumentRuleAction.java b/src/main/java/org/codelibs/fess/web/admin/BoostDocumentRuleAction.java index bc61955d6..3632e643e 100644 --- a/src/main/java/org/codelibs/fess/web/admin/BoostDocumentRuleAction.java +++ b/src/main/java/org/codelibs/fess/web/admin/BoostDocumentRuleAction.java @@ -16,10 +16,7 @@ package org.codelibs.fess.web.admin; -import java.time.LocalDateTime; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.annotation.Resource; @@ -27,7 +24,7 @@ import org.codelibs.fess.beans.FessBeans; import org.codelibs.fess.crud.CommonConstants; import org.codelibs.fess.crud.CrudMessageException; import org.codelibs.fess.crud.util.SAStrutsUtil; -import org.codelibs.fess.db.exentity.BoostDocumentRule; +import org.codelibs.fess.entity.BoostDocumentRule; import org.codelibs.fess.helper.SystemHelper; import org.codelibs.fess.pager.BoostDocumentRulePager; import org.codelibs.fess.service.BoostDocumentRuleService; @@ -253,17 +250,9 @@ public class BoostDocumentRuleAction extends FessAdminAction { } } - protected Map createKeyMap() { - final Map keys = new HashMap(); - - keys.put("id", boostDocumentRuleForm.id); - - return keys; - } - protected void loadBoostDocumentRule() { - final BoostDocumentRule boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(createKeyMap()); + final BoostDocumentRule boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(boostDocumentRuleForm.id); if (boostDocumentRule == null) { // throw an exception throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { boostDocumentRuleForm.id }); @@ -275,9 +264,9 @@ public class BoostDocumentRuleAction extends FessAdminAction { protected BoostDocumentRule createBoostDocumentRule() { BoostDocumentRule boostDocumentRule; final String username = systemHelper.getUsername(); - final LocalDateTime currentTime = systemHelper.getCurrentTime(); + final long currentTime = systemHelper.getCurrentTimeAsLong(); if (boostDocumentRuleForm.crudMode == CommonConstants.EDIT_MODE) { - boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(createKeyMap()); + boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(boostDocumentRuleForm.id); if (boostDocumentRule == null) { // throw an exception throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { boostDocumentRuleForm.id }); @@ -302,17 +291,13 @@ public class BoostDocumentRuleAction extends FessAdminAction { } try { - final BoostDocumentRule boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(createKeyMap()); + final BoostDocumentRule boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(boostDocumentRuleForm.id); if (boostDocumentRule == null) { // throw an exception throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { boostDocumentRuleForm.id }); } - final String username = systemHelper.getUsername(); - final LocalDateTime currentTime = systemHelper.getCurrentTime(); - boostDocumentRule.setDeletedBy(username); - boostDocumentRule.setDeletedTime(currentTime); - boostDocumentRuleService.store(boostDocumentRule); + boostDocumentRuleService.delete(boostDocumentRule); SAStrutsUtil.addSessionMessage("success.crud_delete_crud_table"); return displayList(true); diff --git a/src/main/java/org/codelibs/fess/web/admin/BoostDocumentRuleForm.java b/src/main/java/org/codelibs/fess/web/admin/BoostDocumentRuleForm.java index b4241862c..3acebf206 100644 --- a/src/main/java/org/codelibs/fess/web/admin/BoostDocumentRuleForm.java +++ b/src/main/java/org/codelibs/fess/web/admin/BoostDocumentRuleForm.java @@ -41,7 +41,7 @@ public class BoostDocumentRuleForm { } @Required(target = "confirmfromupdate,update,delete") - @LongType + @Maxbytelength(maxbytelength = 200) public String id; @Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete") @@ -62,23 +62,18 @@ public class BoostDocumentRuleForm { public String createdBy; @Required(target = "confirmfromupdate,update,delete") - @DateType(datePattern = Constants.DEFAULT_DATETIME_FORMAT) + @LongType public String createdTime; @Maxbytelength(maxbytelength = 255) public String updatedBy; - @DateType + @LongType public String updatedTime; - public String deletedBy; - - @DateType(datePattern = Constants.DEFAULT_DATETIME_FORMAT) - public String deletedTime; - @Required(target = "confirmfromupdate,update,delete") - @IntegerType - public String versionNo; + @LongType + public String version; public void initialize() { @@ -90,9 +85,7 @@ public class BoostDocumentRuleForm { createdTime = null; updatedBy = null; updatedTime = null; - deletedBy = null; - deletedTime = null; - versionNo = null; + version = null; sortOrder = "0"; } diff --git a/src/main/resources/fess_indices/.fess_config/boost_document_rule.json b/src/main/resources/fess_indices/.fess_config/boost_document_rule.json new file mode 100644 index 000000000..b5c889407 --- /dev/null +++ b/src/main/resources/fess_indices/.fess_config/boost_document_rule.json @@ -0,0 +1,44 @@ +{ + "boost_document_rule": { + "_source": { + "enabled": true + }, + "_all": { + "enabled": false + }, + "_id" : { + "path" : "id" + }, + "properties": { + "id": { + "type": "string", + "index": "not_analyzed" + }, + "urlExpr": { + "type": "string", + "index": "not_analyzed" + }, + "boostExpr": { + "type": "string", + "index": "not_analyzed" + }, + "sortOrder": { + "type": "integer" + }, + "createdBy": { + "type": "string", + "index": "not_analyzed" + }, + "createdTime": { + "type": "long" + }, + "updatedBy": { + "type": "string", + "index": "not_analyzed" + }, + "updatedTime": { + "type": "long" + } + } + } +} diff --git a/src/main/webapp/WEB-INF/view/admin/boostDocumentRule/confirm.jsp b/src/main/webapp/WEB-INF/view/admin/boostDocumentRule/confirm.jsp index 828358fdf..107356deb 100644 --- a/src/main/webapp/WEB-INF/view/admin/boostDocumentRule/confirm.jsp +++ b/src/main/webapp/WEB-INF/view/admin/boostDocumentRule/confirm.jsp @@ -53,7 +53,7 @@
- + diff --git a/src/main/webapp/WEB-INF/view/admin/boostDocumentRule/edit.jsp b/src/main/webapp/WEB-INF/view/admin/boostDocumentRule/edit.jsp index dad9fc559..3d7ae64b7 100644 --- a/src/main/webapp/WEB-INF/view/admin/boostDocumentRule/edit.jsp +++ b/src/main/webapp/WEB-INF/view/admin/boostDocumentRule/edit.jsp @@ -53,7 +53,7 @@
- +