Search in sources :

Example 6 with EntityTypeMigrationSpec

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

the class GenericMigratorTest method testMigrateDatasetAdditionalToPrimaryArrayString.

@Test
@Ignore
public void testMigrateDatasetAdditionalToPrimaryArrayString() {
    toMigrate.setNamedAnnotations(new NamedAnnotations());
    EntityType type = EntityType.dataset;
    MigrationSpec ms = new MigrationSpec();
    List<EntityTypeMigrationSpec> listEms = new ArrayList<EntityTypeMigrationSpec>();
    EntityTypeMigrationSpec ems = new EntityTypeMigrationSpec();
    ems.setEntityType(type.name());
    List<FieldMigrationSpec> listFms = new ArrayList<FieldMigrationSpec>();
    FieldMigrationSpec fms = new FieldMigrationSpec();
    FieldDescription source = new FieldDescription();
    FieldDescription dest = new FieldDescription();
    source.setName("Disease");
    source.setType("string");
    source.setBucket("additional");
    dest.setName("diseases");
    dest.setType("string");
    dest.setBucket("primary");
    fms.setSource(source);
    fms.setDestination(dest);
    listFms.add(fms);
    listEms.add(ems);
    ems.setFields(listFms);
    ms.setMigrationMetadata(listEms);
    MigrationSpecData msd = new MigrationSpecData();
    msd.setData(ms);
    genericMigrator.setMigrationSpecData(msd);
    String oldKey = "Disease";
    String newKey = "diseases";
    List<String> valuesToMigrate = new ArrayList<String>();
    valuesToMigrate.add("Value1 to be migrated");
    valuesToMigrate.add("Value2 to be migrated");
    valuesToMigrate.add("Value3 to be migrated");
    Annotations additionalAnnotations = toMigrate.getNamedAnnotations().getAdditionalAnnotations();
    Annotations primaryAnnotations = toMigrate.getNamedAnnotations().getPrimaryAnnotations();
    Map<String, List<String>> primaryStringAnnos = primaryAnnotations.getStringAnnotations();
    additionalAnnotations.addAnnotation(oldKey, valuesToMigrate);
    assertNotNull(additionalAnnotations.getAllValues(oldKey));
    genericMigrator.migrateOneStep(toMigrate, type);
    assertNull(additionalAnnotations.getAllValues(oldKey));
    assertNotNull(primaryAnnotations.getAllValues(newKey));
    assertEquals(3, primaryStringAnnos.get(newKey).size());
    assertEquals(valuesToMigrate.iterator().next(), primaryStringAnnos.get(newKey).iterator().next());
    return;
}
Also used : MigrationSpecData(org.sagebionetworks.repo.model.registry.MigrationSpecData) ArrayList(java.util.ArrayList) MigrationSpec(org.sagebionetworks.repo.model.registry.MigrationSpec) FieldMigrationSpec(org.sagebionetworks.repo.model.registry.FieldMigrationSpec) EntityTypeMigrationSpec(org.sagebionetworks.repo.model.registry.EntityTypeMigrationSpec) FieldDescription(org.sagebionetworks.repo.model.registry.FieldDescription) EntityType(org.sagebionetworks.repo.model.EntityType) EntityTypeMigrationSpec(org.sagebionetworks.repo.model.registry.EntityTypeMigrationSpec) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) ArrayList(java.util.ArrayList) List(java.util.List) FieldMigrationSpec(org.sagebionetworks.repo.model.registry.FieldMigrationSpec) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with EntityTypeMigrationSpec

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

the class GenericMigratorTest method testMigrateType.

