use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminRoleAction method post$setting.
// POST /api/admin/role/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.EDIT;
final Role entity = getRole(body).orElseGet(() -> {
throwValidationErrorApi(messages -> {
messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id);
});
return null;
});
try {
roleService.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());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminLabeltypeAction method put$setting.
// 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());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminWebauthAction method put$setting.
// PUT /api/admin/webauth/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
validateApi(body, messages -> {
});
if (!isValidWebConfigId(body.webConfigId)) {
return asJson(new ApiErrorResponse().message("invalid webConfigId").status(Status.BAD_REQUEST).result());
}
body.crudMode = CrudMode.CREATE;
final WebAuthentication webAuth = getWebAuthentication(body).map(entity -> {
try {
webAuthService.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(webAuth.getId()).created(true).status(Status.OK).result());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminSchedulerAction method delete$setting.
// 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());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminSchedulerAction method put$setting.
// 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());
}
Aggregations