fix #495 : add data migration page

This commit is contained in:
Shinsuke Sugaya 2016-05-02 07:09:41 +09:00
parent 41d9723571
commit bbc2a975b3
14 changed files with 438 additions and 0 deletions

View file

@ -0,0 +1,233 @@
/*
* Copyright 2012-2016 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.upgrade;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.codelibs.fess.app.web.base.FessAdminAction;
import org.codelibs.fess.es.config.exbhv.DataConfigBhv;
import org.codelibs.fess.es.config.exbhv.DataConfigToRoleBhv;
import org.codelibs.fess.es.config.exbhv.FileConfigBhv;
import org.codelibs.fess.es.config.exbhv.FileConfigToRoleBhv;
import org.codelibs.fess.es.config.exbhv.LabelToRoleBhv;
import org.codelibs.fess.es.config.exbhv.LabelTypeBhv;
import org.codelibs.fess.es.config.exbhv.RoleTypeBhv;
import org.codelibs.fess.es.config.exbhv.WebConfigBhv;
import org.codelibs.fess.es.config.exbhv.WebConfigToRoleBhv;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.lastaflute.web.Execute;
import org.lastaflute.web.response.HtmlResponse;
import org.lastaflute.web.ruts.process.ActionRuntime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AdminUpgradeAction extends FessAdminAction {
// ===================================================================================
// Constant
//
private static final Logger logger = LoggerFactory.getLogger(AdminUpgradeAction.class);
// ===================================================================================
// Attribute
//
@Resource
protected FessConfig fessConfig;
@Resource
protected RoleTypeBhv roleTypeBhv;
@Resource
protected LabelToRoleBhv labelToRoleBhv;
@Resource
protected LabelTypeBhv labelTypeBhv;
@Resource
protected WebConfigToRoleBhv webConfigToRoleBhv;
@Resource
protected WebConfigBhv webConfigBhv;
@Resource
protected FileConfigToRoleBhv fileConfigToRoleBhv;
@Resource
protected FileConfigBhv fileConfigBhv;
@Resource
protected DataConfigToRoleBhv dataConfigToRoleBhv;
@Resource
protected DataConfigBhv dataConfigBhv;
// ===================================================================================
// Hook
// ======
@Override
protected void setupHtmlData(final ActionRuntime runtime) {
super.setupHtmlData(runtime);
runtime.registerData("helpLink", systemHelper.getHelpLink(fessConfig.getOnlineHelpNameUpgrade()));
}
// ===================================================================================
// Search Execute
// ==============
@Execute
public HtmlResponse index() {
saveToken();
return asIndexHtml();
}
private HtmlResponse asIndexHtml() {
return asHtml(path_AdminUpgrade_AdminUpgradeJsp).useForm(UpgradeForm.class);
}
@Execute
public HtmlResponse upgradeFrom(final UpgradeForm form) {
validate(form, messages -> {}, () -> {
return asIndexHtml();
});
verifyToken(() -> asIndexHtml());
if (form.targetVersion.equals("10.0")) {
upgradeFrom10_0();
} else {
saveError(messages -> messages.addErrorsUnknownVersionForUpgrade(GLOBAL));
}
return redirect(getClass());
}
private void upgradeFrom10_0() {
try {
final Map<String, List<String>> mapping = new HashMap<>();
labelToRoleBhv.selectList(cb -> cb.query().addOrderBy_LabelTypeId_Asc()).forEach(e -> {
List<String> list = mapping.get(e.getLabelTypeId());
if (list == null) {
list = new ArrayList<>();
mapping.put(e.getLabelTypeId(), list);
}
list.add(e.getRoleTypeId());
});
mapping.entrySet().forEach(
e -> {
final String labelTypeId = e.getKey();
final List<String> idList = e.getValue();
labelTypeBhv.selectEntity(cb -> cb.acceptPK(labelTypeId)).ifPresent(
entity -> {
final String[] permissions =
roleTypeBhv.selectList(cb -> cb.query().setId_InScope(idList)).stream()
.map(r -> fessConfig.getRoleSearchRolePrefix() + r.getName())
.toArray(n -> new String[n]);
entity.setPermissions(permissions);
labelTypeBhv.insertOrUpdate(entity);
labelToRoleBhv.queryDelete(cb -> cb.query().setLabelTypeId_Equal(labelTypeId));
});
});
mapping.clear();
webConfigToRoleBhv.selectList(cb -> cb.query().addOrderBy_WebConfigId_Asc()).forEach(e -> {
final String webConfigId = e.getWebConfigId();
List<String> list = mapping.get(webConfigId);
if (list == null) {
list = new ArrayList<>();
mapping.put(webConfigId, list);
}
list.add(e.getRoleTypeId());
});
mapping.entrySet().forEach(
e -> {
final String webConfigTypeId = e.getKey();
final List<String> idList = e.getValue();
webConfigBhv.selectEntity(cb -> cb.acceptPK(webConfigTypeId)).ifPresent(
entity -> {
final String[] permissions =
roleTypeBhv.selectList(cb -> cb.query().setId_InScope(idList)).stream()
.map(r -> fessConfig.getRoleSearchRolePrefix() + r.getName())
.toArray(n -> new String[n]);
entity.setPermissions(permissions);
webConfigBhv.insertOrUpdate(entity);
webConfigToRoleBhv.queryDelete(cb -> cb.query().setWebConfigId_Equal(webConfigTypeId));
});
});
mapping.clear();
fileConfigToRoleBhv.selectList(cb -> cb.query().addOrderBy_FileConfigId_Asc()).forEach(e -> {
final String fileConfigId = e.getFileConfigId();
List<String> list = mapping.get(fileConfigId);
if (list == null) {
list = new ArrayList<>();
mapping.put(fileConfigId, list);
}
list.add(e.getRoleTypeId());
});
mapping.entrySet().forEach(
e -> {
final String fileConfigTypeId = e.getKey();
final List<String> idList = e.getValue();
fileConfigBhv.selectEntity(cb -> cb.acceptPK(fileConfigTypeId)).ifPresent(
entity -> {
final String[] permissions =
roleTypeBhv.selectList(cb -> cb.query().setId_InScope(idList)).stream()
.map(r -> fessConfig.getRoleSearchRolePrefix() + r.getName())
.toArray(n -> new String[n]);
entity.setPermissions(permissions);
fileConfigBhv.insertOrUpdate(entity);
fileConfigToRoleBhv.queryDelete(cb -> cb.query().setFileConfigId_Equal(fileConfigTypeId));
});
});
mapping.clear();
dataConfigToRoleBhv.selectList(cb -> cb.query().addOrderBy_DataConfigId_Asc()).forEach(e -> {
final String dataConfigId = e.getDataConfigId();
List<String> list = mapping.get(dataConfigId);
if (list == null) {
list = new ArrayList<>();
mapping.put(dataConfigId, list);
}
list.add(e.getRoleTypeId());
});
mapping.entrySet().forEach(
e -> {
final String dataConfigTypeId = e.getKey();
final List<String> idList = e.getValue();
dataConfigBhv.selectEntity(cb -> cb.acceptPK(dataConfigTypeId)).ifPresent(
entity -> {
final String[] permissions =
roleTypeBhv.selectList(cb -> cb.query().setId_InScope(idList)).stream()
.map(r -> fessConfig.getRoleSearchRolePrefix() + r.getName())
.toArray(n -> new String[n]);
entity.setPermissions(permissions);
dataConfigBhv.insertOrUpdate(entity);
dataConfigToRoleBhv.queryDelete(cb -> cb.query().setDataConfigId_Equal(dataConfigTypeId));
});
});
saveInfo(messages -> messages.addSuccessUpgradeFrom(GLOBAL));
} catch (Exception e) {
logger.warn("Failed to upgrade data.", e);
saveError(messages -> messages.addErrorsFailedToUpgradeFrom(GLOBAL, "10.0"));
}
}
}

View file

@ -0,0 +1,23 @@
/*
* Copyright 2012-2016 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.upgrade;
import org.lastaflute.web.validation.Required;
public class UpgradeForm {
@Required
public String targetVersion;
}

View file

@ -239,6 +239,9 @@ public interface FessHtmlPath {
/** The path of the HTML: /admin/systeminfo/admin_systeminfo.jsp */
HtmlNext path_AdminSysteminfo_AdminSysteminfoJsp = new HtmlNext("/admin/systeminfo/admin_systeminfo.jsp");
/** The path of the HTML: /admin/upgrade/admin_upgrade.jsp */
HtmlNext path_AdminUpgrade_AdminUpgradeJsp = new HtmlNext("/admin/upgrade/admin_upgrade.jsp");
/** The path of the HTML: /admin/user/admin_user.jsp */
HtmlNext path_AdminUser_AdminUserJsp = new HtmlNext("/admin/user/admin_user.jsp");

