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);
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations