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()));
}
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);
}
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);
}
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);
}
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();
}
}
Aggregations