@Test
public void testMigrateType() {
    for (EntityType type : EntityType.values()) {
        // Setup migration spec
        // MigrationSpec ms = MigratorTestHelper.setupMigrationSpec(type.name(), "primary", "primary");
        MigrationSpec ms = new MigrationSpec();
        List<EntityTypeMigrationSpec> listEms = new ArrayList<EntityTypeMigrationSpec>();
        EntityTypeMigrationSpec ems = new EntityTypeMigrationSpec();
        ems.setEntityType(type.name());
        List<FieldMigrationSpec> listFms = new ArrayList<FieldMigrationSpec>();
        FieldMigrationSpec fms = new FieldMigrationSpec();
        FieldDescription source = new FieldDescription();
        FieldDescription dest = new FieldDescription();
        source.setName("old_name");
        source.setType("string");
        source.setBucket("additional");
        dest.setName("new_name");
        dest.setType("integer");
        dest.setBucket("additional");
        fms.setSource(source);
        fms.setDestination(dest);
        listFms.add(fms);
        listEms.add(ems);
        ems.setFields(listFms);
        ms.setMigrationMetadata(listEms);
        MigrationSpecData msd = new MigrationSpecData();
        msd.setData(ms);
        genericMigrator.setMigrationSpecData(msd);
        // Setup node to migrate
        // toMigrate = MigratorTestHelper.setupNodeRevisionToMigrate();
        String oldKey = "old_name";
        String newKey = "new_name";
        String valueToMigrate = "1000";
        toMigrate.setNamedAnnotations(new NamedAnnotations());
        // Annotations primaryAnnotations = toMigrate.getNamedAnnotations().getPrimaryAnnotations();
        Annotations additionalAnnotations = toMigrate.getNamedAnnotations().getAdditionalAnnotations();
        additionalAnnotations.addAnnotation(oldKey, valueToMigrate);
        Map<String, List<String>> stringAnnos = additionalAnnotations.getStringAnnotations();
        assertNotNull(stringAnnos.get(oldKey));
        genericMigrator.migrateOneStep(toMigrate, type);
        assertNull(stringAnnos.get(oldKey));
        Map<String, List<Long>> longAnnos = additionalAnnotations.getLongAnnotations();
        assertNotNull(longAnnos.get(newKey));
        assertEquals(1, longAnnos.get(newKey).size());
        assertEquals(Long.valueOf(valueToMigrate), longAnnos.get(newKey).iterator().next());
    }
    return;
}
Also used : MigrationSpecData(org.sagebionetworks.repo.model.registry.MigrationSpecData) ArrayList(java.util.ArrayList) MigrationSpec(org.sagebionetworks.repo.model.registry.MigrationSpec) FieldMigrationSpec(org.sagebionetworks.repo.model.registry.FieldMigrationSpec) EntityTypeMigrationSpec(org.sagebionetworks.repo.model.registry.EntityTypeMigrationSpec) FieldDescription(org.sagebionetworks.repo.model.registry.FieldDescription) EntityType(org.sagebionetworks.repo.model.EntityType) EntityTypeMigrationSpec(org.sagebionetworks.repo.model.registry.EntityTypeMigrationSpec) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) ArrayList(java.util.ArrayList) List(java.util.List) FieldMigrationSpec(org.sagebionetworks.repo.model.registry.FieldMigrationSpec) Test(org.junit.Test)

Example 8 with EntityTypeMigrationSpec

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

the class GenericMigratorTest method testMigrateAdditionalToAdditionalArrayString.

@Test
@Ignore
public void testMigrateAdditionalToAdditionalArrayString() {
    for (EntityType type : EntityType.values()) {
        toMigrate.setNamedAnnotations(new NamedAnnotations());
        MigrationSpec ms = new MigrationSpec();
        List<EntityTypeMigrationSpec> listEms = new ArrayList<EntityTypeMigrationSpec>();
        EntityTypeMigrationSpec ems = new EntityTypeMigrationSpec();
        ems.setEntityType(type.name());
        List<FieldMigrationSpec> listFms = new ArrayList<FieldMigrationSpec>();
        FieldMigrationSpec fms = new FieldMigrationSpec();
        FieldDescription source = new FieldDescription();
        FieldDescription dest = new FieldDescription();
        source.setName("old_name");
        source.setType("string");
        source.setBucket("additional");
        dest.setName("new_name");
        dest.setType("string");
        dest.setBucket("additional");
        fms.setSource(source);
        fms.setDestination(dest);
        listFms.add(fms);
        listEms.add(ems);
        ems.setFields(listFms);
        ms.setMigrationMetadata(listEms);
        MigrationSpecData msd = new MigrationSpecData();
        msd.setData(ms);
        genericMigrator.setMigrationSpecData(msd);
        String oldKey = "old_name";
        String newKey = "new_name";
        List<String> valuesToMigrate = new ArrayList<String>();
        valuesToMigrate.add("Value1 to be migrated");
        valuesToMigrate.add("Value2 to be migrated");
        valuesToMigrate.add("Value3 to be migrated");
        Annotations additionalAnnotations = toMigrate.getNamedAnnotations().getAdditionalAnnotations();
        additionalAnnotations.addAnnotation(oldKey, valuesToMigrate);
        Map<String, List<String>> additionalStringAnnos = additionalAnnotations.getStringAnnotations();
        assertNotNull(additionalStringAnnos.get(oldKey));
        genericMigrator.migrateOneStep(toMigrate, type);
        assertNull(additionalStringAnnos.get(oldKey));
        assertNotNull(additionalStringAnnos.get(newKey));
        assertEquals(3, additionalStringAnnos.get(newKey).size());
        assertEquals(valuesToMigrate.iterator().next(), additionalStringAnnos.get(newKey).iterator().next());
    }
    return;
}
Also used : MigrationSpecData(org.sagebionetworks.repo.model.registry.MigrationSpecData) ArrayList(java.util.ArrayList) MigrationSpec(org.sagebionetworks.repo.model.registry.MigrationSpec) FieldMigrationSpec(org.sagebionetworks.repo.model.registry.FieldMigrationSpec) EntityTypeMigrationSpec(org.sagebionetworks.repo.model.registry.EntityTypeMigrationSpec) FieldDescription(org.sagebionetworks.repo.model.registry.FieldDescription) EntityType(org.sagebionetworks.repo.model.EntityType) EntityTypeMigrationSpec(org.sagebionetworks.repo.model.registry.EntityTypeMigrationSpec) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) ArrayList(java.util.ArrayList) List(java.util.List) FieldMigrationSpec(org.sagebionetworks.repo.model.registry.FieldMigrationSpec) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with EntityTypeMigrationSpec

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

the class GenericMigratorTest method TestMigrateTypeAnnotExistsButNotString.

@Test
public void TestMigrateTypeAnnotExistsButNotString() {
    for (EntityType type : EntityType.values()) {
        // Setup migration spec
        // MigrationSpec ms = MigratorTestHelper.setupMigrationSpec(type.name(), "primary", "primary");
        MigrationSpec ms = new MigrationSpec();
        List<EntityTypeMigrationSpec> listEms = new ArrayList<EntityTypeMigrationSpec>();
        EntityTypeMigrationSpec ems = new EntityTypeMigrationSpec();
        ems.setEntityType(type.name());
        List<FieldMigrationSpec> listFms = new ArrayList<FieldMigrationSpec>();
        FieldMigrationSpec fms = new FieldMigrationSpec();
        FieldDescription source = new FieldDescription();
        FieldDescription dest = new FieldDescription();
        source.setName("old_name");
        source.setType("string");
        source.setBucket("additional");
        dest.setName("new_name");
        dest.setType("integer");
        dest.setBucket("additional");
        fms.setSource(source);
        fms.setDestination(dest);
        listFms.add(fms);
        listEms.add(ems);
        ems.setFields(listFms);
        ms.setMigrationMetadata(listEms);
        MigrationSpecData msd = new MigrationSpecData();
        msd.setData(ms);
        genericMigrator.setMigrationSpecData(msd);
        // Setup node to migrate
        // toMigrate = MigratorTestHelper.setupNodeRevisionToMigrate();
        String oldKey = "old_name";
        String newKey = "new_name";
        Long valueToMigrate = 100L;
        toMigrate.setNamedAnnotations(new NamedAnnotations());
        Annotations additionalAnnotations = toMigrate.getNamedAnnotations().getAdditionalAnnotations();
        // Create a long annotation with name expected for string annotation
        additionalAnnotations.addAnnotation(oldKey, valueToMigrate);
        Map<String, List<String>> stringAnnos = additionalAnnotations.getStringAnnotations();
        assertNull(stringAnnos.get(oldKey));
        Map<String, List<Long>> longAnnos = additionalAnnotations.getLongAnnotations();
        assertNotNull(longAnnos.get(oldKey));
        genericMigrator.migrateOneStep(toMigrate, type);
        assertNull(stringAnnos.get(oldKey));
        assertNull(longAnnos.get(oldKey));
        assertNotNull(longAnnos.get(newKey));
        assertEquals(1, longAnnos.get(newKey).size());
        assertEquals(new Long(100), (Long) longAnnos.get(newKey).iterator().next());
    }
    return;
}
Also used : MigrationSpecData(org.sagebionetworks.repo.model.registry.MigrationSpecData) ArrayList(java.util.ArrayList) MigrationSpec(org.sagebionetworks.repo.model.registry.MigrationSpec) FieldMigrationSpec(org.sagebionetworks.repo.model.registry.FieldMigrationSpec) EntityTypeMigrationSpec(org.sagebionetworks.repo.model.registry.EntityTypeMigrationSpec) FieldDescription(org.sagebionetworks.repo.model.registry.FieldDescription) EntityType(org.sagebionetworks.repo.model.EntityType) EntityTypeMigrationSpec(org.sagebionetworks.repo.model.registry.EntityTypeMigrationSpec) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) ArrayList(java.util.ArrayList) List(java.util.List) FieldMigrationSpec(org.sagebionetworks.repo.model.registry.FieldMigrationSpec) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)9 List (java.util.List)9 Test (org.junit.Test)9 Annotations (org.sagebionetworks.repo.model.Annotations)9 EntityType (org.sagebionetworks.repo.model.EntityType)9 NamedAnnotations (org.sagebionetworks.repo.model.NamedAnnotations)9 EntityTypeMigrationSpec (org.sagebionetworks.repo.model.registry.EntityTypeMigrationSpec)9 FieldDescription (org.sagebionetworks.repo.model.registry.FieldDescription)9 FieldMigrationSpec (org.sagebionetworks.repo.model.registry.FieldMigrationSpec)9 MigrationSpec (org.sagebionetworks.repo.model.registry.MigrationSpec)9 MigrationSpecData (org.sagebionetworks.repo.model.registry.MigrationSpecData)9 Ignore (org.junit.Ignore)4