Search in sources :

Example 6 with RepositoryCollection

use of org.molgenis.data.RepositoryCollection in project molgenis by molgenis.

the class EntityTypeValidatorTest method setUpBeforeMethod.

@SuppressWarnings("unchecked")
@BeforeMethod
public void setUpBeforeMethod() {
    dataService = mock(DataService.class);
    MetaDataService metaDataService = mock(MetaDataService.class);
    when(dataService.getMeta()).thenReturn(metaDataService);
    systemEntityTypeRegistry = mock(SystemEntityTypeRegistry.class);
    entityTypeValidator = new EntityTypeValidator(dataService, systemEntityTypeRegistry);
    String backendName = "backend";
    RepositoryCollection repoCollection = mock(RepositoryCollection.class);
    when(metaDataService.getBackend(backendName)).thenReturn(repoCollection);
    // valid entity meta
    entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock();
    idAttr = when(mock(Attribute.class).getName()).thenReturn("idAttr").getMock();
    when(idAttr.getIdentifier()).thenReturn("#idAttr");
    when(idAttr.getDataType()).thenReturn(STRING);
    when(idAttr.isUnique()).thenReturn(true);
    when(idAttr.isNillable()).thenReturn(false);
    labelAttr = when(mock(Attribute.class).getName()).thenReturn("labelAttr").getMock();
    when(labelAttr.getIdentifier()).thenReturn("#labelAttr");
    when(labelAttr.getDataType()).thenReturn(STRING);
    entityQ = mock(Query.class);
    when(dataService.query(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(entityQ);
    Query<EntityType> entityQ0 = mock(Query.class);
    Query<EntityType> entityQ1 = mock(Query.class);
    when(entityQ.eq(ATTRIBUTES, idAttr)).thenReturn(entityQ0);
    when(entityQ.eq(ATTRIBUTES, labelAttr)).thenReturn(entityQ1);
    when(entityQ0.findOne()).thenReturn(null);
    when(entityQ1.findOne()).thenReturn(null);
    attrQ = mock(Query.class);
    Query<Attribute> attrQ0 = mock(Query.class);
    Query<Attribute> attrQ1 = mock(Query.class);
    when(dataService.query(ATTRIBUTE_META_DATA, Attribute.class)).thenReturn(attrQ);
    when(attrQ.eq(CHILDREN, idAttr)).thenReturn(attrQ0);
    when(attrQ.eq(CHILDREN, labelAttr)).thenReturn(attrQ1);
    when(attrQ0.findOne()).thenReturn(null);
    when(attrQ1.findOne()).thenReturn(null);
    String packageName = "package";
    Package package_ = when(mock(Package.class).getId()).thenReturn(packageName).getMock();
    when(entityType.getPackage()).thenReturn(package_);
    String name = "name";
    String label = "label";
    when(entityType.getId()).thenReturn(packageName + PACKAGE_SEPARATOR + name);
    when(entityType.getLabel()).thenReturn(label);
    when(entityType.getOwnAllAttributes()).thenReturn(newArrayList(idAttr, labelAttr));
    when(entityType.getAllAttributes()).thenReturn(newArrayList(idAttr, labelAttr));
    when(entityType.getOwnIdAttribute()).thenReturn(idAttr);
    when(entityType.getOwnLabelAttribute()).thenReturn(labelAttr);
    when(entityType.getOwnLookupAttributes()).thenReturn(singletonList(labelAttr));
    when(entityType.isAbstract()).thenReturn(false);
    when(entityType.getExtends()).thenReturn(null);
    when(entityType.getBackend()).thenReturn(backendName);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) SystemEntityTypeRegistry(org.molgenis.data.meta.system.SystemEntityTypeRegistry) RepositoryCollection(org.molgenis.data.RepositoryCollection) MetaDataService(org.molgenis.data.meta.MetaDataService) Query(org.molgenis.data.Query) Attribute(org.molgenis.data.meta.model.Attribute) Package(org.molgenis.data.meta.model.Package) MetaDataService(org.molgenis.data.meta.MetaDataService) DataService(org.molgenis.data.DataService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with RepositoryCollection

use of org.molgenis.data.RepositoryCollection in project molgenis by molgenis.

the class RepositoryCollectionDecoratorFactoryImpl method createDecoratedRepositoryCollection.

@Override
public RepositoryCollection createDecoratedRepositoryCollection(RepositoryCollection repositoryCollection) {
    RepositoryCollection repoCollectionDecorator = new RepositoryCollectionDecorator(repositoryCollection, repositoryDecoratorFactory);
    repoCollectionDecorator = new IndexActionRepositoryCollectionDecorator(repoCollectionDecorator, indexActionRegisterService);
    return repoCollectionDecorator;
}
Also used : RepositoryCollection(org.molgenis.data.RepositoryCollection) IndexActionRepositoryCollectionDecorator(org.molgenis.data.index.IndexActionRepositoryCollectionDecorator) RepositoryCollectionDecorator(org.molgenis.data.RepositoryCollectionDecorator) IndexActionRepositoryCollectionDecorator(org.molgenis.data.index.IndexActionRepositoryCollectionDecorator)

Example 8 with RepositoryCollection

use of org.molgenis.data.RepositoryCollection in project molgenis by molgenis.

the class SystemEntityTypePersisterTest method setUpBeforeMethod.

@BeforeMethod
public void setUpBeforeMethod() {
    RepositoryCollection defaultRepoCollection = mock(RepositoryCollection.class);
    when(metaDataService.getDefaultBackend()).thenReturn(defaultRepoCollection);
    when(dataService.getMeta()).thenReturn(metaDataService);
    systemEntityTypePersister = new SystemEntityTypePersister(dataService, systemEntityTypeRegistry, entityTypeDependencyResolver, systemPackageRegistry, mutableAclClassService);
}
Also used : RepositoryCollection(org.molgenis.data.RepositoryCollection) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 9 with RepositoryCollection

use of org.molgenis.data.RepositoryCollection in project molgenis by molgenis.

the class SystemEntityTypePersister method persistMetadataMetadata.

private void persistMetadataMetadata() {
    RepositoryCollection metadataRepoCollection = dataService.getMeta().getDefaultBackend();
    // collect meta entity meta
    List<EntityType> metaEntityTypeList = systemEntityTypeRegistry.getSystemEntityTypes().filter(MetaDataService::isMetaEntityType).collect(toList());
    List<EntityType> resolvedEntityTypeList = entityTypeDependencyResolver.resolve(metaEntityTypeList);
    resolvedEntityTypeList.forEach(metaEntityType -> {
        if (!metadataRepoCollection.hasRepository(metaEntityType)) {
            metadataRepoCollection.createRepository(metaEntityType);
        }
    });
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) SystemEntityType(org.molgenis.data.meta.SystemEntityType) RepositoryCollection(org.molgenis.data.RepositoryCollection)

Example 10 with RepositoryCollection

use of org.molgenis.data.RepositoryCollection in project molgenis by molgenis.

the class EntityTypeValidator method validateBackend.

/**
 * Validate that the entity meta data backend exists
 *
 * @param entityType entity meta data
 * @throws MolgenisValidationException if the entity meta data backend does not exist
 */
private void validateBackend(EntityType entityType) {
    // Validate backend exists
    String backendName = entityType.getBackend();
    RepositoryCollection repoCollection = dataService.getMeta().getBackend(backendName);
    if (repoCollection == null) {
        throw new MolgenisValidationException(new ConstraintViolation(format("Unknown backend [%s]", backendName)));
    }
}
Also used : RepositoryCollection(org.molgenis.data.RepositoryCollection) ConstraintViolation(org.molgenis.data.validation.ConstraintViolation) MolgenisValidationException(org.molgenis.data.validation.MolgenisValidationException)

Aggregations

RepositoryCollection (org.molgenis.data.RepositoryCollection)13 MolgenisDataException (org.molgenis.data.MolgenisDataException)4 ImportService (org.molgenis.data.importer.ImportService)4 File (java.io.File)3 DatabaseAction (org.molgenis.data.DatabaseAction)3 EntityType (org.molgenis.data.meta.model.EntityType)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Attribute (org.molgenis.data.meta.model.Attribute)2 Package (org.molgenis.data.meta.model.Package)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1