use of org.codelibs.fess.helper.PermissionHelper in project fess by codelibs.
the class ElevateWordService method importCsv.
public void importCsv(final Reader reader) {
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
final CsvConfig cfg = new CsvConfig(',', '"', '"');
cfg.setEscapeDisabled(false);
cfg.setQuoteDisabled(false);
@SuppressWarnings("resource") final CsvReader csvReader = new CsvReader(reader, cfg);
try {
List<String> list;
// ignore header
csvReader.readValues();
while ((list = csvReader.readValues()) != null) {
final String suggestWord = getValue(list, 0);
if (StringUtil.isBlank(suggestWord)) {
// skip
continue;
}
try {
final String[] permissions = split(getValue(list, 2), ",").get(stream -> stream.map(permissionHelper::encode).filter(StringUtil::isNotBlank).distinct().toArray(n -> new String[n]));
final String label = getValue(list, 3);
ElevateWord elevateWord = elevateWordBhv.selectEntity(cb -> {
cb.query().setSuggestWord_Equal(suggestWord);
if (permissions.length > 0) {
cb.query().setPermissions_InScope(stream(permissions).get(stream -> stream.collect(Collectors.toList())));
}
if (StringUtil.isNotBlank(label)) {
cb.query().setTargetLabel_Equal(label);
}
}).orElse(null);
final String reading = getValue(list, 1);
final String boost = getValue(list, 4);
final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
if (elevateWord == null) {
elevateWord = new ElevateWord();
elevateWord.setSuggestWord(suggestWord);
elevateWord.setReading(reading);
elevateWord.setPermissions(permissions);
elevateWord.setTargetLabel(label);
elevateWord.setBoost(StringUtil.isBlank(boost) ? 1.0f : Float.parseFloat(boost));
elevateWord.setCreatedBy(Constants.SYSTEM_USER);
elevateWord.setCreatedTime(now);
elevateWordBhv.insert(elevateWord);
} else if (StringUtil.isBlank(reading) && StringUtil.isBlank(boost)) {
elevateWordBhv.delete(elevateWord);
} else {
elevateWord.setReading(reading);
elevateWord.setPermissions(permissions);
elevateWord.setBoost(StringUtil.isBlank(boost) ? 1.0f : Float.parseFloat(boost));
elevateWord.setUpdatedBy(Constants.SYSTEM_USER);
elevateWord.setUpdatedTime(now);
elevateWordBhv.update(elevateWord);
}
} catch (final Exception e) {
logger.warn("Failed to read a sugget elevate word: " + list, e);
}
}
elevateWordBhv.refresh();
} catch (final IOException e) {
logger.warn("Failed to read a sugget elevate word.", e);
}
}
use of org.codelibs.fess.helper.PermissionHelper in project fess by codelibs.
the class AdminWebconfigAction method getWebConfig.
public static OptionalEntity<WebConfig> getWebConfig(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 -> {
entity.setUpdatedBy(username);
entity.setUpdatedTime(currentTime);
copyBeanToBean(form, entity, op -> op.exclude(Stream.concat(Stream.of(Constants.COMMON_CONVERSION_RULE), Stream.of(Constants.PERMISSIONS)).toArray(n -> new String[n])));
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
entity.setPermissions(split(form.permissions, "\n").get(stream -> stream.map(s -> permissionHelper.encode(s)).filter(StringUtil::isNotBlank).distinct().toArray(n -> new String[n])));
return entity;
});
}
use of org.codelibs.fess.helper.PermissionHelper in project fess by codelibs.
the class ApiAdminElevatewordAction method get$setting.
// GET /api/admin/elevateword/{id}
@Execute
public JsonResponse<ApiResult> get$setting(final String id) {
final ElevateWord entity = elevateWordService.getElevateWord(id).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
return null;
});
final EditBody body = createEditBody(entity);
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
body.permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
return asJson(new ApiResult.ApiConfigResponse().setting(body).status(ApiResult.Status.OK).result());
}
use of org.codelibs.fess.helper.PermissionHelper in project fess by codelibs.
the class ApiAdminAccesstokenAction method createEditBody.
protected EditBody createEditBody(final AccessToken entity) {
final EditBody body = new EditBody();
copyBeanToBean(entity, body, copyOp -> copyOp.exclude(Constants.PERMISSIONS, AdminAccesstokenAction.EXPIRED_TIME).excludeNull().dateConverter(Constants.DEFAULT_DATETIME_FORMAT, AdminAccesstokenAction.EXPIRES));
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
body.permissions = stream(entity.getPermissions()).get(stream -> stream.map(permissionHelper::decode).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
body.crudMode = null;
return body;
}
use of org.codelibs.fess.helper.PermissionHelper in project fess by codelibs.
the class AdminElevatewordAction method details.
// -----------------------------------------------------
// Details
// -------
@Execute
public HtmlResponse details(final int crudMode, final String id) {
verifyCrudMode(crudMode, CrudMode.DETAILS);
saveToken();
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
return asHtml(path_AdminElevateword_AdminElevatewordDetailsJsp).useForm(EditForm.class, op -> op.setup(form -> {
elevateWordService.getElevateWord(id).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
copyOp.exclude(Constants.PERMISSIONS);
});
form.permissions = stream(entity.getPermissions()).get(stream -> stream.map(permissionHelper::decode).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
form.crudMode = crudMode;
}).orElse(() -> throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asListHtml()));
})).renderWith(data -> registerLabels(data));
}
Aggregations