Search in sources :

Example 11 with NodeRevisionBackup

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

the class SerializationUseCases method createV1DatasetRevision.

public static NodeRevisionBackup createV1DatasetRevision() {
    // Create a dataset with data
    Study ds = createDatasetWithAllFields();
    // Get the annotations for this object
    NamedAnnotations annos = createAnnotationsV1(ds);
    // now create a revision for this node
    NodeRevisionBackup rev = createRevisionV1(ds, annos);
    rev.setXmlVersion(NodeRevisionBackup.XML_V_1);
    return rev;
}
Also used : Study(org.sagebionetworks.repo.model.Study) NodeRevisionBackup(org.sagebionetworks.repo.model.NodeRevisionBackup) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations)

Example 12 with NodeRevisionBackup

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

the class SerializationUseCases method main.

public static void main(String[] args) {
    // project v0
    NodeRevisionBackup rev = createV0ProjectRevision();
    StringWriter writer = new StringWriter();
    NodeSerializerUtil.writeNodeRevision(rev, writer);
    System.out.println("project v0 xml");
    System.out.println(writer.toString());
    // dataset v0
    rev = createV0DatasetRevision();
    writer = new StringWriter();
    NodeSerializerUtil.writeNodeRevision(rev, writer);
    System.out.println("dataset v0 xml");
    System.out.println(writer.toString());
    // project v1
    rev = createV1ProjectRevision();
    writer = new StringWriter();
    NodeSerializerUtil.writeNodeRevision(rev, writer);
    System.out.println("project v1 xml");
    System.out.println(writer.toString());
    // project v1
    rev = createV1DatasetRevision();
    writer = new StringWriter();
    NodeSerializerUtil.writeNodeRevision(rev, writer);
    System.out.println("dataset v1 xml");
    System.out.println(writer.toString());
    // step v1
    rev = createV1StepRevision();
    writer = new StringWriter();
    NodeSerializerUtil.writeNodeRevision(rev, writer);
    System.out.println("step v1 xml");
    System.out.println(writer.toString());
}
Also used : StringWriter(java.io.StringWriter) NodeRevisionBackup(org.sagebionetworks.repo.model.NodeRevisionBackup)

Example 13 with NodeRevisionBackup

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

the class SerializationUseCases method createV1StepRevision.

/**
 * This will create a Step revision with references
 *
 * This is a little more complicated now with references. TODO think about
 * how to factor this more cleanly. The problem is that in the real
 * codebase, we don't go from Node -> NodeRevisionBackup, we go from Entity ->
 * Node -> JDORevision -> NodeRevisionBackup. We wind up writing a bunch of
 * artificial code here instead of testing the real code path.
 *
 * @return
 */
public static NodeRevisionBackup createV1StepRevision() {
    // Create a Step
    Step step = createStepWithReferences();
    /**
     **********
     *  This code is lifted from EntityManagerImpl.createEntity.
     */
    Node node = NodeTranslationUtils.createFromEntity(step);
    // Set the type for this object
    node.setNodeType(EntityType.getNodeTypeForClass(step.getClass()).toString());
    NamedAnnotations named = new NamedAnnotations();
    // Now add all of the annotations and references from the step
    NodeTranslationUtils.updateNodeSecondaryFieldsFromObject(step, named.getPrimaryAnnotations(), node.getReferences());
    /**
     **********
     */
    // Add some annotations
    Annotations additionalAnnos = named.getAdditionalAnnotations();
    addAdditionalAnnotations(additionalAnnos);
    // Now create a revision for this node
    NodeRevisionBackup rev = new NodeRevisionBackup();
    rev.setRevisionNumber(1l);
    rev.setNodeId(node.getId());
    rev.setLabel("The first version of this object");
    rev.setComment("I have no comment at this time");
    rev.setNamedAnnotations(named);
    rev.setReferences(node.getReferences());
    rev.setXmlVersion(NodeRevisionBackup.XML_V_1);
    return rev;
}
Also used : NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) Node(org.sagebionetworks.repo.model.Node) NodeRevisionBackup(org.sagebionetworks.repo.model.NodeRevisionBackup) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Step(org.sagebionetworks.repo.model.Step)

Example 14 with NodeRevisionBackup

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

the class SerializationUseCases method createRevisionV1.

public static <T extends Entity> NodeRevisionBackup createRevisionV1(T ds, NamedAnnotations annos) {
    NodeRevisionBackup rev = createBasicRev(ds);
    rev.setNamedAnnotations(annos);
    return rev;
}
Also used : NodeRevisionBackup(org.sagebionetworks.repo.model.NodeRevisionBackup)

Example 15 with NodeRevisionBackup

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

the class SerializationUseCases method createRevisionV0.

public static <T extends Entity> NodeRevisionBackup createRevisionV0(T ds, Annotations annos) {
    NodeRevisionBackup rev = createBasicRev(ds);
    rev.setAnnotations(annos);
    return rev;
}
Also used : 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