Search in sources :

Example 6 with VSystemException

use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.

the class BeanUtil method getValue.

/**
 * Retourne la valeur d'une propriété d'un bean
 * (ex : "name" -> object.getName() ou "country.name" -> object.getCountry().getName()).
 * @return java.lang.Object
 * @param object java.lang.Object
 * @param propertyName java.lang.String
 */
public static Object getValue(final Object object, final String propertyName) {
    Assertion.checkNotNull(object);
    Assertion.checkNotNull(propertyName);
    Assertion.checkArgument(propertyName.indexOf('.') == -1, "the dot notation is forbidden");
    // -----
    final PropertyDescriptor pd = getPropertyDescriptor(propertyName, object.getClass());
    final Method readMethod = pd.getReadMethod();
    if (readMethod == null) {
        throw new VSystemException("no getter found for property '{0}' on class '{1}'", propertyName, object.getClass().getName());
    }
    return ClassUtil.invoke(object, readMethod);
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) Method(java.lang.reflect.Method) VSystemException(io.vertigo.lang.VSystemException)

Example 7 with VSystemException

use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.

the class ReindexAllTask method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    if (isReindexInProgress()) {
        final String warnMessage = "Reindexation of " + searchIndexDefinition.getName() + " is already in progess (" + getReindexCount() + " elements done)";
        LOGGER.warn(warnMessage);
        reindexFuture.fail(new VSystemException(warnMessage));
    } else {
        // -----
        startReindex();
        long reindexCount = 0;
        final long startTime = System.currentTimeMillis();
        try {
            final Class<S> keyConceptClass = (Class<S>) ClassUtil.classForName(searchIndexDefinition.getKeyConceptDtDefinition().getClassCanonicalName(), KeyConcept.class);
            final SearchLoader<S, DtObject> searchLoader = Home.getApp().getComponentSpace().resolve(searchIndexDefinition.getSearchLoaderId(), SearchLoader.class);
            String lastUri = null;
            LOGGER.info("Reindexation of " + searchIndexDefinition.getName() + " started");
            for (final SearchChunk<S> searchChunk : searchLoader.chunk(keyConceptClass)) {
                final Collection<SearchIndex<S, DtObject>> searchIndexes = searchLoader.loadData(searchChunk);
                final String maxUri = String.valueOf(searchChunk.getLastURI().toString());
                Assertion.checkState(!maxUri.equals(lastUri), "SearchLoader ({0}) error : return the same uri list", searchIndexDefinition.getSearchLoaderId());
                searchManager.removeAll(searchIndexDefinition, urisRangeToListFilter(lastUri, maxUri));
                if (!searchIndexes.isEmpty()) {
                    searchManager.putAll(searchIndexDefinition, searchIndexes);
                }
                lastUri = maxUri;
                reindexCount += searchChunk.getAllURIs().size();
                updateReindexCount(reindexCount);
            }
            // On ne retire pas la fin, il y a un risque de retirer les données ajoutées depuis le démarrage de l'indexation
            reindexFuture.success(reindexCount);
        } catch (final Exception e) {
            LOGGER.error("Reindexation error", e);
            reindexFuture.fail(e);
        } finally {
            stopReindex();
            LOGGER.info("Reindexation of " + searchIndexDefinition.getName() + " finished in " + (System.currentTimeMillis() - startTime) + "ms (" + reindexCount + " elements done)");
        }
    }
}
Also used : SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) DtObject(io.vertigo.dynamo.domain.model.DtObject) VSystemException(io.vertigo.lang.VSystemException) KeyConcept(io.vertigo.dynamo.domain.model.KeyConcept) VSystemException(io.vertigo.lang.VSystemException)

Example 8 with VSystemException

use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.

the class ComponentCmdWebServices method getModuleConfig.

@AnonymousAccessAllowed
@GET("/vertigo/components/modules/{moduleName}")
public String getModuleConfig(@PathParam("moduleName") final String moduleName) {
    Assertion.checkArgNotEmpty(moduleName);
    // -----
    final JsonArray jsonModuleConfigs = doGetModuleConfigs();
    for (int i = 0; i < jsonModuleConfigs.size(); i++) {
        final JsonObject jsonModuleConfig = (JsonObject) jsonModuleConfigs.get(i);
        if (moduleName.equalsIgnoreCase(jsonModuleConfig.get("name").getAsString())) {
            return jsonEngine.toJson(jsonModuleConfig);
        }
    }
    throw new VSystemException("NotFoundException");
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) VSystemException(io.vertigo.lang.VSystemException) GET(io.vertigo.vega.webservice.stereotype.GET) AnonymousAccessAllowed(io.vertigo.vega.webservice.stereotype.AnonymousAccessAllowed)

Example 9 with VSystemException

use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.

the class SqlDataStorePlugin method delete.

/**
 * {@inheritDoc}
 */
