Search in sources :

Example 1 with Annotations

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

the class JDONodeQueryDAOImplTest method populateNodesForTest.

private void populateNodesForTest() throws Exception {
    Iterator<String> it = fieldTypeMap.keySet().iterator();
    while (it.hasNext()) {
        String key = it.next();
        FieldType type = fieldTypeMap.get(key);
    }
    // Create a few datasets
    nodeIds = new ArrayList<String>();
    for (int i = 0; i < totalNumberOfDatasets; i++) {
        Node parent = NodeTestUtils.createNew("dsName" + i, createdBy);
        Date now = new Date(System.currentTimeMillis());
        parent.setDescription("description" + i);
        parent.setCreatedByPrincipalId(createdBy);
        parent.setNodeType(EntityType.dataset.name());
        // Create this dataset
        String parentId = nodeDao.createNew(parent);
        idToNameMap.put(parentId, parent.getName());
        nodeIds.add(parentId);
        NamedAnnotations named = nodeDao.getAnnotations(parentId);
        Annotations parentAnnos = named.getAdditionalAnnotations();
        parentAnnos.addAnnotation(attOnall, "someNumber" + i);
        // Add some attributes to others.
        if ((i % 2) == 0) {
            parentAnnos.addAnnotation(attOnEven, new Long(i));
        } else {
            parentAnnos.addAnnotation(attOnOdd, now);
        }
        // Make sure we add one of each type
        parentAnnos.addAnnotation(attString, "someString" + i);
        parentAnnos.addAnnotation(attDate, new Date(System.currentTimeMillis() + i));
        parentAnnos.addAnnotation(attLong, new Long(123456));
        parentAnnos.addAnnotation(attDouble, new Double(123456.3));
        nodeDao.updateAnnotations(parentId, named);
        // Add a child to the parent
        Node child = createChild(now, i, createdBy);
        child.setParentId(parentId);
        // Add a layer attribute
        String childId = nodeDao.createNew(child);
        idToNameMap.put(childId, child.getName());
        NamedAnnotations childNamed = nodeDao.getAnnotations(childId);
        Annotations childAnnos = childNamed.getPrimaryAnnotations();
        childAnnos.addAnnotation("layerAnnotation", "layerAnnotValue" + i);
        if ((i % 2) == 0) {
            childAnnos.addAnnotation(attLayerType, LayerTypeNames.C.name());
        } else if ((i % 3) == 0) {
            childAnnos.addAnnotation(attLayerType, LayerTypeNames.E.name());
        } else {
            childAnnos.addAnnotation(attLayerType, LayerTypeNames.G.name());
        }
        // Update the child annoations.
        nodeDao.updateAnnotations(childId, childNamed);
    // Thread.sleep(1000);
    }
}
Also used : NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) Node(org.sagebionetworks.repo.model.Node) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Date(java.util.Date) FieldType(org.sagebionetworks.repo.model.query.FieldType)

Example 2 with Annotations

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

the class JDONodeQueryDAOImplTest method testBasicQuery.

// Test basic query
@Test
public void testBasicQuery() throws Exception {
    // This query is basically "select * from datasets"
    BasicQuery query = new BasicQuery();
    query.setFrom(EntityType.dataset.name());
    NodeQueryResults results = nodeQueryDao.executeQuery(query, mockUserInfo);
    assertNotNull(results);
    assertEquals(totalNumberOfDatasets, results.getTotalNumberOfResults());
    // Validate all of the data is there
    List<String> rows = results.getResultIds();
    assertNotNull(rows);
    // Each row should have each primary field
    for (String id : rows) {
        assertNotNull(id);
        // Get the node with this id
        Node node = nodeDao.getNode(id);
        assertNotNull(node);
        assertEquals(EntityType.dataset.name(), node.getNodeType());
        // Load the annotations for this node
        NamedAnnotations named = nodeDao.getAnnotations(id);
        Annotations annos = named.getAdditionalAnnotations();
        // Check for the annotations they all should have.
        // String
        Object annoValue = annos.getStringAnnotations().get(attString);
        assertNotNull(annoValue);
        // Date
        annoValue = annos.getDateAnnotations().get(attDate);
        assertNotNull(annoValue);
        // Long
        annoValue = annos.getLongAnnotations().get(attLong);
        assertNotNull(annoValue);
        // Double
        annoValue = annos.getDoubleAnnotations().get(attDouble);
        assertNotNull(annoValue);
    }
}
Also used : NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) BasicQuery(org.sagebionetworks.repo.model.query.BasicQuery) Node(org.sagebionetworks.repo.model.Node) NodeQueryResults(org.sagebionetworks.repo.model.NodeQueryResults) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Test(org.junit.Test)

