use of org.codelibs.fess.es.config.exentity.LabelType in project fess by codelibs.
the class LabelTypeHelper method getMatchedLabelValueSet.
public Set<String> getMatchedLabelValueSet(final String path) {
if (labelTypePatternList == null) {
synchronized (this) {
if (labelTypePatternList == null) {
final List<LabelType> labelTypeList = ComponentUtil.getComponent(LabelTypeService.class).getLabelTypeList();
final List<LabelTypePattern> list = new ArrayList<>();
for (final LabelType labelType : labelTypeList) {
final String includedPaths = labelType.getIncludedPaths();
final String excludedPaths = labelType.getExcludedPaths();
if (StringUtil.isNotBlank(includedPaths) || StringUtil.isNotBlank(excludedPaths)) {
try {
list.add(new LabelTypePattern(labelType.getValue(), includedPaths, excludedPaths));
} catch (final Exception e) {
logger.warn("Failed to create a matching pattern of a label: " + labelType.getValue() + ", includedPaths:" + includedPaths + ", excludedPaths:" + excludedPaths, e);
}
}
}
labelTypePatternList = list;
}
}
}
if (labelTypePatternList.isEmpty()) {
return Collections.emptySet();
}
final Set<String> valueSet = new HashSet<>();
for (final LabelTypePattern pattern : labelTypePatternList) {
if (pattern.match(path)) {
valueSet.add(pattern.getValue());
}
}
return valueSet;
}
use of org.codelibs.fess.es.config.exentity.LabelType in project fess by codelibs.
the class ApiAdminLabeltypeAction method post$setting.
// POST /api/admin/labeltype/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.EDIT;
final LabelType labelType = getLabelType(body).map(entity -> {
try {
labelTypeService.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(labelType.getId()).created(false).status(Status.OK).result());
}
use of org.codelibs.fess.es.config.exentity.LabelType in project fess by codelibs.
the class GsaConfigParserTest method test_parse.
public void test_parse() throws IOException {
GsaConfigParser parser = new GsaConfigParser();
try (InputStream is = ResourceUtil.getResourceAsStream("data/gsaconfig.xml")) {
parser.parse(new InputSource(is));
}
parser.getWebConfig().ifPresent(c -> {
System.out.println(c.toString());
}).orElse(() -> fail());
parser.getFileConfig().ifPresent(c -> {
System.out.println(c.toString());
}).orElse(() -> fail());
LabelType[] labelTypes = parser.getLabelTypes();
assertEquals(3, labelTypes.length);
}
use of org.codelibs.fess.es.config.exentity.LabelType in project fess by codelibs.
the class AdminLabeltypeAction method getLabelType.
public static OptionalEntity<LabelType> getLabelType(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.es.config.exentity.LabelType in project fess by codelibs.
the class ElevateWordService method exportCsv.
public void exportCsv(final Writer writer) {
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
final CsvConfig cfg = new CsvConfig(',', '"', '"');
cfg.setEscapeDisabled(false);
cfg.setQuoteDisabled(false);
@SuppressWarnings("resource") final CsvWriter csvWriter = new CsvWriter(writer, cfg);
try {
final List<String> list = new ArrayList<>();
list.add("SuggestWord");
list.add("Reading");
list.add("Permissions");
list.add("Labels");
list.add("Boost");
csvWriter.writeValues(list);
elevateWordBhv.selectCursor(cb -> cb.query().matchAll(), new EntityRowHandler<ElevateWord>() {
@Override
public void handle(final ElevateWord entity) {
final List<String> list = new ArrayList<>();
final String permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining(",")));
final String labels = elevateWordToLabelBhv.selectList(cb -> cb.query().setElevateWordId_Equal(entity.getId())).stream().map(e -> labelTypeBhv.selectByPK(e.getLabelTypeId()).map(LabelType::getValue).filter(StringUtil::isNotBlank).orElse(null)).distinct().sorted().collect(Collectors.joining(","));
addToList(list, entity.getSuggestWord());
addToList(list, entity.getReading());
addToList(list, permissions);
addToList(list, labels);
addToList(list, entity.getBoost());
try {
csvWriter.writeValues(list);
} catch (final IOException e) {
logger.warn("Failed to write a sugget elevate word: {}", entity, e);
}
}
private void addToList(final List<String> list, final Object value) {
if (value == null) {
list.add(StringUtil.EMPTY);
} else {
list.add(value.toString());
}
}
});
csvWriter.flush();
} catch (final IOException e) {
logger.warn("Failed to write a sugget elevate word.", e);
}
}
Aggregations