Search in sources :

Example 46 with Application

use of org.qi4j.api.structure.Application in project qi4j-sdk by Qi4j.

the class TestAssembler method assembleInfrastructureLayer.

private void assembleInfrastructureLayer(LayerAssembly infrastructureLayer) throws AssemblyException {
    ModuleAssembly serializationModule = infrastructureLayer.module("INFRASTRUCTURE-Serialization");
    serializationModule.services(OrgJsonValueSerializationService.class).taggedWith(ValueSerialization.Formats.JSON).setMetaInfo(new Function<Application, Module>() {

        @Override
        public Module map(Application application) {
            return application.findModule("CONTEXT", "CONTEXT-RoleMap");
        }
    }).visibleIn(application);
    ModuleAssembly indexingModule = infrastructureLayer.module("INFRASTRUCTURE-Indexing");
    indexingModule.objects(EntityStateSerializer.class, EntityTypeSerializer.class);
    indexingModule.services(MemoryRepositoryService.class, RdfIndexingEngineService.class).visibleIn(application).instantiateOnStartup();
    ModuleAssembly entityStoreModule = infrastructureLayer.module("INFRASTRUCTURE-EntityStore");
    entityStoreModule.addServices(MemoryEntityStoreService.class, UuidIdentityGeneratorService.class).visibleIn(application);
    ModuleAssembly externalServiceModule = infrastructureLayer.module("INFRASTRUCTURE-ExternalService");
    externalServiceModule.importedServices(GraphTraversalService.class).setMetaInfo(new GraphTraversalServiceImpl(new GraphDAO())).visibleIn(application);
}
Also used : MemoryEntityStoreService(org.qi4j.entitystore.memory.MemoryEntityStoreService) UuidIdentityGeneratorService(org.qi4j.spi.uuid.UuidIdentityGeneratorService) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) Function(org.qi4j.functional.Function) OrgJsonValueSerializationService(org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService) GraphTraversalServiceImpl(org.qi4j.sample.dcicargo.pathfinder_b.internal.GraphTraversalServiceImpl) Application(org.qi4j.api.structure.Application) GraphDAO(org.qi4j.sample.dcicargo.pathfinder_b.internal.GraphDAO)

Example 47 with Application

use of org.qi4j.api.structure.Application in project qi4j-sdk by Qi4j.

the class ForumAssembler method assemble.

@Override
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
    ApplicationAssembly assembly = applicationFactory.newApplicationAssembly();
    assembly.setName("Forum");
    LayerAssembly configuration = assembly.layer("Configuration");
    {
        ModuleAssembly configModule = configuration.module("Configuration");
        configModule.entities(NeoConfiguration.class).visibleIn(Visibility.application);
        configModule.services(MemoryEntityStoreService.class);
        configModule.services(UuidIdentityGeneratorService.class);
        new OrgJsonValueSerializationAssembler().assemble(configModule);
    }
    LayerAssembly infrastructure = assembly.layer("Infrastructure").uses(configuration);
    {
        ModuleAssembly entityStore = infrastructure.module("EntityStore");
        entityStore.services(FileConfigurationService.class);
        entityStore.services(NeoEntityStoreService.class).visibleIn(Visibility.application);
        entityStore.services(UuidIdentityGeneratorService.class).visibleIn(Visibility.application);
        new OrgJsonValueSerializationAssembler().visibleIn(Visibility.application).withValuesModuleFinder(new Function<Application, Module>() {

            @Override
            public Module map(Application app) {
                return app.findModule("REST", "Values");
            }
        }).assemble(entityStore);
    }
    LayerAssembly data = assembly.layer("Data").uses(infrastructure);
    {
        ModuleAssembly forum = data.module("Forum");
        for (Class<?> dataClass : filter(hasModifier(Modifier.INTERFACE), filter(isAssignableFrom(EntityComposite.class), ClassScanner.findClasses(User.class)))) {
            forum.entities(dataClass).visibleIn(Visibility.application);
        }
    }
    LayerAssembly context = assembly.layer("Context").uses(data);
    {
        ModuleAssembly contexts = context.module("Context");
        for (Class<?> contextClass : filter(not(hasModifier(Modifier.INTERFACE)), ClassScanner.findClasses(Context.class))) {
            if (contextClass.getName().contains("$")) {
                contexts.transients(contextClass).visibleIn(Visibility.application);
            } else {
                contexts.objects(contextClass).visibleIn(Visibility.application);
            }
        }
        for (Class<?> valueClass : filter(isAssignableFrom(ValueComposite.class), ClassScanner.findClasses(Context.class))) {
            contexts.values(valueClass).visibleIn(Visibility.application);
        }
        contexts.services(EventsService.class);
        context.module("Domain events").values(DomainEventValue.class, ParameterValue.class).visibleIn(Visibility.application);
    }
    LayerAssembly services = assembly.layer("Service").uses(data);
    {
        ModuleAssembly bootstrap = services.module("Bootstrap");
        bootstrap.services(BootstrapData.class).identifiedBy("bootstrap").instantiateOnStartup();
    }
    LayerAssembly rest = assembly.layer("REST").uses(context, data);
    {
        ModuleAssembly values = rest.module("Values");
        {
            new ValueAssembler().assemble(values);
        }
        ModuleAssembly transformation = rest.module("Transformation");
        {
            new RestServerAssembler().assemble(transformation);
            transformation.objects(RequestReaderDelegator.class, ResponseWriterDelegator.class).visibleIn(Visibility.layer);
            new OrgJsonValueSerializationAssembler().assemble(transformation);
        }
        ModuleAssembly resources = rest.module("Resources");
        for (Class<?> resourceClass : ClassScanner.findClasses(RootResource.class)) {
            resources.objects(resourceClass).visibleIn(Visibility.layer);
        }
        ModuleAssembly restlet = rest.module("Restlet");
        restlet.objects(ForumRestlet.class);
        restlet.importedServices(CommandResult.class).setMetaInfo(new DomainCommandResult());
        restlet.importedServices(MetadataService.class);
    }
    return assembly;
}
Also used : MemoryEntityStoreService(org.qi4j.entitystore.memory.MemoryEntityStoreService) UuidIdentityGeneratorService(org.qi4j.spi.uuid.UuidIdentityGeneratorService) RootResource(org.qi4j.samples.forum.rest.resource.RootResource) EntityComposite(org.qi4j.api.entity.EntityComposite) User(org.qi4j.samples.forum.data.entity.User) ResponseWriterDelegator(org.qi4j.library.rest.server.restlet.ResponseWriterDelegator) BootstrapData(org.qi4j.samples.forum.service.BootstrapData) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) DomainCommandResult(org.qi4j.samples.forum.domainevent.DomainCommandResult) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) MetadataService(org.restlet.service.MetadataService) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) FileConfigurationService(org.qi4j.library.fileconfig.FileConfigurationService) RequestReaderDelegator(org.qi4j.library.rest.server.restlet.RequestReaderDelegator) RestServerAssembler(org.qi4j.library.rest.server.assembler.RestServerAssembler) Module(org.qi4j.api.structure.Module) ValueAssembler(org.qi4j.library.rest.common.ValueAssembler) Application(org.qi4j.api.structure.Application) EventsService(org.qi4j.samples.forum.context.EventsService) ForumRestlet(org.qi4j.samples.forum.rest.ForumRestlet) OrgJsonValueSerializationAssembler(org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler)

Example 48 with Application

use of org.qi4j.api.structure.Application in project qi4j-sdk by Qi4j.

the class PostgreSQLEntityStorePerformanceTest method cleanUp.

@Override
protected void cleanUp() throws Exception {
    try {
        super.cleanUp();
    } finally {
        Energy4Java qi4j = new Energy4Java();
        Assembler[][][] assemblers = new Assembler[][][] { { { createAssembler() } } };
        Application application = qi4j.newApplication(new ApplicationAssemblerAdapter(assemblers) {
        });
        application.activate();
        Module moduleInstance = application.findModule("Layer 1", "config");
        UnitOfWorkFactory uowf = moduleInstance;
        UnitOfWork uow = uowf.newUnitOfWork();
        try {
            SQLConfiguration config = uow.get(SQLConfiguration.class, PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY);
            // TODO fix AbstractEntityStorePerformanceTest to extend from AbstractQi4jTest
            // SQLUtil.getConnection( this.serviceLocator );
            Connection connection = null;
            String schemaName = config.schemaName().get();
            if (schemaName == null) {
                schemaName = SQLs.DEFAULT_SCHEMA_NAME;
            }
            Statement stmt = null;
            try {
                stmt = connection.createStatement();
                stmt.execute(String.format("DELETE FROM %s." + SQLs.TABLE_NAME, schemaName));
                connection.commit();
            } finally {
                SQLUtil.closeQuietly(stmt);
            }
        } finally {
            uow.discard();
        }
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Statement(java.sql.Statement) Connection(java.sql.Connection) Energy4Java(org.qi4j.bootstrap.Energy4Java) UnitOfWorkFactory(org.qi4j.api.unitofwork.UnitOfWorkFactory) SQLConfiguration(org.qi4j.library.sql.common.SQLConfiguration) DBCPDataSourceServiceAssembler(org.qi4j.library.sql.dbcp.DBCPDataSourceServiceAssembler) PostgreSQLEntityStoreAssembler(org.qi4j.entitystore.sql.assembly.PostgreSQLEntityStoreAssembler) Assembler(org.qi4j.bootstrap.Assembler) DataSourceAssembler(org.qi4j.library.sql.assembly.DataSourceAssembler) Module(org.qi4j.api.structure.Module) Application(org.qi4j.api.structure.Application) ApplicationAssemblerAdapter(org.qi4j.bootstrap.ApplicationAssemblerAdapter)

Example 49 with Application

use of org.qi4j.api.structure.Application in project qi4j-sdk by Qi4j.

the class StorageModule method assemble.

@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
    module.services(MemoryEntityStoreService.class).visibleIn(Visibility.application);
    module.services(UuidIdentityGeneratorService.class).visibleIn(Visibility.application);
    new OrgJsonValueSerializationAssembler().visibleIn(Visibility.application).withValuesModuleFinder(new Function<Application, Module>() {

        @Override
        public Module map(Application app) {
            return app.findModule("DomainLayer", "RentalModule");
        }
    }).assemble(module);
}
Also used : MemoryEntityStoreService(org.qi4j.entitystore.memory.MemoryEntityStoreService) UuidIdentityGeneratorService(org.qi4j.spi.uuid.UuidIdentityGeneratorService) Function(org.qi4j.functional.Function) Application(org.qi4j.api.structure.Application) OrgJsonValueSerializationAssembler(org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler)

Example 50 with Application

use of org.qi4j.api.structure.Application in project qi4j-sdk by Qi4j.

the class Main method main.

public static void main(String[] args) throws Exception {
    final Application application = new Energy4Java().newApplication(new AppAssembler());
    application.activate();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        @SuppressWarnings("CallToThreadDumpStack")
        public void run() {
            try {
                application.passivate();
            } catch (Exception ex) {
                System.err.println("Unable to passivate Qi4j application!");
                ex.printStackTrace();
            }
        }
    }));
    Module domainModule = application.findModule("app", "domain");
    int exitStatus = 0;
    try {
        UnitOfWork uow = domainModule.newUnitOfWork();
        EntityBuilder<PretextEntity> builder = uow.newEntityBuilder(PretextEntity.class);
        PretextEntity pretext = builder.instance();
        pretext.reason().set("Testing purpose");
        builder.newInstance();
        uow.complete();
        uow = domainModule.newUnitOfWork();
        QueryBuilder<PretextEntity> queryBuilder = domainModule.newQueryBuilder(PretextEntity.class);
        queryBuilder = queryBuilder.where(eq(templateFor(PretextEntity.class).reason(), "Testing purpose"));
        Query<PretextEntity> query = uow.newQuery(queryBuilder);
        pretext = query.find();
        if (pretext == null) {
            System.err.println("ERROR: Unable to find pretext!");
            exitStatus = -1;
        } else {
            System.out.println("SUCCESS: Found Pretext with reason: " + pretext.reason().get());
        }
        uow.discard();
    } finally {
        deleteData(application.findModule("infra", "persistence"));
    }
    System.exit(exitStatus);
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) SQLException(java.sql.SQLException) Energy4Java(org.qi4j.bootstrap.Energy4Java) Module(org.qi4j.api.structure.Module) Application(org.qi4j.api.structure.Application)

Aggregations

Application (org.qi4j.api.structure.Application)50 Test (org.junit.Test)32 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)26 Module (org.qi4j.api.structure.Module)18 Energy4Java (org.qi4j.bootstrap.Energy4Java)18 Assembler (org.qi4j.bootstrap.Assembler)13 ApplicationAssemblerAdapter (org.qi4j.bootstrap.ApplicationAssemblerAdapter)10 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)10 AssemblyException (org.qi4j.bootstrap.AssemblyException)8 Function (org.qi4j.functional.Function)7 ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)6 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)6 UnitOfWorkFactory (org.qi4j.api.unitofwork.UnitOfWorkFactory)5 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)5 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)4 MemoryEntityStoreService (org.qi4j.entitystore.memory.MemoryEntityStoreService)4 UuidIdentityGeneratorService (org.qi4j.spi.uuid.UuidIdentityGeneratorService)4 OrgJsonValueSerializationService (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService)4 ArrayList (java.util.ArrayList)3 ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)3