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);
}
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)");
}
}
}
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");
}
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");
}
}
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;
}
}
Aggregations