Example 3 with Annotations

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

the class JDONodeQueryDAOImplTest method testSortOnStringAttribute.

// Sorting on a string attribute
@Test
public void testSortOnStringAttribute() throws Exception {
    BasicQuery query = new BasicQuery();
    query.setFrom(EntityType.dataset.name());
    query.setSort(attString);
    query.setAscending(false);
    NodeQueryResults results = nodeQueryDao.executeQuery(query, mockUserInfo);
    assertNotNull(results);
    // Sorting should not reduce the number of columns
    assertEquals(totalNumberOfDatasets, results.getTotalNumberOfResults());
    // Validate the sort
    List<String> rows = results.getResultIds();
    assertNotNull(rows);
    // Each row should have each primary field
    String previousName = null;
    String name = null;
    for (String id : rows) {
        previousName = name;
        NamedAnnotations named = nodeDao.getAnnotations(id);
        Annotations annos = named.getAdditionalAnnotations();
        Collection<String> collection = annos.getStringAnnotations().get(attString);
        name = collection.iterator().next();
        System.out.println(name);
        if (previousName != null) {
            assertTrue(previousName.compareTo(name) > 0);
        }
    }
}
Also used : NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) BasicQuery(org.sagebionetworks.repo.model.query.BasicQuery) NodeQueryResults(org.sagebionetworks.repo.model.NodeQueryResults) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Test(org.junit.Test)

Example 4 with Annotations

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

the class JDONodeQueryDAOImplTest method testFilterOnSingleAttributeAndSinglePrimary.

@Test
public void testFilterOnSingleAttributeAndSinglePrimary() throws Exception {
    BasicQuery query = new BasicQuery();
    query.setFrom(EntityType.dataset.name());
    query.setSort(attOnall);
    query.setAscending(false);
    List<Expression> filters = new ArrayList<Expression>();
    // Filter on an annotation using does not equal with a bogus value to
    // get all datasets.
    String onAllValue = "someNumber2";
    Long creator = createdBy;
    Expression expression = new Expression(new CompoundId("dataset", attOnall), Comparator.EQUALS, onAllValue);
    Expression expression2 = new Expression(new CompoundId("dataset", "createdByPrincipalId"), Comparator.EQUALS, creator);
    filters.add(expression);
    filters.add(expression2);
    query.setFilters(filters);
    NodeQueryResults results = nodeQueryDao.executeQuery(query, mockUserInfo);
    assertNotNull(results);
    // Every dataset should have this creator so the count should match the
    // total
    assertEquals(1, results.getTotalNumberOfResults());
    List<String> list = results.getResultIds();
    assertNotNull(list);
    assertEquals(1, list.size());
    String id = list.get(0);
    NamedAnnotations named = nodeDao.getAnnotations(id);
    Annotations annos = named.getAdditionalAnnotations();
    Collection<String> values = annos.getStringAnnotations().get(attOnall);
    assertNotNull(values);
    assertEquals(1, values.size());
    assertEquals(onAllValue, values.iterator().next());
    Node node = nodeDao.getNode(id);
    assertNotNull(node);
    assertEquals(creator, node.getCreatedByPrincipalId());
}
Also used : Node(org.sagebionetworks.repo.model.Node) ArrayList(java.util.ArrayList) CompoundId(org.sagebionetworks.repo.model.query.CompoundId) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) BasicQuery(org.sagebionetworks.repo.model.query.BasicQuery) Expression(org.sagebionetworks.repo.model.query.Expression) NodeQueryResults(org.sagebionetworks.repo.model.NodeQueryResults) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Test(org.junit.Test)

Example 5 with Annotations

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

the class AdministrationControllerTest method testBackupRestoreBatchRoundTrip.

/**
 * This test attempts to create a backup of a single node and restore it.  This should not trigger an full backup or restore.
 */
