use of io.vertigo.lang.VUserException 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;
}
}
use of io.vertigo.lang.VUserException in project vertigo by KleeGroup.
the class ESStatement method loadList.
/**
* @param indexDefinition Index de recherche
* @param searchQuery Mots clés de recherche
* @param listState Etat de la liste (tri et pagination)
* @param defaultMaxRows Nombre de ligne max par defaut
* @return Résultat de la recherche
*/
FacetedQueryResult<I, SearchQuery> loadList(final SearchIndexDefinition indexDefinition, final SearchQuery searchQuery, final DtListState listState, final int defaultMaxRows) {
Assertion.checkNotNull(searchQuery);
// -----
final SearchRequestBuilder searchRequestBuilder = new ESSearchRequestBuilder(indexName, typeName, esClient).withSearchIndexDefinition(indexDefinition).withSearchQuery(searchQuery).withListState(listState, defaultMaxRows).build();
LOGGER.info("loadList " + searchRequestBuilder);
try {
final SearchResponse queryResponse = searchRequestBuilder.execute().actionGet();
return new ESFacetedQueryResultBuilder(esDocumentCodec, indexDefinition, queryResponse, searchQuery).build();
} catch (final SearchPhaseExecutionException e) {
final VUserException vue = new VUserException(SearchResource.DYNAMO_SEARCH_QUERY_SYNTAX_ERROR);
vue.initCause(e);
throw vue;
}
}
use of io.vertigo.lang.VUserException in project vertigo by KleeGroup.
the class AbstractSqlExceptionHandler method handleConstraintSQLException.
/**
* Traite l'exception lié à la contrainte d'intégrité.
* Et lance une KUserException avec le message par défaut passé en paramètre et une MessageKey basé sur le nom de la contrainte.
* @param sqle Exception SQL
* @param defaultMsg Message par defaut
*/
protected final VUserException handleConstraintSQLException(final SQLException sqle, final MessageKey defaultMsg) {
final String msg = sqle.getMessage();
// recherche le nom de la contrainte d'intégrité
final String constraintName = extractConstraintName(msg);
Assertion.checkNotNull(constraintName, "Impossible d''extraire le nom de la contrainte : {0}", msg);
// recherche le message pour l'utilisateur
// On crée une clé de MessageText dynamiquement sur le nom de la contrainte d'intégrité
// Ex: CK_PERSON_FULL_NAME_UNIQUE
final MessageKey constraintKey = new SQLConstraintMessageKey(constraintName);
// On récupère ici le message externalisé par défaut : Resources.DYNAMO_SQL_CONSTRAINT_IMPOSSIBLE_TO_DELETE ou Resources.DYNAMO_SQL_CONSTRAINT_ALREADY_REGISTRED)
final String defaultConstraintMsg = MessageText.of(defaultMsg).getDisplay();
final MessageText userContraintMessageText = MessageText.builder().withKey(constraintKey).withDefaultMsg(defaultConstraintMsg).build();
final VUserException constraintException = new VUserException(userContraintMessageText);
constraintException.initCause(sqle);
return constraintException;
}
use of io.vertigo.lang.VUserException in project vertigo by KleeGroup.
the class ContactsWebServices method readContactView.
@GET("/contactView/{conId}")
public ContactView readContactView(@PathParam("conId") final long conId) {
final Contact contact = contactDao.get(conId);
if (contact == null) {
// 404 ?
throw new VUserException("Contact #" + conId + " unknown");
}
// we sheet and use 3 times the same address.
final DtList<Address> addresses = DtList.of(contact.getAddressAccessor().get(), contact.getAddressAccessor().get(), contact.getAddressAccessor().get());
final ContactView contactView = new ContactView();
contactView.setName(contact.getName());
contactView.setFirstName(contact.getFirstName());
contactView.setHonorificCode(contact.getHonorificCode());
contactView.setEmail(contact.getEmail());
contactView.setBirthday(contact.getBirthday());
contactView.setAddresses(addresses);
// 200
return contactView;
}
use of io.vertigo.lang.VUserException in project vertigo by KleeGroup.
the class RestfulServiceWebServiceHandlerPlugin method handle.
/**
* {@inheritDoc}
*/
@Override
public Object handle(final Request request, final Response response, final WebServiceCallContext routeContext, final HandlerChain chain) throws SessionException {
final WebServiceDefinition webServiceDefinition = routeContext.getWebServiceDefinition();
final Object[] serviceArgs = makeArgs(routeContext);
final Method method = webServiceDefinition.getMethod();
final WebServices webServices = (WebServices) Home.getApp().getComponentSpace().resolve(method.getDeclaringClass());
if (method.getName().startsWith("create")) {
// by convention, if method starts with 'create', an http 201 status code is returned (if ok)
response.status(HttpServletResponse.SC_CREATED);
}
try {
return ClassUtil.invoke(webServices, method, serviceArgs);
} catch (final RuntimeException e) {
// If throwed exception was ValidationUserException, VUserException, SessionException, VSecurityException, RuntimeException
// we re throw it
final Throwable cause = e.getCause();
if (cause instanceof InvocationTargetException) {
final Throwable targetException = ((InvocationTargetException) cause).getTargetException();
if (targetException instanceof ValidationUserException) {
throw (ValidationUserException) targetException;
} else if (targetException instanceof VUserException) {
throw (VUserException) targetException;
} else if (targetException instanceof SessionException) {
throw (SessionException) targetException;
} else if (targetException instanceof VSecurityException) {
throw (VSecurityException) targetException;
} else if (targetException instanceof RuntimeException) {
throw (RuntimeException) targetException;
}
}
throw e;
}
}
Aggregations