Search in sources :

Example 21 with IllegalBehaviorStateException

use of org.dbflute.exception.IllegalBehaviorStateException in project fess by codelibs.

the class EsAbstractBehavior method delegateQueryDelete.

@Override
protected int delegateQueryDelete(final ConditionBean cb, final DeleteOption<? extends ConditionBean> option) {
    SearchResponse response = null;
    int count = 0;
    while (true) {
        if (response == null) {
            final SearchRequestBuilder builder = client.prepareSearch(asEsIndex()).setTypes(asEsIndexType()).setScroll(scrollForDelete).setSize(sizeForDelete);
            final EsAbstractConditionBean esCb = (EsAbstractConditionBean) cb;
            if (esCb.getPreference() != null) {
                esCb.setPreference(esCb.getPreference());
            }
            esCb.request().build(builder);
            response = esCb.build(builder).execute().actionGet(scrollSearchTimeout);
        } else {
            final String scrollId = response.getScrollId();
            response = client.prepareSearchScroll(scrollId).setScroll(scrollForDelete).execute().actionGet(scrollSearchTimeout);
        }
        final SearchHits searchHits = response.getHits();
        final SearchHit[] hits = searchHits.getHits();
        if (hits.length == 0) {
            break;
        }
        final BulkRequestBuilder bulkRequest = client.prepareBulk();
        for (final SearchHit hit : hits) {
            bulkRequest.add(client.prepareDelete(asEsIndex(), asEsIndexType(), hit.getId()));
        }
        count += hits.length;
        final BulkResponse bulkResponse = bulkRequest.execute().actionGet(bulkTimeout);
        if (bulkResponse.hasFailures()) {
            throw new IllegalBehaviorStateException(bulkResponse.buildFailureMessage());
        }
    }
    return count;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) SearchHits(org.elasticsearch.search.SearchHits) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 22 with IllegalBehaviorStateException

use of org.dbflute.exception.IllegalBehaviorStateException in project fess by codelibs.

the class GroupBhv method createEntity.

@Override
protected <RESULT extends Group> RESULT createEntity(final Map<String, Object> source, final Class<? extends RESULT> entityType) {
    try {
        final RESULT result = entityType.newInstance();
        result.setName(DfTypeUtil.toString(source.get("name")));
        result.setAttributes(source.entrySet().stream().filter(e -> !"name".equals(e.getKey())).map(e -> new Pair<>(e.getKey(), (String) e.getValue())).collect(Collectors.toMap(t -> t.getFirst(), t -> t.getSecond())));
        return result;
    } catch (InstantiationException | IllegalAccessException e) {
        final String msg = "Cannot create a new instance: " + entityType.getName();
        throw new IllegalBehaviorStateException(msg, e);
    }
}
Also used : BsGroupBhv(org.codelibs.fess.es.user.bsbhv.BsGroupBhv) DfTypeUtil(org.dbflute.util.DfTypeUtil) Map(java.util.Map) Pair(org.codelibs.core.misc.Pair) IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException) Collectors(java.util.stream.Collectors) Group(org.codelibs.fess.es.user.exentity.Group) IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException)

Example 23 with IllegalBehaviorStateException

use of org.dbflute.exception.IllegalBehaviorStateException in project fess by codelibs.

the class RoleBhv method createEntity.

@Override
protected <RESULT extends Role> RESULT createEntity(final Map<String, Object> source, final Class<? extends RESULT> entityType) {
    try {
        final RESULT result = entityType.newInstance();
        result.setName(DfTypeUtil.toString(source.get("name")));
        result.setAttributes(source.entrySet().stream().filter(e -> !"name".equals(e.getKey())).map(e -> new Pair<>(e.getKey(), (String) e.getValue())).collect(Collectors.toMap(t -> t.getFirst(), t -> t.getSecond())));
        return result;
    } catch (InstantiationException | IllegalAccessException e) {
        final String msg = "Cannot create a new instance: " + entityType.getName();
        throw new IllegalBehaviorStateException(msg, e);
    }
}
Also used : Role(org.codelibs.fess.es.user.exentity.Role) DfTypeUtil(org.dbflute.util.DfTypeUtil) Map(java.util.Map) Pair(org.codelibs.core.misc.Pair) IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException) Collectors(java.util.stream.Collectors) BsRoleBhv(org.codelibs.fess.es.user.bsbhv.BsRoleBhv) IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException)

Example 24 with IllegalBehaviorStateException

use of org.dbflute.exception.IllegalBehaviorStateException in project fess by codelibs.

the class BsThumbnailQueueBhv method createEntity.

@Override
protected <RESULT extends ThumbnailQueue> RESULT createEntity(Map<String, Object> source, Class<? extends RESULT> entityType) {
    try {
        final RESULT result = entityType.newInstance();
        result.setCreatedBy(DfTypeUtil.toString(source.get("createdBy")));
        result.setCreatedTime(DfTypeUtil.toLong(source.get("createdTime")));
        result.setTarget(DfTypeUtil.toString(source.get("target")));
        result.setGenerator(DfTypeUtil.toString(source.get("generator")));
        result.setThumbnailId(DfTypeUtil.toString(source.get("thumbnail_id")));
        result.setPath(DfTypeUtil.toString(source.get("path")));
        result.setUrl(DfTypeUtil.toString(source.get("url")));
        return updateEntity(source, result);
    } catch (InstantiationException | IllegalAccessException e) {
        final String msg = "Cannot create a new instance: " + entityType.getName();
        throw new IllegalBehaviorStateException(msg, e);
    }
}
Also used : IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException)

Example 25 with IllegalBehaviorStateException

use of org.dbflute.exception.IllegalBehaviorStateException in project fess by codelibs.

the class BsWebAuthenticationBhv method createEntity.

@Override
protected <RESULT extends WebAuthentication> RESULT createEntity(Map<String, Object> source, Class<? extends RESULT> entityType) {
    try {
        final RESULT result = entityType.newInstance();
        result.setAuthRealm(DfTypeUtil.toString(source.get("authRealm")));
        result.setCreatedBy(DfTypeUtil.toString(source.get("createdBy")));
        result.setCreatedTime(DfTypeUtil.toLong(source.get("createdTime")));
        result.setHostname(DfTypeUtil.toString(source.get("hostname")));
        result.setParameters(DfTypeUtil.toString(source.get("parameters")));
        result.setPassword(DfTypeUtil.toString(source.get("password")));
        result.setPort(DfTypeUtil.toInteger(source.get("port")));
        result.setProtocolScheme(DfTypeUtil.toString(source.get("protocolScheme")));
        result.setUpdatedBy(DfTypeUtil.toString(source.get("updatedBy")));
        result.setUpdatedTime(DfTypeUtil.toLong(source.get("updatedTime")));
        result.setUsername(DfTypeUtil.toString(source.get("username")));
        result.setWebConfigId(DfTypeUtil.toString(source.get("webConfigId")));
        return updateEntity(source, result);
    } catch (InstantiationException | IllegalAccessException e) {
        final String msg = "Cannot create a new instance: " + entityType.getName();
        throw new IllegalBehaviorStateException(msg, e);
    }
}
Also used : IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException)

Aggregations

IllegalBehaviorStateException (org.dbflute.exception.IllegalBehaviorStateException)44 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)4 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)4 SearchResponse (org.elasticsearch.action.search.SearchResponse)4 SearchHit (org.elasticsearch.search.SearchHit)4 SearchHits (org.elasticsearch.search.SearchHits)4 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Pair (org.codelibs.core.misc.Pair)3 DfTypeUtil (org.dbflute.util.DfTypeUtil)3 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)3 BsGroupBhv (org.codelibs.fess.es.user.bsbhv.BsGroupBhv)1 BsRoleBhv (org.codelibs.fess.es.user.bsbhv.BsRoleBhv)1 BsUserBhv (org.codelibs.fess.es.user.bsbhv.BsUserBhv)1 Group (org.codelibs.fess.es.user.exentity.Group)1 Role (org.codelibs.fess.es.user.exentity.Role)1 User (org.codelibs.fess.es.user.exentity.User)1 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)1 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)1