diff --git a/pom.xml b/pom.xml index 35f0978e0..04da8997d 100644 --- a/pom.xml +++ b/pom.xml @@ -89,19 +89,12 @@ UTF-8 - org/codelibs/fess/app/web/admin/WizardAction.java org/codelibs/fess/app/web/admin/dict/UserDictForm.java org/codelibs/fess/app/web/admin/dict/SynonymForm.java org/codelibs/fess/app/web/admin/dict/UserDictAction.java org/codelibs/fess/app/web/admin/dict/SynonymAction.java - org/codelibs/fess/app/web/admin/DocumentAction.java org/codelibs/fess/app/web/admin/DictForm.java - org/codelibs/fess/app/web/admin/DocumentForm.java - org/codelibs/fess/app/web/admin/DataForm.java - org/codelibs/fess/app/web/admin/IndexAction.java org/codelibs/fess/app/web/admin/DictAction.java - org/codelibs/fess/app/web/admin/DataAction.java - org/codelibs/fess/app/web/admin/WizardForm.java diff --git a/src/main/java/org/codelibs/fess/app/web/admin/AdminAction.java b/src/main/java/org/codelibs/fess/app/web/admin/AdminAction.java new file mode 100644 index 000000000..e3280d0c4 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/admin/AdminAction.java @@ -0,0 +1,42 @@ +/* + * 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.app.web.admin; + +import org.codelibs.fess.app.web.admin.wizard.AdminWizardAction; +import org.codelibs.fess.app.web.base.FessAdminAction; +import org.lastaflute.web.Execute; +import org.lastaflute.web.response.HtmlResponse; + +public class AdminAction extends FessAdminAction { + + // =================================================================================== + // Constant + // + + // =================================================================================== + // Attribute + // + + // =================================================================================== + // Search Execute + // ============== + @Execute + public HtmlResponse index() { + return redirect(AdminWizardAction.class); + } + +} \ No newline at end of file diff --git a/src/main/java/org/codelibs/fess/app/web/admin/DataAction.java b/src/main/java/org/codelibs/fess/app/web/admin/DataAction.java deleted file mode 100644 index 9708b8ed3..000000000 --- a/src/main/java/org/codelibs/fess/app/web/admin/DataAction.java +++ /dev/null @@ -1,181 +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.app.web.admin; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.Serializable; -import java.io.Writer; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.io.IOUtils; -import org.codelibs.core.CoreLibConstants; -import org.codelibs.core.io.CopyUtil; -import org.codelibs.core.misc.DynamicProperties; -import org.codelibs.fess.Constants; -import org.codelibs.fess.FessSystemException; -import org.codelibs.fess.crud.util.SAStrutsUtil; -import org.codelibs.fess.exception.SSCActionMessagesException; -import org.codelibs.fess.helper.SystemHelper; -import org.codelibs.fess.app.service.CrawlingSessionService; -import org.lastaflute.web.util.LaResponseUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DataAction implements Serializable { - - private static final long serialVersionUID = 1L; - - private static final Logger logger = LoggerFactory.getLogger(DataAction.class); - - @Resource - //@ActionForm - protected DataForm dataForm; - - @Resource - protected CrawlingSessionService crawlingSessionService; - - @Resource - protected DynamicProperties crawlerProperties; - - @Resource - protected SystemHelper systemHelper; - - public String getHelpLink() { - return systemHelper.getHelpLink("data"); - } - - //@Execute(validator = false) - public String index() { - // set a default value - dataForm.overwrite = "on"; - return "index.jsp"; - } - - //@Execute(validator = false) - public String downloadCrawlingSession() { - final DateFormat df = new SimpleDateFormat(CoreLibConstants.DATE_FORMAT_DIGIT_ONLY); - final StringBuilder buf = new StringBuilder(); - buf.append("backup-cs-"); - buf.append(df.format(new Date())); - buf.append(".csv"); - - final HttpServletResponse response = LaResponseUtil.getResponse(); - response.setContentType("application/octet-stream"); - response.setHeader("Content-Disposition", "attachment; filename=\"" + buf.toString() + "\""); - - Writer writer = null; - try { - writer = - new BufferedWriter(new OutputStreamWriter(response.getOutputStream(), crawlerProperties.getProperty( - Constants.CSV_FILE_ENCODING_PROPERTY, Constants.UTF_8))); - crawlingSessionService.exportCsv(writer); - writer.flush(); - return null; - } catch (final Exception e) { - logger.error("Failed to export data.", e); - throw new SSCActionMessagesException(e, "errors.failed_to_export_data"); - } finally { - IOUtils.closeQuietly(writer); - } - } - - //@Execute(validator = true, input = "index") - public String upload() { - final String fileName = dataForm.uploadedFile.getFileName(); - if (fileName.endsWith(".csv")) { - BufferedInputStream is = null; - File tempFile = null; - FileOutputStream fos = null; - final byte[] b = new byte[20]; - try { - tempFile = File.createTempFile("fess-import-", ".csv"); - is = new BufferedInputStream(dataForm.uploadedFile.getInputStream()); - is.mark(20); - if (is.read(b, 0, 20) <= 0) { - throw new FessSystemException("no import data."); - } - is.reset(); - fos = new FileOutputStream(tempFile); - CopyUtil.copy(is, fos); - } catch (final Exception e) { - if (tempFile != null && !tempFile.delete()) { - logger.warn("Could not delete " + tempFile.getAbsolutePath()); - } - logger.error("Failed to import data.", e); - throw new SSCActionMessagesException(e, "errors.failed_to_import_data"); - } finally { - IOUtils.closeQuietly(is); - IOUtils.closeQuietly(fos); - } - - final File oFile = tempFile; - try { - final String head = new String(b, Constants.UTF_8); - if (!head.startsWith("SessionId,")) { - logger.error("Unknown file: " + dataForm.uploadedFile); - throw new SSCActionMessagesException("errors.unknown_import_file"); - } - final String enc = crawlerProperties.getProperty(Constants.CSV_FILE_ENCODING_PROPERTY, Constants.UTF_8); - new Thread(() -> { - Reader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(new FileInputStream(oFile), enc)); - if (head.startsWith("SessionId,")) { - // Crawling Session - crawlingSessionService.importCsv(reader); - } - } catch (final Exception e) { - logger.error("Failed to import data.", e); - throw new FessSystemException("Failed to import data.", e); - } finally { - if (!oFile.delete()) { - logger.warn("Could not delete " + oFile.getAbsolutePath()); - } - IOUtils.closeQuietly(reader); - } - } ).start(); - } catch (final ActionMessagesException e) { - if (!oFile.delete()) { - logger.warn("Could not delete " + oFile.getAbsolutePath()); - } - throw e; - } catch (final Exception e) { - if (!oFile.delete()) { - logger.warn("Could not delete " + oFile.getAbsolutePath()); - } - logger.error("Failed to import data.", e); - throw new SSCActionMessagesException(e, "errors.failed_to_import_data"); - } - } - - SAStrutsUtil.addSessionMessage("success.importing_data"); - return "index?redirect=true"; - } -} \ No newline at end of file diff --git a/src/main/java/org/codelibs/fess/app/web/admin/DataForm.java b/src/main/java/org/codelibs/fess/app/web/admin/DataForm.java deleted file mode 100644 index bb2648a1c..000000000 --- a/src/main/java/org/codelibs/fess/app/web/admin/DataForm.java +++ /dev/null @@ -1,29 +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.app.web.admin; - -import java.io.Serializable; - -public class DataForm implements Serializable { - - private static final long serialVersionUID = 1L; - - //@Required - //public FormFile uploadedFile; - - public String overwrite; -} diff --git a/src/main/java/org/codelibs/fess/app/web/admin/DocumentAction.java b/src/main/java/org/codelibs/fess/app/web/admin/DocumentAction.java deleted file mode 100644 index d106a3cbf..000000000 --- a/src/main/java/org/codelibs/fess/app/web/admin/DocumentAction.java +++ /dev/null @@ -1,247 +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.app.web.admin; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; - -import org.codelibs.fess.annotation.Token; -import org.codelibs.fess.client.FessEsClient; -import org.codelibs.fess.crud.util.SAStrutsUtil; -import org.codelibs.fess.exception.SSCActionMessagesException; -import org.codelibs.fess.helper.FieldHelper; -import org.codelibs.fess.helper.JobHelper; -import org.codelibs.fess.helper.SystemHelper; -import org.codelibs.fess.helper.WebManagementHelper; -import org.codelibs.fess.util.ComponentUtil; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.aggregations.AggregationBuilders; -import org.elasticsearch.search.aggregations.bucket.terms.Terms; -import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket; -import org.elasticsearch.search.aggregations.bucket.terms.Terms.Order; -import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder; -import org.lastaflute.taglib.function.LaFunctions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DocumentAction implements Serializable { - private static final Logger logger = LoggerFactory.getLogger(DocumentAction.class); - - private static final long serialVersionUID = 1L; - - //@ActionForm - @Resource - protected DocumentForm documentForm; - - @Resource - protected FessEsClient fessEsClient; - - @Resource - protected WebManagementHelper webManagementHelper; - - @Resource - protected SystemHelper systemHelper; - - @Resource - protected FieldHelper fieldHelper; - - @Resource - protected JobHelper jobHelper; - - public Map suggestDocumentNums; - - public String getHelpLink() { - return systemHelper.getHelpLink("document"); - } - - protected String showIndex(final boolean redirect) { - // TODO - - if (redirect) { - return "index?redirect=true"; - } else { - return "index.jsp"; - } - } - - @Token(save = true, validate = false) - //@Execute(validator = false) - public String index() { - return showIndex(false); - } - - @Token(save = false, validate = true) - //@Execute(validator = true, input = "index") - public String commit() { - // TODO change to flush - if (jobHelper.isCrawlProcessRunning()) { - throw new SSCActionMessagesException("errors.failed_to_start_solr_process_because_of_running"); - } - - fessEsClient.flush(ComponentUtil.getFieldHelper().docIndex); - SAStrutsUtil.addSessionMessage("success.commit_solr_index"); - return showIndex(true); - } - - @Token(save = false, validate = true) - //@Execute(validator = true, input = "index") - public String optimize() { - // TODO change to optimize - if (jobHelper.isCrawlProcessRunning()) { - throw new SSCActionMessagesException("errors.failed_to_start_solr_process_because_of_running"); - } - fessEsClient.optimize(ComponentUtil.getFieldHelper().docIndex); - SAStrutsUtil.addSessionMessage("success.optimize_solr_index"); - return showIndex(true); - } - - @Token(save = false, validate = true) - //@Execute(validator = true, input = "index") - public String delete() { - QueryBuilder deleteQuery; - if ("*".equals(documentForm.sessionId)) { - deleteQuery = QueryBuilders.matchAllQuery(); - } else { - deleteQuery = QueryBuilders.termQuery(fieldHelper.segmentField, documentForm.sessionId); - } - return deleteByQuery(deleteQuery); - } - - @Token(save = false, validate = true) - //@Execute(validator = true, input = "index") - public String confirmByUrl() { - final String confirmQuery = fieldHelper.urlField + ":\"" + documentForm.deleteUrl + "\""; - return "/admin/searchList/search?query=" + LaFunctions.u(confirmQuery) + "&redirect=true"; - } - - @Token(save = false, validate = true) - //@Execute(validator = true, input = "index") - public String deleteByUrl() { - return deleteByQuery(QueryBuilders.termQuery(fieldHelper.urlField, documentForm.deleteUrl)); - } - - private String deleteByQuery(final QueryBuilder queryBuilder) { - if (jobHelper.isCrawlProcessRunning()) { - throw new SSCActionMessagesException("errors.failed_to_start_solr_process_because_of_running"); - } - - fessEsClient.deleteByQuery(fieldHelper.docIndex, fieldHelper.docType, queryBuilder); - SAStrutsUtil.addSessionMessage("success.delete_solr_index"); - return showIndex(true); - } - - protected SessionIdList> getSessionIdList(final String groupName) { - // TODO remove groupName? - final FieldHelper fieldHelper = ComponentUtil.getFieldHelper(); - return fessEsClient.search( - fieldHelper.docIndex, - fieldHelper.docType, - queryRequestBuilder -> { - queryRequestBuilder.setQuery(QueryBuilders.matchAllQuery()); - final TermsBuilder termsBuilder = - AggregationBuilders.terms(fieldHelper.segmentField).field(fieldHelper.segmentField).size(100) - .order(Order.count(false)); - queryRequestBuilder.addAggregation(termsBuilder); - return true; - }, (queryRequestBuilder, execTime, searchResponse) -> { - final SessionIdList> sessionIdList = new SessionIdList>(); - searchResponse.ifPresent(response -> { - final Terms terms = response.getAggregations().get(fieldHelper.segmentField); - for (final Bucket bucket : terms.getBuckets()) { - final Map map = new HashMap(3); - map.put("label", bucket.getKey() + " (" + bucket.getDocCount() + ")"); - map.put("value", bucket.getKey()); - map.put("count", Long.toString(bucket.getDocCount())); - sessionIdList.add(map); - sessionIdList.addTotalCount(bucket.getDocCount()); - } - }); - return sessionIdList; - }); - - } - - public boolean isSolrProcessRunning() { - return jobHelper.isCrawlProcessRunning(); - } - - public Set getRunningSessionIdSet() { - return jobHelper.getRunningSessionIdSet(); - } - - protected Map getSuggestDocumentNum() { - final Map map = new HashMap(); - // map.put(SUGGEST_TYPE_CONTENT, - // suggestService.getContentDocumentNum()); - // map.put(SUGGEST_TYPE_SEARCH_LOG, - // suggestService.getSearchLogDocumentNum()); - // map.put(SUGGEST_TYPE_ALL, suggestService.getDocumentNum()); - return map; - } - - @Token(save = false, validate = true) - //@Execute(validator = true, input = "index") - public String deleteSuggest() { - // TODO - /* - * final SuggestSolrServer suggestSolrServer = - * suggestService.getSuggestSolrServer(); final String query; if - * (SUGGEST_TYPE_CONTENT.equals(documentForm.deleteSuggestType)) { query - * = "*:* NOT " + SuggestConstants.SuggestFieldNames.SEGMENT + ":" + - * SuggestConstants.SEGMENT_ELEVATE + " NOT " + - * SuggestConstants.SuggestFieldNames.SEGMENT + ":" + - * SuggestConstants.SEGMENT_QUERY; } else if - * (SUGGEST_TYPE_SEARCH_LOG.equals(documentForm.deleteSuggestType)) { - * query = SuggestConstants.SuggestFieldNames.SEGMENT + ":" + - * SuggestConstants.SEGMENT_QUERY; } else { query = ""; } - * - * if (StringUtil.isNotBlank(query)) { final Thread thread = new - * Thread(new Runnable() { - * - * @Override public void run() { if (!jobHelper.isCrawlProcessRunning()) - * { final long execTime = System.currentTimeMillis(); try { - * suggestSolrServer.deleteByQuery(query); suggestSolrServer.commit(); - * if (logger.isInfoEnabled()) { - * logger.info("[EXEC TIME] suggest index cleanup time: " + - * (System.currentTimeMillis() - execTime) + "ms"); } } catch (final - * Exception e) { logger.error("Failed to delete suggest index (query=" - * + query + ").", e); } } else { if (logger.isInfoEnabled()) { - * logger.info("could not start index cleanup process" + - * " because of running solr process."); } } } }); thread.start(); - * SAStrutsUtil.addSessionMessage("success.delete_solr_index"); } - */ - return showIndex(true); - } - - private static class SessionIdList extends ArrayList { - - private static final long serialVersionUID = 1L; - - private long totalCount = 0; - - public void addTotalCount(final long count) { - totalCount += count; - } - - } -} \ No newline at end of file diff --git a/src/main/java/org/codelibs/fess/app/web/admin/DocumentForm.java b/src/main/java/org/codelibs/fess/app/web/admin/DocumentForm.java deleted file mode 100644 index 090688756..000000000 --- a/src/main/java/org/codelibs/fess/app/web/admin/DocumentForm.java +++ /dev/null @@ -1,52 +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.app.web.admin; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class DocumentForm implements Serializable { - - private static final long serialVersionUID = 1L; - - public String currentServerForUpdate; - - public String currentServerForSelect; - - public String currentServerStatusForUpdate; - - public String currentServerStatusForSelect; - - public List> serverStatusList = new ArrayList>(); - - //@Required(target = "commit,optimize,delete") - public String groupName; - - //@Required(target = "delete") - public String sessionId; - - //@Required(target = "deleteByUrl,confirmByUrl") - public String deleteUrl; - - //@Required(target = "startSolrInstance,stopSolrInstance,reloadSolrInstance") - public String solrInstanceName; - - //@Required(target = "deleteSuggest") - public String deleteSuggestType; -} diff --git a/src/main/java/org/codelibs/fess/app/web/admin/IndexAction.java b/src/main/java/org/codelibs/fess/app/web/admin/IndexAction.java deleted file mode 100644 index a9d38dde2..000000000 --- a/src/main/java/org/codelibs/fess/app/web/admin/IndexAction.java +++ /dev/null @@ -1,48 +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.app.web.admin; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; - -import org.codelibs.fess.helper.SystemHelper; -import org.codelibs.fess.util.ActivityUtil; -import org.lastaflute.web.util.LaRequestUtil; - -public class IndexAction { - - @Resource - protected SystemHelper systemHelper; - - public String getHelpLink() { - return systemHelper.getHelpLink("wizard"); - } - - //@Execute(validator = false) - public String index() { - return "/admin/wizard/index?redirect=true"; - } - - //@Execute(validator = false) - public String logout() { - final HttpServletRequest request = LaRequestUtil.getRequest(); - ActivityUtil.logout(request.getRemoteUser(), request); - - request.getSession().invalidate(); - return "/admin/wizard/index?redirect=true"; - } -} \ No newline at end of file diff --git a/src/main/java/org/codelibs/fess/app/web/admin/WizardForm.java b/src/main/java/org/codelibs/fess/app/web/admin/WizardForm.java deleted file mode 100644 index bdd0551d5..000000000 --- a/src/main/java/org/codelibs/fess/app/web/admin/WizardForm.java +++ /dev/null @@ -1,42 +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.app.web.admin; - -import java.io.Serializable; - -public class WizardForm implements Serializable { - - private static final long serialVersionUID = 1L; - - //@Maxbytelength(maxbytelength = 200, target = "crawlingConfig,crawlingConfigNext") - public String crawlingConfigName; - - //@Required(target = "crawlingConfig,crawlingConfigNext") - //@Maxbytelength(maxbytelength = 1000) - public String crawlingConfigPath; - - //@LongRange(min = 0, max = Long.MAX_VALUE, target = "crawlingConfig,crawlingConfigNext") - public String maxAccessCount; - - //@IntRange(min = 0, max = Integer.MAX_VALUE, target = "crawlingConfig,crawlingConfigNext") - public String depth; - - public WizardForm() { - maxAccessCount = "10000"; - depth = null; - } -} diff --git a/src/main/java/org/codelibs/fess/app/web/admin/WizardAction.java b/src/main/java/org/codelibs/fess/app/web/admin/wizard/AdminWizardAction.java similarity index 66% rename from src/main/java/org/codelibs/fess/app/web/admin/WizardAction.java rename to src/main/java/org/codelibs/fess/app/web/admin/wizard/AdminWizardAction.java index 35e08e15e..dd6c12531 100644 --- a/src/main/java/org/codelibs/fess/app/web/admin/WizardAction.java +++ b/src/main/java/org/codelibs/fess/app/web/admin/wizard/AdminWizardAction.java @@ -14,44 +14,48 @@ * governing permissions and limitations under the License. */ -package org.codelibs.fess.app.web.admin; +package org.codelibs.fess.app.web.admin.wizard; -import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.List; import javax.annotation.Resource; +import org.apache.commons.lang3.StringUtils; import org.codelibs.core.lang.StringUtil; import org.codelibs.core.misc.DynamicProperties; import org.codelibs.fess.Constants; import org.codelibs.fess.annotation.Token; -import org.codelibs.fess.crud.util.SAStrutsUtil; -import org.codelibs.fess.es.exentity.FileConfig; -import org.codelibs.fess.es.exentity.ScheduledJob; -import org.codelibs.fess.es.exentity.WebConfig; -import org.codelibs.fess.exception.SSCActionMessagesException; -import org.codelibs.fess.helper.JobHelper; -import org.codelibs.fess.helper.SystemHelper; -import org.codelibs.fess.job.TriggeredJob; import org.codelibs.fess.app.service.FileConfigService; import org.codelibs.fess.app.service.ScheduledJobService; import org.codelibs.fess.app.service.WebConfigService; +import org.codelibs.fess.app.web.admin.system.AdminSystemAction; +import org.codelibs.fess.app.web.base.FessAdminAction; +import org.codelibs.fess.es.exentity.FileConfig; +import org.codelibs.fess.es.exentity.ScheduledJob; +import org.codelibs.fess.es.exentity.WebConfig; +import org.codelibs.fess.helper.JobHelper; +import org.codelibs.fess.helper.SystemHelper; +import org.codelibs.fess.job.TriggeredJob; import org.codelibs.fess.util.ComponentUtil; import org.codelibs.robot.util.CharUtil; +import org.lastaflute.web.Execute; +import org.lastaflute.web.callback.ActionRuntime; +import org.lastaflute.web.response.HtmlResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class WizardAction implements Serializable { - private static final long serialVersionUID = 1L; +public class AdminWizardAction extends FessAdminAction { - private static final Logger logger = LoggerFactory.getLogger(WizardAction.class); - - //@ActionForm - @Resource - protected WizardForm wizardForm; + // =================================================================================== + // Constant + // + private static final Logger logger = LoggerFactory.getLogger(AdminWizardAction.class); + // =================================================================================== + // Attribute + // @Resource protected DynamicProperties crawlerProperties; @@ -70,47 +74,62 @@ public class WizardAction implements Serializable { @Resource protected ScheduledJobService scheduledJobService; - public String getHelpLink() { - return systemHelper.getHelpLink("wizard"); + // =================================================================================== + // Hook + // ====== + @Override + protected void setupHtmlData(final ActionRuntime runtime) { + super.setupHtmlData(runtime); + runtime.registerData("helpLink", systemHelper.getHelpLink("wizard")); } - //@Execute(validator = false) - public String index() { - return "index.jsp"; + // =================================================================================== + // Search Execute + // ============== + + @Execute + public HtmlResponse index() { + return asHtml(path_AdminWizard_IndexJsp).useForm(IndexForm.class); } @Token(save = true, validate = false) - //@Execute(validator = false) - public String crawlingConfigForm() { - return "crawlingConfig.jsp"; + @Execute + public HtmlResponse crawlingConfigForm() { + return asHtml(path_AdminWizard_CrawlingConfigJsp).useForm(CrawlingConfigForm.class); } @Token(save = false, validate = true) - //@Execute(validator = true, input = "crawlingConfigForm") - public String crawlingConfig() { - final String name = crawlingConfigInternal(wizardForm.crawlingConfigName, wizardForm.crawlingConfigPath); - SAStrutsUtil.addSessionMessage("success.create_crawling_config_at_wizard", name); - return "crawlingConfigForm?redirect=true"; + @Execute + public HtmlResponse crawlingConfig(CrawlingConfigForm form) { + validate(form, messages -> {}, () -> { + return asHtml(path_AdminWizard_CrawlingConfigJsp); + }); + final String name = crawlingConfigInternal(form); + saveInfo(messages -> messages.addSuccessCreateCrawlingConfigAtWizard(GLOBAL, name)); + return redirectWith(getClass(), moreUrl("crawlingConfigForm")); } @Token(save = false, validate = true) - //@Execute(validator = true, input = "crawlingConfigForm") - public String crawlingConfigNext() { - final String name = crawlingConfigInternal(wizardForm.crawlingConfigName, wizardForm.crawlingConfigPath); - SAStrutsUtil.addSessionMessage("success.create_crawling_config_at_wizard", name); - return "startCrawlingForm?redirect=true"; + @Execute + public HtmlResponse crawlingConfigNext(CrawlingConfigForm form) { + validate(form, messages -> {}, () -> { + return asHtml(path_AdminWizard_CrawlingConfigJsp); + }); + final String name = crawlingConfigInternal(form); + saveInfo(messages -> messages.addSuccessCreateCrawlingConfigAtWizard(GLOBAL, name)); + return redirectWith(getClass(), moreUrl("startCrawlingForm")); } - protected String crawlingConfigInternal(final String crawlingConfigName, final String crawlingConfigPath) { + protected String crawlingConfigInternal(final CrawlingConfigForm form) { - String configName = crawlingConfigName; - String configPath = crawlingConfigPath.trim(); + String configName = form.crawlingConfigName; + String configPath = form.crawlingConfigPath.trim(); if (StringUtil.isBlank(configName)) { configName = StringUtils.abbreviate(configPath, 30); } // normalize - final StringBuilder buf = new StringBuilder(); + final StringBuilder buf = new StringBuilder(1000); for (int i = 0; i < configPath.length(); i++) { final char c = configPath.charAt(i); if (c == '\\') { @@ -138,16 +157,16 @@ public class WizardAction implements Serializable { wConfig.setBoost(1.0f); wConfig.setCreatedBy(username); wConfig.setCreatedTime(now); - if (StringUtil.isNotBlank(wizardForm.depth)) { - wConfig.setDepth(Integer.parseInt(wizardForm.depth)); + if (StringUtil.isNotBlank(form.depth)) { + wConfig.setDepth(Integer.parseInt(form.depth)); } wConfig.setExcludedDocUrls(getDefaultString("default.config.web.excludedDocUrls", StringUtil.EMPTY)); wConfig.setExcludedUrls(getDefaultString("default.config.web.excludedUrls", StringUtil.EMPTY)); wConfig.setIncludedDocUrls(getDefaultString("default.config.web.includedDocUrls", StringUtil.EMPTY)); wConfig.setIncludedUrls(getDefaultString("default.config.web.includedUrls", StringUtil.EMPTY)); wConfig.setIntervalTime(getDefaultInteger("default.config.web.intervalTime", Constants.DEFAULT_INTERVAL_TIME_FOR_WEB)); - if (StringUtil.isNotBlank(wizardForm.maxAccessCount)) { - wConfig.setMaxAccessCount(Long.parseLong(wizardForm.maxAccessCount)); + if (StringUtil.isNotBlank(form.maxAccessCount)) { + wConfig.setMaxAccessCount(Long.parseLong(form.maxAccessCount)); } wConfig.setName(configName); wConfig.setNumOfThread(getDefaultInteger("default.config.web.numOfThread", Constants.DEFAULT_NUM_OF_THREAD_FOR_WEB)); @@ -166,16 +185,16 @@ public class WizardAction implements Serializable { fConfig.setBoost(1.0f); fConfig.setCreatedBy(username); fConfig.setCreatedTime(now); - if (StringUtil.isNotBlank(wizardForm.depth)) { - fConfig.setDepth(Integer.parseInt(wizardForm.depth)); + if (StringUtil.isNotBlank(form.depth)) { + fConfig.setDepth(Integer.parseInt(form.depth)); } fConfig.setExcludedDocPaths(getDefaultString("default.config.file.excludedDocPaths", StringUtil.EMPTY)); fConfig.setExcludedPaths(getDefaultString("default.config.file.excludedPaths", StringUtil.EMPTY)); fConfig.setIncludedDocPaths(getDefaultString("default.config.file.includedDocPaths", StringUtil.EMPTY)); fConfig.setIncludedPaths(getDefaultString("default.config.file.includedPaths", StringUtil.EMPTY)); fConfig.setIntervalTime(getDefaultInteger("default.config.file.intervalTime", Constants.DEFAULT_INTERVAL_TIME_FOR_FS)); - if (StringUtil.isNotBlank(wizardForm.maxAccessCount)) { - fConfig.setMaxAccessCount(Long.parseLong(wizardForm.maxAccessCount)); + if (StringUtil.isNotBlank(form.maxAccessCount)) { + fConfig.setMaxAccessCount(Long.parseLong(form.maxAccessCount)); } fConfig.setName(configName); fConfig.setNumOfThread(getDefaultInteger("default.config.file.numOfThread", Constants.DEFAULT_NUM_OF_THREAD_FOR_FS)); @@ -188,8 +207,11 @@ public class WizardAction implements Serializable { } return configName; } catch (final Exception e) { - logger.error("Failed to create crawling config: " + wizardForm.crawlingConfigPath, e); - throw new SSCActionMessagesException(e, "errors.failed_to_create_crawling_config_at_wizard", wizardForm.crawlingConfigPath); + logger.error("Failed to create crawling config: " + form.crawlingConfigPath, e); + throwValidationError(messages -> messages.addErrorsFailedToCreateCrawlingConfigAtWizard(GLOBAL), () -> { + return asHtml(path_AdminWizard_CrawlingConfigJsp); + }); + return null; } } @@ -249,23 +271,23 @@ public class WizardAction implements Serializable { } @Token(save = true, validate = false) - //@Execute(validator = false) - public String startCrawlingForm() { - return "startCrawling.jsp"; + @Execute + public HtmlResponse startCrawlingForm() { + return asHtml(path_AdminWizard_StartCrawlingJsp).useForm(StartCrawlingForm.class); } @Token(save = false, validate = true) - //@Execute(validator = false) - public String startCrawling() { + @Execute + public HtmlResponse startCrawling(StartCrawlingForm form) { if (!jobHelper.isCrawlProcessRunning()) { final List scheduledJobList = scheduledJobService.getCrawloerJobList(); for (final ScheduledJob scheduledJob : scheduledJobList) { new Thread(() -> new TriggeredJob().execute(scheduledJob)).start(); } - SAStrutsUtil.addSessionMessage("success.start_crawl_process"); + saveInfo(messages -> messages.addSuccessStartCrawlProcess(GLOBAL)); } else { - SAStrutsUtil.addSessionMessage("success.failed_to_start_crawl_process"); + saveError(messages -> messages.addErrorsFailedToStartCrawlProcess(GLOBAL)); } - return "../system/index?redirect=true"; + return redirect(AdminSystemAction.class); } } \ No newline at end of file diff --git a/src/main/java/org/codelibs/fess/app/web/admin/wizard/CrawlingConfigForm.java b/src/main/java/org/codelibs/fess/app/web/admin/wizard/CrawlingConfigForm.java new file mode 100644 index 000000000..650ea44e8 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/admin/wizard/CrawlingConfigForm.java @@ -0,0 +1,32 @@ +package org.codelibs.fess.app.web.admin.wizard; + +import java.io.Serializable; + +import javax.validation.constraints.Size; + +import org.lastaflute.web.validation.Required; + +public class CrawlingConfigForm implements Serializable { + + private static final long serialVersionUID = 1L; + + @Required + @Size(max = 200) + public String crawlingConfigName; + + @Required + @Size(max = 1000) + public String crawlingConfigPath; + + // TODO + // @Min(0) + // @Max(Integer.MAX_VALUE) + public String depth; + + // TODO + @Size(max = 100) + // @Min(0) + // @Max(Long.MAX_VALUE) + public String maxAccessCount; + +} diff --git a/src/main/java/org/codelibs/fess/app/web/admin/wizard/IndexForm.java b/src/main/java/org/codelibs/fess/app/web/admin/wizard/IndexForm.java new file mode 100644 index 000000000..ee18806a7 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/admin/wizard/IndexForm.java @@ -0,0 +1,9 @@ +package org.codelibs.fess.app.web.admin.wizard; + +import java.io.Serializable; + +public class IndexForm implements Serializable { + + private static final long serialVersionUID = 1L; + +} diff --git a/src/main/java/org/codelibs/fess/app/web/admin/wizard/StartCrawlingForm.java b/src/main/java/org/codelibs/fess/app/web/admin/wizard/StartCrawlingForm.java new file mode 100644 index 000000000..f3edbc83c --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/admin/wizard/StartCrawlingForm.java @@ -0,0 +1,9 @@ +package org.codelibs.fess.app.web.admin.wizard; + +import java.io.Serializable; + +public class StartCrawlingForm implements Serializable { + + private static final long serialVersionUID = 1L; + +} diff --git a/src/main/java/org/codelibs/fess/app/web/base/FessAdminAction.java b/src/main/java/org/codelibs/fess/app/web/base/FessAdminAction.java index 5dde0a540..22de3c843 100644 --- a/src/main/java/org/codelibs/fess/app/web/base/FessAdminAction.java +++ b/src/main/java/org/codelibs/fess/app/web/base/FessAdminAction.java @@ -47,6 +47,12 @@ public abstract class FessAdminAction extends FessBaseAction { sessionManager.info().save(messages); } + protected void saveError(final VaMessenger validationMessagesLambda) { + final FessMessages messages = createMessages(); + validationMessagesLambda.message(messages); + sessionManager.errors().save(messages); + } + protected void write(final String path, final byte[] data) { LdiFileUtil.write(path, data); } diff --git a/src/main/webapp/WEB-INF/view/admin/document/index.jsp b/src/main/webapp/WEB-INF/view/admin/document/index.jsp deleted file mode 100644 index 218e32c0b..000000000 --- a/src/main/webapp/WEB-INF/view/admin/document/index.jsp +++ /dev/null @@ -1,207 +0,0 @@ -<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> - - - - - - - - - - -
- <%-- Message: BEGIN --%> -
- -
${msg}
-
- -
- <%-- Message: END --%> - - -
-
- -
-

- -

- - - - - - - - - - - -
${f:h(groupAction.groupName)} - - - - - - - -
-
- -
-

- -

- - - - - - - - - - - - - - -
${f:h(groupAction.groupName)} - - - - - - ${f:h(sessionIdItem.label)} - - - (${f:h(groupAction.totalCount)}) - - - - - -
- - - - - - - -
-
- -
-

- -

- - - - - - - - - - - - - - - - - - - - - - - - - - -
${f:h(groupAction.groupName)}${f:h(groupAction.totalCount)}
${f:h(groupAction.groupName)}${f:h(sessionIdItem.value)}${f:h(sessionIdItem.count)}
-
-
-

- -

- - - - - - - - - - - - - - - - - - - - - - - - - -
${suggestDocumentNums.all} -
${suggestDocumentNums.content} - - - - - - -
${suggestDocumentNums.searchLog} - - - - - - -
-
-
-
- - - - -
-
diff --git a/src/main/webapp/WEB-INF/view/common/admin2/sidebar.jsp b/src/main/webapp/WEB-INF/view/common/admin2/sidebar.jsp index 802373630..452833272 100644 --- a/src/main/webapp/WEB-INF/view/common/admin2/sidebar.jsp +++ b/src/main/webapp/WEB-INF/view/common/admin2/sidebar.jsp @@ -27,10 +27,10 @@ >
    -
  • class="active"> +
  • class="active"> -
  • +
  • class="active">