Search in sources :

Example 31 with Package

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

the class SystemEntityTypePersister method injectExistingPackageIdentifiers.

private void injectExistingPackageIdentifiers(List<Package> systemPackages) {
    Map<String, Package> existingPackageMap = dataService.findAll(PACKAGE, Package.class).collect(toMap(Package::getId, pack -> pack));
    systemPackages.forEach(pack -> {
        Package existingPackage = existingPackageMap.get(pack.getId());
        if (existingPackage != null) {
            pack.setId(existingPackage.getId());
        }
    });
}
Also used : EntityUtils(org.molgenis.data.util.EntityUtils) RepositoryCollection(org.molgenis.data.RepositoryCollection) Attribute(org.molgenis.data.meta.model.Attribute) EntityType(org.molgenis.data.meta.model.EntityType) Function(java.util.function.Function) MetaDataService(org.molgenis.data.meta.MetaDataService) MutableAclClassService(org.molgenis.security.acl.MutableAclClassService) Component(org.springframework.stereotype.Component) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ENTITY_TYPE_META_DATA(org.molgenis.data.meta.model.EntityTypeMetadata.ENTITY_TYPE_META_DATA) PACKAGE(org.molgenis.data.meta.model.PackageMetadata.PACKAGE) Stream(java.util.stream.Stream) Collectors.toMap(java.util.stream.Collectors.toMap) StreamSupport.stream(java.util.stream.StreamSupport.stream) SystemEntityType(org.molgenis.data.meta.SystemEntityType) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) DataService(org.molgenis.data.DataService) Package(org.molgenis.data.meta.model.Package) EntityIdentityUtils(org.molgenis.data.security.EntityIdentityUtils) EntityTypeDependencyResolver(org.molgenis.data.meta.EntityTypeDependencyResolver) Package(org.molgenis.data.meta.model.Package)

Example 32 with Package

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

the class PermissionManagerControllerTest method setUp.

@BeforeMethod
public void setUp() {
    config.resetMocks();
    mockMvc = MockMvcBuilders.standaloneSetup(permissionManagerController).setMessageConverters(gsonHttpMessageConverter).build();
    user1 = when(mock(User.class).getId()).thenReturn("1").getMock();
    when(user1.isSuperuser()).thenReturn(true);
    when(user1.getUsername()).thenReturn("Ipsum");
    userSid = new PrincipalSid("Ipsum");
    user2 = when(mock(User.class).getId()).thenReturn("2").getMock();
    group1 = when(mock(Group.class).getId()).thenReturn("1").getMock();
    groupSid = new GrantedAuthoritySid("ROLE_1");
    group2 = when(mock(Group.class).getId()).thenReturn("2").getMock();
    plugin1 = when(mock(Plugin.class).getId()).thenReturn("1").getMock();
    plugin2 = when(mock(Plugin.class).getId()).thenReturn("2").getMock();
    pluginIdentity1 = new PluginIdentity(plugin1);
    pluginIdentity2 = new PluginIdentity(plugin2);
    entityType1 = when(mock(EntityType.class).getId()).thenReturn("1").getMock();
    entityType2 = when(mock(EntityType.class).getId()).thenReturn("2").getMock();
    entityType3 = when(mock(EntityType.class).getId()).thenReturn("3").getMock();
    when(entityType1.getLabel()).thenReturn("label1");
    when(entityType2.getLabel()).thenReturn("label2");
    when(entityType3.getLabel()).thenReturn("label3");
    entityIdentity1 = new EntityTypeIdentity(entityType1);
    entityIdentity2 = new EntityTypeIdentity(entityType2);
    entityIdentity3 = new EntityTypeIdentity(entityType3);
    package1 = when(mock(Package.class).getId()).thenReturn("1").getMock();
    package2 = when(mock(Package.class).getId()).thenReturn("2").getMock();
    package3 = when(mock(Package.class).getId()).thenReturn("3").getMock();
    packageIdentity1 = new PackageIdentity(package1);
    packageIdentity2 = new PackageIdentity(package2);
    packageIdentity3 = new PackageIdentity(package3);
    when(dataService.findAll(USER, User.class)).thenReturn(Stream.of(user1, user2));
    when(dataService.findAll(GROUP, Group.class)).thenReturn(Stream.of(group1, group2));
    when(dataService.findOneById(GROUP, "1", Group.class)).thenReturn(group1);
    when(dataService.findOneById(USER, "1", User.class)).thenReturn(user1);
    when(dataService.findAll(PLUGIN, Plugin.class)).thenReturn(Stream.of(plugin1, plugin2));
    when(dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(Stream.of(entityType1, entityType2, entityType3));
    when(dataService.findAll(PACKAGE, Package.class)).thenReturn(Stream.of(package1, package2, package3));
    pluginPermissionRead = PluginPermission.READ;
    cumulativeEntityPermissionWritemeta = new CumulativePermission();
    cumulativeEntityPermissionWritemeta.set(EntityTypePermission.WRITEMETA).set(EntityTypePermission.WRITE).set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
    cumulativeEntityPermissionWrite = new CumulativePermission();
    cumulativeEntityPermissionWrite.set(EntityTypePermission.WRITE).set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
    cumulativeEntityPermissionRead = new CumulativePermission();
    cumulativeEntityPermissionRead.set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
    cumulativeEntityPermissionCount = new CumulativePermission();
    cumulativeEntityPermissionCount.set(EntityTypePermission.COUNT);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Group(org.molgenis.data.security.auth.Group) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) User(org.molgenis.data.security.auth.User) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) CumulativePermission(org.springframework.security.acls.domain.CumulativePermission) PackageIdentity(org.molgenis.data.security.PackageIdentity) Package(org.molgenis.data.meta.model.Package) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Plugin(org.molgenis.data.plugin.model.Plugin) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 33 with Package

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

