Search in sources :

Example 11 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().setRefresh(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 12 with VSystemException

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

the class BerkeleyKVStoreManagerTest method testRollback.

@Test(expected = RuntimeException.class)
public void testRollback() {
    try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final Flower tulip = buildFlower("tulip", 100);
        kvStoreManager.put("flowers", "1", tulip);
        transaction.commit();
    }
    final Optional<Flower> flower1 = kvStoreManager.find("flowers", "1", Flower.class);
    Assert.assertTrue("Flower id 1 not found", flower1.isPresent());
    final Optional<Flower> flower2 = kvStoreManager.find("flowers", "2", Flower.class);
    Assert.assertFalse("There is already a flower id 2", flower2.isPresent());
    try {
        try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
            final Flower tulip = buildFlower("rose", 100);
            kvStoreManager.put("flowers", "2", tulip);
            throw new VSystemException("Error");
        }
    } catch (final RuntimeException e) {
    // on doit passer par là
    }
    final Optional<Flower> flower2bis = kvStoreManager.find("flowers", "2", Flower.class);
    Assert.assertFalse("Rollback flower id 2 failed", flower2bis.isPresent());
}
Also used : Flower(io.vertigo.dynamo.kvstore.data.Flower) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) VSystemException(io.vertigo.lang.VSystemException) AbstractKVStoreManagerTest(io.vertigo.dynamo.kvstore.AbstractKVStoreManagerTest) Test(org.junit.Test)

Example 13 with VSystemException

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

the class ComponentLoader method registerComponents.

/**
 * registers all the components defined by their configs.
 * @param paramManagerOpt the optional manager of params
 * @param moduleName the name of the module
 * @param componentConfigs the configs of the components
 */
public void registerComponents(final Optional<ParamManager> paramManagerOpt, final String moduleName, final List<ComponentConfig> componentConfigs) {
    Assertion.checkNotNull(componentSpace);
    Assertion.checkNotNull(paramManagerOpt);
    Assertion.checkNotNull(moduleName);
    Assertion.checkNotNull(componentConfigs);
    // ---- Proxies----
    componentConfigs.stream().filter(ComponentConfig::isProxy).forEach(componentConfig -> {
        final Component component = createProxyWithOptions(/*paramManagerOpt,*/
        componentConfig);
        componentSpace.registerComponent(componentConfig.getId(), component);
    });
    // ---- No proxy----
    final DIReactor reactor = new DIReactor();
    // 0; On ajoute la liste des ids qui sont déjà résolus.
    for (final String id : componentSpace.keySet()) {
        reactor.addParent(id);
    }
    // Map des composants définis par leur id
    final Map<String, ComponentConfig> componentConfigById = componentConfigs.stream().filter(componentConfig -> !componentConfig.isProxy()).peek(componentConfig -> reactor.addComponent(componentConfig.getId(), componentConfig.getImplClass(), componentConfig.getParams().keySet())).collect(Collectors.toMap(ComponentConfig::getId, Function.identity()));
    // Comment trouver des plugins orphenlins ?
    final List<String> ids = reactor.proceed();
    // On a récupéré la liste ordonnée des ids.
    // On positionne un proxy pour compter les plugins non utilisés
    final ComponentUnusedKeysContainer componentProxyContainer = new ComponentUnusedKeysContainer(componentSpace);
    for (final String id : ids) {
        if (componentConfigById.containsKey(id)) {
            // Si il s'agit d'un composant (y compris plugin)
            final ComponentConfig componentConfig = componentConfigById.get(id);
            // 2.a On crée le composant avec AOP et autres options (elastic)
            final Component component = createComponentWithOptions(paramManagerOpt, componentProxyContainer, componentConfig);
            // 2.b. On enregistre le composant
            componentSpace.registerComponent(componentConfig.getId(), component);
        }
    }
    // --Search for unuseds plugins
    final List<String> unusedPluginIds = componentConfigs.stream().filter(componentConfig -> !componentConfig.isProxy()).filter(componentConfig -> Plugin.class.isAssignableFrom(componentConfig.getImplClass())).map(ComponentConfig::getId).filter(pluginId -> !componentProxyContainer.getUsedKeys().contains(pluginId)).collect(Collectors.toList());
    if (!unusedPluginIds.isEmpty()) {
        throw new VSystemException("plugins '{0}' in module'{1}' are not used by injection", unusedPluginIds, moduleName);
    }
}
Also used : ComponentSpaceWritable(io.vertigo.core.component.ComponentSpaceWritable) VSystemException(io.vertigo.lang.VSystemException) DIInjector(io.vertigo.core.component.di.injector.DIInjector) Aspect(io.vertigo.core.component.aop.Aspect) Container(io.vertigo.core.component.Container) DIReactor(io.vertigo.core.component.di.reactor.DIReactor) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ModuleConfig(io.vertigo.app.config.ModuleConfig) List(java.util.List) ProxyMethod(io.vertigo.core.component.proxy.ProxyMethod) ParamManager(io.vertigo.core.param.ParamManager) AspectConfig(io.vertigo.app.config.AspectConfig) Plugin(io.vertigo.core.component.Plugin) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) Optional(java.util.Optional) Component(io.vertigo.core.component.Component) AopPlugin(io.vertigo.core.component.AopPlugin) Method(java.lang.reflect.Method) ComponentConfig(io.vertigo.app.config.ComponentConfig) ProxyMethodConfig(io.vertigo.app.config.ProxyMethodConfig) ComponentConfig(io.vertigo.app.config.ComponentConfig) Component(io.vertigo.core.component.Component) DIReactor(io.vertigo.core.component.di.reactor.DIReactor) VSystemException(io.vertigo.lang.VSystemException)

