Search in sources :

Example 1 with EntityTypeMigrationSpec

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

the class GenericMigratorTest method testMigrateTypeInvalid.

@Test
public void testMigrateTypeInvalid() {
    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 = "abc";
        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(new Long(-1), (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)

Example 2 with EntityTypeMigrationSpec

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

the class GenericMigratorTest method testMigratePrimaryToPrimaryArrayString.

@Test
@Ignore
public void testMigratePrimaryToPrimaryArrayString() {
    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("primary");
        dest.setName("name");
        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 = "old_name";
        String newKey = "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 primaryAnnotations = toMigrate.getNamedAnnotations().getPrimaryAnnotations();
        primaryAnnotations.addAnnotation(oldKey, valuesToMigrate);
        Map<String, List<String>> primaryStringAnnos = primaryAnnotations.getStringAnnotations();
        assertNotNull(primaryStringAnnos.get(oldKey));
        genericMigrator.migrateOneStep(toMigrate, type);
        assertNull(primaryStringAnnos.get(oldKey));
        assertNotNull(primaryStringAnnos.get(newKey));
        assertEquals(3, primaryStringAnnos.get(newKey).size());
        assertEquals(valuesToMigrate.iterator().next(), primaryStringAnnos.get(newKey).iterator().next());
    }
}
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 3 with EntityTypeMigrationSpec

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

the class GenericMigratorTest method testMigrateDatasetAdditionalToPrimarySingleLong.

@Test
@Ignore
public void testMigrateDatasetAdditionalToPrimarySingleLong() {
    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("Number_of_Samples");
    source.setType("long");
    source.setBucket("additional");
    dest.setName("numberOfSamples");
    dest.setType("long");
    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 = "Number_of_Samples";
    String newKey = "numberOfSamples";
    List<Long> valuesToMigrate = new ArrayList<Long>();
    valuesToMigrate.add(100L);
    Annotations additionalAnnotations = toMigrate.getNamedAnnotations().getAdditionalAnnotations();
    Annotations primaryAnnotations = toMigrate.getNamedAnnotations().getPrimaryAnnotations();
    Map<String, List<Long>> primaryLongAnnos = primaryAnnotations.getLongAnnotations();
    additionalAnnotations.addAnnotation(oldKey, valuesToMigrate);
    assertNotNull(additionalAnnotations.getAllValues(oldKey));
    genericMigrator.migrateOneStep(toMigrate, type);
    assertNull(additionalAnnotations.getAllValues(oldKey));
    assertNotNull(primaryAnnotations.getAllValues(newKey));
    assertEquals(1, primaryLongAnnos.get(newKey).size());
    assertEquals(valuesToMigrate.iterator().next(), primaryLongAnnos.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 4 with EntityTypeMigrationSpec

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

the class GenericMigratorTest method testMigratePrimaryToPrimaryString.

@Test
public void testMigratePrimaryToPrimaryString() {
    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("primary");
        dest.setName("name");
        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);
        // Setup node to migrate
        // toMigrate = MigratorTestHelper.setupNodeRevisionToMigrate();
        String oldKey = "old_name";
        String newKey = "name";
        String valueToMigrate = "String to migrate";
        toMigrate.setNamedAnnotations(new NamedAnnotations());
        Annotations primaryAnnotations = toMigrate.getNamedAnnotations().getPrimaryAnnotations();
        primaryAnnotations.addAnnotation(oldKey, valueToMigrate);
        Map<String, List<String>> stringAnnos = primaryAnnotations.getStringAnnotations();
        assertNotNull(stringAnnos.get(oldKey));
        genericMigrator.migrateOneStep(toMigrate, type);
        assertNull(stringAnnos.get(oldKey));
        assertNotNull(stringAnnos.get(newKey));
        assertEquals(1, stringAnnos.get(newKey).size());
        assertEquals(valueToMigrate, stringAnnos.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 5 with EntityTypeMigrationSpec

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

the class GenericMigratorTest method testMigratePrimaryToAdditionalString.

@Test
public void testMigratePrimaryToAdditionalString() {
    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("primary");
        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";
        String valueToMigrate = "Value to be migrated";
        Annotations primaryAnnotations = toMigrate.getNamedAnnotations().getPrimaryAnnotations();
        Annotations additionalAnnotations = toMigrate.getNamedAnnotations().getAdditionalAnnotations();
        primaryAnnotations.addAnnotation(oldKey, valueToMigrate);
        Map<String, List<String>> primaryStringAnnos = primaryAnnotations.getStringAnnotations();
        Map<String, List<String>> additionalStringAnnos = additionalAnnotations.getStringAnnotations();
        assertNotNull(primaryStringAnnos.get(oldKey));
        genericMigrator.migrateOneStep(toMigrate, type);
        assertNull(primaryStringAnnos.get(oldKey));
        assertNotNull(additionalStringAnnos.get(newKey));
        assertEquals(1, additionalStringAnnos.get(newKey).size());
        assertEquals(valueToMigrate, 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) 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