#279 modify BoostDocumentRule
This commit is contained in:
parent
c180c80fa5
commit
f4a4bcf085
9 changed files with 121 additions and 214 deletions
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
|
@ -8,4 +8,20 @@ import org.codelibs.fess.es.bsentity.BsBoostDocumentRule;
|
|||
public class BoostDocumentRule extends BsBoostDocumentRule {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public String getId() {
|
||||
return asDocMeta().id();
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
asDocMeta().id(id);
|
||||
}
|
||||
|
||||
public Long getVersionNo() {
|
||||
return asDocMeta().version();
|
||||
}
|
||||
|
||||
public void setVersionNo(Long version) {
|
||||
asDocMeta().version(version);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.codelibs.core.misc.DynamicProperties;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.db.exentity.FileCrawlingConfig;
|
||||
import org.codelibs.fess.db.exentity.WebCrawlingConfig;
|
||||
import org.codelibs.fess.entity.BoostDocumentRule;
|
||||
import org.codelibs.fess.es.exentity.BoostDocumentRule;
|
||||
import org.codelibs.fess.interval.FessIntervalController;
|
||||
import org.codelibs.fess.service.BoostDocumentRuleService;
|
||||
import org.codelibs.fess.service.FailureUrlService;
|
||||
|
|
|
@ -18,23 +18,17 @@ 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.entity.BoostDocumentRule;
|
||||
import org.codelibs.fess.helper.FieldHelper;
|
||||
import org.codelibs.fess.es.cbean.BoostDocumentRuleCB;
|
||||
import org.codelibs.fess.es.exbhv.BoostDocumentRuleBhv;
|
||||
import org.codelibs.fess.es.exentity.BoostDocumentRule;
|
||||
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 {
|
||||
|
@ -42,47 +36,18 @@ public class BoostDocumentRuleService implements Serializable {
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Resource
|
||||
protected FessEsClient fessEsClient;
|
||||
protected BoostDocumentRuleBhv boostDocumentRuleBhv;
|
||||
|
||||
@Resource
|
||||
protected FieldHelper fieldHelper;
|
||||
public BoostDocumentRuleService() {
|
||||
super();
|
||||
}
|
||||
|
||||
public List<BoostDocumentRule> getBoostDocumentRuleList(final BoostDocumentRulePager boostDocumentRulePager) {
|
||||
final PagingResultBean<BoostDocumentRule> 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 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<BoostDocumentRule> 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<BoostDocumentRule> emptyList = new PagingResultBean<>();
|
||||
emptyList.setTableDbName(getType());
|
||||
emptyList.setAllRecordCount(0);
|
||||
emptyList.setPageSize(boostDocumentRulePager.getPageSize());
|
||||
emptyList.setCurrentPageNumber(1);
|
||||
return emptyList;
|
||||
});
|
||||
});
|
||||
final PagingResultBean<BoostDocumentRule> boostDocumentRuleList = boostDocumentRuleBhv.selectPage(cb -> {
|
||||
cb.paging(boostDocumentRulePager.getPageSize(), boostDocumentRulePager.getCurrentPageNumber());
|
||||
setupListCondition(cb, boostDocumentRulePager);
|
||||
});
|
||||
|
||||
// update pager
|
||||
Beans.copy(boostDocumentRuleList, boostDocumentRulePager).includes(CommonConstants.PAGER_CONVERSION_RULE).execute();
|
||||
|
@ -93,41 +58,72 @@ public class BoostDocumentRuleService implements Serializable {
|
|||
return boostDocumentRuleList;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
public BoostDocumentRule getBoostDocumentRule(final Map<String, String> keys) {
|
||||
final BoostDocumentRule boostDocumentRule = boostDocumentRuleBhv.selectEntity(cb -> {
|
||||
cb.query().docMeta().setId_Equal(keys.get("id"));
|
||||
setupEntityCondition(cb, keys);
|
||||
}).orElse(null);//TODO
|
||||
if (boostDocumentRule == null) {
|
||||
// TODO exception?
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String getType() {
|
||||
return fieldHelper.boostDocumentRuleType;
|
||||
}
|
||||
|
||||
protected String getIndex() {
|
||||
return fieldHelper.configIndex;
|
||||
}
|
||||
|
||||
public void store(final BoostDocumentRule boostDocumentRule) throws CrudMessageException {
|
||||
fessEsClient.store(getIndex(), getType(), boostDocumentRule);
|
||||
}
|
||||
|
||||
public void delete(final BoostDocumentRule boostDocumentRule) throws CrudMessageException {
|
||||
fessEsClient.delete(getIndex(), getType(), boostDocumentRule.getId(), boostDocumentRule.getVersion());
|
||||
}
|
||||
|
||||
public List<BoostDocumentRule> getAvailableBoostDocumentRuleList() {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
public void store(final BoostDocumentRule boostDocumentRule) throws CrudMessageException {
|
||||
setupStoreCondition(boostDocumentRule);
|
||||
|
||||
boostDocumentRuleBhv.insertOrUpdate(boostDocumentRule, op -> {
|
||||
op.setRefresh(true);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void delete(final BoostDocumentRule boostDocumentRule) throws CrudMessageException {
|
||||
setupDeleteCondition(boostDocumentRule);
|
||||
|
||||
boostDocumentRuleBhv.delete(boostDocumentRule, op -> {
|
||||
op.setRefresh(true);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected void setupListCondition(final BoostDocumentRuleCB cb, final BoostDocumentRulePager boostDocumentRulePager) {
|
||||
if (boostDocumentRulePager.id != null) {
|
||||
cb.query().docMeta().setId_Equal(boostDocumentRulePager.id);
|
||||
}
|
||||
// TODO Long, Integer, String supported only.
|
||||
|
||||
// setup condition
|
||||
cb.query().addOrderBy_SortOrder_Asc();
|
||||
|
||||
// search
|
||||
|
||||
}
|
||||
|
||||
protected void setupEntityCondition(final BoostDocumentRuleCB cb, final Map<String, String> keys) {
|
||||
|
||||
// setup condition
|
||||
|
||||
}
|
||||
|
||||
protected void setupStoreCondition(final BoostDocumentRule boostDocumentRule) {
|
||||
|
||||
// setup condition
|
||||
|
||||
}
|
||||
|
||||
protected void setupDeleteCondition(final BoostDocumentRule boostDocumentRule) {
|
||||
|
||||
// setup condition
|
||||
|
||||
}
|
||||
|
||||
public List<BoostDocumentRule> getAvailableBoostDocumentRuleList() {
|
||||
return boostDocumentRuleBhv.selectList(cb -> {
|
||||
cb.query().addOrderBy_SortOrder_Asc();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -33,7 +33,7 @@ public class BoostDocumentRule {
|
|||
// nothing
|
||||
}
|
||||
|
||||
public BoostDocumentRule(final org.codelibs.fess.entity.BoostDocumentRule rule) {
|
||||
public BoostDocumentRule(final org.codelibs.fess.es.exentity.BoostDocumentRule rule) {
|
||||
matchExpression = rule.getUrlExpr();
|
||||
boostExpression = rule.getBoostExpr();
|
||||
}
|
||||
|
|
|
@ -16,7 +16,10 @@
|
|||
|
||||
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;
|
||||
|
||||
|
@ -24,7 +27,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.entity.BoostDocumentRule;
|
||||
import org.codelibs.fess.es.exentity.BoostDocumentRule;
|
||||
import org.codelibs.fess.helper.SystemHelper;
|
||||
import org.codelibs.fess.pager.BoostDocumentRulePager;
|
||||
import org.codelibs.fess.service.BoostDocumentRuleService;
|
||||
|
@ -250,9 +253,17 @@ public class BoostDocumentRuleAction extends FessAdminAction {
|
|||
}
|
||||
}
|
||||
|
||||
protected Map<String, String> createKeyMap() {
|
||||
final Map<String, String> keys = new HashMap<String, String>();
|
||||
|
||||
keys.put("id", boostDocumentRuleForm.id);
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
protected void loadBoostDocumentRule() {
|
||||
|
||||
final BoostDocumentRule boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(boostDocumentRuleForm.id);
|
||||
final BoostDocumentRule boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(createKeyMap());
|
||||
if (boostDocumentRule == null) {
|
||||
// throw an exception
|
||||
throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { boostDocumentRuleForm.id });
|
||||
|
@ -266,7 +277,7 @@ public class BoostDocumentRuleAction extends FessAdminAction {
|
|||
final String username = systemHelper.getUsername();
|
||||
final long currentTime = systemHelper.getCurrentTimeAsLong();
|
||||
if (boostDocumentRuleForm.crudMode == CommonConstants.EDIT_MODE) {
|
||||
boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(boostDocumentRuleForm.id);
|
||||
boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(createKeyMap());
|
||||
if (boostDocumentRule == null) {
|
||||
// throw an exception
|
||||
throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { boostDocumentRuleForm.id });
|
||||
|
@ -291,7 +302,7 @@ public class BoostDocumentRuleAction extends FessAdminAction {
|
|||
}
|
||||
|
||||
try {
|
||||
final BoostDocumentRule boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(boostDocumentRuleForm.id);
|
||||
final BoostDocumentRule boostDocumentRule = boostDocumentRuleService.getBoostDocumentRule(createKeyMap());
|
||||
if (boostDocumentRule == null) {
|
||||
// throw an exception
|
||||
throw new SSCActionMessagesException("errors.crud_could_not_find_crud_table", new Object[] { boostDocumentRuleForm.id });
|
||||
|
@ -312,4 +323,4 @@ public class BoostDocumentRuleAction extends FessAdminAction {
|
|||
throw new SSCActionMessagesException(e, "errors.crud_failed_to_delete_crud_table");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,8 +19,7 @@ package org.codelibs.fess.web.admin;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.seasar.struts.annotation.DateType;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.seasar.struts.annotation.IntRange;
|
||||
import org.seasar.struts.annotation.IntegerType;
|
||||
import org.seasar.struts.annotation.LongType;
|
||||
|
@ -41,7 +40,7 @@ public class BoostDocumentRuleForm {
|
|||
}
|
||||
|
||||
@Required(target = "confirmfromupdate,update,delete")
|
||||
@Maxbytelength(maxbytelength = 200)
|
||||
@Maxbytelength(maxbytelength = 1000)
|
||||
public String id;
|
||||
|
||||
@Required(target = "confirmfromcreate,create,confirmfromupdate,update,delete")
|
||||
|
@ -72,8 +71,8 @@ public class BoostDocumentRuleForm {
|
|||
public String updatedTime;
|
||||
|
||||
@Required(target = "confirmfromupdate,update,delete")
|
||||
@LongType
|
||||
public String version;
|
||||
@IntegerType
|
||||
public String versionNo;
|
||||
|
||||
public void initialize() {
|
||||
|
||||
|
@ -81,13 +80,13 @@ public class BoostDocumentRuleForm {
|
|||
urlExpr = null;
|
||||
boostExpr = null;
|
||||
sortOrder = null;
|
||||
createdBy = null;
|
||||
createdTime = null;
|
||||
createdBy = "system";
|
||||
createdTime = Long.toString(ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
|
||||
updatedBy = null;
|
||||
updatedTime = null;
|
||||
version = null;
|
||||
versionNo = null;
|
||||
|
||||
sortOrder = "0";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -53,7 +53,7 @@
|
|||
<div>
|
||||
<c:if test="${crudMode==2 || crudMode==3 || crudMode==4}">
|
||||
<html:hidden property="id" />
|
||||
<html:hidden property="version" />
|
||||
<html:hidden property="versionNo" />
|
||||
</c:if>
|
||||
<html:hidden property="createdBy" />
|
||||
<html:hidden property="createdTime" />
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
<div>
|
||||
<c:if test="${crudMode==2}">
|
||||
<html:hidden property="id" />
|
||||
<html:hidden property="version" />
|
||||
<html:hidden property="versionNo" />
|
||||
</c:if>
|
||||
<html:hidden property="createdBy" />
|
||||
<html:hidden property="createdTime" />
|
||||
|
|
Loading…
Add table
Reference in a new issue