Example 14 with VSystemException

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

the class KprLoader method doGetKspFiles.

private static List<URL> doGetKspFiles(final URL kprURL, final Charset charset, final ResourceManager resourceManager) throws Exception {
    final List<URL> kspFiles = new ArrayList<>();
    try (final BufferedReader reader = new BufferedReader(new InputStreamReader(kprURL.openStream(), charset))) {
        String path = kprURL.getPath();
        path = path.substring(0, path.lastIndexOf('/'));
        for (String line = reader.readLine(); line != null; line = reader.readLine()) {
            final String fileName = line.trim();
            if (fileName.length() > 0) {
                // voir http://commons.apache.org/vfs/filesystems.html
                // Protocol : vfszip pour jboss par exemple
                final URL url = new URL(kprURL.getProtocol() + ':' + path + '/' + fileName);
                if (fileName.endsWith(KPR_EXTENSION)) {
                    // kpr
                    kspFiles.addAll(getKspFiles(url, charset, resourceManager));
                } else if (fileName.endsWith(KSP_EXTENSION)) {
                    // ksp
                    kspFiles.add(url);
                } else {
                    throw new VSystemException("Type de fichier inconnu : {0}", fileName);
                }
            }
        }
    }
    return kspFiles;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) URL(java.net.URL) VSystemException(io.vertigo.lang.VSystemException)

Example 15 with VSystemException

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

the class BrokerNNImpl method appendNN.

/**
 * Créer une association.
 * @param nn description de la nn
 * @param targetValue targetValue
 */
private void appendNN(final DescriptionNN nn, final Object targetValue) {
    // FieldName
    final String sourceFieldName = nn.sourceField.getName();
    final String targetFieldName = nn.targetField.getName();
    final String taskName = "TK_INSERT_" + nn.tableName;
    final String request = String.format("insert into %s (%s, %s) values (#%s#, #%s#)", nn.tableName, sourceFieldName, targetFieldName, sourceFieldName, 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 inserted");
    } else if (sqlRowCount == 0) {
        throw new VSystemException("No row inserted");
    }
}
Also used : 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