use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class VcfToEntityTest method testGetEntityType.
@Test
public void testGetEntityType() {
EntityType expectedEntityType = entityTypeFactory.create("EntityNameSmall");
expectedEntityType.addAttribute(vcfAttrs.getChromAttribute());
expectedEntityType.addAttribute(vcfAttrs.getAltAttribute());
expectedEntityType.addAttribute(vcfAttrs.getPosAttribute());
expectedEntityType.addAttribute(vcfAttrs.getRefAttribute());
expectedEntityType.addAttribute(vcfAttrs.getFilterAttribute());
expectedEntityType.addAttribute(vcfAttrs.getQualAttribute());
expectedEntityType.addAttribute(vcfAttrs.getIdAttribute());
Attribute internalIdMeta = attrMetaFactory.create().setName(INTERNAL_ID).setDataType(STRING).setVisible(false);
expectedEntityType.addAttribute(internalIdMeta, ROLE_ID);
Attribute infoMetaData = attrMetaFactory.create().setName(INFO).setDataType(COMPOUND).setNillable(true);
Attribute infoNS = attrMetaFactory.create().setName("NS").setDataType(INT).setDescription("Number of Samples With Data").setAggregatable(true).setParent(infoMetaData);
Attribute infoDF = attrMetaFactory.create().setName("DF").setDataType(BOOL).setDescription("Flag field").setAggregatable(true).setParent(infoMetaData);
Attribute infoDF2 = attrMetaFactory.create().setName("DF2").setDataType(BOOL).setDescription("Flag field 2").setAggregatable(true).setParent(infoMetaData);
Attribute infoChar2 = attrMetaFactory.create().setName("CHAR").setDataType(STRING).setDescription("char field").setAggregatable(true).setParent(infoMetaData);
expectedEntityType.addAttribute(infoNS);
expectedEntityType.addAttribute(infoDF);
expectedEntityType.addAttribute(infoDF2);
expectedEntityType.addAttribute(infoChar2);
expectedEntityType.addAttribute(infoMetaData);
EntityType actualEntityType = vcfToEntitySmall.getEntityType();
String backend = "test";
expectedEntityType.setBackend(backend);
actualEntityType.setBackend(backend);
Package package_ = mock(Package.class);
when(package_.getIdValue()).thenReturn("pck0");
expectedEntityType.setPackage(package_);
actualEntityType.setPackage(package_);
expectedEntityType.setId("dummyId");
expectedEntityType.setLabel("EntityNameSmall");
expectedEntityType.getOwnAllAttributes().forEach(attr -> attr.setIdentifier(null));
actualEntityType.setId("dummyId");
actualEntityType.getOwnAllAttributes().forEach(attr -> attr.setIdentifier(null));
assertTrue(EntityUtils.equals(expectedEntityType, actualEntityType));
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class VcfImporterServiceTest method doImportVcfWithSamples.
@SuppressWarnings("unchecked")
@Test
public void doImportVcfWithSamples() {
// Test with multiple input repositories not possible due to
// https://github.com/molgenis/molgenis/issues/4544
String entityTypeId0 = "entity0";
List<String> entityTypeIds = Arrays.asList(entityTypeId0);
String sampleEntityName0 = "entity0sample";
EntityType sampleEntityType0 = mock(EntityType.class);
when(sampleEntityType0.getId()).thenReturn(sampleEntityName0);
when(sampleEntityType0.getOwnAttributes()).thenReturn(emptyList());
when(sampleEntityType0.getOwnLookupAttributes()).thenReturn(emptyList());
Repository<Entity> outSampleRepo0 = mock(Repository.class);
when(outSampleRepo0.getName()).thenReturn(sampleEntityName0);
when(metaDataService.createRepository(argThat(eqName(sampleEntityType0)))).thenReturn(outSampleRepo0);
Attribute sampleAttr = mock(Attribute.class);
when(sampleAttr.getName()).thenReturn(VcfAttributes.SAMPLES);
when(sampleAttr.getRefEntity()).thenReturn(sampleEntityType0);
when(sampleAttr.getDataType()).thenReturn(MREF);
EntityType entityType0 = mock(EntityType.class);
when(entityType0.getId()).thenReturn(entityTypeId0);
when(entityType0.getAttribute(VcfAttributes.SAMPLES)).thenReturn(sampleAttr);
when(entityType0.getOwnAttributes()).thenReturn(singletonList(sampleAttr));
when(entityType0.getOwnLookupAttributes()).thenReturn(emptyList());
Entity entity0Sample0 = mock(Entity.class);
Entity entity0Sample1 = mock(Entity.class);
Entity entity1Sample0 = mock(Entity.class);
Entity entity1Sample1 = mock(Entity.class);
Entity entity0 = mock(Entity.class);
when(entity0.getEntities(VcfAttributes.SAMPLES)).thenReturn(Arrays.asList(entity0Sample0, entity0Sample1));
Entity entity1 = mock(Entity.class);
when(entity1.getEntities(VcfAttributes.SAMPLES)).thenReturn(Arrays.asList(entity1Sample0, entity1Sample1));
List<Entity> entities = Arrays.asList(entity0, entity1);
Repository<Entity> repo0 = Mockito.spy(new AbstractRepository() {
@Override
public Set<RepositoryCapability> getCapabilities() {
return null;
}
public EntityType getEntityType() {
return entityType0;
}
@Override
public Iterator<Entity> iterator() {
return entities.iterator();
}
@Override
public Spliterator<Entity> spliterator() {
return entities.spliterator();
}
@Override
public String getName() {
return entityTypeId0;
}
@Override
public void forEachBatched(Consumer<List<Entity>> consumer, int batchSize) {
this.forEachBatched(null, consumer, batchSize);
}
});
when(dataService.hasRepository(entityTypeId0)).thenReturn(false);
Repository<Entity> outRepo0 = mock(Repository.class);
when(metaDataService.createRepository(argThat(eqName(entityType0)))).thenReturn(outRepo0);
when(outRepo0.add(any(Stream.class))).thenAnswer(invocation -> {
Stream<Entity> entities1 = (Stream<Entity>) invocation.getArguments()[0];
List<Entity> entityList = entities1.collect(Collectors.toList());
return entityList.size();
});
RepositoryCollection source = mock(RepositoryCollection.class);
when(source.getEntityTypeIds()).thenReturn(entityTypeIds);
when(source.getRepository(entityTypeId0)).thenReturn(repo0);
String defaultPackage = "package";
Package pack = mock(Package.class);
when(metaDataService.getPackage(defaultPackage)).thenReturn(pack);
EntityImportReport entityImportReport = vcfImporterService.doImport(source, DatabaseAction.ADD, defaultPackage);
EntityImportReport expectedEntityImportReport = new EntityImportReport();
expectedEntityImportReport.addNewEntity(sampleEntityName0);
expectedEntityImportReport.addEntityCount(sampleEntityName0, 4);
expectedEntityImportReport.addNewEntity(entityTypeId0);
expectedEntityImportReport.addEntityCount(entityTypeId0, entities.size());
assertEquals(entityImportReport, expectedEntityImportReport);
verify(metaDataService).createRepository(argThat(eqName(sampleEntityType0)));
verify(metaDataService).createRepository(argThat(eqName(entityType0)));
verify(permissionSystemService).giveUserWriteMetaPermissions(entityType0);
verify(permissionSystemService).giveUserWriteMetaPermissions(sampleEntityType0);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class VcfImporterServiceTest method doImportVcfWithoutSamples.
@SuppressWarnings("unchecked")
@Test
public void doImportVcfWithoutSamples() {
// Test with multiple input repositories not possible due to
// https://github.com/molgenis/molgenis/issues/4544
String entityTypeId0 = "entity0";
List<String> entityTypeIds = Arrays.asList(entityTypeId0);
EntityType entityType0 = mock(EntityType.class);
when(entityType0.getId()).thenReturn(entityTypeId0);
when(entityType0.getOwnAttributes()).thenReturn(emptyList());
when(entityType0.getOwnLookupAttributes()).thenReturn(emptyList());
Entity entity0 = mock(Entity.class);
Entity entity1 = mock(Entity.class);
List<Entity> entities = Arrays.asList(entity0, entity1);
Repository<Entity> repo0 = Mockito.spy(new AbstractRepository() {
@Override
public Set<RepositoryCapability> getCapabilities() {
return null;
}
public EntityType getEntityType() {
return entityType0;
}
@Override
public Iterator<Entity> iterator() {
return entities.iterator();
}
@Override
public Spliterator<Entity> spliterator() {
return entities.spliterator();
}
@Override
public String getName() {
return entityTypeId0;
}
@Override
public void forEachBatched(Consumer<List<Entity>> consumer, int batchSize) {
this.forEachBatched(null, consumer, batchSize);
}
});
when(dataService.hasRepository(entityTypeId0)).thenReturn(false);
Repository<Entity> outRepo0 = mock(Repository.class);
when(metaDataService.createRepository(argThat(eqName(entityType0)))).thenReturn(outRepo0);
when(outRepo0.add(any(Stream.class))).thenAnswer(invocation -> {
Stream<Entity> entities1 = (Stream<Entity>) invocation.getArguments()[0];
List<Entity> entityList = entities1.collect(Collectors.toList());
return entityList.size();
});
RepositoryCollection source = mock(RepositoryCollection.class);
when(source.getEntityTypeIds()).thenReturn(entityTypeIds);
when(source.getRepository(entityTypeId0)).thenReturn(repo0);
String defaultPackage = "package";
Package pack = mock(Package.class);
when(metaDataService.getPackage(defaultPackage)).thenReturn(pack);
EntityImportReport entityImportReport = vcfImporterService.doImport(source, DatabaseAction.ADD, defaultPackage);
EntityImportReport expectedEntityImportReport = new EntityImportReport();
expectedEntityImportReport.addEntityCount(entityTypeId0, entities.size());
expectedEntityImportReport.addNewEntity(entityTypeId0);
assertEquals(entityImportReport, expectedEntityImportReport);
verify(metaDataService, times(1)).createRepository(argThat(eqName(entityType0)));
verify(permissionSystemService, times(1)).giveUserWriteMetaPermissions(entityType0);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PackageRepositoryValidationDecorator method deleteById.
@Override
public void deleteById(Object id) {
Package package_ = findOneById(id);
if (package_ == null) {
throw new UnknownEntityException(format("Unknown package [%s]", id.toString()));
}
packageValidator.validate(package_);
super.deleteById(id);
}
use of org.molgenis.data.meta.model.Package in project molgenis by molgenis.
the class PermissionManagerController method toPackagePermissions.
private Permissions toPackagePermissions(List<Package> packages, Map<ObjectIdentity, Acl> aclMap, Sid sid) {
Permissions permissions = new Permissions();
// set permissions: entity ids
Map<String, String> entityTypeMap = packages.stream().collect(toMap(Package::getId, Package::getId, (u, v) -> {
throw new IllegalStateException(format("Duplicate key %s", u));
}, LinkedHashMap::new));
permissions.setEntityIds(entityTypeMap);
return toEntityTypePermissions(aclMap, sid, permissions);
}
Aggregations