refactoring for search list
This commit is contained in:
parent
14cfdd6680
commit
a09f088d91
2 changed files with 52 additions and 97 deletions
|
@ -22,7 +22,6 @@ import javax.annotation.Resource;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.service.SearchService;
|
||||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.entity.SearchRenderData;
|
||||
|
@ -113,11 +112,11 @@ public class AdminSearchlistAction extends FessAdminAction {
|
|||
// Search Execute
|
||||
// ==============
|
||||
@Execute
|
||||
public HtmlResponse index(final SearchListForm form) {
|
||||
public HtmlResponse index(final ListForm form) {
|
||||
return asHtml(path_AdminSearchlist_IndexJsp);
|
||||
}
|
||||
|
||||
protected HtmlResponse doSearch(final SearchListForm form) {
|
||||
protected HtmlResponse doSearch(final ListForm form) {
|
||||
|
||||
if (StringUtil.isBlank(form.query)) {
|
||||
// redirect to index page
|
||||
|
@ -129,31 +128,8 @@ public class AdminSearchlistAction extends FessAdminAction {
|
|||
});
|
||||
}
|
||||
|
||||
private void doSearchInternal(final RenderData data, final SearchListForm form) {
|
||||
// init pager
|
||||
if (StringUtil.isBlank(form.start)) {
|
||||
form.start = String.valueOf(Constants.DEFAULT_START_COUNT);
|
||||
} else {
|
||||
try {
|
||||
Long.parseLong(form.start);
|
||||
} catch (final NumberFormatException e) {
|
||||
form.start = String.valueOf(Constants.DEFAULT_START_COUNT);
|
||||
}
|
||||
}
|
||||
if (StringUtil.isBlank(form.num)) {
|
||||
form.num = String.valueOf(Constants.DEFAULT_PAGE_SIZE);
|
||||
} else {
|
||||
try {
|
||||
final int num = Integer.parseInt(form.num);
|
||||
if (num > 100) {
|
||||
// max page size
|
||||
form.num = "100";
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
form.num = String.valueOf(Constants.DEFAULT_PAGE_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
private void doSearchInternal(final RenderData data, final ListForm form) {
|
||||
form.initialize();
|
||||
try {
|
||||
final WebRenderData renderData = new WebRenderData(data);
|
||||
searchService.search(request, form, renderData);
|
||||
|
@ -173,52 +149,35 @@ public class AdminSearchlistAction extends FessAdminAction {
|
|||
}
|
||||
|
||||
@Execute
|
||||
public HtmlResponse search(final SearchListForm form) {
|
||||
public HtmlResponse search(final ListForm form) {
|
||||
return doSearch(form);
|
||||
}
|
||||
|
||||
@Execute
|
||||
public HtmlResponse prev(final SearchListForm form) {
|
||||
public HtmlResponse prev(final ListForm form) {
|
||||
return doMove(form, -1);
|
||||
}
|
||||
|
||||
@Execute
|
||||
public HtmlResponse next(final SearchListForm form) {
|
||||
public HtmlResponse next(final ListForm form) {
|
||||
return doMove(form, 1);
|
||||
}
|
||||
|
||||
@Execute
|
||||
public HtmlResponse move(final SearchListForm form) {
|
||||
public HtmlResponse move(final ListForm form) {
|
||||
return doMove(form, 0);
|
||||
}
|
||||
|
||||
protected HtmlResponse doMove(final SearchListForm form, final int move) {
|
||||
int size = Constants.DEFAULT_PAGE_SIZE;
|
||||
if (StringUtil.isBlank(form.num)) {
|
||||
form.num = String.valueOf(Constants.DEFAULT_PAGE_SIZE);
|
||||
} else {
|
||||
try {
|
||||
size = Integer.parseInt(form.num);
|
||||
} catch (final NumberFormatException e) {
|
||||
form.num = String.valueOf(Constants.DEFAULT_PAGE_SIZE);
|
||||
protected HtmlResponse doMove(final ListForm form, final int move) {
|
||||
form.initialize();
|
||||
Integer pageNumber = form.pn;
|
||||
if (pageNumber != null && pageNumber > 0) {
|
||||
pageNumber = pageNumber + move;
|
||||
if (pageNumber < 1) {
|
||||
pageNumber = 1;
|
||||
}
|
||||
form.start = (pageNumber - 1) * form.num;
|
||||
}
|
||||
|
||||
if (StringUtil.isBlank(form.pn)) {
|
||||
form.start = String.valueOf(Constants.DEFAULT_START_COUNT);
|
||||
} else {
|
||||
Integer pageNumber = Integer.parseInt(form.pn);
|
||||
if (pageNumber != null && pageNumber > 0) {
|
||||
pageNumber = pageNumber + move;
|
||||
if (pageNumber < 1) {
|
||||
pageNumber = 1;
|
||||
}
|
||||
form.start = String.valueOf((pageNumber - 1) * size);
|
||||
} else {
|
||||
form.start = String.valueOf(Constants.DEFAULT_START_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
return doSearch(form);
|
||||
}
|
||||
|
||||
|
@ -226,16 +185,16 @@ public class AdminSearchlistAction extends FessAdminAction {
|
|||
// Confirm
|
||||
// -------
|
||||
@Execute
|
||||
public HtmlResponse confirmDelete(final SearchListForm form) {
|
||||
public HtmlResponse confirmDelete(final ListForm form) {
|
||||
return asHtml(path_AdminSearchlist_ConfirmDeleteJsp);
|
||||
}
|
||||
|
||||
@Execute
|
||||
public HtmlResponse delete(final SearchListForm form) {
|
||||
public HtmlResponse delete(final ListForm form) {
|
||||
return deleteByQuery(form);
|
||||
}
|
||||
|
||||
private HtmlResponse deleteByQuery(final SearchListForm form) {
|
||||
private HtmlResponse deleteByQuery(final ListForm form) {
|
||||
final String docId = form.docId;
|
||||
if (jobHelper.isCrawlProcessRunning()) {
|
||||
// TODO Error
|
||||
|
|
|
@ -19,42 +19,45 @@ import java.io.Serializable;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.codelibs.fess.entity.FacetInfo;
|
||||
import org.codelibs.fess.entity.GeoInfo;
|
||||
import org.codelibs.fess.entity.SearchRequestParams;
|
||||
import org.codelibs.fess.helper.QueryHelper;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.lastaflute.web.validation.Required;
|
||||
import org.lastaflute.web.validation.theme.conversion.ValidateTypeFailure;
|
||||
|
||||
/**
|
||||
* @author codelibs
|
||||
* @author Keiichi Watanabe
|
||||
*/
|
||||
//public class SearchListForm implements Serializable {
|
||||
public class SearchListForm implements SearchRequestParams, Serializable {
|
||||
public class ListForm implements SearchRequestParams, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
//@Maxbytelength(maxbytelength = 1000)
|
||||
@Size(max = 1000)
|
||||
public String query;
|
||||
|
||||
public String sort;
|
||||
|
||||
//@Digits(integer=10, fraction=0)
|
||||
public String start;
|
||||
@ValidateTypeFailure
|
||||
public Integer start;
|
||||
|
||||
//@Digits(integer=10, fraction=0)
|
||||
public String pn;
|
||||
@ValidateTypeFailure
|
||||
public Integer pn;
|
||||
|
||||
//@Digits(integer=10, fraction=0)
|
||||
public String num;
|
||||
@ValidateTypeFailure
|
||||
public Integer num;
|
||||
|
||||
public String[] lang;
|
||||
|
||||
//@Required(target = "confirmDelete,delete")
|
||||
@Required
|
||||
public String docId;
|
||||
|
||||
//@Required(target = "confirmDelete")
|
||||
@Required
|
||||
public String url;
|
||||
|
||||
@Override
|
||||
|
@ -66,7 +69,7 @@ public class SearchListForm implements SearchRequestParams, Serializable {
|
|||
|
||||
public String additional[];
|
||||
|
||||
//@Maxbytelength(maxbytelength = 10)
|
||||
@Size(max = 10)
|
||||
public String op;
|
||||
|
||||
@Override
|
||||
|
@ -101,18 +104,7 @@ public class SearchListForm implements SearchRequestParams, Serializable {
|
|||
if (startPosition != -1) {
|
||||
return startPosition;
|
||||
}
|
||||
|
||||
final QueryHelper queryHelper = ComponentUtil.getQueryHelper();
|
||||
if (StringUtil.isBlank(start)) {
|
||||
startPosition = queryHelper.getDefaultStart();
|
||||
} else {
|
||||
try {
|
||||
startPosition = Integer.parseInt(start);
|
||||
} catch (final NumberFormatException e) {
|
||||
startPosition = queryHelper.getDefaultStart();
|
||||
}
|
||||
}
|
||||
start = String.valueOf(startPosition);
|
||||
startPosition = start;
|
||||
return startPosition;
|
||||
}
|
||||
|
||||
|
@ -121,21 +113,12 @@ public class SearchListForm implements SearchRequestParams, Serializable {
|
|||
if (pageSize != -1) {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
final QueryHelper queryHelper = ComponentUtil.getQueryHelper();
|
||||
if (StringUtil.isBlank(num)) {
|
||||
pageSize = queryHelper.getDefaultPageSize();
|
||||
} else {
|
||||
try {
|
||||
pageSize = Integer.parseInt(num);
|
||||
if (pageSize > queryHelper.getMaxPageSize() || pageSize <= 0) {
|
||||
pageSize = queryHelper.getMaxPageSize();
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
pageSize = queryHelper.getDefaultPageSize();
|
||||
}
|
||||
pageSize = num;
|
||||
if (pageSize > queryHelper.getMaxPageSize() || pageSize <= 0) {
|
||||
pageSize = queryHelper.getMaxPageSize();
|
||||
}
|
||||
num = String.valueOf(pageSize);
|
||||
num = pageSize;
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
|
@ -158,4 +141,17 @@ public class SearchListForm implements SearchRequestParams, Serializable {
|
|||
public String getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
final QueryHelper queryHelper = ComponentUtil.getQueryHelper();
|
||||
if (start == null) {
|
||||
start = queryHelper.getDefaultStart();
|
||||
}
|
||||
if (num == null) {
|
||||
num = queryHelper.getDefaultPageSize();
|
||||
} else if (num > queryHelper.getMaxPageSize()) {
|
||||
num = queryHelper.getMaxPageSize();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue