Search in sources :

Example 6 with Package

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

the class EntityTypeUtilsTest method isSystemEntityIfInSystemSubPackage.

@Test
public void isSystemEntityIfInSystemSubPackage() {
    EntityType entity = mock(EntityType.class);
    Package entityPackage = mock(Package.class);
    when(entity.getPackage()).thenReturn(entityPackage);
    when(entityPackage.getId()).thenReturn("not-system");
    when(entity.getId()).thenReturn("sys_foo_bar_Entity");
    assertTrue(EntityTypeUtils.isSystemEntity(entity));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 7 with Package

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

the class EntityTypeUtilsTest method isSystemEntityIfInSystemPackage.

@Test
public void isSystemEntityIfInSystemPackage() {
    EntityType entity = mock(EntityType.class);
    Package entityPackage = mock(Package.class);
    when(entity.getPackage()).thenReturn(entityPackage);
    when(entityPackage.getId()).thenReturn("sys");
    assertTrue(EntityTypeUtils.isSystemEntity(entity));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Package(org.molgenis.data.meta.model.Package) Test(org.testng.annotations.Test)

Example 8 with Package

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

the class PackageMapperTest method testToPackageReference.

@Test
public void testToPackageReference() {
    String id = "id0";
    EditorPackageIdentifier packageIdentifier = EditorPackageIdentifier.create(id, "label");
    Package package_ = packageMapper.toPackageReference(packageIdentifier);
    assertEquals(package_.getIdValue(), id);
}
Also used : Package(org.molgenis.data.meta.model.Package) EditorPackageIdentifier(org.molgenis.metadata.manager.model.EditorPackageIdentifier) Test(org.testng.annotations.Test)

Example 9 with Package

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

the class OptionsWizardPage method validateInput.

private String validateInput(File file, ImportWizard wizard, BindingResult result) {
    // decide what importer to use...
    RepositoryCollection source = fileRepositoryCollectionFactory.createFileRepositoryCollection(file);
    ImportService importService = importServiceFactory.getImportService(file, source);
    EntitiesValidationReport validationReport = importService.validateImport(file, source);
    wizard.setEntitiesImportable(validationReport.getSheetsImportable());
    wizard.setFieldsDetected(validationReport.getFieldsImportable());
    wizard.setFieldsRequired(validationReport.getFieldsRequired());
    wizard.setFieldsAvailable(validationReport.getFieldsAvailable());
    wizard.setFieldsUnknown(validationReport.getFieldsUnknown());
    Set<String> allPackages = new HashSet<>(validationReport.getPackages());
    for (Package p : dataService.getMeta().getPackages()) {
        allPackages.add(p.getId());
    }
    List<String> entitiesInDefaultPackage = new ArrayList<>();
    for (String entityTypeId : validationReport.getSheetsImportable().keySet()) {
        if (validationReport.getSheetsImportable().get(entityTypeId)) {
            if (isInDefaultPackage(entityTypeId, allPackages))
                entitiesInDefaultPackage.add(entityTypeId);
        }
    }
    wizard.setEntitiesInDefaultPackage(entitiesInDefaultPackage);
    List<String> packages = new ArrayList<>(validationReport.getPackages());
    packages.add(0, PACKAGE_DEFAULT);
    wizard.setPackages(packages);
    String msg = null;
    if (validationReport.valid()) {
        wizard.setFile(file);
        msg = "File is validated and can be imported.";
    } else {
        wizard.setValidationMessage("File did not pass validation see results below. Please resolve the errors and try again.");
    }
    return msg;
}
Also used : RepositoryCollection(org.molgenis.data.RepositoryCollection) EntitiesValidationReport(org.molgenis.data.importer.EntitiesValidationReport) ImportService(org.molgenis.data.importer.ImportService) ArrayList(java.util.ArrayList) Package(org.molgenis.data.meta.model.Package) HashSet(java.util.HashSet)

Example 10 with Package

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

the class PackageRepositorySecurityDecoratorTest method testAdd1.

@Test
public void testAdd1() {
    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.add(packages);
    ArgumentCaptor<Stream<Package>> captor = ArgumentCaptor.forClass(Stream.class);
    verify(delegateRepository).add(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)

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