the class MetaUtils method getFullyQualyfiedName.

public static String getFullyQualyfiedName(Package package_) {
    String packageId = package_.getId();
    Package parentPackage = package_.getParent();
    return parentPackage == null ? packageId : getFullyQualyfiedName(parentPackage) + PACKAGE_SEPARATOR + packageId;
}
Also used : Package(org.molgenis.data.meta.model.Package)

Example 34 with Package

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

the class PackagePersister method upsertPackages.

private void upsertPackages(Collection<Package> packages) {
    List<Package> packagesToAdd = new ArrayList<>(packages.size());
    List<Package> packagesToUpdate = new ArrayList<>(packages.size());
    Map<String, Package> packageMap = getCandidateExistingPackageMap(packages);
    packages.forEach(pack -> {
        Package existingPackage = packageMap.get(pack.getId());
        if (existingPackage != null) {
            // inject existing package identifier into package
            pack.setId(existingPackage.getId());
            if (!pack.equals(existingPackage)) {
                packagesToUpdate.add(pack);
            }
        } else {
            packagesToAdd.add(pack);
        }
    });
    if (!packagesToAdd.isEmpty()) {
        dataService.add(PACKAGE, packagesToAdd.stream());
    }
    if (!packagesToUpdate.isEmpty()) {
        dataService.update(PACKAGE, packagesToUpdate.stream());
    }
}
Also used : Package(org.molgenis.data.meta.model.Package)

Example 35 with Package

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

the class EmxImportServiceIT method verifyItEmxTags.

private void verifyItEmxTags() {
    verifyFirstAndLastRows("sys_md_Tag", tagFirstRow, tagLastRow);
    EntityType entityType = dataService.getEntityType("it_emx_tags_TagEntity");
    Iterable<Tag> entityTags = entityType.getTags();
    assertEquals(getIdsAsSet(entityTags), newHashSet("entitytag0", "entitytag1"));
    Iterable<Tag> idTags = entityType.getAttribute("id").getTags();
    Iterable<Tag> labelTags = entityType.getAttribute("label").getTags();
    assertEquals(getIdsAsSet(idTags), newHashSet("attributetag0", "attributetag1"));
    assertEquals(getIdsAsSet(labelTags), newHashSet("attributetag0", "attributetag1"));
    Package emxPackage = entityType.getPackage();
    Iterable<Tag> packageTags = emxPackage.getTags();
    assertEquals(getIdsAsSet(packageTags), newHashSet("packagetag0", "packagetag1"));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Tag(org.molgenis.data.meta.model.Tag) 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