pathMapping
This commit is contained in:
parent
acbfc80e07
commit
b52fb0a7e6
3 changed files with 214 additions and 88 deletions
115
src/main/java/org/codelibs/fess/entity/PathMapping.java
Normal file
115
src/main/java/org/codelibs/fess/entity/PathMapping.java
Normal file
|
@ -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 PathMapping {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -78,4 +78,6 @@ public class FieldHelper {
|
|||
|
||||
public String boostDocumentRuleType = "boost_document_rule";
|
||||
|
||||
public String pathMappingType = "path_mapping";
|
||||
|
||||
}
|
||||
|
|
|
@ -17,116 +17,125 @@
|
|||
package org.codelibs.fess.service;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
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.allcommon.CDef;
|
||||
import org.codelibs.fess.db.cbean.PathMappingCB;
|
||||
import org.codelibs.fess.db.exbhv.PathMappingBhv;
|
||||
import org.codelibs.fess.db.exentity.PathMapping;
|
||||
import org.codelibs.fess.entity.PathMapping;
|
||||
import org.codelibs.fess.helper.FieldHelper;
|
||||
import org.codelibs.fess.pager.PathMappingPager;
|
||||
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 PathMappingService implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Resource
|
||||
protected PathMappingBhv pathMappingBhv;
|
||||
@Resource
|
||||
protected FessEsClient fessEsClient;
|
||||
|
||||
public PathMappingService() {
|
||||
super();
|
||||
}
|
||||
@Resource
|
||||
protected FieldHelper fieldHelper;
|
||||
|
||||
public List<PathMapping> getPathMappingList(final PathMappingPager pathMappingPager) {
|
||||
public List<PathMapping> getPathMappingList(final PathMappingPager pathMappingPager) {
|
||||
|
||||
final PagingResultBean<PathMapping> pathMappingList = pathMappingBhv.selectPage(cb -> {
|
||||
cb.paging(pathMappingPager.getPageSize(), pathMappingPager.getCurrentPageNumber());
|
||||
setupListCondition(cb, pathMappingPager);
|
||||
});
|
||||
final PagingResultBean<PathMapping> pathMappingList =
|
||||
fessEsClient.search(getIndex(),getType(),searchRequestBuilder -> {
|
||||
if (pathMappingPager.id != null) {
|
||||
searchRequestBuilder.setQuery(QueryBuilders.idsQuery(getType()).addIds(pathMappingPager.id));
|
||||
}
|
||||
searchRequestBuilder.addSort(SortBuilders.fieldSort("sortOrder").order(SortOrder.ASC));
|
||||
searchRequestBuilder.setVersion(true);
|
||||
|
||||
// update pager
|
||||
Beans.copy(pathMappingList, pathMappingPager).includes(CommonConstants.PAGER_CONVERSION_RULE).execute();
|
||||
pathMappingPager.setPageNumberList(pathMappingList.pageRange(op -> {
|
||||
op.rangeSize(5);
|
||||
}).createPageNumberList());
|
||||
final int size = pathMappingPager.getPageSize();
|
||||
final int pageNum = pathMappingPager.getCurrentPageNumber();
|
||||
// TODO modify size/pageNum
|
||||
searchRequestBuilder.setFrom(size * (pageNum - 1));
|
||||
searchRequestBuilder.setSize(size);
|
||||
return true;
|
||||
}, (searchRequestBuilder, execTime, searchResponse) -> {
|
||||
return searchResponse.map(response -> {
|
||||
final PagingResultBean<PathMapping> 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(pathMappingPager.getPageSize());
|
||||
list.setCurrentPageNumber(pathMappingPager.getCurrentPageNumber());
|
||||
return list;
|
||||
}).orElseGet(() -> {
|
||||
final PagingResultBean<PathMapping> emptyList = new PagingResultBean<>();
|
||||
emptyList.setTableDbName(getType());
|
||||
emptyList.setAllRecordCount(0);
|
||||
emptyList.setPageSize(pathMappingPager.getPageSize());
|
||||
emptyList.setCurrentPageNumber(1);
|
||||
return emptyList;
|
||||
});
|
||||
});
|
||||
|
||||
return pathMappingList;
|
||||
}
|
||||
// update pager
|
||||
Beans.copy(pathMappingList, pathMappingPager).includes(CommonConstants.PAGER_CONVERSION_RULE).execute();
|
||||
pathMappingPager.setPageNumberList(pathMappingList.pageRange(op -> {
|
||||
op.rangeSize(5);
|
||||
}).createPageNumberList());
|
||||
|
||||
public PathMapping getPathMapping(final Map<String, String> keys) {
|
||||
final PathMapping pathMapping = pathMappingBhv.selectEntity(cb -> {
|
||||
cb.query().setId_Equal(Long.parseLong(keys.get("id")));
|
||||
setupEntityCondition(cb, keys);
|
||||
}).orElse(null);//TODO
|
||||
if (pathMapping == null) {
|
||||
// TODO exception?
|
||||
return null;
|
||||
}
|
||||
return pathMappingList;
|
||||
}
|
||||
|
||||
public PathMapping getPathMapping(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 pathMapping;
|
||||
}
|
||||
protected String getType() {
|
||||
return fieldHelper.pathMappingType;
|
||||
}
|
||||
|
||||
protected String getIndex() {
|
||||
return fieldHelper.configIndex;
|
||||
}
|
||||
|
||||
public void store(final PathMapping pathMapping) throws CrudMessageException {
|
||||
fessEsClient.store(getIndex(), getType(), pathMapping);
|
||||
}
|
||||
|
||||
public void delete(final PathMapping pathMapping) throws CrudMessageException {
|
||||
fessEsClient.delete(getIndex(), getType(), pathMapping.getId(), pathMapping.getVersion());
|
||||
}
|
||||
|
||||
public List<PathMapping> getAvailablePathMappingList() {
|
||||
return fessEsClient.getDocumentList(getIndex(), getType(), searchRequestBuilder -> {
|
||||
return true;
|
||||
}, this::createEntity);
|
||||
}
|
||||
|
||||
public void store(final PathMapping pathMapping) throws CrudMessageException {
|
||||
setupStoreCondition(pathMapping);
|
||||
protected void setupDeleteCondition(final PathMapping pathMapping) {
|
||||
|
||||
pathMappingBhv.insertOrUpdate(pathMapping);
|
||||
// setup condition
|
||||
|
||||
}
|
||||
|
||||
public void delete(final PathMapping pathMapping) throws CrudMessageException {
|
||||
setupDeleteCondition(pathMapping);
|
||||
|
||||
pathMappingBhv.delete(pathMapping);
|
||||
|
||||
}
|
||||
|
||||
public List<PathMapping> getPathMappingList(final Collection<CDef.ProcessType> cdefList) {
|
||||
|
||||
return pathMappingBhv.selectList(cb -> {
|
||||
cb.query().setDeletedBy_IsNull();
|
||||
cb.query().addOrderBy_SortOrder_Asc();
|
||||
cb.query().setProcessType_InScope_AsProcessType(cdefList);
|
||||
});
|
||||
}
|
||||
|
||||
protected void setupListCondition(final PathMappingCB cb, final PathMappingPager pathMappingPager) {
|
||||
if (pathMappingPager.id != null) {
|
||||
cb.query().setId_Equal(Long.parseLong(pathMappingPager.id));
|
||||
}
|
||||
// TODO Long, Integer, String supported only.
|
||||
|
||||
// setup condition
|
||||
cb.query().setDeletedBy_IsNull();
|
||||
cb.query().addOrderBy_SortOrder_Asc();
|
||||
|
||||
// search
|
||||
|
||||
}
|
||||
|
||||
protected void setupEntityCondition(final PathMappingCB cb, final Map<String, String> keys) {
|
||||
|
||||
// setup condition
|
||||
cb.query().setDeletedBy_IsNull();
|
||||
|
||||
}
|
||||
|
||||
protected void setupStoreCondition(final PathMapping pathMapping) {
|
||||
|
||||
// setup condition
|
||||
|
||||
}
|
||||
|
||||
protected void setupDeleteCondition(final PathMapping pathMapping) {
|
||||
|
||||
// setup condition
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected PathMapping createEntity(SearchResponse response, SearchHit hit) {
|
||||
final PathMapping pathMapping = BeanUtil.copyMapToNewBean(hit.getSource(), PathMapping.class);
|
||||
pathMapping.setId(hit.getId());
|
||||
pathMapping.setVersion(hit.getVersion());
|
||||
return pathMapping;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue