Search in sources :

Example 21 with Function

use of org.qi4j.functional.Function in project qi4j-sdk by Qi4j.

the class DomainEventTest method testDomainEvent.

@Test
public void testDomainEvent() throws UnitOfWorkCompletionException, IOException {
    // Set principal for the UoW
    Principal administratorPrincipal = new Principal() {

        public String getName() {
            return "administrator";
        }
    };
    // Perform UoW with usecase defined
    UnitOfWork uow = module.newUnitOfWork(UsecaseBuilder.newUsecase("Change description"));
    uow.setMetaInfo(administratorPrincipal);
    TestEntity entity = uow.newEntity(TestEntity.class);
    entity.changedDescription("New description");
    uow.complete();
    // Print events
    EventSource source = (EventSource) module.findService(EventSource.class).get();
    source.events(0, Long.MAX_VALUE).transferTo(Transforms.map(new Function<UnitOfWorkDomainEventsValue, String>() {

        public String map(UnitOfWorkDomainEventsValue unitOfWorkDomainEventsValue) {
            return unitOfWorkDomainEventsValue.toString();
        }
    }, Outputs.systemOut()));
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Function(org.qi4j.functional.Function) EventSource(org.qi4j.library.eventsourcing.domain.source.EventSource) Principal(java.security.Principal) CurrentUserUoWPrincipal(org.qi4j.library.eventsourcing.domain.factory.CurrentUserUoWPrincipal) UnitOfWorkDomainEventsValue(org.qi4j.library.eventsourcing.domain.api.UnitOfWorkDomainEventsValue) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 22 with Function

use of org.qi4j.functional.Function in project qi4j-sdk by Qi4j.

the class Assembler 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(OrgJsonValueSerializationService.class);
    indexingModule.services(MemoryRepositoryService.class, RdfIndexingEngineService.class).instantiateOnStartup().visibleIn(application);
    ModuleAssembly entityStoreModule = infrastructureLayer.module("INFRASTRUCTURE-EntityStore");
    entityStoreModule.services(MemoryEntityStoreService.class, UuidIdentityGeneratorService.class).instantiateOnStartup().visibleIn(application);
    ModuleAssembly externalServiceModule = infrastructureLayer.module("INFRASTRUCTURE-ExternalService");
    externalServiceModule.importedServices(GraphTraversalService.class).setMetaInfo(new GraphTraversalServiceImpl(new GraphDAO())).visibleIn(application);
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) Function(org.qi4j.functional.Function) OrgJsonValueSerializationService(org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService) GraphTraversalServiceImpl(org.qi4j.sample.dcicargo.pathfinder.internal.GraphTraversalServiceImpl) Application(org.qi4j.api.structure.Application) GraphDAO(org.qi4j.sample.dcicargo.pathfinder.internal.GraphDAO)

Example 23 with Function

use of org.qi4j.functional.Function 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.internal.GraphTraversalServiceImpl) Application(org.qi4j.api.structure.Application) GraphDAO(org.qi4j.sample.dcicargo.pathfinder.internal.GraphDAO)

Example 24 with Function

use of org.qi4j.functional.Function 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-ContextSupport");
        }
    }).visibleIn(application);
    ModuleAssembly indexingModule = infrastructureLayer.module("INFRASTRUCTURE-Indexing");
    indexingModule.objects(EntityStateSerializer.class, EntityTypeSerializer.class);
    indexingModule.addServices(MemoryRepositoryService.class, RdfIndexingEngineService.class).visibleIn(application);
    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) RdfIndexingEngineService(org.qi4j.index.rdf.RdfIndexingEngineService) GraphTraversalServiceImpl(org.qi4j.sample.dcicargo.pathfinder.internal.GraphTraversalServiceImpl) MemoryRepositoryService(org.qi4j.library.rdf.repository.MemoryRepositoryService) Application(org.qi4j.api.structure.Application) GraphDAO(org.qi4j.sample.dcicargo.pathfinder.internal.GraphDAO)

Example 25 with Function

use of org.qi4j.functional.Function 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)

Aggregations

Function (org.qi4j.functional.Function)25 Type (java.lang.reflect.Type)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Application (org.qi4j.api.structure.Application)7 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)6 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)5 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)4 GraphDAO (org.qi4j.sample.dcicargo.pathfinder.internal.GraphDAO)4 GraphTraversalServiceImpl (org.qi4j.sample.dcicargo.pathfinder.internal.GraphTraversalServiceImpl)4 OrgJsonValueSerializationService (org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService)4 EntityReference (org.qi4j.api.entity.EntityReference)3 Annotations.isType (org.qi4j.api.util.Annotations.isType)3 Classes.wrapperClass (org.qi4j.api.util.Classes.wrapperClass)3 MemoryEntityStoreService (org.qi4j.entitystore.memory.MemoryEntityStoreService)3 UuidIdentityGeneratorService (org.qi4j.spi.uuid.UuidIdentityGeneratorService)3 Principal (java.security.Principal)2 AssociationDescriptor (org.qi4j.api.association.AssociationDescriptor)2 Concerns (org.qi4j.api.concern.Concerns)2 Constraint (org.qi4j.api.constraint.Constraint)2