Search in sources :

Example 76 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class PermissionManagerController method updatePackagePermissions.

private void updatePackagePermissions(WebRequest webRequest, Sid sid) {
    for (Package package_ : getPackages()) {
        String param = "radio-" + package_.getId();
        String value = webRequest.getParameter(param);
        if (value != null) {
            if (!value.equals("none")) {
                createSidPackagePermission(package_, sid, toEntityTypePermission(value));
            } else {
                removeSidPackagePermission(package_, sid);
            }
        }
    }
}
Also used : Package(org.molgenis.data.meta.model.Package)

Example 77 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class MetaDataServiceImplTest method getRootPackages.

@Test
public void getRootPackages() {
    Package package0 = mock(Package.class);
    Package package1 = mock(Package.class);
    @SuppressWarnings("unchecked") Query<Package> packageQ = mock(Query.class);
    when(packageQ.eq(PARENT, null)).thenReturn(packageQ);
    when(packageQ.findAll()).thenReturn(Stream.of(package0, package1));
    when(dataService.query(PACKAGE, Package.class)).thenReturn(packageQ);
    assertEquals(metaDataServiceImpl.getRootPackages(), newArrayList(package0, package1));
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 78 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class MetaDataServiceImplTest method createRepositoryTyped.

@SuppressWarnings("unchecked")
@Test
public void createRepositoryTyped() {
    String backendName = "backend";
    Class<Package> entityClass = Package.class;
    EntityType entityType = mock(EntityType.class);
    when(entityType.getBackend()).thenReturn(backendName);
    Attribute attr0 = mock(Attribute.class);
    Attribute attr1 = mock(Attribute.class);
    when(entityType.getOwnAllAttributes()).thenReturn(newArrayList(attr0, attr1));
    RepositoryCollection repoCollection = mock(RepositoryCollection.class);
    when(repoCollectionRegistry.getRepositoryCollection(backendName)).thenReturn(repoCollection);
    Repository<Package> repo = mock(Repository.class);
    when(repoCollection.getRepository(entityType)).thenReturn((Repository<Entity>) (Repository<?>) repo);
    assertEquals(metaDataServiceImpl.createRepository(entityType, entityClass), repo);
    ArgumentCaptor<Stream<Entity>> attrsCaptor = ArgumentCaptor.forClass(Stream.class);
    verify(dataService).add(eq(ATTRIBUTE_META_DATA), attrsCaptor.capture());
    assertEquals(attrsCaptor.getValue().collect(toList()), newArrayList(attr0, attr1));
    verify(dataService).add(ENTITY_TYPE_META_DATA, entityType);
    verifyNoMoreInteractions(dataService);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Attribute(org.molgenis.data.meta.model.Attribute) Stream(java.util.stream.Stream) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 79 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class MetaDataServiceImplTest method getPackageString.

@Test
public void getPackageString() {
    Package package_ = mock(Package.class);
    String packageId = "package";
    when(dataService.findOneById(PACKAGE, packageId, Package.class)).thenReturn(package_);
    assertEquals(metaDataServiceImpl.getPackage(packageId), package_);
}
Also used : Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 80 with Package

use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.

the class MetaDataServiceImplTest method upsertPackages.

@Test
public void upsertPackages() {
    Package package0 = mock(Package.class);
    Package package1 = mock(Package.class);
    metaDataServiceImpl.upsertPackages(Stream.of(package0, package1));
    @SuppressWarnings("unchecked") ArgumentCaptor<Stream<Package>> captor = ArgumentCaptor.forClass(Stream.class);
    verify(packagePersister).upsertPackages(captor.capture());
    assertEquals(captor.getValue().collect(toList()), asList(package0, package1));
}
Also used : Stream(java.util.stream.Stream) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

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