@Override
public void delete(final DtDefinition dtDefinition, final URI uri) {
    Assertion.checkNotNull(dtDefinition);
    Assertion.checkNotNull(uri);
    // ---
    final DtField idField = getIdField(dtDefinition);
    final String tableName = getTableName(dtDefinition);
    final String taskName = TASK.TK_DELETE + "_" + tableName;
    final String idFieldName = idField.getName();
    final String request = new StringBuilder().append("delete from ").append(tableName).append(" where ").append(idFieldName).append(" = #").append(idFieldName).append('#').toString();
    final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineProc.class).withDataSpace(dataSpace).withRequest(request).addInRequired(idFieldName, idField.getDomain()).withOutRequired(AbstractTaskEngineSQL.SQL_ROWCOUNT, integerDomain).build();
    final Task task = Task.builder(taskDefinition).addValue(idFieldName, uri.getId()).build();
    final int sqlRowCount = taskManager.execute(task).getResult();
    if (sqlRowCount > 1) {
        throw new VSystemException("more than one row has been deleted");
    } else if (sqlRowCount == 0) {
        throw new VSystemException("no row has been deleted");
    }
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineProc(io.vertigo.dynamox.task.TaskEngineProc) VSystemException(io.vertigo.lang.VSystemException) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 10 with VSystemException

use of io.vertigo.lang.VSystemException in project vertigo by KleeGroup.

the class ESStatement method remove.

/**
 * Supprime des documents.
 * @param query Requete de filtrage des documents à supprimer
 */
void remove(final ListFilter query) {
    Assertion.checkNotNull(query);
    // -----
    final QueryBuilder queryBuilder = ESSearchRequestBuilder.translateToQueryBuilder(query);
    final SearchRequestBuilder searchRequestBuilder = esClient.prepareSearch().setIndices(indexName).setTypes(typeName).setSearchType(SearchType.QUERY_THEN_FETCH).setNoFields().setSize(// 
    DEFAULT_SCROLL_SIZE).setScroll(// 
    DEFAULT_SCROLL_KEEP_ALIVE).addSort("_id", SortOrder.ASC).setQuery(queryBuilder);
    try {
        // get first scroll doc_id
        SearchResponse queryResponse = searchRequestBuilder.execute().actionGet();
        // the scrolling id
        final String scrollid = queryResponse.getScrollId();
        SearchHits searchHits = queryResponse.getHits();
        while (searchHits.getHits().length > 0) {
            // collect the id for this scroll
            final BulkRequestBuilder bulkRequest = esClient.prepareBulk().setRefresh(BULK_REFRESH);
            for (final SearchHit searchHit : searchHits) {
                bulkRequest.add(esClient.prepareDelete(indexName, typeName, searchHit.getId()));
            }
            // bulk delete all ids
            final BulkResponse bulkResponse = bulkRequest.execute().actionGet();
            if (bulkResponse.hasFailures()) {
                throw new VSystemException("Can't removeBQuery {0} into {1} index.\nCause by {3}", typeName, indexName, bulkResponse.buildFailureMessage());
            }
            LOGGER.info("Deleted " + searchHits.getHits().length + " elements from index " + indexName);
            // new scrolling
            queryResponse = // 
            esClient.prepareSearchScroll(scrollid).setScroll(// 
            DEFAULT_SCROLL_KEEP_ALIVE).execute().actionGet();
            searchHits = queryResponse.getHits();
        }
    } catch (final SearchPhaseExecutionException e) {
        final VUserException vue = new VUserException(SearchResource.DYNAMO_SEARCH_QUERY_SYNTAX_ERROR);
        vue.initCause(e);
        throw vue;
    }
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchHits(org.elasticsearch.search.SearchHits) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) VSystemException(io.vertigo.lang.VSystemException) SearchResponse(org.elasticsearch.action.search.SearchResponse) VUserException(io.vertigo.lang.VUserException)

Aggregations

VSystemException (io.vertigo.lang.VSystemException)22 DatabaseEntry (com.sleepycat.je.DatabaseEntry)3 DatabaseException (com.sleepycat.je.DatabaseException)3 OperationStatus (com.sleepycat.je.OperationStatus)3 Method (java.lang.reflect.Method)3 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)3 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 DtField (io.vertigo.dynamo.domain.metamodel.DtField)2 URI (io.vertigo.dynamo.domain.model.URI)2 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)2 Task (io.vertigo.dynamo.task.model.Task)2 AnonymousAccessAllowed (io.vertigo.vega.webservice.stereotype.AnonymousAccessAllowed)2 GET (io.vertigo.vega.webservice.stereotype.GET)2 PropertyDescriptor (java.beans.PropertyDescriptor)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AspectConfig (io.vertigo.app.config.AspectConfig)1 ComponentConfig (io.vertigo.app.config.ComponentConfig)1