Search in sources :

Example 6 with Application

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

the class ApplicationModelFactoryImpl method newApplicationModel.

@Override
public ApplicationDescriptor newApplicationModel(ApplicationAssembly assembly) throws AssemblyException {
    AssemblyHelper helper = new AssemblyHelper();
    ApplicationAssemblyImpl applicationAssembly = (ApplicationAssemblyImpl) assembly;
    ActivatorsModel<Application> applicationActivators = new ActivatorsModel<>(applicationAssembly.activators());
    List<LayerModel> layerModels = new ArrayList<>();
    final ApplicationModel applicationModel = new ApplicationModel(applicationAssembly.name(), applicationAssembly.version(), applicationAssembly.mode(), applicationAssembly.metaInfo(), applicationActivators, layerModels);
    Map<LayerAssembly, LayerModel> mapAssemblyModel = new HashMap<>();
    Map<LayerAssembly, List<LayerModel>> mapUsedLayers = new HashMap<>();
    // Build all layers
    List<LayerAssemblyImpl> layerAssemblies = new ArrayList<>(applicationAssembly.layerAssemblies());
    for (LayerAssemblyImpl layerAssembly : layerAssemblies) {
        List<LayerModel> usedLayers = new ArrayList<>();
        mapUsedLayers.put(layerAssembly, usedLayers);
        UsedLayersModel usedLayersModel = new UsedLayersModel(usedLayers);
        List<ModuleModel> moduleModels = new ArrayList<>();
        String name = layerAssembly.name();
        if (name == null) {
            throw new AssemblyException("Layer must have name set");
        }
        ActivatorsModel<Layer> layerActivators = new ActivatorsModel<>(layerAssembly.activators());
        LayerModel layerModel = new LayerModel(name, layerAssembly.metaInfo(), usedLayersModel, layerActivators, moduleModels);
        for (ModuleAssemblyImpl moduleAssembly : layerAssembly.moduleAssemblies()) {
            moduleModels.add(moduleAssembly.assembleModule(helper));
        }
        mapAssemblyModel.put(layerAssembly, layerModel);
        layerModels.add(layerModel);
    }
    // Populate used layer lists
    for (LayerAssemblyImpl layerAssembly : layerAssemblies) {
        Set<LayerAssembly> usesLayers = layerAssembly.uses();
        List<LayerModel> usedLayers = mapUsedLayers.get(layerAssembly);
        for (LayerAssembly usesLayer : usesLayers) {
            LayerModel layerModel = mapAssemblyModel.get(usesLayer);
            usedLayers.add(layerModel);
        }
    }
    // This will resolve all dependencies
    try {
        //            applicationModel.bind();
        applicationModel.accept(new BindingVisitor(applicationModel));
    } catch (BindingException e) {
        throw new AssemblyException("Unable to bind: " + applicationModel, e);
    }
    return applicationModel;
}
Also used : LayerModel(org.qi4j.runtime.structure.LayerModel) UsedLayersModel(org.qi4j.runtime.structure.UsedLayersModel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationModel(org.qi4j.runtime.structure.ApplicationModel) ModuleModel(org.qi4j.runtime.structure.ModuleModel) AssemblyException(org.qi4j.bootstrap.AssemblyException) ArrayList(java.util.ArrayList) List(java.util.List) ActivatorsModel(org.qi4j.runtime.activation.ActivatorsModel) Layer(org.qi4j.api.structure.Layer) LayerAssembly(org.qi4j.bootstrap.LayerAssembly) BindingException(org.qi4j.bootstrap.BindingException) Application(org.qi4j.api.structure.Application)

Example 7 with Application

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

the class PluginTest method testPlugins.

@Test
@Ignore("Must fix the TODOs below. This example relied on ability to set Service MetaInfo at runtime, it seems it's not possible anymore.")
public void testPlugins() throws Exception {
    Energy4Java runtime = new Energy4Java();
    Application app = runtime.newApplication(new MainApplicationAssembler());
    app.activate();
}
Also used : Energy4Java(org.qi4j.bootstrap.Energy4Java) Application(org.qi4j.api.structure.Application) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Application

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

the class ApplicationActivationTest method testApplicationActivator.

@Test
public void testApplicationActivator() throws Exception {
    SingletonAssembler assembly = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.layer().application().withActivators(TestedActivator.class);
        }
    };
    // Activate
    Application application = assembly.application();
    // Assert activated
    Assert.assertEquals("Activation Level", 2, activationLevel);
    // Passivate
    application.passivate();
    // Assert passivated
    Assert.assertEquals("Passivation Level", 2, passivationLevel);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Application(org.qi4j.api.structure.Application) Test(org.junit.Test)

Example 9 with Application

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

the class ImportedServiceActivationTest method testServiceImporterImportedServiceActivators.

@Test
public void testServiceImporterImportedServiceActivators() throws Exception {
    SingletonAssembler assembler = new SingletonAssembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.importedServices(TestedService.class).importedBy(ImportedServiceDeclaration.SERVICE_IMPORTER).setMetaInfo("testimporter").withActivators(TestedActivator.class).importOnStartup();
            module.services(TestedServiceImporterService.class).identifiedBy("testimporter");
        }
    };
    Application application = assembler.application();
    assertEquals("Activation Level", 2, activationLevel);
    application.passivate();
    assertEquals("Passivation Level", 2, passivationLevel);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) SingletonAssembler(org.qi4j.bootstrap.SingletonAssembler) Application(org.qi4j.api.structure.Application) Test(org.junit.Test)

Example 10 with Application

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

the class MixinVisibilityTest method testMixinInLowerLayerIsVisible.

@Test
public void testMixinInLowerLayerIsVisible() throws Exception {
    Energy4Java boot = new Energy4Java();
    Assembler[][][] assemblers = new Assembler[][][] { { // Layer 1
    { new Assembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.setName("Module A");
            module.objects(ObjectA.class);
        }
    } } }, { // Layer 2
    { new Assembler() {

        public void assemble(ModuleAssembly module) throws AssemblyException {
            module.setName("Module B");
            module.transients(B1Composite.class).visibleIn(Visibility.application);
        }
    } } } };
    Application app = boot.newApplication(new ApplicationAssemblerAdapter(assemblers) {
    });
    app.activate();
    ObjectA object = app.findModule("Layer 1", "Module A").newObject(ObjectA.class);
    assertEquals("ok", object.test1());
    assertEquals("abc", object.test2());
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) Energy4Java(org.qi4j.bootstrap.Energy4Java) Assembler(org.qi4j.bootstrap.Assembler) Application(org.qi4j.api.structure.Application) ApplicationAssemblerAdapter(org.qi4j.bootstrap.ApplicationAssemblerAdapter) Test(org.junit.Test)

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