Merge pull request #997 from kw-udon/add-admin-apis
Add several Admin APIs
This commit is contained in:
commit
d2975547ad
24 changed files with 901 additions and 16 deletions
|
@ -23,6 +23,8 @@ import org.codelibs.fess.app.service.DuplicateHostService;
|
|||
import org.codelibs.fess.app.web.CrudMode;
|
||||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.es.config.exentity.DuplicateHost;
|
||||
import org.codelibs.fess.helper.SystemHelper;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.RenderDataUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
import org.dbflute.optional.OptionalThing;
|
||||
|
@ -225,7 +227,7 @@ public class AdminDuplicatehostAction extends FessAdminAction {
|
|||
// ===================================================================================
|
||||
// Assist Logic
|
||||
// ============
|
||||
private OptionalEntity<DuplicateHost> getEntity(final CreateForm form, final String username, final long currentTime) {
|
||||
public static OptionalEntity<DuplicateHost> getEntity(final CreateForm form, final String username, final long currentTime) {
|
||||
switch (form.crudMode) {
|
||||
case CrudMode.CREATE:
|
||||
return OptionalEntity.of(new DuplicateHost()).map(entity -> {
|
||||
|
@ -235,7 +237,7 @@ public class AdminDuplicatehostAction extends FessAdminAction {
|
|||
});
|
||||
case CrudMode.EDIT:
|
||||
if (form instanceof EditForm) {
|
||||
return duplicateHostService.getDuplicateHost(((EditForm) form).id);
|
||||
return ComponentUtil.getComponent(DuplicateHostService.class).getDuplicateHost(((EditForm) form).id);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -244,7 +246,8 @@ public class AdminDuplicatehostAction extends FessAdminAction {
|
|||
return OptionalEntity.empty();
|
||||
}
|
||||
|
||||
protected OptionalEntity<DuplicateHost> getDuplicateHost(final CreateForm form) {
|
||||
public static OptionalEntity<DuplicateHost> getDuplicateHost(final CreateForm form) {
|
||||
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
|
||||
final String username = systemHelper.getUsername();
|
||||
final long currentTime = systemHelper.getCurrentTimeAsLong();
|
||||
return getEntity(form, username, currentTime).map(entity -> {
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.codelibs.fess.app.web.CrudMode;
|
|||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.es.config.exentity.KeyMatch;
|
||||
import org.codelibs.fess.helper.KeyMatchHelper;
|
||||
import org.codelibs.fess.helper.SystemHelper;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.RenderDataUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
|
@ -241,7 +242,7 @@ public class AdminKeymatchAction extends FessAdminAction {
|
|||
// Assist Logic
|
||||
// ============
|
||||
|
||||
private OptionalEntity<KeyMatch> getEntity(final CreateForm form, final String username, final long currentTime) {
|
||||
public static OptionalEntity<KeyMatch> getEntity(final CreateForm form, final String username, final long currentTime) {
|
||||
switch (form.crudMode) {
|
||||
case CrudMode.CREATE:
|
||||
return OptionalEntity.of(new KeyMatch()).map(entity -> {
|
||||
|
@ -251,7 +252,7 @@ public class AdminKeymatchAction extends FessAdminAction {
|
|||
});
|
||||
case CrudMode.EDIT:
|
||||
if (form instanceof EditForm) {
|
||||
return keyMatchService.getKeyMatch(((EditForm) form).id);
|
||||
return ComponentUtil.getComponent(KeyMatchService.class).getKeyMatch(((EditForm) form).id);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -260,7 +261,8 @@ public class AdminKeymatchAction extends FessAdminAction {
|
|||
return OptionalEntity.empty();
|
||||
}
|
||||
|
||||
protected OptionalEntity<KeyMatch> getKeyMatch(final CreateForm form) {
|
||||
public static OptionalEntity<KeyMatch> getKeyMatch(final CreateForm form) {
|
||||
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
|
||||
final String username = systemHelper.getUsername();
|
||||
final long currentTime = systemHelper.getCurrentTimeAsLong();
|
||||
return getEntity(form, username, currentTime).map(entity -> {
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.codelibs.fess.app.web.CrudMode;
|
|||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.es.config.exentity.LabelType;
|
||||
import org.codelibs.fess.helper.PermissionHelper;
|
||||
import org.codelibs.fess.helper.SystemHelper;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.RenderDataUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
|
@ -268,7 +269,7 @@ public class AdminLabeltypeAction extends FessAdminAction {
|
|||
// Assist Logic
|
||||
// ============
|
||||
|
||||
private OptionalEntity<LabelType> getEntity(final CreateForm form, final String username, final long currentTime) {
|
||||
public static OptionalEntity<LabelType> getEntity(final CreateForm form, final String username, final long currentTime) {
|
||||
switch (form.crudMode) {
|
||||
case CrudMode.CREATE:
|
||||
return OptionalEntity.of(new LabelType()).map(entity -> {
|
||||
|
@ -278,7 +279,7 @@ public class AdminLabeltypeAction extends FessAdminAction {
|
|||
});
|
||||
case CrudMode.EDIT:
|
||||
if (form instanceof EditForm) {
|
||||
return labelTypeService.getLabelType(((EditForm) form).id);
|
||||
return ComponentUtil.getComponent(LabelTypeService.class).getLabelType(((EditForm) form).id);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -287,7 +288,8 @@ public class AdminLabeltypeAction extends FessAdminAction {
|
|||
return OptionalEntity.empty();
|
||||
}
|
||||
|
||||
protected OptionalEntity<LabelType> getLabelType(final CreateForm form) {
|
||||
public static OptionalEntity<LabelType> getLabelType(final CreateForm form) {
|
||||
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
|
||||
final String username = systemHelper.getUsername();
|
||||
final long currentTime = systemHelper.getCurrentTimeAsLong();
|
||||
return getEntity(form, username, currentTime).map(
|
||||
|
|
|
@ -32,6 +32,8 @@ import java.util.stream.Stream;
|
|||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.exception.FessSystemException;
|
||||
import org.codelibs.fess.helper.SystemHelper;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.RenderDataUtil;
|
||||
import org.lastaflute.di.exception.IORuntimeException;
|
||||
import org.lastaflute.web.Execute;
|
||||
|
@ -74,7 +76,8 @@ public class AdminLogAction extends FessAdminAction {
|
|||
return redirect(getClass()); // no-op
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getLogFileItems() {
|
||||
public static List<Map<String, Object>> getLogFileItems() {
|
||||
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
|
||||
final List<Map<String, Object>> logFileItems = new ArrayList<>();
|
||||
final String logFilePath = systemHelper.getLogFilePath();
|
||||
if (StringUtil.isNotBlank(logFilePath)) {
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.codelibs.fess.app.web.api;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.codelibs.fess.Constants;
|
||||
|
@ -114,6 +115,60 @@ public class ApiResult {
|
|||
}
|
||||
}
|
||||
|
||||
public static class ApiLogResponse extends ApiResponse {
|
||||
protected Object log;
|
||||
|
||||
public ApiLogResponse log(final Object log) {
|
||||
this.log = log;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult result() {
|
||||
return new ApiResult(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApiLogsResponse<T> extends ApiResponse {
|
||||
protected List<T> logs;
|
||||
protected long total = 0;
|
||||
|
||||
public ApiLogsResponse<T> logs(final List<T> logs) {
|
||||
this.logs = logs;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiLogsResponse<T> total(final long total) {
|
||||
this.total = total;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult result() {
|
||||
return new ApiResult(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApiLogFilesResponse extends ApiResponse {
|
||||
protected List<Map<String, Object>> logfiles;
|
||||
protected long total = 0;
|
||||
|
||||
public ApiLogFilesResponse logfiles(final List<Map<String, Object>> logfiles) {
|
||||
this.logfiles = logfiles;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApiLogFilesResponse total(final long total) {
|
||||
this.total = total;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult result() {
|
||||
return new ApiResult(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ApiErrorResponse extends ApiResponse {
|
||||
protected String message;
|
||||
|
||||
|
|
|
@ -51,8 +51,8 @@ public class ApiAdminDataconfigAction extends FessApiAdminAction {
|
|||
// Search Execute
|
||||
// ==============
|
||||
|
||||
// GET /api/admin/dataconfig
|
||||
// POST /api/admin/dataconfig
|
||||
// GET /api/admin/dataconfig/settings
|
||||
// POST /api/admin/dataconfig/settings
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> settings(final SearchBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* 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.duplicatehost;
|
||||
|
||||
import static org.codelibs.fess.app.web.admin.duplicatehost.AdminDuplicatehostAction.getDuplicateHost;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.pager.DuplicateHostPager;
|
||||
import org.codelibs.fess.app.service.DuplicateHostService;
|
||||
import org.codelibs.fess.app.web.CrudMode;
|
||||
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.ApiUpdateResponse;
|
||||
import org.codelibs.fess.app.web.api.ApiResult.Status;
|
||||
import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
|
||||
import org.codelibs.fess.es.config.exentity.DuplicateHost;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.JsonResponse;
|
||||
|
||||
/**
|
||||
* @author Keiichi Watanabe
|
||||
*/
|
||||
public class ApiAdminDuplicatehostAction extends FessApiAdminAction {
|
||||
|
||||
// ===================================================================================
|
||||
// Attribute
|
||||
// =========
|
||||
@Resource
|
||||
private DuplicateHostService duplicateHostService;
|
||||
|
||||
// ===================================================================================
|
||||
// Search Execute
|
||||
// ==============
|
||||
|
||||
// GET /api/admin/duplicatehost/settings
|
||||
// POST /api/admin/duplicatehost/settings
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> settings(final SearchBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
final DuplicateHostPager pager = new DuplicateHostPager();
|
||||
copyBeanToBean(body, pager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
|
||||
final List<DuplicateHost> list = duplicateHostService.getDuplicateHostList(pager);
|
||||
return asJson(new ApiResult.ApiConfigsResponse<EditBody>()
|
||||
.settings(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList()))
|
||||
.total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
|
||||
}
|
||||
|
||||
// GET /api/admin/duplicatehost/setting/{id}
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> get$setting(final String id) {
|
||||
return asJson(new ApiConfigResponse()
|
||||
.setting(duplicateHostService.getDuplicateHost(id).map(entity -> createEditBody(entity)).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
|
||||
return null;
|
||||
})).status(Status.OK).result());
|
||||
}
|
||||
|
||||
// PUT /api/admin/duplicatehost/setting
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
body.crudMode = CrudMode.CREATE;
|
||||
final DuplicateHost duplicateHost = getDuplicateHost(body).map(entity -> {
|
||||
try {
|
||||
duplicateHostService.store(entity);
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
return entity;
|
||||
}).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
|
||||
return null;
|
||||
});
|
||||
|
||||
return asJson(new ApiUpdateResponse().id(duplicateHost.getId()).created(true).status(Status.OK).result());
|
||||
}
|
||||
|
||||
// POST /api/admin/duplicatehost/setting
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> post$setting(final EditBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
body.crudMode = CrudMode.EDIT;
|
||||
final DuplicateHost duplicateHost = getDuplicateHost(body).map(entity -> {
|
||||
try {
|
||||
duplicateHostService.store(entity);
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
return entity;
|
||||
}).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id));
|
||||
return null;
|
||||
});
|
||||
return asJson(new ApiUpdateResponse().id(duplicateHost.getId()).created(false).status(Status.OK).result());
|
||||
}
|
||||
|
||||
// DELETE /api/admin/duplicatehost/setting/{id}
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> delete$setting(final String id) {
|
||||
duplicateHostService.getDuplicateHost(id).ifPresent(entity -> {
|
||||
try {
|
||||
duplicateHostService.delete(entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
}).orElse(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
|
||||
});
|
||||
return asJson(new ApiResponse().status(Status.OK).result());
|
||||
}
|
||||
|
||||
protected EditBody createEditBody(final DuplicateHost entity) {
|
||||
final EditBody body = new EditBody();
|
||||
copyBeanToBean(entity, body, copyOp -> {
|
||||
copyOp.excludeNull();
|
||||
});
|
||||
return body;
|
||||
}
|
||||
}
|
|
@ -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.duplicatehost;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.duplicatehost.CreateForm;
|
||||
|
||||
public class CreateBody extends CreateForm {
|
||||
|
||||
}
|
|
@ -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.duplicatehost;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.duplicatehost.EditForm;
|
||||
|
||||
public class EditBody extends EditForm {
|
||||
|
||||
}
|
|
@ -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.duplicatehost;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.duplicatehost.SearchForm;
|
||||
|
||||
public class SearchBody extends SearchForm {
|
||||
|
||||
}
|
|
@ -51,8 +51,8 @@ public class ApiAdminFileconfigAction extends FessApiAdminAction {
|
|||
// Search Execute
|
||||
// ==============
|
||||
|
||||
// GET /api/admin/fileconfig
|
||||
// POST /api/admin/fileconfig
|
||||
// GET /api/admin/fileconfig/settings
|
||||
// POST /api/admin/fileconfig/settings
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> settings(final SearchBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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.joblog;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.pager.JobLogPager;
|
||||
import org.codelibs.fess.app.service.JobLogService;
|
||||
import org.codelibs.fess.app.web.api.ApiResult;
|
||||
import org.codelibs.fess.app.web.api.ApiResult.ApiLogResponse;
|
||||
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.codelibs.fess.es.config.exentity.JobLog;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.JsonResponse;
|
||||
|
||||
/**
|
||||
* @author Keiichi Watanabe
|
||||
*/
|
||||
public class ApiAdminJoblogAction extends FessApiAdminAction {
|
||||
|
||||
// ===================================================================================
|
||||
// Attribute
|
||||
// =========
|
||||
@Resource
|
||||
private JobLogService jobLogService;
|
||||
|
||||
// ===================================================================================
|
||||
// Search Execute
|
||||
// ==============
|
||||
|
||||
// GET /api/admin/joblog/logs
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> logs(final SearchBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
final JobLogPager pager = new JobLogPager();
|
||||
copyBeanToBean(body, pager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
|
||||
final List<JobLog> list = jobLogService.getJobLogList(pager);
|
||||
return asJson(new ApiResult.ApiLogsResponse<EditBody>()
|
||||
.logs(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList())).total(pager.getAllRecordCount())
|
||||
.status(ApiResult.Status.OK).result());
|
||||
}
|
||||
|
||||
// GET /api/admin/joblog/log/{id}
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> get$log(final String id) {
|
||||
return asJson(new ApiLogResponse().log(jobLogService.getJobLog(id).map(entity -> createEditBody(entity)).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
|
||||
return null;
|
||||
})).status(Status.OK).result());
|
||||
}
|
||||
|
||||
// DELETE /api/admin/joblog/log/{id}
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> delete$log(final String id) {
|
||||
jobLogService.getJobLog(id).ifPresent(entity -> {
|
||||
try {
|
||||
jobLogService.delete(entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
}).orElse(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
|
||||
});
|
||||
return asJson(new ApiResponse().status(Status.OK).result());
|
||||
}
|
||||
|
||||
protected EditBody createEditBody(final JobLog entity) {
|
||||
final EditBody body = new EditBody();
|
||||
copyBeanToBean(entity, body, copyOp -> {
|
||||
copyOp.excludeNull();
|
||||
});
|
||||
return body;
|
||||
}
|
||||
}
|
|
@ -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.joblog;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.joblog.EditForm;
|
||||
|
||||
public class EditBody extends EditForm {
|
||||
|
||||
}
|
|
@ -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.joblog;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.joblog.SearchForm;
|
||||
|
||||
public class SearchBody extends SearchForm {
|
||||
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* 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.keymatch;
|
||||
|
||||
import static org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.pager.KeyMatchPager;
|
||||
import org.codelibs.fess.app.service.KeyMatchService;
|
||||
import org.codelibs.fess.app.web.CrudMode;
|
||||
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.ApiUpdateResponse;
|
||||
import org.codelibs.fess.app.web.api.ApiResult.Status;
|
||||
import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
|
||||
import org.codelibs.fess.es.config.exentity.KeyMatch;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.JsonResponse;
|
||||
|
||||
/**
|
||||
* @author Keiichi Watanabe
|
||||
*/
|
||||
public class ApiAdminKeymatchAction extends FessApiAdminAction {
|
||||
|
||||
// ===================================================================================
|
||||
// Attribute
|
||||
// =========
|
||||
@Resource
|
||||
private KeyMatchService keyMatchService;
|
||||
|
||||
// ===================================================================================
|
||||
// Search Execute
|
||||
// ==============
|
||||
|
||||
// GET /api/admin/keymatch/settings
|
||||
// POST /api/admin/keymatch/settings
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> settings(final SearchBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
final KeyMatchPager pager = new KeyMatchPager();
|
||||
copyBeanToBean(body, pager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
|
||||
final List<KeyMatch> list = keyMatchService.getKeyMatchList(pager);
|
||||
return asJson(new ApiResult.ApiConfigsResponse<EditBody>()
|
||||
.settings(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList()))
|
||||
.total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
|
||||
}
|
||||
|
||||
// GET /api/admin/keymatch/setting/{id}
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> get$setting(final String id) {
|
||||
return asJson(new ApiConfigResponse()
|
||||
.setting(keyMatchService.getKeyMatch(id).map(entity -> createEditBody(entity)).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
|
||||
return null;
|
||||
})).status(Status.OK).result());
|
||||
}
|
||||
|
||||
// PUT /api/admin/keymatch/setting
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
body.crudMode = CrudMode.CREATE;
|
||||
final KeyMatch keyMatch = getKeyMatch(body).map(entity -> {
|
||||
try {
|
||||
keyMatchService.store(entity);
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
return entity;
|
||||
}).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
|
||||
return null;
|
||||
});
|
||||
|
||||
return asJson(new ApiUpdateResponse().id(keyMatch.getId()).created(true).status(Status.OK).result());
|
||||
}
|
||||
|
||||
// POST /api/admin/keymatch/setting
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> post$setting(final EditBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
body.crudMode = CrudMode.EDIT;
|
||||
final KeyMatch keyMatch = getKeyMatch(body).map(entity -> {
|
||||
try {
|
||||
keyMatchService.store(entity);
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
return entity;
|
||||
}).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id));
|
||||
return null;
|
||||
});
|
||||
return asJson(new ApiUpdateResponse().id(keyMatch.getId()).created(false).status(Status.OK).result());
|
||||
}
|
||||
|
||||
// DELETE /api/admin/keymatch/setting/{id}
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> delete$setting(final String id) {
|
||||
keyMatchService.getKeyMatch(id).ifPresent(entity -> {
|
||||
try {
|
||||
keyMatchService.delete(entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
}).orElse(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
|
||||
});
|
||||
return asJson(new ApiResponse().status(Status.OK).result());
|
||||
}
|
||||
|
||||
protected EditBody createEditBody(final KeyMatch entity) {
|
||||
final EditBody body = new EditBody();
|
||||
copyBeanToBean(entity, body, copyOp -> {
|
||||
copyOp.excludeNull();
|
||||
});
|
||||
return body;
|
||||
}
|
||||
}
|
|
@ -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.keymatch;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.keymatch.CreateForm;
|
||||
|
||||
public class CreateBody extends CreateForm {
|
||||
|
||||
}
|
|
@ -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.keymatch;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.keymatch.EditForm;
|
||||
|
||||
public class EditBody extends EditForm {
|
||||
|
||||
}
|
|
@ -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.keymatch;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.keymatch.SearchForm;
|
||||
|
||||
public class SearchBody extends SearchForm {
|
||||
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* 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.labeltype;
|
||||
|
||||
import static org.codelibs.fess.app.web.admin.labeltype.AdminLabeltypeAction.getLabelType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.pager.LabelTypePager;
|
||||
import org.codelibs.fess.app.service.LabelTypeService;
|
||||
import org.codelibs.fess.app.web.CrudMode;
|
||||
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.ApiUpdateResponse;
|
||||
import org.codelibs.fess.app.web.api.ApiResult.Status;
|
||||
import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
|
||||
import org.codelibs.fess.es.config.exentity.LabelType;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.JsonResponse;
|
||||
|
||||
/**
|
||||
* @author Keiichi Watanabe
|
||||
*/
|
||||
public class ApiAdminLabeltypeAction extends FessApiAdminAction {
|
||||
|
||||
// ===================================================================================
|
||||
// Attribute
|
||||
// =========
|
||||
@Resource
|
||||
private LabelTypeService labelTypeService;
|
||||
|
||||
// ===================================================================================
|
||||
// Search Execute
|
||||
// ==============
|
||||
|
||||
// GET /api/admin/labeltype/settings
|
||||
// POST /api/admin/labeltype/settings
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> settings(final SearchBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
final LabelTypePager pager = new LabelTypePager();
|
||||
copyBeanToBean(body, pager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
|
||||
final List<LabelType> list = labelTypeService.getLabelTypeList(pager);
|
||||
return asJson(new ApiResult.ApiConfigsResponse<EditBody>()
|
||||
.settings(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList()))
|
||||
.total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
|
||||
}
|
||||
|
||||
// GET /api/admin/labeltype/setting/{id}
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> get$setting(final String id) {
|
||||
return asJson(new ApiConfigResponse()
|
||||
.setting(labelTypeService.getLabelType(id).map(entity -> createEditBody(entity)).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
|
||||
return null;
|
||||
})).status(Status.OK).result());
|
||||
}
|
||||
|
||||
// PUT /api/admin/labeltype/setting
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
body.crudMode = CrudMode.CREATE;
|
||||
final LabelType labelType = getLabelType(body).map(entity -> {
|
||||
try {
|
||||
labelTypeService.store(entity);
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
return entity;
|
||||
}).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
|
||||
return null;
|
||||
});
|
||||
|
||||
return asJson(new ApiUpdateResponse().id(labelType.getId()).created(true).status(Status.OK).result());
|
||||
}
|
||||
|
||||
// POST /api/admin/labeltype/setting
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> post$setting(final EditBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
body.crudMode = CrudMode.EDIT;
|
||||
final LabelType labelType = getLabelType(body).map(entity -> {
|
||||
try {
|
||||
labelTypeService.store(entity);
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
return entity;
|
||||
}).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id));
|
||||
return null;
|
||||
});
|
||||
return asJson(new ApiUpdateResponse().id(labelType.getId()).created(false).status(Status.OK).result());
|
||||
}
|
||||
|
||||
// DELETE /api/admin/labeltype/setting/{id}
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> delete$setting(final String id) {
|
||||
labelTypeService.getLabelType(id).ifPresent(entity -> {
|
||||
try {
|
||||
labelTypeService.delete(entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
}).orElse(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
|
||||
});
|
||||
return asJson(new ApiResponse().status(Status.OK).result());
|
||||
}
|
||||
|
||||
protected EditBody createEditBody(final LabelType entity) {
|
||||
final EditBody body = new EditBody();
|
||||
copyBeanToBean(entity, body, copyOp -> {
|
||||
copyOp.excludeNull();
|
||||
});
|
||||
return body;
|
||||
}
|
||||
}
|
|
@ -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.labeltype;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.labeltype.CreateForm;
|
||||
|
||||
public class CreateBody extends CreateForm {
|
||||
|
||||
}
|
|
@ -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.labeltype;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.labeltype.EditForm;
|
||||
|
||||
public class EditBody extends EditForm {
|
||||
|
||||
}
|
|
@ -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.labeltype;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.labeltype.SearchForm;
|
||||
|
||||
public class SearchBody extends SearchForm {
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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.log;
|
||||
|
||||
import static org.codelibs.fess.app.web.admin.log.AdminLogAction.getLogFileItems;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.app.web.api.ApiResult;
|
||||
import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.JsonResponse;
|
||||
import org.lastaflute.web.response.StreamResponse;
|
||||
|
||||
/**
|
||||
* @author Keiichi Watanabe
|
||||
*/
|
||||
public class ApiAdminLogAction extends FessApiAdminAction {
|
||||
|
||||
// ===================================================================================
|
||||
// Search Execute
|
||||
// ==============
|
||||
|
||||
// GET /api/admin/log/logfiles
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> logfiles() {
|
||||
List<Map<String, Object>> list = getLogFileItems();
|
||||
return asJson(new ApiResult.ApiLogFilesResponse().logfiles(list).total(list.size()).status(ApiResult.Status.OK).result());
|
||||
}
|
||||
|
||||
// GET /api/admin/log/logfile/{id}
|
||||
@Execute
|
||||
public StreamResponse get$logfile(final String id) {
|
||||
final String filename = new String(Base64.getDecoder().decode(id), StandardCharsets.UTF_8).replace("..", "").replaceAll("\\s", "");
|
||||
final String logFilePath = systemHelper.getLogFilePath();
|
||||
if (StringUtil.isNotBlank(logFilePath)) {
|
||||
final Path path = Paths.get(logFilePath, filename);
|
||||
return asStream(filename).contentTypeOctetStream().stream(out -> {
|
||||
try (InputStream in = Files.newInputStream(path)) {
|
||||
out.write(in);
|
||||
}
|
||||
});
|
||||
}
|
||||
return StreamResponse.asEmptyBody();
|
||||
}
|
||||
}
|
|
@ -51,8 +51,8 @@ public class ApiAdminWebconfigAction extends FessApiAdminAction {
|
|||
// Search Execute
|
||||
// ==============
|
||||
|
||||
// GET /api/admin/webconfig
|
||||
// POST /api/admin/webconfig
|
||||
// GET /api/admin/webconfig/settings
|
||||
// POST /api/admin/webconfig/settings
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> settings(final SearchBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
|
|
Loading…
Add table
Reference in a new issue