use of org.codelibs.fess.es.config.exentity.PathMapping in project fess by codelibs.
the class ApiAdminPathmapAction method post$setting.
// POST /api/admin/pathmap/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.EDIT;
final PathMapping entity = getPathMapping(body).orElseGet(() -> {
throwValidationErrorApi(messages -> {
messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id);
});
return null;
});
try {
pathMappingService.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.codelibs.fess.es.config.exentity.PathMapping in project fess by codelibs.
the class ApiAdminPathmapAction method settings.
// GET /api/admin/pathmap
// POST /api/admin/pathmap
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
validateApi(body, messages -> {
});
final PathMapPager pager = copyBeanToNewBean(body, PathMapPager.class);
final List<PathMapping> list = pathMappingService.getPathMappingList(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());
}
use of org.codelibs.fess.es.config.exentity.PathMapping in project fess by codelibs.
the class ApiAdminPathmapAction method delete$setting.
// DELETE /api/admin/pathmap/setting/{id}
@Execute
public JsonResponse<ApiResult> delete$setting(final String id) {
final PathMapping entity = pathMappingService.getPathMapping(id).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
return null;
});
try {
pathMappingService.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.codelibs.fess.es.config.exentity.PathMapping in project fess by codelibs.
the class PathMappingHelperTest method test_replaceUrls.
public void test_replaceUrls() {
final List<PathMapping> pathMappingList = new ArrayList<PathMapping>();
final PathMapping pathMapping = new PathMapping();
pathMapping.setRegex("file:///home/");
pathMapping.setReplacement("http://localhost/");
pathMappingList.add(pathMapping);
pathMappingHelper.cachedPathMappingList = pathMappingList;
String text = "\"file:///home/\"";
assertEquals("\"http://localhost/\"", pathMappingHelper.replaceUrls(text));
text = "\"file:///home/user/\"";
assertEquals("\"http://localhost/user/\"", pathMappingHelper.replaceUrls(text));
text = "\"aaafile:///home/user/\"";
assertEquals("\"aaahttp://localhost/user/\"", pathMappingHelper.replaceUrls(text));
text = "aaa\"file:///home/user/\"bbb";
assertEquals("aaa\"http://localhost/user/\"bbb", pathMappingHelper.replaceUrls(text));
}
use of org.codelibs.fess.es.config.exentity.PathMapping in project fess by codelibs.
the class ApiAdminPathmapAction method put$setting.
// PUT /api/admin/pathmap/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.CREATE;
final PathMapping entity = getPathMapping(body).orElseGet(() -> {
throwValidationErrorApi(messages -> {
messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
});
return null;
});
try {
pathMappingService.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