use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminSearchlistAction method post$doc.
// POST /api/admin/searchlist/doc
@Execute
public JsonResponse<ApiResult> post$doc(final EditBody body) {
validateApi(body, messages -> {
});
validateUpdateFields(body, v -> throwValidationErrorApi(v));
body.crudMode = CrudMode.EDIT;
final Map<String, Object> doc = getDoc(body).map(entity -> {
try {
entity.putAll(fessConfig.convertToStorableDoc(body.doc));
final String newId = ComponentUtil.getCrawlingInfoHelper().generateId(entity);
String oldId = null;
if (newId.equals(body.id)) {
entity.put(fessConfig.getIndexFieldId(), body.id);
entity.put(fessConfig.getIndexFieldVersion(), body.version);
} else {
oldId = body.id;
entity.put(fessConfig.getIndexFieldId(), newId);
entity.remove(fessConfig.getIndexFieldVersion());
}
final String index = fessConfig.getIndexDocumentUpdateIndex();
final String type = fessConfig.getIndexDocumentType();
fessEsClient.store(index, type, entity);
if (oldId != null) {
fessEsClient.delete(index, type, oldId, body.version);
}
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.error("Failed to update " + entity, 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(doc.get(fessConfig.getIndexFieldDocId()).toString()).created(false).status(Status.OK).result());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminUserAction method delete$setting.
// DELETE /api/admin/user/setting/{id}
@Execute
public JsonResponse<ApiResult> delete$setting(final String id) {
final User entity = userService.getUser(id).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
return null;
});
getUserBean().ifPresent(u -> {
if (u.getFessUser() instanceof User && entity.getName().equals(u.getUserId())) {
throwValidationErrorApi(messages -> messages.addErrorsCouldNotDeleteLoggedInUser(GLOBAL));
}
});
try {
userService.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 ApiAdminUserAction method post$setting.
// POST /api/admin/user/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.EDIT;
final User entity = getUser(body).orElseGet(() -> {
throwValidationErrorApi(messages -> {
messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id);
});
return null;
});
try {
userService.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 ApiAdminUserAction method put$setting.
// PUT /api/admin/user/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.CREATE;
final User entity = getUser(body).orElseGet(() -> {
throwValidationErrorApi(messages -> {
messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
});
return null;
});
try {
userService.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());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminWebauthAction method post$setting.
// POST /api/admin/webauth/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.EDIT;
final WebAuthentication webAuth = getWebAuthentication(body).map(entity -> {
try {
webAuthService.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(webAuth.getId()).created(false).status(Status.OK).result());
}
Aggregations