fix #979
This commit is contained in:
parent
e748a84d3f
commit
d0e30815ad
5 changed files with 162 additions and 3 deletions
|
@ -27,6 +27,8 @@ import org.codelibs.fess.app.web.CrudMode;
|
|||
import org.codelibs.fess.app.web.base.FessAdminAction;
|
||||
import org.codelibs.fess.es.config.exentity.ScheduledJob;
|
||||
import org.codelibs.fess.helper.ProcessHelper;
|
||||
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;
|
||||
|
@ -321,7 +323,7 @@ public class AdminSchedulerAction extends FessAdminAction {
|
|||
form.available = entity.isEnabled() ? Constants.ON : null;
|
||||
}
|
||||
|
||||
private OptionalEntity<ScheduledJob> getEntity(final CreateForm form, final String username, final long currentTime) {
|
||||
private static OptionalEntity<ScheduledJob> getEntity(final CreateForm form, final String username, final long currentTime) {
|
||||
switch (form.crudMode) {
|
||||
case CrudMode.CREATE:
|
||||
return OptionalEntity.of(new ScheduledJob()).map(entity -> {
|
||||
|
@ -331,7 +333,7 @@ public class AdminSchedulerAction extends FessAdminAction {
|
|||
});
|
||||
case CrudMode.EDIT:
|
||||
if (form instanceof EditForm) {
|
||||
return scheduledJobService.getScheduledJob(((EditForm) form).id);
|
||||
return ComponentUtil.getComponent(ScheduledJobService.class).getScheduledJob(((EditForm) form).id);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -340,7 +342,8 @@ public class AdminSchedulerAction extends FessAdminAction {
|
|||
return OptionalEntity.empty();
|
||||
}
|
||||
|
||||
protected OptionalEntity<ScheduledJob> getScheduledJob(final CreateForm form) {
|
||||
public static OptionalEntity<ScheduledJob> getScheduledJob(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 -> {
|
||||
|
|
|
@ -17,15 +17,24 @@ package org.codelibs.fess.app.web.api.admin.scheduler;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.pager.SchedulerPager;
|
||||
import org.codelibs.fess.app.service.ScheduledJobService;
|
||||
import org.codelibs.fess.app.web.CrudMode;
|
||||
import org.codelibs.fess.app.web.api.ApiResult;
|
||||
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.ScheduledJob;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.HtmlResponse;
|
||||
import org.lastaflute.web.response.JsonResponse;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.codelibs.fess.app.web.admin.scheduler.AdminSchedulerAction.getScheduledJob;
|
||||
|
||||
public class ApiAdminSchedulerAction extends FessApiAdminAction {
|
||||
|
||||
@Resource
|
||||
|
@ -79,4 +88,88 @@ public class ApiAdminSchedulerAction extends FessApiAdminAction {
|
|||
return asJson(new ApiResponse().status(Status.OK).result());
|
||||
}
|
||||
|
||||
// GET /api/admin/scheduler
|
||||
// POST /api/admin/scheduler
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> settings(final SearchBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
final SchedulerPager pager = new SchedulerPager();
|
||||
copyBeanToBean(body, pager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
|
||||
final List<ScheduledJob> list = scheduledJobService.getScheduledJobList(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/scheduler/setting/{id}
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> get$setting(final String id) {
|
||||
return asJson(new ApiResult.ApiConfigResponse()
|
||||
.setting(scheduledJobService.getScheduledJob(id).map(entity -> createEditBody(entity)).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
|
||||
return null;
|
||||
})).status(ApiResult.Status.OK).result());
|
||||
}
|
||||
|
||||
// PUT /api/admin/scheduler/setting
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
body.crudMode = CrudMode.CREATE;
|
||||
final ScheduledJob entity = getScheduledJob(body).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> {
|
||||
messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
|
||||
});
|
||||
return null;
|
||||
});
|
||||
try {
|
||||
scheduledJobService.store(entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(true).status(ApiResult.Status.OK).result());
|
||||
}
|
||||
|
||||
// POST /api/admin/scheduler/setting
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> post$setting(final EditBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
body.crudMode = CrudMode.EDIT;
|
||||
final ScheduledJob entity = getScheduledJob(body).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> {
|
||||
messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id);
|
||||
});
|
||||
return null;
|
||||
});
|
||||
try {
|
||||
scheduledJobService.store(entity);
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(false).status(ApiResult.Status.OK).result());
|
||||
}
|
||||
|
||||
// DELETE /api/admin/scheduler/setting/{id}
|
||||
@Execute
|
||||
public JsonResponse<ApiResult> delete$setting(final String id) {
|
||||
final ScheduledJob entity = scheduledJobService.getScheduledJob(id).orElseGet(() -> {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
|
||||
return null;
|
||||
});
|
||||
try {
|
||||
scheduledJobService.delete(entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
|
||||
} catch (final Exception e) {
|
||||
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
|
||||
}
|
||||
return asJson(new ApiResult.ApiUpdateResponse().id(id).created(false).status(ApiResult.Status.OK).result());
|
||||
}
|
||||
|
||||
protected EditBody createEditBody(final ScheduledJob entity) {
|
||||
final EditBody body = new EditBody();
|
||||
copyBeanToBean(entity, body, op -> op.exclude(Constants.COMMON_CONVERSION_RULE));
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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.scheduler;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.scheduler.CreateForm;
|
||||
|
||||
public class CreateBody extends CreateForm {
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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.scheduler;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.scheduler.EditForm;
|
||||
|
||||
public class EditBody extends EditForm {
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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.scheduler;
|
||||
|
||||
import org.codelibs.fess.app.web.admin.scheduler.SearchForm;
|
||||
|
||||
public class SearchBody extends SearchForm {
|
||||
}
|
Loading…
Add table
Reference in a new issue