Search in sources :

Example 1 with ValueSerializerFactory

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());
}
Also used : ValueSerializerFactory(cz.o2.proxima.scheme.ValueSerializerFactory) TransactionSerializerSchemeProvider(cz.o2.proxima.transaction.TransactionSerializerSchemeProvider)

Example 2 with ValueSerializerFactory

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;
}
Also used : List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Repository(cz.o2.proxima.repository.Repository) ValueSerializerFactory(cz.o2.proxima.scheme.ValueSerializerFactory) Configuration(freemarker.template.Configuration) StringWriter(java.io.StringWriter) Map(java.util.Map) HashMap(java.util.HashMap) Template(freemarker.template.Template) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ValueSerializerFactory(cz.o2.proxima.scheme.ValueSerializerFactory) Template(freemarker.template.Template) StringWriter(java.io.StringWriter) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ValueSerializerFactory (cz.o2.proxima.scheme.ValueSerializerFactory)2 Repository (cz.o2.proxima.repository.Repository)1 TransactionSerializerSchemeProvider (cz.o2.proxima.transaction.TransactionSerializerSchemeProvider)1 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1