@Test
public void testBackupRestoreBatchRoundTrip() throws DatastoreException, InvalidModelException, NotFoundException, UnauthorizedException, ServletException, IOException, InterruptedException {
    UserInfo nonAdmin = testUserProvider.getTestAdminUserInfo();
    Node nodeWithAnnotations = new Node();
    nodeWithAnnotations.setName("testBatchRoundTripAnnotations");
    nodeWithAnnotations.setNodeType(EntityType.project.name());
    Annotations annos = RandomAnnotationsUtil.generateRandom(334, 50);
    NamedAnnotations named = new NamedAnnotations();
    named.put(NamedAnnotations.NAME_SPACE_ADDITIONAL, annos);
    String idOfNodeWithAnnotations = nodeManager.createNewNode(nodeWithAnnotations, named, nonAdmin);
    assertNotNull(idOfNodeWithAnnotations);
    toDelete.add(idOfNodeWithAnnotations);
    Node nodeWithRefs = new Node();
    nodeWithRefs.setName("testBatchRoundTrip References");
    nodeWithRefs.setNodeType(EntityType.project.name());
    Reference reference = new Reference();
    reference.setTargetId(idOfNodeWithAnnotations);
    reference.setTargetVersionNumber(42L);
    Set<Reference> referenceGroup = new HashSet<Reference>();
    referenceGroup.add(reference);
    Map<String, Set<Reference>> referenceGroups = new HashMap<String, Set<Reference>>();
    referenceGroups.put("backedUpRefs", referenceGroup);
    nodeWithRefs.setReferences(referenceGroups);
    String idOfNodeWithRefs = nodeManager.createNewNode(nodeWithRefs, new NamedAnnotations(), nonAdmin);
    assertNotNull(idOfNodeWithRefs);
    toDelete.add(idOfNodeWithRefs);
    // Fetch them back
    nodeWithAnnotations = nodeManager.get(nonAdmin, idOfNodeWithAnnotations);
    named = nodeManager.getAnnotations(nonAdmin, idOfNodeWithAnnotations);
    annos = named.getAdditionalAnnotations();
    nodeWithRefs = nodeManager.get(nonAdmin, idOfNodeWithRefs);
    // Start a backup
    BackupSubmission submission = new BackupSubmission();
    submission.setEntityIdsToBackup(new HashSet<String>());
    // We are just going to backup the node with references.
    submission.getEntityIdsToBackup().add(idOfNodeWithRefs);
    BackupRestoreStatus status = ServletTestHelper.startBackup(dispatchServlet, adminUserName, submission);
    // Wait for it to finish
    assertNotNull(status);
    assertNotNull(status.getId());
    // Wait for it finish
    status = waitForStatus(DaemonStatus.COMPLETED, status.getId());
    assertNotNull(status.getBackupUrl());
    String fullUrl = status.getBackupUrl();
    System.out.println(fullUrl);
    int index = fullUrl.lastIndexOf("/");
    String fileName = status.getBackupUrl().substring(index + 1, fullUrl.length());
    // Now delete both nodes that we created.
    nodeManager.delete(nonAdmin, idOfNodeWithAnnotations);
    nodeManager.delete(nonAdmin, idOfNodeWithRefs);
    // Now restore the nodes from the backup
    RestoreSubmission file = new RestoreSubmission();
    file.setFileName(fileName);
    // The backup should only restore a single node.
    status = ServletTestHelper.startRestore(dispatchServlet, adminUserName, file);
    assertNotNull(status);
    assertNotNull(status.getId());
    // Wait for it finish
    status = waitForStatus(DaemonStatus.COMPLETED, status.getId());
    assertNotNull(status.getBackupUrl());
    System.out.println(status.getBackupUrl());
    // Now make sure the nodes are resurrected
    try {
        nodeManager.get(nonAdmin, idOfNodeWithAnnotations);
        fail("The first node was not included in the restore so it should no longer exist");
    } catch (NotFoundException e) {
    // This is expected
    }
    Node nodeWithRefsClone = nodeManager.get(nonAdmin, idOfNodeWithRefs);
    assertEquals(referenceGroups, nodeWithRefsClone.getReferences());
}
Also used : BackupSubmission(org.sagebionetworks.repo.model.daemon.BackupSubmission) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Reference(org.sagebionetworks.repo.model.Reference) BackupRestoreStatus(org.sagebionetworks.repo.model.daemon.BackupRestoreStatus) Node(org.sagebionetworks.repo.model.Node) RestoreSubmission(org.sagebionetworks.repo.model.daemon.RestoreSubmission) NotFoundException(org.sagebionetworks.repo.web.NotFoundException) UserInfo(org.sagebionetworks.repo.model.UserInfo) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) Annotations(org.sagebionetworks.repo.model.Annotations) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Annotations (org.sagebionetworks.repo.model.Annotations)112 Test (org.junit.Test)78 NamedAnnotations (org.sagebionetworks.repo.model.NamedAnnotations)63 ArrayList (java.util.ArrayList)26 List (java.util.List)24 Node (org.sagebionetworks.repo.model.Node)23 Date (java.util.Date)20 EntityType (org.sagebionetworks.repo.model.EntityType)13 AccessControlList (org.sagebionetworks.repo.model.AccessControlList)12 Study (org.sagebionetworks.repo.model.Study)12 UserInfo (org.sagebionetworks.repo.model.UserInfo)11 HashSet (java.util.HashSet)10 EntityBundle (org.sagebionetworks.repo.model.EntityBundle)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 HashMap (java.util.HashMap)8 Project (org.sagebionetworks.repo.model.Project)8