fix #943 /api/admin/general
This commit is contained in:
parent
fdca48cef4
commit
bcffa82995
7 changed files with 313 additions and 42 deletions
|
@ -73,7 +73,7 @@ public class AdminGeneralAction extends FessAdminAction {
|
|||
saveToken();
|
||||
return asHtml(path_AdminGeneral_AdminGeneralJsp).useForm(EditForm.class, setup -> {
|
||||
setup.setup(form -> {
|
||||
updateForm(form);
|
||||
updateForm(fessConfig, form);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -119,50 +119,121 @@ public class AdminGeneralAction extends FessAdminAction {
|
|||
return asHtml(path_AdminGeneral_AdminGeneralJsp);
|
||||
});
|
||||
|
||||
fessConfig.setLoginRequired(Constants.ON.equalsIgnoreCase(form.loginRequired));
|
||||
fessConfig.setLoginLinkEnabled(Constants.ON.equalsIgnoreCase(form.loginLink));
|
||||
fessConfig.setThumbnailEnabled(Constants.ON.equalsIgnoreCase(form.thumbnail));
|
||||
fessConfig.setIncrementalCrawling(Constants.ON.equalsIgnoreCase(form.incrementalCrawling));
|
||||
fessConfig.setDayForCleanup(form.dayForCleanup);
|
||||
fessConfig.setCrawlingThreadCount(form.crawlingThreadCount);
|
||||
fessConfig.setSearchLog(Constants.ON.equalsIgnoreCase(form.searchLog));
|
||||
fessConfig.setUserInfo(Constants.ON.equalsIgnoreCase(form.userInfo));
|
||||
fessConfig.setUserFavorite(Constants.ON.equalsIgnoreCase(form.userFavorite));
|
||||
fessConfig.setWebApiJson(Constants.ON.equalsIgnoreCase(form.webApiJson));
|
||||
fessConfig.setDefaultLabelValue(form.defaultLabelValue);
|
||||
fessConfig.setDefaultSortValue(form.defaultSortValue);
|
||||
fessConfig.setAppendQueryParameter(Constants.ON.equalsIgnoreCase(form.appendQueryParameter));
|
||||
fessConfig.setIgnoreFailureType(form.ignoreFailureType);
|
||||
fessConfig.setFailureCountThreshold(form.failureCountThreshold);
|
||||
fessConfig.setWebApiPopularWord(Constants.ON.equalsIgnoreCase(form.popularWord));
|
||||
fessConfig.setCsvFileEncoding(form.csvFileEncoding);
|
||||
fessConfig.setPurgeSearchLogDay(form.purgeSearchLogDay);
|
||||
fessConfig.setPurgeJobLogDay(form.purgeJobLogDay);
|
||||
fessConfig.setPurgeUserInfoDay(form.purgeUserInfoDay);
|
||||
fessConfig.setPurgeByBots(form.purgeByBots);
|
||||
fessConfig.setNotificationTo(form.notificationTo);
|
||||
fessConfig.setSuggestSearchLog(Constants.ON.equalsIgnoreCase(form.suggestSearchLog));
|
||||
fessConfig.setSuggestDocuments(Constants.ON.equalsIgnoreCase(form.suggestDocuments));
|
||||
fessConfig.setPurgeSuggestSearchLogDay(form.purgeSuggestSearchLogDay);
|
||||
fessConfig.setLdapProviderUrl(form.ldapProviderUrl);
|
||||
fessConfig.setLdapSecurityPrincipal(form.ldapSecurityPrincipal);
|
||||
fessConfig.setLdapAdminSecurityPrincipal(form.ldapAdminSecurityPrincipal);
|
||||
if (form.ldapAdminSecurityCredentials != null && StringUtil.isNotBlank(form.ldapAdminSecurityCredentials.replace("*", " "))) {
|
||||
fessConfig.setLdapAdminSecurityCredentials(form.ldapAdminSecurityCredentials);
|
||||
}
|
||||
fessConfig.setLdapBaseDn(form.ldapBaseDn);
|
||||
fessConfig.setLdapAccountFilter(form.ldapAccountFilter);
|
||||
fessConfig.setLdapMemberofAttribute(form.ldapMemberofAttribute);
|
||||
fessConfig.setNotificationLogin(form.notificationLogin);
|
||||
fessConfig.setNotificationSearchTop(form.notificationSearchTop);
|
||||
|
||||
fessConfig.storeSystemProperties();
|
||||
ComponentUtil.getLdapManager().updateConfig();
|
||||
updateConfig(fessConfig, form);
|
||||
saveInfo(messages -> messages.addSuccessUpdateCrawlerParams(GLOBAL));
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
||||
protected void updateForm(final EditForm form) {
|
||||
public static void updateConfig(final FessConfig fessConfig, final EditForm form) {
|
||||
if (form.loginRequired != null) {
|
||||
fessConfig.setLoginRequired(Constants.ON.equalsIgnoreCase(form.loginRequired));
|
||||
}
|
||||
if (form.loginLink != null) {
|
||||
fessConfig.setLoginLinkEnabled(Constants.ON.equalsIgnoreCase(form.loginLink));
|
||||
}
|
||||
if (form.thumbnail != null) {
|
||||
fessConfig.setThumbnailEnabled(Constants.ON.equalsIgnoreCase(form.thumbnail));
|
||||
}
|
||||
if (form.incrementalCrawling != null) {
|
||||
fessConfig.setIncrementalCrawling(Constants.ON.equalsIgnoreCase(form.incrementalCrawling));
|
||||
}
|
||||
if (form.dayForCleanup != null) {
|
||||
fessConfig.setDayForCleanup(form.dayForCleanup);
|
||||
}
|
||||
if (form.crawlingThreadCount != null) {
|
||||
fessConfig.setCrawlingThreadCount(form.crawlingThreadCount);
|
||||
}
|
||||
if (form.searchLog != null) {
|
||||
fessConfig.setSearchLog(Constants.ON.equalsIgnoreCase(form.searchLog));
|
||||
}
|
||||
if (form.userInfo != null) {
|
||||
fessConfig.setUserInfo(Constants.ON.equalsIgnoreCase(form.userInfo));
|
||||
}
|
||||
if (form.userFavorite != null) {
|
||||
fessConfig.setUserFavorite(Constants.ON.equalsIgnoreCase(form.userFavorite));
|
||||
}
|
||||
if (form.webApiJson != null) {
|
||||
fessConfig.setWebApiJson(Constants.ON.equalsIgnoreCase(form.webApiJson));
|
||||
}
|
||||
if (form.defaultLabelValue != null) {
|
||||
fessConfig.setDefaultLabelValue(form.defaultLabelValue);
|
||||
}
|
||||
if (form.defaultSortValue != null) {
|
||||
fessConfig.setDefaultSortValue(form.defaultSortValue);
|
||||
}
|
||||
if (form.appendQueryParameter != null) {
|
||||
fessConfig.setAppendQueryParameter(Constants.ON.equalsIgnoreCase(form.appendQueryParameter));
|
||||
}
|
||||
if (form.ignoreFailureType != null) {
|
||||
fessConfig.setIgnoreFailureType(form.ignoreFailureType);
|
||||
}
|
||||
if (form.failureCountThreshold != null) {
|
||||
fessConfig.setFailureCountThreshold(form.failureCountThreshold);
|
||||
}
|
||||
if (form.popularWord != null) {
|
||||
fessConfig.setWebApiPopularWord(Constants.ON.equalsIgnoreCase(form.popularWord));
|
||||
}
|
||||
if (form.csvFileEncoding != null) {
|
||||
fessConfig.setCsvFileEncoding(form.csvFileEncoding);
|
||||
}
|
||||
if (form.purgeSearchLogDay != null) {
|
||||
fessConfig.setPurgeSearchLogDay(form.purgeSearchLogDay);
|
||||
}
|
||||
if (form.purgeJobLogDay != null) {
|
||||
fessConfig.setPurgeJobLogDay(form.purgeJobLogDay);
|
||||
}
|
||||
if (form.purgeUserInfoDay != null) {
|
||||
fessConfig.setPurgeUserInfoDay(form.purgeUserInfoDay);
|
||||
}
|
||||
if (form.purgeByBots != null) {
|
||||
fessConfig.setPurgeByBots(form.purgeByBots);
|
||||
}
|
||||
if (form.notificationTo != null) {
|
||||
fessConfig.setNotificationTo(form.notificationTo);
|
||||
}
|
||||
if (form.suggestSearchLog != null) {
|
||||
fessConfig.setSuggestSearchLog(Constants.ON.equalsIgnoreCase(form.suggestSearchLog));
|
||||
}
|
||||
if (form.suggestDocuments != null) {
|
||||
fessConfig.setSuggestDocuments(Constants.ON.equalsIgnoreCase(form.suggestDocuments));
|
||||
}
|
||||
if (form.purgeSuggestSearchLogDay != null) {
|
||||
fessConfig.setPurgeSuggestSearchLogDay(form.purgeSuggestSearchLogDay);
|
||||
}
|
||||
if (form.ldapProviderUrl != null) {
|
||||
fessConfig.setLdapProviderUrl(form.ldapProviderUrl);
|
||||
}
|
||||
if (form.ldapSecurityPrincipal != null) {
|
||||
fessConfig.setLdapSecurityPrincipal(form.ldapSecurityPrincipal);
|
||||
}
|
||||
if (form.ldapAdminSecurityPrincipal != null) {
|
||||
fessConfig.setLdapAdminSecurityPrincipal(form.ldapAdminSecurityPrincipal);
|
||||
}
|
||||
if (form.ldapAdminSecurityCredentials != null && form.ldapAdminSecurityCredentials != null
|
||||
&& StringUtil.isNotBlank(form.ldapAdminSecurityCredentials.replace("*", " "))) {
|
||||
fessConfig.setLdapAdminSecurityCredentials(form.ldapAdminSecurityCredentials);
|
||||
}
|
||||
if (form.ldapBaseDn != null) {
|
||||
fessConfig.setLdapBaseDn(form.ldapBaseDn);
|
||||
}
|
||||
if (form.ldapAccountFilter != null) {
|
||||
fessConfig.setLdapAccountFilter(form.ldapAccountFilter);
|
||||
}
|
||||
if (form.ldapMemberofAttribute != null) {
|
||||
fessConfig.setLdapMemberofAttribute(form.ldapMemberofAttribute);
|
||||
}
|
||||
if (form.notificationLogin != null) {
|
||||
fessConfig.setNotificationLogin(form.notificationLogin);
|
||||
}
|
||||
if (form.notificationSearchTop != null) {
|
||||
fessConfig.setNotificationSearchTop(form.notificationSearchTop);
|
||||
}
|
||||
|
||||
fessConfig.storeSystemProperties();
|
||||
ComponentUtil.getLdapManager().updateConfig();
|
||||
}
|
||||
|
||||
public static void updateForm(final FessConfig fessConfig, final EditForm form) {
|
||||
form.loginRequired = fessConfig.isLoginRequired() ? Constants.TRUE : Constants.FALSE;
|
||||
form.loginLink = fessConfig.isLoginLinkEnabled() ? Constants.TRUE : Constants.FALSE;
|
||||
form.thumbnail = fessConfig.isThumbnailEnabled() ? Constants.TRUE : Constants.FALSE;
|
||||
|
|
|
@ -59,6 +59,19 @@ public class ApiResult {
|
|||
}
|
||||
}
|
||||
|
||||
public static class ApiConfigResponse extends ApiResponse {
|
||||
protected Object config;
|
||||
|
||||
public ApiConfigResponse config(Object config) {
|
||||
this.config = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiResult result() {
|
||||
return new ApiResult(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApiErrorResponse extends ApiResponse {
|
||||
protected String message;
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright 2012-2017 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.api.admin.general;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.core.misc.DynamicProperties;
|
||||
import org.codelibs.fess.app.web.admin.general.AdminGeneralAction;
|
||||
import org.codelibs.fess.app.web.api.ApiResult;
|
||||
import org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse;
|
||||
import org.codelibs.fess.app.web.api.ApiResult.ApiResponse;
|
||||
import org.codelibs.fess.app.web.api.ApiResult.Status;
|
||||
import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.JsonResponse;
|
||||
|
||||
/**
|
||||
* @author shinsuke
|
||||
*/
|
||||
public class ApiAdminGeneralAction extends FessApiAdminAction {
|
||||
|
||||
// ===================================================================================
|
||||
// Attribute
|
||||
// =========
|
||||
@Resource
|
||||
protected DynamicProperties systemProperties;
|
||||
|
||||
// ===================================================================================
|
||||
//
|
||||
|
||||
// GET /api/admin/general
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> get$index() {
|
||||
final EditBody form = new EditBody();
|
||||
AdminGeneralAction.updateForm(fessConfig, form);
|
||||
form.ldapAdminSecurityCredentials = null;
|
||||
return asJson(new ApiConfigResponse().config(form).status(Status.OK).result());
|
||||
}
|
||||
|
||||
// POST /api/admin/general
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> post$index(final EditBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
// TODO skip null
|
||||
AdminGeneralAction.updateConfig(fessConfig, body);
|
||||
return asJson(new ApiResponse().status(Status.OK).result());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright 2012-2017 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.api.admin.general;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.general.EditForm;
|
||||
|
||||
public class EditBody extends EditForm {
|
||||
|
||||
}
|
|
@ -26,6 +26,7 @@ import org.codelibs.fess.mylasta.direction.sponsor.FessApiFailureHook;
|
|||
import org.codelibs.fess.mylasta.direction.sponsor.FessCookieResourceProvider;
|
||||
import org.codelibs.fess.mylasta.direction.sponsor.FessCurtainBeforeHook;
|
||||
import org.codelibs.fess.mylasta.direction.sponsor.FessCurtainFinallyHook;
|
||||
import org.codelibs.fess.mylasta.direction.sponsor.FessJsonResourceProvider;
|
||||
import org.codelibs.fess.mylasta.direction.sponsor.FessListedClassificationProvider;
|
||||
import org.codelibs.fess.mylasta.direction.sponsor.FessMailDeliveryDepartmentCreator;
|
||||
import org.codelibs.fess.mylasta.direction.sponsor.FessMultipartRequestHandler;
|
||||
|
@ -85,6 +86,11 @@ public class FessFwAssistantDirector extends CachedFwAssistantDirector {
|
|||
direction.directSecurity(createSecurityResourceProvider());
|
||||
direction.directTime(createTimeResourceProvider());
|
||||
direction.directMail(createFessMailDeliveryDepartmentCreator().create());
|
||||
direction.directJson(createJsonResourceProvider());
|
||||
}
|
||||
|
||||
protected FessJsonResourceProvider createJsonResourceProvider() {
|
||||
return new FessJsonResourceProvider();
|
||||
}
|
||||
|
||||
protected FessCurtainBeforeHook createCurtainBeforeHook() {
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright 2012-2017 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.mylasta.direction.sponsor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.dbflute.optional.OptionalThing;
|
||||
import org.lastaflute.core.json.JsonMappingOption;
|
||||
import org.lastaflute.core.json.JsonResourceProvider;
|
||||
import org.lastaflute.core.json.bind.JsonYourCollectionResource;
|
||||
import org.lastaflute.core.json.engine.GsonJsonEngine;
|
||||
import org.lastaflute.core.json.engine.RealJsonEngine;
|
||||
|
||||
import com.google.gson.FieldNamingPolicy;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.internal.bind.LaYourCollectionTypeAdapterFactory;
|
||||
|
||||
public class FessJsonResourceProvider implements JsonResourceProvider {
|
||||
public boolean isNullsSuppressed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isPrettyPrintSuppressed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public JsonMappingOption provideOption() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<JsonYourCollectionResource> provideYourCollections() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public RealJsonEngine swtichJsonEngine() {
|
||||
final boolean serializeNulls = !isNullsSuppressed();
|
||||
final boolean prettyPrinting = !isPrettyPrintSuppressed();
|
||||
final OptionalThing<JsonMappingOption> mappingOption =
|
||||
provideOption() != null ? OptionalThing.of(provideOption()) : OptionalThing.empty();
|
||||
return new GsonJsonEngine(builder -> {
|
||||
setupSerializeNullsSettings(builder, serializeNulls);
|
||||
setupPrettyPrintingSettings(builder, prettyPrinting);
|
||||
setupYourCollectionSettings(builder);
|
||||
builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
|
||||
}, op -> {
|
||||
mappingOption.ifPresent(another -> op.acceptAnother(another));
|
||||
});
|
||||
}
|
||||
|
||||
protected void setupSerializeNullsSettings(GsonBuilder builder, boolean serializeNulls) {
|
||||
if (serializeNulls) {
|
||||
builder.serializeNulls();
|
||||
}
|
||||
}
|
||||
|
||||
protected void setupPrettyPrintingSettings(GsonBuilder builder, boolean prettyPrinting) {
|
||||
if (prettyPrinting) {
|
||||
builder.setPrettyPrinting();
|
||||
}
|
||||
}
|
||||
|
||||
protected void setupYourCollectionSettings(GsonBuilder builder) {
|
||||
for (JsonYourCollectionResource resource : provideYourCollections()) {
|
||||
builder.registerTypeAdapterFactory(createYourCollectionTypeAdapterFactory(resource));
|
||||
}
|
||||
}
|
||||
|
||||
protected LaYourCollectionTypeAdapterFactory createYourCollectionTypeAdapterFactory(JsonYourCollectionResource resource) {
|
||||
return new LaYourCollectionTypeAdapterFactory(resource.getYourType(), resource.getYourCollectionCreator());
|
||||
}
|
||||
}
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package org.codelibs.fess.mylasta;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.codelibs.fess.unit.UnitFessTestCase;
|
||||
import org.dbflute.utflute.lastaflute.police.NonActionExtendsActionPolice;
|
||||
import org.dbflute.utflute.lastaflute.police.NonWebHasWebReferencePolice;
|
||||
|
@ -40,6 +42,16 @@ public class FessActionDefTest extends UnitFessTestCase {
|
|||
}
|
||||
|
||||
public void test_webPackageNinjaReferencePolice() throws Exception {
|
||||
policeStoryOfJavaClassChase(new WebPackageNinjaReferencePolice());
|
||||
policeStoryOfJavaClassChase(new WebPackageNinjaReferencePolice() {
|
||||
public void handle(File srcFile, Class<?> clazz) {
|
||||
final String webPackageKeyword = getWebPackageKeyword();
|
||||
if (!clazz.getName().contains(webPackageKeyword) ||
|
||||
// exclude app.web.api.admin packages
|
||||
clazz.getName().contains(".app.web.api.admin.")) {
|
||||
return;
|
||||
}
|
||||
check(srcFile, clazz, webPackageKeyword);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue