Search in sources :

Example 6 with ApplicationAssembly

use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.

the class SchoolAssembler method assemble.

@Override
public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
    final ApplicationAssembly appAssembly = applicationFactory.newApplicationAssembly();
    appAssembly.setName("School");
    // Create layers
    LayerAssembly layerUI = createUILayer(appAssembly);
    LayerAssembly layerDomain = createDomainLayer(appAssembly);
    LayerAssembly layerInfra = createInfrastructureLayer(appAssembly);
    LayerAssembly layerConfig = createConfigLayer(appAssembly);
    layerUI.uses(layerDomain);
    layerDomain.uses(layerInfra);
    layerDomain.uses(layerConfig);
    return appAssembly;
}
Also used : ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) LayerAssembly(org.qi4j.bootstrap.LayerAssembly)

Example 7 with ApplicationAssembly

use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.

the class ApplicationAssemblyFactoryImpl method newApplicationAssembly.

@Override
public ApplicationAssembly newApplicationAssembly(Assembler[][][] assemblers) throws AssemblyException {
    ApplicationAssembly applicationAssembly = newApplicationAssembly();
    // Build all layers bottom-up
    LayerAssembly below = null;
    for (int layer = assemblers.length - 1; layer >= 0; layer--) {
        // Create Layer
        LayerAssembly layerAssembly = applicationAssembly.layer("Layer " + (layer + 1));
        for (int module = 0; module < assemblers[layer].length; module++) {
            // Create Module
            ModuleAssembly moduleAssembly = layerAssembly.module("Module " + (module + 1));
            for (Assembler assembler : assemblers[layer][module]) {
                // Register Assembler
                assembler.assemble(moduleAssembly);
            }
        }
        if (below != null) {
            // Link layers
            layerAssembly.uses(below);
        }
        below = layerAssembly;
    }
    return applicationAssembly;
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) Assembler(org.qi4j.bootstrap.Assembler) LayerAssembly(org.qi4j.bootstrap.LayerAssembly)

Example 8 with ApplicationAssembly

use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.

the class ApplicationDocs method createAssembly.

private static ApplicationAssembly createAssembly(ApplicationAssemblyFactory factory) throws AssemblyException {
    String applicationName = "Example Application";
    ApplicationAssembly app = factory.newApplicationAssembly();
    app.setName(applicationName);
    LayerAssembly webLayer = createWebLayer(app);
    LayerAssembly domainLayer = createDomainLayer(app);
    LayerAssembly infraLayer = createInfrastructureLayer(app);
    webLayer.uses(domainLayer);
    // Accesses the WebService
    webLayer.uses(infraLayer);
    // For persistence
    domainLayer.uses(infraLayer);
    return app;
}
Also used : ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) LayerAssembly(org.qi4j.bootstrap.LayerAssembly)

Example 9 with ApplicationAssembly

use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.

the class DocumentationSupport method assembledWithValuesModuleSerialization.

// END SNIPPET: io
@Test
public // TODO Include in each ValueSerialization extensions documentation
void assembledWithValuesModuleSerialization() throws Exception {
    Application app = new Energy4Java().newApplication(new ApplicationAssembler() {

        @Override
        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            Assembler[][][] pancakes = new Assembler[][][] { { { new Assembler() {

                @Override
                public void assemble(ModuleAssembly valuesModule) throws AssemblyException {
                    valuesModule.layer().setName("SINGLE-Layer");
                    valuesModule.setName("VALUES-Module");
                    valuesModule.values(SomeValue.class);
                }
            } }, { new Assembler() {

                @Override
                public void assemble(ModuleAssembly servicesModule) throws AssemblyException {
                    servicesModule.setName("SERVICES-Module");
                    Function<Application, Module> valuesModuleFinder = new Function<Application, Module>() {

                        @Override
                        public Module map(Application app) {
                            return app.findModule("SINGLE-Layer", "VALUES-Module");
                        }
                    };
                    new OrgJsonValueSerializationAssembler().withValuesModuleFinder(valuesModuleFinder).assemble(servicesModule);
                }
            } } } };
            return applicationFactory.newApplicationAssembly(pancakes);
        }
    });
    app.activate();
    try {
        Module valuesModule = app.findModule("SINGLE-Layer", "VALUES-Module");
        SomeValue someValue = someNewValueInstance(valuesModule);
        Module servicesModule = app.findModule("SINGLE-Layer", "SERVICES-Module");
        ValueSerialization valueSerialization = servicesModule.findService(ValueSerialization.class).get();
        String json = valueSerialization.serialize(someValue);
        assertThat(json, equalTo("{\"foo\":\"bar\"}"));
        SomeValue someNewValue = valueSerialization.deserialize(SomeValue.class, json);
        assertThat(someNewValue, equalTo(someValue));
    } finally {
        app.passivate();
    }
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) Function(org.qi4j.functional.Function) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) Assembler(org.qi4j.bootstrap.Assembler) OrgJsonValueSerializationAssembler(org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Module(org.qi4j.api.structure.Module) Application(org.qi4j.api.structure.Application) OrgJsonValueSerializationAssembler(org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 10 with ApplicationAssembly

use of org.qi4j.bootstrap.ApplicationAssembly in project qi4j-sdk by Qi4j.

the class ServiceInjectionTest method testInjectionServiceBetweenLayers.

@Test
public void testInjectionServiceBetweenLayers() throws ActivationException, AssemblyException {
    SingletonAssembler assembly = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.services(MyServiceComposite.class).identifiedBy("Foo").setMetaInfo(new ServiceName("Foo"));
            module.services(StringService.class, LongService.class);
            LayerAssembly layerAssembly = module.layer();
            module.objects(ServiceUser.class);
            ApplicationAssembly applicationAssembly = layerAssembly.application();
            LayerAssembly layer2Assembly = applicationAssembly.layer("Other layer");
            layerAssembly.uses(layer2Assembly);
            ModuleAssembly module2 = layer2Assembly.module("Other module");
            ServiceDeclaration service2Decl = module2.services(MyServiceComposite2.class);
            service2Decl.identifiedBy("Bar").setMetaInfo(new ServiceName("Bar")).visibleIn(application);
        }
    };
    testInjection(assembly);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) ServiceDeclaration(org.qi4j.bootstrap.ServiceDeclaration) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) Test(org.junit.Test)

Aggregations

ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)20 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)16 ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)8 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)8 AssemblyException (org.qi4j.bootstrap.AssemblyException)8 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)8 Energy4Java (org.qi4j.bootstrap.Energy4Java)7 Test (org.junit.Test)6 Application (org.qi4j.api.structure.Application)6 ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)4 Module (org.qi4j.api.structure.Module)3 Assembler (org.qi4j.bootstrap.Assembler)3 OrgJsonValueSerializationAssembler (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler)2 HashMap (java.util.HashMap)1 ActivationEventListener (org.qi4j.api.activation.ActivationEventListener)1 EntityComposite (org.qi4j.api.entity.EntityComposite)1 Identity (org.qi4j.api.entity.Identity)1 LayerDescriptor (org.qi4j.api.structure.LayerDescriptor)1 EntityTypeNotFoundException (org.qi4j.api.unitofwork.EntityTypeNotFoundException)1 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)1