add #973 Admin API: /api/admin/joblog
This commit is contained in:
parent
8ef47a1ac9
commit
87901a305b
4 changed files with 172 additions and 0 deletions
|
@ -114,6 +114,40 @@ 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 ApiErrorResponse extends ApiResponse {
|
||||
protected String message;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue