Search in sources :

Example 1 with Entity

use of org.sagebionetworks.repo.model.Entity in project BridgeServer2 by Sage-Bionetworks.

the class Exporter3ServiceTest method initExporter3.

@Test
public void initExporter3() throws Exception {
    // App has no exporter3config.
    app.setExporter3Configuration(null);
    app.setExporter3Enabled(false);
    // Mock SynapseHelper.
    Team createdTeam = new Team();
    createdTeam.setId(String.valueOf(DATA_ACCESS_TEAM_ID));
    when(mockSynapseHelper.createTeamWithRetry(any())).thenReturn(createdTeam);
    Project createdProject = new Project();
    createdProject.setId(PROJECT_ID);
    when(mockSynapseHelper.createEntityWithRetry(any(Project.class))).thenReturn(createdProject);
    EntityView trackingView = new EntityView();
    trackingView.setScopeIds(new ArrayList<>());
    when(mockSynapseHelper.getEntityWithRetry(SYNAPSE_TRACKING_VIEW_ID, EntityView.class)).thenReturn(trackingView);
    TableEntity createdTable = new TableEntity();
    createdTable.setId(PARTICIPANT_VERSION_TABLE_ID);
    when(mockSynapseHelper.createTableWithColumnsAndAcls(anyList(), anySet(), anySet(), anyString(), anyString())).thenReturn(PARTICIPANT_VERSION_TABLE_ID);
    Folder createdFolder = new Folder();
    createdFolder.setId(RAW_FOLDER_ID);
    when(mockSynapseHelper.createEntityWithRetry(any(Folder.class))).thenReturn(createdFolder);
    ExternalS3StorageLocationSetting createdStorageLocation = new ExternalS3StorageLocationSetting();
    createdStorageLocation.setStorageLocationId(STORAGE_LOCATION_ID);
    when(mockSynapseHelper.createStorageLocationForEntity(eq(RAW_FOLDER_ID), any(ExternalS3StorageLocationSetting.class))).thenReturn(createdStorageLocation);
    // Execute and verify output.
    Exporter3Configuration returnedEx3Config = exporter3Service.initExporter3(TestConstants.TEST_APP_ID);
    assertEquals(returnedEx3Config.getDataAccessTeamId().longValue(), DATA_ACCESS_TEAM_ID);
    assertEquals(returnedEx3Config.getParticipantVersionTableId(), PARTICIPANT_VERSION_TABLE_ID);
    assertEquals(returnedEx3Config.getProjectId(), PROJECT_ID);
    assertEquals(returnedEx3Config.getRawDataFolderId(), RAW_FOLDER_ID);
    assertEquals(returnedEx3Config.getStorageLocationId().longValue(), STORAGE_LOCATION_ID);
    // Verify created team.
    ArgumentCaptor<Team> teamToCreateCaptor = ArgumentCaptor.forClass(Team.class);
    verify(mockSynapseHelper).createTeamWithRetry(teamToCreateCaptor.capture());
    Team teamToCreate = teamToCreateCaptor.getValue();
    assertEquals(teamToCreate.getName(), EXPECTED_TEAM_NAME);
    // Verify created project. Note that we call this method again later, which is why we verify it twice now.
    ArgumentCaptor<Entity> entitiesToCreateCaptor = ArgumentCaptor.forClass(Project.class);
    verify(mockSynapseHelper, times(2)).createEntityWithRetry(entitiesToCreateCaptor.capture());
    List<Entity> entitiesToCreateList = entitiesToCreateCaptor.getAllValues();
    Project projectToCreate = (Project) entitiesToCreateList.get(0);
    assertEquals(projectToCreate.getName(), EXPECTED_PROJECT_NAME);
    // Verify project ACLs.
    verify(mockSynapseHelper).createAclWithRetry(PROJECT_ID, ADMIN_PRINCIPAL_ID_SET, READ_ONLY_PRINCIPAL_ID_SET);
    // Verify project added to tracking view. For whatever reason, view scope IDs don't include the "syn" prefix.
    ArgumentCaptor<EntityView> viewToUpdateCaptor = ArgumentCaptor.forClass(EntityView.class);
    verify(mockSynapseHelper).updateEntityWithRetry(viewToUpdateCaptor.capture());
    EntityView viewToUpdate = viewToUpdateCaptor.getValue();
    assertTrue(viewToUpdate.getScopeIds().contains(PROJECT_ID_WITHOUT_PREFIX));
    // Verify created participant version table.
    verify(mockSynapseHelper).createTableWithColumnsAndAcls(Exporter3Service.PARTICIPANT_VERSION_COLUMN_MODELS, READ_ONLY_PRINCIPAL_ID_SET, ADMIN_PRINCIPAL_ID_SET, PROJECT_ID, Exporter3Service.TABLE_NAME_PARTICIPANT_VERSIONS);
    // Verify created folder.
    Folder folderToCreate = (Folder) entitiesToCreateList.get(1);
    assertEquals(folderToCreate.getName(), Exporter3Service.FOLDER_NAME_BRIDGE_RAW_DATA);
    assertEquals(folderToCreate.getParentId(), PROJECT_ID);
    // Verify folder ACLs.
    verify(mockSynapseHelper).createAclWithRetry(RAW_FOLDER_ID, ADMIN_PRINCIPAL_ID_SET, READ_ONLY_PRINCIPAL_ID_SET);
    // Verify we write to S3 for the storage location.
    verify(mockS3Helper).writeLinesToS3(RAW_HEALTH_DATA_BUCKET, TestConstants.TEST_APP_ID + "/owner.txt", ImmutableList.of(EXPORTER_SYNAPSE_USER));
    // Verify created storage location.
    ArgumentCaptor<ExternalS3StorageLocationSetting> storageLocationToCreateCaptor = ArgumentCaptor.forClass(ExternalS3StorageLocationSetting.class);
    verify(mockSynapseHelper).createStorageLocationForEntity(eq(RAW_FOLDER_ID), storageLocationToCreateCaptor.capture());
    ExternalS3StorageLocationSetting storageLocationToCreate = storageLocationToCreateCaptor.getValue();
    assertEquals(storageLocationToCreate.getBaseKey(), TestConstants.TEST_APP_ID);
    assertEquals(storageLocationToCreate.getBucket(), RAW_HEALTH_DATA_BUCKET);
    assertTrue(storageLocationToCreate.getStsEnabled());
    // Verify updated app.
    ArgumentCaptor<App> appToUpdateCaptor = ArgumentCaptor.forClass(App.class);
    verify(mockAppService).updateApp(appToUpdateCaptor.capture(), eq((true)));
    App appToUpdate = appToUpdateCaptor.getValue();
    assertTrue(appToUpdate.isExporter3Enabled());
    Exporter3Configuration ex3ConfigToCreate = appToUpdate.getExporter3Configuration();
    assertEquals(ex3ConfigToCreate, returnedEx3Config);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) Entity(org.sagebionetworks.repo.model.Entity) TableEntity(org.sagebionetworks.repo.model.table.TableEntity) EntityView(org.sagebionetworks.repo.model.table.EntityView) Folder(org.sagebionetworks.repo.model.Folder) Project(org.sagebionetworks.repo.model.Project) ExternalS3StorageLocationSetting(org.sagebionetworks.repo.model.project.ExternalS3StorageLocationSetting) TableEntity(org.sagebionetworks.repo.model.table.TableEntity) Team(org.sagebionetworks.repo.model.Team) Exporter3Configuration(org.sagebionetworks.bridge.models.apps.Exporter3Configuration) Test(org.testng.annotations.Test)

Example 2 with Entity

use of org.sagebionetworks.repo.model.Entity in project Synapse-Repository-Services by Sage-Bionetworks.

the class DefaultControllerAutowiredAllTypesTest method testUpdateEntityAcl.

@Test
public void testUpdateEntityAcl() throws Exception {
    // First create one of each type
    List<Entity> created = createEntitesOfEachType(1);
    assertNotNull(created);
    assertTrue(created.size() >= EntityType.values().length);
    // Now update each
    for (Entity entity : created) {
        AccessControlList acl = null;
        try {
            acl = ServletTestHelper.getEntityACL(dispatchServlet, entity.getId(), userName);
        } catch (ACLInheritanceException e) {
            acl = ServletTestHelper.getEntityACL(dispatchServlet, e.getBenefactorId(), userName);
        }
        assertNotNull(acl);
        ServletTestHelper.updateEntityAcl(dispatchServlet, acl.getId(), acl, userName);
    }
}
Also used : AccessControlList(org.sagebionetworks.repo.model.AccessControlList) ACLInheritanceException(org.sagebionetworks.repo.model.ACLInheritanceException) Entity(org.sagebionetworks.repo.model.Entity) Test(org.junit.Test)

Example 3 with Entity

use of org.sagebionetworks.repo.model.Entity in project Synapse-Repository-Services by Sage-Bionetworks.

the class DefaultControllerAutowiredAllTypesTest method testUpdateAnnotations.

@Test
public void testUpdateAnnotations() throws Exception {
    // First create one of each type
    List<Entity> created = createEntitesOfEachType(1);
    assertNotNull(created);
    assertTrue(created.size() >= EntityType.values().length);
    // Now update each
    for (Entity entity : created) {
        // Make sure we can get the annotations for this entity.
        Annotations annos = ServletTestHelper.getEntityAnnotations(dispatchServlet, entity.getClass(), entity.getId(), userName);
        assertNotNull(annos);
        assertNotNull(annos.getEtag());
        annos.addAnnotation("someStringKey", "one");
        annos.addAnnotation("someBlobKey", "I am a very long string".getBytes("UTF-8"));
        // Do the update
        Annotations updatedAnnos = ServletTestHelper.updateEntityAnnotations(dispatchServlet, entity.getClass(), annos, userName);
        assertNotNull(updatedAnnos);
        assertNotNull(updatedAnnos.getEtag());
        assertFalse(updatedAnnos.getEtag().equals(annos.getEtag()));
        assertEquals("one", updatedAnnos.getSingleValue("someStringKey"));
        assertNotNull(updatedAnnos.getBlobAnnotations().get("someBlobKey"));
    }
}
Also used : Entity(org.sagebionetworks.repo.model.Entity) Annotations(org.sagebionetworks.repo.model.Annotations) Test(org.junit.Test)

Example 4 with Entity

use of org.sagebionetworks.repo.model.Entity in project Synapse-Repository-Services by Sage-Bionetworks.

the class DefaultControllerAutowiredAllTypesTest method testLocationableS3Token.

/**
 * This test should help ensure that if a new locationable entity is created, its url mapping
 * gets added to the S3TokenController
 *
 * @throws Exception
 */
@Test
public void testLocationableS3Token() throws Exception {
    testHelper.setUp();
    testHelper.setTestUser(userName);
    // First create one of each type
    List<Entity> created = createEntitesOfEachType(1);
    assertNotNull(created);
    assertTrue(created.size() >= EntityType.values().length);
    // Now update each
    for (Entity entity : created) {
        // We can only create S3Tokens for locationable entities.
        if (entity instanceof Locationable) {
            Locationable locationableEntity = (Locationable) entity;
            // Now create a new S3Token
            S3Token token = new S3Token();
            token.setPath("20111204/data.tsv");
            token.setMd5("76af51ccdd0aabacca67d083d0b422e6");
            token = testHelper.createObject(locationableEntity.getS3Token(), token);
            assertNotNull(token.getSecretAccessKey());
            assertNotNull(token.getAccessKeyId());
            assertNotNull(token.getSessionToken());
            assertNotNull(token.getPresignedUrl());
        }
    }
}
Also used : Entity(org.sagebionetworks.repo.model.Entity) Locationable(org.sagebionetworks.repo.model.Locationable) S3Token(org.sagebionetworks.repo.model.S3Token) Test(org.junit.Test)

Example 5 with Entity

use of org.sagebionetworks.repo.model.Entity in project Synapse-Repository-Services by Sage-Bionetworks.

the class DefaultControllerAutowiredAllTypesTest method testGetEntityAnnotationsForVersion.

@Test
public void testGetEntityAnnotationsForVersion() throws Exception {
    // First create one of each type
    List<Entity> created = createEntitesOfEachType(1);
    assertNotNull(created);
    assertTrue(created.size() >= EntityType.values().length);
    // Now update each
    for (Entity entity : created) {
        // We can only create new versions for versionable entities.
        if (entity instanceof Versionable) {
            Versionable versionableEntity = (Versionable) entity;
            // Before we create a new version make sure the current version has some annotations
            Annotations v1Annos = ServletTestHelper.getEntityAnnotations(dispatchServlet, versionableEntity.getClass(), entity.getId(), userName);
            assertNotNull(v1Annos);
            String v1Value = "I am on the first version, whooo hooo!...";
            v1Annos.addAnnotation("stringKey", v1Value);
            v1Annos = ServletTestHelper.updateEntityAnnotations(dispatchServlet, versionableEntity.getClass(), v1Annos, userName);
            // Now create a new version
            // We must give it a new version label or it will fail
            versionableEntity = ServletTestHelper.getEntity(dispatchServlet, versionableEntity.getClass(), entity.getId(), userName);
            versionableEntity.setVersionLabel("1.1.80");
            versionableEntity.setVersionComment("Testing the DefaultController.EntityAnnotationsForVersion()");
            Versionable newVersion = ServletTestHelper.createNewVersion(dispatchServlet, versionableEntity, userName);
            assertNotNull(newVersion);
            // Make sure the new version has the annotations
            Annotations v2Annos = ServletTestHelper.getEntityAnnotations(dispatchServlet, versionableEntity.getClass(), entity.getId(), userName);
            assertNotNull(v2Annos);
            assertEquals(v1Value, v2Annos.getSingleValue("stringKey"));
            // Now update the v2 annotations
            v2Annos.getStringAnnotations().clear();
            String v2Value = "I am on the second version, booo hooo!...";
            v2Annos.addAnnotation("stringKey", v2Value);
            v2Annos = ServletTestHelper.updateEntityAnnotations(dispatchServlet, versionableEntity.getClass(), v2Annos, userName);
            // Now make sure we can get both v1 and v2 annotations and each has the correct values
            // v1
            v1Annos = ServletTestHelper.getEntityAnnotationsForVersion(dispatchServlet, versionableEntity.getClass(), entity.getId(), 1l, userName);
            assertNotNull(v1Annos);
            assertEquals(v1Value, v1Annos.getSingleValue("stringKey"));
            // v2
            v2Annos = ServletTestHelper.getEntityAnnotationsForVersion(dispatchServlet, versionableEntity.getClass(), entity.getId(), 2l, userName);
            assertNotNull(v2Annos);
            assertEquals(v2Value, v2Annos.getSingleValue("stringKey"));
        }
    }
}
Also used : Versionable(org.sagebionetworks.repo.model.Versionable) Entity(org.sagebionetworks.repo.model.Entity) Annotations(org.sagebionetworks.repo.model.Annotations) Test(org.junit.Test)

Aggregations

Entity (org.sagebionetworks.repo.model.Entity)38 Test (org.junit.Test)19 EntityType (org.sagebionetworks.repo.model.EntityType)8 Versionable (org.sagebionetworks.repo.model.Versionable)7 ACLInheritanceException (org.sagebionetworks.repo.model.ACLInheritanceException)5 AccessControlList (org.sagebionetworks.repo.model.AccessControlList)5 Annotations (org.sagebionetworks.repo.model.Annotations)5 EntityHeader (org.sagebionetworks.repo.model.EntityHeader)4 Transactional (org.springframework.transaction.annotation.Transactional)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Ignore (org.junit.Ignore)3 TypeSpecificMetadataProvider (org.sagebionetworks.repo.web.controller.metadata.TypeSpecificMetadataProvider)3 JSONEntity (org.sagebionetworks.schema.adapter.JSONEntity)3 IOException (java.io.IOException)2 JSONException (org.json.JSONException)2 Before (org.junit.Before)2 Data (org.sagebionetworks.repo.model.Data)2 DatastoreException (org.sagebionetworks.repo.model.DatastoreException)2 EntityPath (org.sagebionetworks.repo.model.EntityPath)2 InvalidModelException (org.sagebionetworks.repo.model.InvalidModelException)2