use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PackageRepositorySecurityDecoratorTest method testDeleteAll.
@Test
public void testDeleteAll() {
Package package1 = mock(Package.class);
Package package2 = mock(Package.class);
when(package1.getId()).thenReturn("1");
when(package2.getId()).thenReturn("2");
when(delegateRepository.iterator()).thenReturn(Arrays.asList(package1, package2).iterator());
repo.deleteAll();
// TODO: how to verify the deleteAcl method in the "filter" of the stream
verify(delegateRepository).deleteAll();
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PackageRepositorySecurityDecoratorTest method testUpdate1.
@Test
public void testUpdate1() {
Package package1 = mock(Package.class);
Package package2 = mock(Package.class);
when(package1.getId()).thenReturn("1");
when(package2.getId()).thenReturn("2");
Stream<Package> packages = Stream.of(package1, package2);
repo.update(packages);
// TODO: how to verify the deleteAcl method in the "filter" of the stream
ArgumentCaptor<Stream<Package>> captor = ArgumentCaptor.forClass(Stream.class);
verify(delegateRepository).update(captor.capture());
assertEquals(captor.getValue().collect(toList()), asList(package1, package2));
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PackageRepositorySecurityDecoratorTest method testAdd.
@Test
public void testAdd() {
Package pack = mock(Package.class);
Package parent = mock(Package.class);
when(pack.getId()).thenReturn("1");
when(parent.getId()).thenReturn("2");
when(pack.getParent()).thenReturn(parent);
MutableAcl acl = mock(MutableAcl.class);
MutableAcl parentAcl = mock(MutableAcl.class);
when(mutableAclService.createAcl(new PackageIdentity("1"))).thenReturn(acl);
when(mutableAclService.readAclById(new PackageIdentity("2"))).thenReturn(parentAcl);
repo.add(pack);
verify(mutableAclService).createAcl(new PackageIdentity("1"));
verify(mutableAclService).updateAcl(acl);
verify(delegateRepository).add(pack);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class VcfImporterService method importVcf.
private EntityImportReport importVcf(Repository<Entity> inRepository, List<EntityType> addedEntities, String packageId) throws IOException {
EntityImportReport report = new EntityImportReport();
String entityTypeId = inRepository.getName();
if (runAsSystem(() -> dataService.hasRepository(entityTypeId))) {
throw new MolgenisDataException("Can't overwrite existing " + entityTypeId);
}
EntityType entityType = inRepository.getEntityType();
entityType.setBackend(metaDataService.getDefaultBackend().getName());
Package targetPackage = determineTargetPackage(packageId, entityType);
Repository<Entity> sampleRepository = createSampleRepository(addedEntities, entityType, targetPackage);
Iterator<Entity> inIterator = inRepository.iterator();
try (Repository<Entity> outRepository = runAsSystem(() -> dataService.getMeta().createRepository(entityType))) {
permissionSystemService.giveUserWriteMetaPermissions(entityType);
addedEntities.add(entityType);
if (sampleRepository != null) {
int sampleEntityCount = addSampleEntities(sampleRepository, inIterator);
report.addNewEntity(sampleRepository.getName());
if (sampleEntityCount > 0) {
report.addEntityCount(sampleRepository.getName(), sampleEntityCount);
}
}
AtomicInteger vcfEntityCount = new AtomicInteger();
runAsSystem(() -> outRepository.add(StreamSupport.stream(inRepository.spliterator(), false).filter(entity -> {
vcfEntityCount.incrementAndGet();
return true;
})));
if (vcfEntityCount.get() > 0) {
report.addEntityCount(entityTypeId, vcfEntityCount.get());
}
}
report.addNewEntity(entityTypeId);
return report;
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class VcfImporterService method determineTargetPackage.
private Package determineTargetPackage(String packageId, EntityType entityType) {
Package targetPackage;
if (packageId != null) {
targetPackage = dataService.getMeta().getPackage(packageId);
if (targetPackage == null)
throw new MolgenisDataException(String.format("Unknown package [%s]", packageId));
entityType.setPackage(targetPackage);
} else {
targetPackage = defaultPackage;
}
return targetPackage;
}
Aggregations