Search in sources :

Example 1 with VSystemException

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

the class SqlDataStorePlugin method put.

/**
 * @param entity Objet à persiter
 * @param insert Si opération de type insert (update sinon)
 */
private void put(final Entity entity, final boolean insert) {
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(entity);
    final String tableName = getTableName(dtDefinition);
    final String taskName = (insert ? TASK.TK_INSERT : TASK.TK_UPDATE) + "_" + tableName;
    final String request = insert ? sqlDialect.createInsertQuery(dtDefinition.getIdField().get().getName(), getDataFields(dtDefinition), sequencePrefix, tableName) : createUpdateQuery(dtDefinition);
    final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(getTaskEngineClass(insert)).withDataSpace(dataSpace).withRequest(request).addInRequired("DTO", Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + dtDefinition.getName() + "_DTO", Domain.class)).withOutRequired(AbstractTaskEngineSQL.SQL_ROWCOUNT, integerDomain).build();
    final Task task = Task.builder(taskDefinition).addValue("DTO", entity).build();
    final int sqlRowCount = taskManager.execute(task).getResult();
    if (sqlRowCount > 1) {
        throw new VSystemException("more than one row has been " + (insert ? "created" : "updated"));
    }
    if (sqlRowCount == 0) {
        throw new VSystemException("no data " + (insert ? "created" : "updated"));
    }
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain) VSystemException(io.vertigo.lang.VSystemException)

Example 2 with VSystemException

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

the class ESStatement method putAll.

/**
 * @param indexCollection Collection des indexes à insérer
 */
void putAll(final Collection<SearchIndex<K, I>> indexCollection) {
    // Injection spécifique au moteur d'indexation.
    try {
        final BulkRequestBuilder bulkRequest = esClient.prepareBulk().setRefreshPolicy(BULK_REFRESH);
        for (final SearchIndex<K, I> index : indexCollection) {
            try (final XContentBuilder xContentBuilder = esDocumentCodec.index2XContentBuilder(index)) {
                bulkRequest.add(esClient.prepareIndex().setIndex(indexName).setType(typeName).setId(index.getURI().urn()).setSource(xContentBuilder));
            }
        }
        final BulkResponse bulkResponse = bulkRequest.execute().actionGet();
        if (bulkResponse.hasFailures()) {
            throw new VSystemException("Can't putAll {0} into {1} index.\nCause by {2}", typeName, indexName, bulkResponse.buildFailureMessage());
        }
    } catch (final IOException e) {
        handleIOException(e);
    }
}
Also used : URI(io.vertigo.dynamo.domain.model.URI) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) VSystemException(io.vertigo.lang.VSystemException)

Example 3 with VSystemException

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

the class BrokerNNImpl method removeNN.

/**
 * Supprime une association.
 * @param nn description de la nn
 * @param targetValue targetValue
 */
private void removeNN(final DescriptionNN nn, final Object targetValue) {
    // FieldName
    final String sourceFieldName = nn.sourceField.getName();
    final String targetFieldName = nn.targetField.getName();
    final String taskName = "TK_DELETE_" + nn.tableName;
    final String request = String.format("delete from %s where %s = #%s# and %s = #%s#", nn.tableName, sourceFieldName, sourceFieldName, targetFieldName, targetFieldName);
    final int sqlRowCount = processNN(taskName, request, nn.dataSpace, nn.sourceField, nn.sourceValue, nn.targetField, targetValue);
    if (sqlRowCount > 1) {
        throw new VSystemException("More than one row removed");
    } else if (sqlRowCount == 0) {
        throw new VSystemException("No row removed");
    }
}
Also used : VSystemException(io.vertigo.lang.VSystemException)

Example 4 with VSystemException

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

the class BerkeleyDatabase method delete.

/**
 * @param id Element id to remove
 */
void delete(final String id) {
    Assertion.checkArgNotEmpty(id);
    // -----
    final DatabaseEntry idEntry = new DatabaseEntry();
    keyBinding.objectToEntry(id, idEntry);
    final OperationStatus status;
    try {
        status = database.delete(getCurrentBerkeleyTransaction(), idEntry);
    } catch (final DatabaseException e) {
        throw WrappedException.wrap(e);
    }
    if (OperationStatus.NOTFOUND.equals(status)) {
        throw new VSystemException("delete has failed because no data found with key : {0}", id);
    }
    if (!OperationStatus.SUCCESS.equals(status)) {
        throw new VSystemException("delete has failed");
    }
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException) VSystemException(io.vertigo.lang.VSystemException)

Example 5 with VSystemException

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

the class DateQueryParserUtil method parse.

/**
 * Retourne la date correspondant à l'expression passée en parametre.
 * La syntaxe est de type now((+/-)eeeUNIT) ou une date au format dd/MM/yy
 *
 * @param dateExpression Expression
 * @param datePattern Pattern used to define a date (dd/MM/YYYY)
 * @return date
 */
static Date parse(final String dateExpression, final String datePattern) {
    Assertion.checkArgNotEmpty(dateExpression);
    Assertion.checkArgNotEmpty(datePattern, "you must define a valid datePattern such as dd/MM/yyyy or MM/dd/yy");
    // ---
    if (NOW.equals(dateExpression)) {
        // today is gonna be the day
        return new Date();
    }
    if (dateExpression.startsWith(NOW)) {
        final int index = NOW.length();
        final char operator = dateExpression.charAt(index);
        final int sign = buildSign(dateExpression, operator);
        // ---
        // operand = 21d
        final String operand = dateExpression.substring(index + 1);
        // NOW+21DAY or NOW-12MONTH
        final Matcher matcher = PATTERN.matcher(operand);
        Assertion.checkState(matcher.matches(), "Le second operande ne respecte pas le pattern {0}", PATTERN.toString());
        // ---
        final int unitCount = sign * Integer.parseInt(matcher.group(1));
        final String calendarUnit = matcher.group(2);
        // We check that we have found a real unit Calendar and not 'NOW+15DAL'
        if (!CALENDAR_UNITS.containsKey(calendarUnit)) {
            throw new VSystemException("unit '" + calendarUnit + "' is not allowed. You must use a unit among : " + CALENDAR_UNITS.keySet());
        }
        // ---
        final Calendar calendar = new GregorianCalendar();
        calendar.add(CALENDAR_UNITS.get(calendarUnit), unitCount);
        return calendar.getTime();
    }
    return format(dateExpression, datePattern);
}
Also used : Matcher(java.util.regex.Matcher) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) VSystemException(io.vertigo.lang.VSystemException)

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