diff --git a/src/main/java/org/codelibs/fess/app/web/admin/duplicatehost/AdminDuplicatehostAction.java b/src/main/java/org/codelibs/fess/app/web/admin/duplicatehost/AdminDuplicatehostAction.java index 2538f2a10..7b7aae13e 100644 --- a/src/main/java/org/codelibs/fess/app/web/admin/duplicatehost/AdminDuplicatehostAction.java +++ b/src/main/java/org/codelibs/fess/app/web/admin/duplicatehost/AdminDuplicatehostAction.java @@ -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 getEntity(final CreateForm form, final String username, final long currentTime) { + public static OptionalEntity 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 getDuplicateHost(final CreateForm form) { + public static OptionalEntity 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 -> { diff --git a/src/main/java/org/codelibs/fess/app/web/admin/keymatch/AdminKeymatchAction.java b/src/main/java/org/codelibs/fess/app/web/admin/keymatch/AdminKeymatchAction.java index 92135d653..c159cd688 100644 --- a/src/main/java/org/codelibs/fess/app/web/admin/keymatch/AdminKeymatchAction.java +++ b/src/main/java/org/codelibs/fess/app/web/admin/keymatch/AdminKeymatchAction.java @@ -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 getEntity(final CreateForm form, final String username, final long currentTime) { + public static OptionalEntity 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 getKeyMatch(final CreateForm form) { + public static OptionalEntity 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 -> { diff --git a/src/main/java/org/codelibs/fess/app/web/admin/labeltype/AdminLabeltypeAction.java b/src/main/java/org/codelibs/fess/app/web/admin/labeltype/AdminLabeltypeAction.java index 3e7e4bbe8..162a34cbd 100644 --- a/src/main/java/org/codelibs/fess/app/web/admin/labeltype/AdminLabeltypeAction.java +++ b/src/main/java/org/codelibs/fess/app/web/admin/labeltype/AdminLabeltypeAction.java @@ -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 getEntity(final CreateForm form, final String username, final long currentTime) { + public static OptionalEntity 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 getLabelType(final CreateForm form) { + public static OptionalEntity 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( diff --git a/src/main/java/org/codelibs/fess/app/web/admin/log/AdminLogAction.java b/src/main/java/org/codelibs/fess/app/web/admin/log/AdminLogAction.java index 2418c9b54..ff3205ec1 100644 --- a/src/main/java/org/codelibs/fess/app/web/admin/log/AdminLogAction.java +++ b/src/main/java/org/codelibs/fess/app/web/admin/log/AdminLogAction.java @@ -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> getLogFileItems() { + public static List> getLogFileItems() { + final SystemHelper systemHelper = ComponentUtil.getSystemHelper(); final List> logFileItems = new ArrayList<>(); final String logFilePath = systemHelper.getLogFilePath(); if (StringUtil.isNotBlank(logFilePath)) { diff --git a/src/main/java/org/codelibs/fess/app/web/api/ApiResult.java b/src/main/java/org/codelibs/fess/app/web/api/ApiResult.java index f922c4c26..fedc9970a 100644 --- a/src/main/java/org/codelibs/fess/app/web/api/ApiResult.java +++ b/src/main/java/org/codelibs/fess/app/web/api/ApiResult.java @@ -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 extends ApiResponse { + protected List logs; + protected long total = 0; + + public ApiLogsResponse logs(final List logs) { + this.logs = logs; + return this; + } + + public ApiLogsResponse 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> logfiles; + protected long total = 0; + + public ApiLogFilesResponse logfiles(final List> 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; diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/dataconfig/ApiAdminDataconfigAction.java b/src/main/java/org/codelibs/fess/app/web/api/admin/dataconfig/ApiAdminDataconfigAction.java index ebb98ed8a..3e7b512d3 100644 --- a/src/main/java/org/codelibs/fess/app/web/api/admin/dataconfig/ApiAdminDataconfigAction.java +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/dataconfig/ApiAdminDataconfigAction.java @@ -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 settings(final SearchBody body) { validateApi(body, messages -> {}); diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/ApiAdminDuplicatehostAction.java b/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/ApiAdminDuplicatehostAction.java new file mode 100644 index 000000000..3b41fb801 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/ApiAdminDuplicatehostAction.java @@ -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 settings(final SearchBody body) { + validateApi(body, messages -> {}); + final DuplicateHostPager pager = new DuplicateHostPager(); + copyBeanToBean(body, pager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE)); + final List list = duplicateHostService.getDuplicateHostList(pager); + return asJson(new ApiResult.ApiConfigsResponse() + .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 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 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 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 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; + } +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/CreateBody.java b/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/CreateBody.java new file mode 100644 index 000000000..b00461822 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/CreateBody.java @@ -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 { + +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/EditBody.java b/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/EditBody.java new file mode 100644 index 000000000..c97143fab --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/EditBody.java @@ -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 { + +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/SearchBody.java b/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/SearchBody.java new file mode 100644 index 000000000..42af9d558 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/duplicatehost/SearchBody.java @@ -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 { + +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/fileconfig/ApiAdminFileconfigAction.java b/src/main/java/org/codelibs/fess/app/web/api/admin/fileconfig/ApiAdminFileconfigAction.java index a356eb62a..a1ded4716 100644 --- a/src/main/java/org/codelibs/fess/app/web/api/admin/fileconfig/ApiAdminFileconfigAction.java +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/fileconfig/ApiAdminFileconfigAction.java @@ -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 settings(final SearchBody body) { validateApi(body, messages -> {}); diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/joblog/ApiAdminJoblogAction.java b/src/main/java/org/codelibs/fess/app/web/api/admin/joblog/ApiAdminJoblogAction.java new file mode 100644 index 000000000..1a3dbb1ed --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/joblog/ApiAdminJoblogAction.java @@ -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 logs(final SearchBody body) { + validateApi(body, messages -> {}); + final JobLogPager pager = new JobLogPager(); + copyBeanToBean(body, pager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE)); + final List list = jobLogService.getJobLogList(pager); + return asJson(new ApiResult.ApiLogsResponse() + .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 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 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; + } +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/joblog/EditBody.java b/src/main/java/org/codelibs/fess/app/web/api/admin/joblog/EditBody.java new file mode 100644 index 000000000..21ad532c7 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/joblog/EditBody.java @@ -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 { + +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/joblog/SearchBody.java b/src/main/java/org/codelibs/fess/app/web/api/admin/joblog/SearchBody.java new file mode 100644 index 000000000..cd7015e4b --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/joblog/SearchBody.java @@ -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 { + +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/ApiAdminKeymatchAction.java b/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/ApiAdminKeymatchAction.java new file mode 100644 index 000000000..57aab6703 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/ApiAdminKeymatchAction.java @@ -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 settings(final SearchBody body) { + validateApi(body, messages -> {}); + final KeyMatchPager pager = new KeyMatchPager(); + copyBeanToBean(body, pager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE)); + final List list = keyMatchService.getKeyMatchList(pager); + return asJson(new ApiResult.ApiConfigsResponse() + .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 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 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 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 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; + } +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/CreateBody.java b/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/CreateBody.java new file mode 100644 index 000000000..e02f064e2 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/CreateBody.java @@ -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 { + +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/EditBody.java b/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/EditBody.java new file mode 100644 index 000000000..5eddfab82 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/EditBody.java @@ -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 { + +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/SearchBody.java b/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/SearchBody.java new file mode 100644 index 000000000..f9800818a --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/keymatch/SearchBody.java @@ -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 { + +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/ApiAdminLabeltypeAction.java b/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/ApiAdminLabeltypeAction.java new file mode 100644 index 000000000..a5fd346c4 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/ApiAdminLabeltypeAction.java @@ -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 settings(final SearchBody body) { + validateApi(body, messages -> {}); + final LabelTypePager pager = new LabelTypePager(); + copyBeanToBean(body, pager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE)); + final List list = labelTypeService.getLabelTypeList(pager); + return asJson(new ApiResult.ApiConfigsResponse() + .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 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 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 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 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; + } +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/CreateBody.java b/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/CreateBody.java new file mode 100644 index 000000000..1f64423cf --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/CreateBody.java @@ -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 { + +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/EditBody.java b/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/EditBody.java new file mode 100644 index 000000000..913ac22a5 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/EditBody.java @@ -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 { + +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/SearchBody.java b/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/SearchBody.java new file mode 100644 index 000000000..11f6d6fe4 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/labeltype/SearchBody.java @@ -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 { + +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/log/ApiAdminLogAction.java b/src/main/java/org/codelibs/fess/app/web/api/admin/log/ApiAdminLogAction.java new file mode 100644 index 000000000..f019d4de1 --- /dev/null +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/log/ApiAdminLogAction.java @@ -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 logfiles() { + List> 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(); + } +} diff --git a/src/main/java/org/codelibs/fess/app/web/api/admin/webconfig/ApiAdminWebconfigAction.java b/src/main/java/org/codelibs/fess/app/web/api/admin/webconfig/ApiAdminWebconfigAction.java index 963abed21..2bd2d49c2 100644 --- a/src/main/java/org/codelibs/fess/app/web/api/admin/webconfig/ApiAdminWebconfigAction.java +++ b/src/main/java/org/codelibs/fess/app/web/api/admin/webconfig/ApiAdminWebconfigAction.java @@ -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 settings(final SearchBody body) { validateApi(body, messages -> {});