Search in sources :

Example 16 with LayerAssembly

use of org.qi4j.bootstrap.LayerAssembly 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 17 with LayerAssembly

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

the class ApplicationDocs method createDomainLayer.

private static LayerAssembly createDomainLayer(ApplicationAssembly application) {
    LayerAssembly layer = application.layer("Domain Layer");
    createCustomerDomainModule(layer);
    // :
    return layer;
}
Also used : LayerAssembly(org.qi4j.bootstrap.LayerAssembly)

Example 18 with LayerAssembly

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

the class ApplicationDocs method createInfrastructureLayer.

private static LayerAssembly createInfrastructureLayer(ApplicationAssembly application) throws AssemblyException {
    LayerAssembly layer = application.layer("Infrastructure Layer");
    createWebServiceModule(layer);
    createPersistenceModule(layer);
    return layer;
}
Also used : LayerAssembly(org.qi4j.bootstrap.LayerAssembly)

Example 19 with LayerAssembly

use of org.qi4j.bootstrap.LayerAssembly 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)

Example 20 with LayerAssembly

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

the class IssueTest method testLayersCanBeCreatedInOrderDifferentFromTheirDependency.

@Test
public void testLayersCanBeCreatedInOrderDifferentFromTheirDependency() throws AssemblyException {
    Energy4Java qi4j = new Energy4Java();
    Application app = qi4j.newApplication(new ApplicationAssembler() {

        public ApplicationAssembly assemble(ApplicationAssemblyFactory applicationFactory) throws AssemblyException {
            ApplicationAssembly assembly = applicationFactory.newApplicationAssembly();
            LayerAssembly domainLayer = assembly.layer(null);
            domainLayer.setName("Domain");
            LayerAssembly infrastructureLayer = assembly.layer(null);
            infrastructureLayer.setName("Infrastructure");
            domainLayer.uses(infrastructureLayer);
            return assembly;
        }
    });
    ApplicationDescriptor model = app.descriptor();
    model.accept(new HierarchicalVisitorAdapter<Object, Object, RuntimeException>() {

        @Override
        public boolean visitEnter(Object visited) throws RuntimeException {
            return visited instanceof ApplicationDescriptor;
        }

        @Override
        public boolean visitLeave(Object visited) throws RuntimeException {
            return visited instanceof LayerDescriptor;
        }

        @Override
        public boolean visit(Object visited) throws RuntimeException {
            if (visited instanceof LayerDescriptor) {
                Iterable<? extends LayerDescriptor> usedLayers = ((LayerDescriptor) visited).usedLayers().layers();
                for (LayerDescriptor usedLayerModel : usedLayers) {
                    Assert.assertNotNull("Used layer model is null", usedLayerModel);
                }
            }
            return false;
        }
    });
}
Also used : ApplicationAssemblyFactory(org.qi4j.bootstrap.ApplicationAssemblyFactory) ApplicationAssembly(org.qi4j.bootstrap.ApplicationAssembly) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) ApplicationDescriptor(org.qi4j.api.structure.ApplicationDescriptor) AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java) Application(org.qi4j.api.structure.Application) LayerDescriptor(org.qi4j.api.structure.LayerDescriptor) Test(org.junit.Test)

Aggregations

LayerAssembly (org.qi4j.bootstrap.LayerAssembly)31 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)16 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)15 AssemblyException (org.qi4j.bootstrap.AssemblyException)5 Test (org.junit.Test)4 Application (org.qi4j.api.structure.Application)4 ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)4 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)4 Energy4Java (org.qi4j.bootstrap.Energy4Java)4 ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)3 HashMap (java.util.HashMap)2 OrgJsonValueSerializationAssembler (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationAssembler)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ActivationEventListener (org.qi4j.api.activation.ActivationEventListener)1 EntityComposite (org.qi4j.api.entity.EntityComposite)1 Layer (org.qi4j.api.structure.Layer)1 LayerDescriptor (org.qi4j.api.structure.LayerDescriptor)1 Module (org.qi4j.api.structure.Module)1 Assembler (org.qi4j.bootstrap.Assembler)1