Search in sources :

Example 11 with RepositoryCollection

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

the class ImportWizardController method importFile.

private ImportRun importFile(HttpServletRequest request, File file, String action, Boolean notify, String packageId) {
    // no action specified? default is ADD just like the importerPlugin
    ImportRun importRun;
    String fileExtension = getExtension(file.getName());
    DatabaseAction databaseAction = getDatabaseAction(file, action);
    if (fileExtension.contains("vcf") && dataService.hasRepository(getBaseName(file.getName()))) {
        throw new MolgenisDataException("A repository with name " + getBaseName(file.getName()) + " already exists");
    }
    ImportService importService = importServiceFactory.getImportService(file.getName());
    RepositoryCollection repositoryCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(file);
    importRun = importRunService.addImportRun(SecurityUtils.getCurrentUsername(), Boolean.TRUE.equals(notify));
    asyncImportJobs.execute(new ImportJob(importService, SecurityContextHolder.getContext(), repositoryCollection, databaseAction, importRun.getId(), importRunService, request.getSession(), packageId));
    return importRun;
}
Also used : DatabaseAction(org.molgenis.data.DatabaseAction) RepositoryCollection(org.molgenis.data.RepositoryCollection) MolgenisDataException(org.molgenis.data.MolgenisDataException)

Example 12 with RepositoryCollection

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

the class EntityTypeRepositoryDecoratorTest method addRemoveAttributeAbstractEntityType.

@Test
public void addRemoveAttributeAbstractEntityType() {
    when(entityType1.getId()).thenReturn(entityTypeId1);
    when(entityType2.getId()).thenReturn(entityTypeId2);
    String entityTypeId3 = "EntityType3";
    when(entityType3.getId()).thenReturn(entityTypeId3);
    when(dataService.getMeta()).thenReturn(metaDataService);
    EntityType currentEntityType = mock(EntityType.class);
    EntityType currentEntityType2 = mock(EntityType.class);
    EntityType currentEntityType3 = mock(EntityType.class);
    doReturn(currentEntityType).when(delegateRepository).findOneById(entityTypeId1);
    doReturn(currentEntityType2).when(delegateRepository).findOneById(entityTypeId2);
    doReturn(currentEntityType3).when(delegateRepository).findOneById(entityTypeId3);
    Attribute attributeStays = mock(Attribute.class);
    when(attributeStays.getName()).thenReturn("attributeStays");
    Attribute attributeRemoved = mock(Attribute.class);
    when(attributeRemoved.getName()).thenReturn("attributeRemoved");
    Attribute attributeAdded = mock(Attribute.class);
    when(attributeAdded.getName()).thenReturn("attributeAdded");
    when(currentEntityType.isAbstract()).thenReturn(true);
    when(currentEntityType.getOwnAllAttributes()).thenReturn(Lists.newArrayList(attributeStays, attributeRemoved));
    when(entityType1.getOwnAllAttributes()).thenReturn(Lists.newArrayList(attributeStays, attributeAdded));
    when(metaDataService.getConcreteChildren(entityType1)).thenReturn(Stream.of(entityType2, entityType3));
    RepositoryCollection backend2 = mock(RepositoryCollection.class);
    RepositoryCollection backend3 = mock(RepositoryCollection.class);
    doReturn(backend2).when(metaDataService).getBackend(entityType2);
    doReturn(backend3).when(metaDataService).getBackend(entityType3);
    repo.update(entityType1);
    // verify that attributes got added and deleted in concrete extending entities
    verify(backend2).addAttribute(currentEntityType2, attributeAdded);
    verify(backend2).deleteAttribute(currentEntityType2, attributeRemoved);
    verify(backend3).addAttribute(currentEntityType3, attributeAdded);
    verify(backend3).deleteAttribute(currentEntityType3, attributeRemoved);
    verify(backend2, never()).updateRepository(any(), any());
    verify(backend3, never()).updateRepository(any(), any());
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) RepositoryCollection(org.molgenis.data.RepositoryCollection) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 13 with RepositoryCollection

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

the class AmazonBucketIngester method ingest.

public FileMeta ingest(String jobExecutionID, String targetEntityTypeName, String bucket, String key, String extension, String accessKey, String secretKey, String region, boolean isExpression, Progress progress) {
    FileMeta fileMeta;
    try {
        progress.setProgressMax(3);
        progress.progress(0, "Connection to Amazon Bucket with accessKey '" + accessKey + "'");
        AmazonS3 client = amazonBucketClient.getClient(accessKey, secretKey, region);
        progress.progress(1, "downloading...");
        File file = amazonBucketClient.downloadFile(client, fileStore, jobExecutionID, bucket, key, extension, isExpression, targetEntityTypeName);
        if (targetEntityTypeName != null && ExcelUtils.isExcelFile(file.getName())) {
            if (ExcelUtils.getNumberOfSheets(file) == 1) {
                ExcelUtils.renameSheet(targetEntityTypeName, file, 0);
            } else {
                throw new MolgenisDataException("Amazon Bucket imports to a specified entityType are only possible with CSV files or Excel files with one sheet");
            }
        }
        progress.progress(2, "Importing...");
        ImportService importService = importServiceFactory.getImportService(file.getName());
        File renamed = new File(String.format("%s%s%s.%s", file.getParent(), File.separatorChar, targetEntityTypeName, extension));
        Files.copy(file.toPath(), renamed.toPath(), StandardCopyOption.REPLACE_EXISTING);
        RepositoryCollection repositoryCollection = fileRepositoryCollectionFactory.createFileRepositoryCollection(renamed);
        EntityImportReport report = importService.doImport(repositoryCollection, DatabaseAction.ADD_UPDATE_EXISTING, "base");
        progress.status("Download and import from Amazon Bucket done.");
        progress.progress(3, "Successfully imported " + report.getNrImportedEntitiesMap().keySet().toString() + " entities.");
        fileMeta = createFileMeta(jobExecutionID, file);
    } catch (Exception e) {
        throw new MolgenisDataException(e);
    }
    return fileMeta;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) RepositoryCollection(org.molgenis.data.RepositoryCollection) MolgenisDataException(org.molgenis.data.MolgenisDataException) ImportService(org.molgenis.data.importer.ImportService) File(java.io.File) FileMeta(org.molgenis.data.file.model.FileMeta) MolgenisDataException(org.molgenis.data.MolgenisDataException) EntityImportReport(org.molgenis.data.importer.EntityImportReport)

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