Search in sources :

Example 26 with NodeRevisionBackup

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

the class NodeSerializerUtilTest method testRoundTripNodeRevisionRandom.

@Test
public void testRoundTripNodeRevisionRandom() throws UnsupportedEncodingException {
    // Create a node backup with all of the values.
    NodeRevisionBackup rev = RandomNodeRevisionUtil.generateRandom(489, 12);
    StringWriter writer = new StringWriter();
    NodeSerializerUtil.writeNodeRevision(rev, writer);
    // System.out.println(writer.toString());
    // Now read it back
    StringReader reader = new StringReader(writer.toString());
    NodeRevisionBackup clone = NodeSerializerUtil.readNodeRevision(reader);
    assertNotNull(clone);
    assertEquals(rev, clone);
}
Also used : StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) NodeRevisionBackup(org.sagebionetworks.repo.model.NodeRevisionBackup) Test(org.junit.Test)

Example 27 with NodeRevisionBackup

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

the class NodeSerializerUtilTest method main.

/**
 * This main method is used to create a blob of the current version of annotations.
 * Each time we change the annotations object, we should create a new version and add it to the
 * files to test.
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    // There should be three args
    if (args == null || args.length != 3)
        throw new IllegalArgumentException("This utility requires three arguments: 0=filname, 1=randomSeed, 2=count");
    String name = args[0];
    long seed;
    int count;
    try {
        seed = Long.parseLong(args[1]);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("The second argument should be a long representing the random seed to use.", e);
    }
    try {
        count = Integer.parseInt(args[2]);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("The thrid argument should be the number of annotations to used", e);
    }
    NodeBackup backupToSave = null;
    NodeRevisionBackup revToSave = null;
    if (name.startsWith("node-backup")) {
        backupToSave = RandomNodeBackupUtil.generateRandome(seed);
    } else if (name.startsWith("node-revision")) {
        revToSave = RandomNodeRevisionUtil.generateRandom(seed, count);
    } else {
        throw new IllegalArgumentException("The file name for the first argument should either start with 'node-backup' for a NodeBackup or 'node-revision' for a NodeRevisionBackup");
    }
    // Now create the output file
    File outputFile = new File("src/test/resources/" + name);
    System.out.println("Creating file: " + outputFile.getAbsolutePath());
    if (outputFile.exists()) {
        outputFile.delete();
    }
    outputFile.createNewFile();
    FileOutputStream fos = new FileOutputStream(outputFile);
    try {
        // Write this blob to the file
        BufferedOutputStream buffer = new BufferedOutputStream(fos);
        if (backupToSave != null) {
            NodeSerializerUtil.writeNodeBackup(backupToSave, buffer);
        } else if (revToSave != null) {
            NodeSerializerUtil.writeNodeRevision(revToSave, buffer);
        } else {
            throw new Exception("Both backupToSave and revToSave cannot be null");
        }
        System.out.println("Finished building File: " + outputFile.getAbsolutePath());
        buffer.flush();
        fos.flush();
    } finally {
        fos.close();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) NodeBackup(org.sagebionetworks.repo.model.NodeBackup) NodeRevisionBackup(org.sagebionetworks.repo.model.NodeRevisionBackup) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 28 with NodeRevisionBackup

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

the class SerializationUseCases method createV0DatasetRevision.

/**
 * This will create a revision with annotations
 *
 * @return
 */
public static NodeRevisionBackup createV0DatasetRevision() {
    // Create a dataset with data
    Study ds = createDatasetWithAllFields();
    // Get the annotations for this object
    Annotations annos = createAnnotationsV0(ds);
    // now create a revision for this node
    NodeRevisionBackup rev = createRevisionV0(ds, annos);
    // We did not have this field in v0
    rev.setXmlVersion(null);
    return rev;
}
Also used : Study(org.sagebionetworks.repo.model.Study) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) NodeRevisionBackup(org.sagebionetworks.repo.model.NodeRevisionBackup)

Example 29 with NodeRevisionBackup

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

the class SerializationUseCases method createBasicRev.

public static <T extends Entity> NodeRevisionBackup createBasicRev(T ds) {
    NodeRevisionBackup rev = new NodeRevisionBackup();
    rev.setRevisionNumber(1l);
    rev.setNodeId(ds.getId());
    rev.setLabel("The first version of this object");
    rev.setComment("I have not comment at this time");
    return rev;
}
Also used : NodeRevisionBackup(org.sagebionetworks.repo.model.NodeRevisionBackup)

Example 30 with NodeRevisionBackup

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

the class SerializationUseCases method createV0ProjectRevision.

/**
 * This will create a revision with annotations
 *
 * @return
 */
public static NodeRevisionBackup createV0ProjectRevision() {
    // Create a dataset with data
    Project project = createProjectWithAllFields();
    // Get the annotations for this object
    Annotations annos = createAnnotationsV0(project);
    // now create a revision for this node
    NodeRevisionBackup rev = createRevisionV0(project, annos);
    // We did not have this field in v0
    rev.setXmlVersion(null);
    return rev;
}
Also used : Project(org.sagebionetworks.repo.model.Project) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) NodeRevisionBackup(org.sagebionetworks.repo.model.NodeRevisionBackup)

Aggregations

NodeRevisionBackup (org.sagebionetworks.repo.model.NodeRevisionBackup)42 Test (org.junit.Test)16 NamedAnnotations (org.sagebionetworks.repo.model.NamedAnnotations)12 Node (org.sagebionetworks.repo.model.Node)11 NodeBackup (org.sagebionetworks.repo.model.NodeBackup)9 Date (java.util.Date)7 Annotations (org.sagebionetworks.repo.model.Annotations)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)4 Set (java.util.Set)4 StringWriter (java.io.StringWriter)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 AccessControlList (org.sagebionetworks.repo.model.AccessControlList)3 EntityPath (org.sagebionetworks.repo.model.EntityPath)3 EntityType (org.sagebionetworks.repo.model.EntityType)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ZipEntry (java.util.zip.ZipEntry)2 Project (org.sagebionetworks.repo.model.Project)2