use of net.n2oapp.framework.api.metadata.SourceMetadata in project n2o-framework by i-novus-llc.
the class DynamicConfigReaderTest method test.
@Test
public void test() throws Exception {
List<SourceMetadata> cache = new ArrayList<>();
N2oDynamicMetadataProviderFactory providerFactory = new N2oDynamicMetadataProviderFactory();
providerFactory.add(new TestDynamicMetadataProvider("sec", asList(setId(new N2oStandardPage(), "sec?role"), setId(new N2oObject(), "sec?role"))), new TestDynamicMetadataProvider("amb", asList(setId(new N2oStandardPage(), "amb?page1"), setId(new N2oStandardPage(), "amb?page2"), setId(new N2oObject(), "amb?object1"))));
JavaSourceLoader reader = new JavaSourceLoader(providerFactory, cache::add);
// проверяем чтение
SourceMetadata metadata = reader.load(new JavaInfo("sec", N2oPage.class), "role");
assert metadata.getId().equals("sec?role");
cache.clear();
metadata = reader.load(new JavaInfo("sec", N2oObject.class), "role");
assert metadata.getId().equals("sec?role");
// проверяем кэширование
List ids = cache.stream().map(SourceMetadata::getId).collect(Collectors.toList());
assert ids.size() == 2;
assert ids.contains("sec?role");
cache.clear();
// проверяем чтение
metadata = reader.load(new JavaInfo("amb", N2oPage.class), "page1");
// проверяем кэширование
ids = cache.stream().map(SourceMetadata::getId).collect(Collectors.toList());
assert ids.size() == 3;
assert ids.contains("amb?page1");
assert ids.contains("amb?page2");
assert ids.contains("amb?object1");
assert metadata.getId().equals("amb?page1");
metadata = reader.load(new JavaInfo("amb", N2oPage.class), "page2");
assert metadata.getId().equals("amb?page2");
metadata = reader.load(new JavaInfo("amb", N2oObject.class), "object1");
assert metadata.getId().equals("amb?object1");
}
use of net.n2oapp.framework.api.metadata.SourceMetadata in project n2o-framework by i-novus-llc.
the class N2oReadPipeline method read.
@Override
public ReadTerminalPipeline<ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline>> read() {
pullOp(READ);
return new ReadTerminalPipeline<ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline>>() {
@Override
public <S extends SourceMetadata> S get(String id, Class<S> sourceClass) {
return execute(new DummyCompileContext<>(id, sourceClass), null, null);
}
@Override
public <S extends SourceMetadata> S get(String id, Class<S> sourceClass, SourceProcessor p) {
return execute(ops(), new DummyCompileContext<>(id, sourceClass), null, null, null, null, p);
}
@Override
public ReadPersistTerminalPipeline persist() {
pullOp(PERSIST);
return new ReadPersistTerminalPipeline() {
@Override
public <S extends SourceMetadata> InputStream get(String id, Class<S> sourceClass) {
return execute(new DummyCompileContext<>(id, sourceClass), null, null);
}
@Override
public <S extends SourceMetadata> void set(String id, Class<S> sourceClass, OutputStream output) {
try (InputStream is = get(id, sourceClass)) {
IOUtils.copy(is, output);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
@Override
public <S extends SourceMetadata> void set(String id, MetaType metaType, String directory) {
String path = PathUtil.concatFileNameAndBasePath(id + "." + metaType.getSourceType() + ".xml", directory);
FileSystemUtil.saveContentToFile(get(id, metaType.getBaseSourceClass()), new File(path));
}
};
}
@Override
public ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline> compile() {
pullOp(COMPILE);
return new ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline>() {
@Override
public <D extends Compiled> D get(CompileContext<D, ?> ctx) {
return execute(ctx, null, null);
}
@Override
public <D extends Compiled> D get(CompileContext<D, ?> ctx, CompileProcessor p) {
return execute(ctx, null, null, (N2oCompileProcessor) p);
}
@Override
public ReadCompileBindTerminalPipeline bind() {
pullOp(BIND);
return new ReadCompileBindTerminalPipeline() {
@Override
public <D extends Compiled> D get(CompileContext<D, ?> context, DataSet data) {
return execute(context, data, null);
}
@Override
public <D extends Compiled> D get(CompileContext<D, ?> context, DataSet data, SubModelsProcessor subModelsProcessor) {
return execute(context, data, null, subModelsProcessor);
}
@Override
public ReadCompileBindTerminalPipeline bind() {
pullOp(BIND);
return this;
}
};
}
@Override
public ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline> transform() {
pullOp(COMPILE_TRANSFORM);
return this;
}
@Override
public ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline> cache() {
pullOp(COMPILE_CACHE);
return this;
}
@Override
public ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline> copy() {
pullOp(COPY);
return this;
}
};
}
@Override
public ReadTerminalPipeline<ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline>> validate() {
pullOp(VALIDATE);
return this;
}
@Override
public ReadTerminalPipeline<ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline>> merge() {
pullOp(MERGE);
return this;
}
@Override
public ReadTerminalPipeline<ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline>> transform() {
pullOp(SOURCE_TRANSFORM);
return this;
}
@Override
public ReadTerminalPipeline<ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline>> cache() {
pullOp(SOURCE_CACHE);
return this;
}
@Override
public ReadTerminalPipeline<ReadCompileTerminalPipeline<ReadCompileBindTerminalPipeline>> copy() {
pullOp(COPY);
return this;
}
};
}
use of net.n2oapp.framework.api.metadata.SourceMetadata in project n2o-framework by i-novus-llc.
the class JavaSourceLoader method readContent.
@SuppressWarnings("unchecked")
private <T extends SourceMetadata> T readContent(String id, Class<T> metadataClass, String params) {
DynamicMetadataProvider provider = providerFactory.produce(id);
List<SourceMetadata> metadataList = provider.read(params);
// проверяем что id динамические
metadataList.stream().filter(m -> m.getId() == null).forEach(m -> m.setId(provider.getCode() + "?" + params));
DynamicUtil.checkDynamicIds(metadataList.stream().map(SourceMetadata::getId).collect(Collectors.toList()), provider.getCode());
// кэшируем все что нашли
if (cacheService != null && provider.cache(params))
cache(metadataList);
// ищем ту единственную
Optional<? extends SourceMetadata> optional = metadataList.stream().filter(m -> m.getId().equals(id + "?" + params)).filter(m -> metadataClass.isAssignableFrom(m.getClass())).findAny();
if (optional.isPresent())
return (T) optional.get();
else
throw new ReferentialIntegrityViolationException(id, metadataClass);
}
use of net.n2oapp.framework.api.metadata.SourceMetadata in project n2o-framework by i-novus-llc.
the class XmlMetadataLoaderTest method testLoadWithParams.
/**
* Проверка, что параметры переданные в load резолвятся в xml
*/
@Test
public void testLoadWithParams() {
XmlInfo info = new XmlInfo("testXmlInfo", N2oSimplePage.class, "net/n2oapp/framework/config/metadata/testXmlInfo.page.xml");
XmlMetadataLoader xmlMetadataLoader = new XmlMetadataLoader(new ReaderFactoryByMap().register(new SimplePageElementIOv3()).register(new FormElementIOV4()));
SourceMetadata metadata = xmlMetadataLoader.load(info, "formName=Patients");
assertThat(((N2oSimplePage) metadata).getWidget().getName(), is("Patients"));
assertThat(MetadataParamHolder.getParams().isEmpty(), is(true));
}
Aggregations