#495 add permissions to mappings
This commit is contained in:
parent
bbc2a975b3
commit
87ce91ca04
3 changed files with 38 additions and 6 deletions
|
@ -23,6 +23,7 @@ import java.util.Map;
|
|||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.es.client.FessEsClient;
|
||||
import org.codelibs.fess.es.config.exbhv.DataConfigBhv;
|
||||
import org.codelibs.fess.es.config.exbhv.DataConfigToRoleBhv;
|
||||
import org.codelibs.fess.es.config.exbhv.FileConfigBhv;
|
||||
|
@ -33,6 +34,9 @@ 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.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
|
||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
|
||||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.HtmlResponse;
|
||||
import org.lastaflute.web.ruts.process.ActionRuntime;
|
||||
|
@ -79,6 +83,9 @@ public class AdminUpgradeAction extends FessAdminAction {
|
|||
@Resource
|
||||
protected DataConfigBhv dataConfigBhv;
|
||||
|
||||
@Resource
|
||||
protected FessEsClient fessEsClient;
|
||||
|
||||
// ===================================================================================
|
||||
// Hook
|
||||
// ======
|
||||
|
@ -119,7 +126,19 @@ public class AdminUpgradeAction extends FessAdminAction {
|
|||
|
||||
private void upgradeFrom10_0() {
|
||||
|
||||
IndicesAdminClient indicesClient = fessEsClient.admin().indices();
|
||||
final String configIndex = ".fess_config";
|
||||
|
||||
try {
|
||||
addFieldMapping(indicesClient, configIndex, "label_type", "permissions",
|
||||
"{\"properties\":{\"permissions\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
|
||||
addFieldMapping(indicesClient, configIndex, "web_config", "permissions",
|
||||
"{\"properties\":{\"permissions\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
|
||||
addFieldMapping(indicesClient, configIndex, "file_config", "permissions",
|
||||
"{\"properties\":{\"permissions\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
|
||||
addFieldMapping(indicesClient, configIndex, "data_config", "permissions",
|
||||
"{\"properties\":{\"permissions\":{\"type\":\"string\",\"index\":\"not_analyzed\"}}}");
|
||||
|
||||
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());
|
||||
|
@ -226,7 +245,19 @@ public class AdminUpgradeAction extends FessAdminAction {
|
|||
saveInfo(messages -> messages.addSuccessUpgradeFrom(GLOBAL));
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to upgrade data.", e);
|
||||
saveError(messages -> messages.addErrorsFailedToUpgradeFrom(GLOBAL, "10.0"));
|
||||
saveError(messages -> messages.addErrorsFailedToUpgradeFrom(GLOBAL, "10.0", e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
private void addFieldMapping(IndicesAdminClient indicesClient, final String index, final String type, final String field,
|
||||
final String source) {
|
||||
GetFieldMappingsResponse gfmResponse =
|
||||
indicesClient.prepareGetFieldMappings(index).addTypes(type).setFields(field).execute().actionGet();
|
||||
if (gfmResponse.fieldMappings(index, type, field).isNull()) {
|
||||
PutMappingResponse pmResponse = indicesClient.preparePutMapping(index).setType(type).setSource(source).execute().actionGet();
|
||||
if (!pmResponse.isAcknowledged()) {
|
||||
logger.warn("Failed to add " + field + " to " + index + "/" + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -284,7 +284,7 @@ public class FessMessages extends FessLabels {
|
|||
/** 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}. */
|
||||
/** The key of the message: Failed to upgrade from {0}: {1} */
|
||||
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. */
|
||||
|
@ -1661,15 +1661,16 @@ public class FessMessages extends FessLabels {
|
|||
/**
|
||||
* Add the created action message for the key 'errors.failed_to_upgrade_from' with parameters.
|
||||
* <pre>
|
||||
* message: Failed to upgrade from {0}.
|
||||
* message: Failed to upgrade from {0}: {1}
|
||||
* </pre>
|
||||
* @param property The property name for the message. (NotNull)
|
||||
* @param arg0 The parameter arg0 for message. (NotNull)
|
||||
* @param arg1 The parameter arg1 for message. (NotNull)
|
||||
* @return this. (NotNull)
|
||||
*/
|
||||
public FessMessages addErrorsFailedToUpgradeFrom(String property, String arg0) {
|
||||
public FessMessages addErrorsFailedToUpgradeFrom(String property, String arg0, String arg1) {
|
||||
assertPropertyNotNull(property);
|
||||
add(property, new ActionMessage(ERRORS_failed_to_upgrade_from, arg0));
|
||||
add(property, new ActionMessage(ERRORS_failed_to_upgrade_from, arg0, arg1));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ 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.failed_to_upgrade_from=Failed to upgrade from {0}: {1}
|
||||
|
||||
errors.invalid_query_unknown=The given query has unknown condition.
|
||||
errors.invalid_query_parse_error=The given query is invalid.
|
||||
|
|
Loading…
Add table
Reference in a new issue