View file

@ -2283,6 +2283,21 @@ public class FessLabels extends ActionMessages {
/** The key of the message: homeDirectory */
public static final String LABELS_HOME_DIRECTORY = "{labels.homeDirectory}";
/** The key of the message: Upgrade */
public static final String LABELS_upgrade_title_configuration = "{labels.upgrade_title_configuration}";
/** The key of the message: Data Migration */
public static final String LABELS_upgrade_data_migration = "{labels.upgrade_data_migration}";
/** The key of the message: Start */
public static final String LABELS_upgrade_start_button = "{labels.upgrade_start_button}";
/** The key of the message: Version */
public static final String LABELS_TARGET_VERSION = "{labels.targetVersion}";
/** The key of the message: Version From */
public static final String LABELS_target_version = "{labels.target_version}";
/**
* Assert the property is not null.
* @param property The value of the property. (NotNull)

View file

@ -281,6 +281,12 @@ public class FessMessages extends FessLabels {
/** The key of the message: Failed to change your password. */
public static final String ERRORS_failed_to_change_password = "{errors.failed_to_change_password}";
/** The key of the message: Unknown version information. */
public static final String ERRORS_unknown_version_for_upgrade = "{errors.unknown_version_for_upgrade}";
/** The key of the message: Failed to upgrade from {0}. */
public static final String ERRORS_failed_to_upgrade_from = "{errors.failed_to_upgrade_from}";
/** The key of the message: The given query has unknown condition. */
public static final String ERRORS_invalid_query_unknown = "{errors.invalid_query_unknown}";
@ -368,6 +374,9 @@ public class FessMessages extends FessLabels {
/** The key of the message: Changed your password. */
public static final String SUCCESS_changed_password = "{success.changed_password}";
/** The key of the message: Upgraded data. */
public static final String SUCCESS_upgrade_from = "{success.upgrade_from}";
/** The key of the message: Created data. */
public static final String SUCCESS_crud_create_crud_table = "{success.crud_create_crud_table}";
@ -1635,6 +1644,35 @@ public class FessMessages extends FessLabels {
return this;
}
/**
* Add the created action message for the key 'errors.unknown_version_for_upgrade' with parameters.
* <pre>
* message: Unknown version information.
* </pre>
* @param property The property name for the message. (NotNull)
* @return this. (NotNull)
*/
public FessMessages addErrorsUnknownVersionForUpgrade(String property) {
assertPropertyNotNull(property);
add(property, new ActionMessage(ERRORS_unknown_version_for_upgrade));
return this;
}
/**
* Add the created action message for the key 'errors.failed_to_upgrade_from' with parameters.
* <pre>
* message: Failed to upgrade from {0}.
* </pre>
* @param property The property name for the message. (NotNull)
* @param arg0 The parameter arg0 for message. (NotNull)
* @return this. (NotNull)
*/
public FessMessages addErrorsFailedToUpgradeFrom(String property, String arg0) {
assertPropertyNotNull(property);
add(property, new ActionMessage(ERRORS_failed_to_upgrade_from, arg0));
return this;
}
/**
* Add the created action message for the key 'errors.invalid_query_unknown' with parameters.
* <pre>
@ -2056,6 +2094,20 @@ public class FessMessages extends FessLabels {
return this;
}
/**
* Add the created action message for the key 'success.upgrade_from' with parameters.
* <pre>
* message: Upgraded data.
* </pre>
* @param property The property name for the message. (NotNull)
* @return this. (NotNull)
*/
public FessMessages addSuccessUpgradeFrom(String property) {
assertPropertyNotNull(property);
add(property, new ActionMessage(SUCCESS_upgrade_from));
return this;
}
/**
* Add the created action message for the key 'success.crud_create_crud_table' with parameters.
* <pre>

View file

@ -676,6 +676,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. backup */
String ONLINE_HELP_NAME_BACKUP = "online.help.name.backup";
/** The key of the configuration. e.g. upgrade */
String ONLINE_HELP_NAME_UPGRADE = "online.help.name.upgrade";
/** The key of the configuration. e.g. ja */
String ONLINE_HELP_SUPPORTED_LANGS = "online.help.supported.langs";
@ -2945,6 +2948,13 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
String getOnlineHelpNameBackup();
/**
* Get the value for the key 'online.help.name.upgrade'. <br>
* The value is, e.g. upgrade <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getOnlineHelpNameUpgrade();
/**
* Get the value for the key 'online.help.supported.langs'. <br>
* The value is, e.g. ja <br>
@ -4664,6 +4674,10 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
return get(FessConfig.ONLINE_HELP_NAME_BACKUP);
}
public String getOnlineHelpNameUpgrade() {
return get(FessConfig.ONLINE_HELP_NAME_UPGRADE);
}
public String getOnlineHelpSupportedLangs() {
return get(FessConfig.ONLINE_HELP_SUPPORTED_LANGS);
}

View file

@ -367,6 +367,7 @@ online.help.name.duplicatehost=duplicatehost
online.help.name.scheduler=scheduler
online.help.name.crawlinginfo=crawlinginfo
online.help.name.backup=backup
online.help.name.upgrade=upgrade
online.help.supported.langs=ja

View file

@ -751,3 +751,8 @@ labels.group_gidNumber=gidNumber
labels.gidNumber=gidNumber
labels.user_homeDirectory=homeDirectory
labels.homeDirectory=homeDirectory
labels.upgrade_title_configuration=Upgrade
labels.upgrade_data_migration=Data Migration
labels.upgrade_start_button=Start
labels.targetVersion=Version
labels.target_version=Version From

View file

@ -751,3 +751,8 @@ labels.group_gidNumber=gidNumber
labels.gidNumber=gidNumber
labels.user_homeDirectory=homeDirectory
labels.homeDirectory=homeDirectory
labels.upgrade_title_configuration=Upgrade
labels.upgrade_data_migration=Data Migration
labels.upgrade_start_button=Start
labels.targetVersion=Version
labels.target_version=Version From

View file

@ -751,3 +751,8 @@ labels.group_gidNumber=gidNumber
labels.gidNumber=gidNumber
labels.user_homeDirectory=homeDirectory
labels.homeDirectory=homeDirectory
labels.upgrade_title_configuration=\u30a2\u30c3\u30d7\u30b0\u30ec\u30fc\u30c9
labels.upgrade_data_migration=\u30c7\u30fc\u30bf\u79fb\u884c
labels.upgrade_start_button=\u958b\u59cb
labels.targetVersion=\u5bfe\u8c61\u30d0\u30fc\u30b8\u30e7\u30f3
labels.target_version=\u5bfe\u8c61\u30d0\u30fc\u30b8\u30e7\u30f3

View file

@ -115,6 +115,8 @@ errors.failed_to_send_testmail=Failed to send the test mail.
errors.could_not_find_backup_index=Could not find index for backup.
errors.no_user_for_changing_password=The current password is incorrect.
errors.failed_to_change_password=Failed to change your password.
errors.unknown_version_for_upgrade=Unknown version information.
errors.failed_to_upgrade_from=Failed to upgrade from {0}.
errors.invalid_query_unknown=The given query has unknown condition.
errors.invalid_query_parse_error=The given query is invalid.
@ -147,6 +149,7 @@ success.upload_bad_word=Uploaded Bad Word file.
success.send_testmail=Sent the test mail.
success.job_log_delete_all=Deleted job logs.
success.changed_password=Changed your password.
success.upgrade_from=Upgraded data.
success.crud_create_crud_table=Created data.
success.crud_update_crud_table=Updated data.

View file

@ -115,6 +115,8 @@ errors.failed_to_send_testmail=Failed to send the test mail.
errors.could_not_find_backup_index=Could not find index for backup.
errors.no_user_for_changing_password=The current password is incorrect.
errors.failed_to_change_password=Failed to change your password.
errors.unknown_version_for_upgrade=Unknown version information.
errors.failed_to_upgrade_from=Failed to upgrade from {0}.
errors.invalid_query_unknown=The given query has unknown condition.
errors.invalid_query_parse_error=The given query is invalid.
@ -147,6 +149,7 @@ success.upload_bad_word=Uploaded Bad Word file.
success.send_testmail=Sent the test mail.
success.job_log_delete_all=Deleted job logs.
success.changed_password=Changed your password.
success.upgrade_from=Upgraded data.
success.crud_create_crud_table=Created data.
success.crud_update_crud_table=Updated data.

View file

@ -122,6 +122,8 @@ errors.crud_could_not_find_crud_table = \u30c7\u30fc\u30bf {0} \u304c\u898b\u306
errors.could_not_find_backup_index=\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u7528\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002
errors.no_user_for_changing_password=\u73fe\u5728\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002
errors.failed_to_change_password=\u30d1\u30b9\u30ef\u30fc\u30c9\u306e\u5909\u66f4\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002
errors.unknown_version_for_upgrade=\u4e0d\u660e\u306a\u30d0\u30fc\u30b8\u30e7\u30f3\u60c5\u5831\u3067\u3059\u3002
errors.failed_to_upgrade_from={0}\u304b\u3089\u306e\u30a2\u30c3\u30d7\u30b0\u30ec\u30fc\u30c9\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002
success.update_crawler_params = \u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u66f4\u65b0\u3057\u307e\u3057\u305f\u3002
success.delete_doc_from_index = \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304b\u3089\u6587\u66f8\u3092\u524a\u9664\u3059\u308b\u30d7\u30ed\u30bb\u30b9\u3092\u958b\u59cb\u3057\u307e\u3057\u305f\u3002
@ -141,6 +143,7 @@ success.upload_bad_word = \u9664\u5916\u30ef\u30fc\u30c9\u30d5\u30a1\u30a4\u30eb
success.send_testmail=\u30c6\u30b9\u30c8\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3057\u307e\u3057\u305f\u3002
success.job_log_delete_all=\u30b8\u30e7\u30d6\u30ed\u30b0\u3092\u524a\u9664\u3057\u307e\u3057\u305f\u3002
success.changed_password=\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u5909\u66f4\u3057\u307e\u3057\u305f\u3002
success.upgrade_from=\u30c7\u30fc\u30bf\u3092\u66f4\u65b0\u3057\u307e\u3057\u305f\u3002
success.crud_create_crud_table = \u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002
success.crud_update_crud_table = \u30c7\u30fc\u30bf\u3092\u66f4\u65b0\u3057\u307e\u3057\u305f\u3002

View file

@ -0,0 +1,73 @@
<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><la:message key="labels.admin_brand_title" /> | <la:message
key="labels.upgrade_title_configuration" /></title>
<jsp:include page="/WEB-INF/view/common/admin/head.jsp"></jsp:include>
</head>
<body class="skin-blue sidebar-mini">
<div class="wrapper">
<jsp:include page="/WEB-INF/view/common/admin/header.jsp"></jsp:include>
<jsp:include page="/WEB-INF/view/common/admin/sidebar.jsp">
<jsp:param name="menuCategoryType" value="system" />
<jsp:param name="menuType" value="wizard" />
</jsp:include>
<div class="content-wrapper">
<section class="content-header">
<h1>
<la:message key="labels.upgrade_title_configuration" />
</h1>
</section>
<section class="content">
<la:form action="/admin/upgrade/">
<div class="row">
<div class="col-md-12">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">
<la:message key="labels.upgrade_data_migration" />
</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<%-- Message: BEGIN --%>
<div>
<la:info id="msg" message="true">
<div class="alert alert-info">${msg}</div>
</la:info>
<la:errors />
</div>
<%-- Message: END --%>
<div class="form-group">
<label for="targetVersion" class="col-sm-3 control-label"><la:message key="labels.target_version" /></label>
<div class="col-sm-9">
<la:errors property="targetVersion" />
<la:select property="targetVersion" styleClass="form-control">
<la:option value="10.0">10.0</la:option>
</la:select>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary"
name="upgradeFrom"
value="<la:message key="labels.upgrade_start_button"/>">
<i class="fa fa-arrow-circle-right"></i>
<la:message key="labels.upgrade_start_button" />
</button>
</div>
<!-- /.box-footer -->
</div>
<!-- /.box -->
</div>
</div>
</la:form>
</section>
</div>
<jsp:include page="/WEB-INF/view/common/admin/footer.jsp"></jsp:include>
</div>
<jsp:include page="/WEB-INF/view/common/admin/foot.jsp"></jsp:include>
</body>
</html>