use of cz.o2.proxima.scheme.ValueSerializerFactory in project proxima-platform by O2-Czech-Republic.
the class ConfigRepository method createEntityTransaction.
private void createEntityTransaction(Config transactionsConfig) {
String schemeProviderScheme = "java";
if (transactionsConfig.hasPath(SCHEME_PROVIDER)) {
schemeProviderScheme = transactionsConfig.getString(SCHEME_PROVIDER);
}
Optional<ValueSerializerFactory> factory = getValueSerializerFactory(schemeProviderScheme);
if (!factory.isPresent() || !factory.get().canProvideTransactionSerializer()) {
throw new IllegalArgumentException("Scheme provider for transactions " + schemeProviderScheme + ", is either missing or unable to provide transaction schemes.");
}
TransactionSerializerSchemeProvider schemeProvider = factory.get().createTransactionSerializerSchemeProvider();
EntityDescriptor.Builder builder = EntityDescriptor.newBuilder().setName(TRANSACTION_ENTITY);
loadRegular(TRANSACTION_ENTITY, REQUEST_ATTRIBUTE, Collections.singletonMap(SCHEME, schemeProvider.getRequestScheme()), builder);
loadRegular(TRANSACTION_ENTITY, RESPONSE_ATTRIBUTE, Collections.singletonMap(SCHEME, schemeProvider.getResponseScheme()), builder);
loadRegular(TRANSACTION_ENTITY, STATE_ATTRIBUTE, Collections.singletonMap(SCHEME, schemeProvider.getStateScheme()), builder);
loadRegular(TRANSACTION_ENTITY, COMMIT_ATTRIBUTE, Collections.singletonMap(SCHEME, schemeProvider.getCommitScheme()), builder);
entitiesByName.put(TRANSACTION_ENTITY, builder.build());
}
use of cz.o2.proxima.scheme.ValueSerializerFactory in project proxima-platform by O2-Czech-Republic.
the class GroovyEnv method getSource.
public static String getSource(Configuration conf, Repository repo, String packageName) throws Exception {
Map<String, Object> root = new HashMap<>();
List<Map<String, Object>> entities = new ArrayList<>();
repo.getAllEntities().forEach(entityDesc -> {
Map<String, Object> entity = new HashMap<>();
List<Map<String, Object>> attributes = entityDesc.getAllAttributes().stream().map(a -> {
ValueSerializerFactory serializerFactory = repo.getValueSerializerFactory(a.getSchemeUri().getScheme()).orElseThrow(() -> new IllegalStateException("Unable to get ValueSerializerFactory for attribute " + a.getName() + " with scheme " + a.getSchemeUri().toString() + "."));
Map<String, Object> ret = new HashMap<>();
String name = a.toAttributePrefix(false);
ret.put("classname", toFirstUpper(name));
ret.put("type", serializerFactory.getClassName(a.getSchemeUri()));
ret.put("origname", a.getName());
ret.put("name", name);
ret.put("fieldname", name.toLowerCase());
ret.put("wildcard", a.isWildcard());
return ret;
}).collect(Collectors.toList());
entity.put("attributes", attributes);
entity.put("classname", toFirstUpper(entityDesc.getName()));
entity.put("name", entityDesc.getName());
entities.add(entity);
});
root.put("entities", entities);
root.put("groovyPackage", packageName);
Template template = conf.getTemplate("class-entitydesc.ftlh");
StringWriter writer = new StringWriter();
template.process(root, writer);
writer.flush();
String ret = writer.toString();
log.debug("Generated groovy source {}", ret);
return ret;
}
Aggregations