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