Search in sources :

Example 66 with Package

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();
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 67 with Package

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));
}
Also used : Stream(java.util.stream.Stream) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 68 with Package

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);
}
Also used : PackageIdentity(org.molgenis.data.security.PackageIdentity) MutableAcl(org.springframework.security.acls.model.MutableAcl) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 69 with Package

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;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultPackage(org.molgenis.data.meta.DefaultPackage) Package(org.molgenis.data.meta.model.Package) EntityImportReport(org.molgenis.data.importer.EntityImportReport)

Example 70 with Package

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;
}
Also used : DefaultPackage(org.molgenis.data.meta.DefaultPackage) Package(org.molgenis.data.meta.model.Package)

Aggregations

Package (org.molgenis.data.meta.model.Package)98 Test (org.testng.annotations.Test)70 EntityType (org.molgenis.data.meta.model.EntityType)22 Stream (java.util.stream.Stream)20 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)13 Attribute (org.molgenis.data.meta.model.Attribute)11 DefaultPackage (org.molgenis.data.meta.DefaultPackage)10 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)10 Objects.requireNonNull (java.util.Objects.requireNonNull)6 L10nString (org.molgenis.data.i18n.model.L10nString)6 PackageIdentity (org.molgenis.data.security.PackageIdentity)6 Collectors.toList (java.util.stream.Collectors.toList)5 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)5 DataService (org.molgenis.data.DataService)5 QueryImpl (org.molgenis.data.support.QueryImpl)5 RepositoryCollection (org.molgenis.data.RepositoryCollection)4 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 java.util (java.util)3 Collections.singletonList (java.util.Collections.singletonList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3