Search in sources :

Example 1 with NamedAnnotations

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

the class JDONodeQueryAuthorizationTest method afterPropertiesSet.

/**
 * The setup for this test is expensive so we only do it once after all of the
 * beans are ready.
 */
@Override
public void afterPropertiesSet() throws Exception {
    Long creatorUserGroupId = Long.parseLong(userGroupDAO.findGroup(AuthorizationConstants.BOOTSTRAP_USER_GROUP_NAME, false).getId());
    if (instance != null) {
        return;
    }
    instance = this;
    // Keeps track of the users to delete
    nodesToDelete = new ArrayList<String>();
    groupsToDelete = new ArrayList<String>();
    // Create some users
    adminUser = createUser("admin@JDONodeQueryAuthorizationTest.org", true);
    // Create two groups
    groupA = createGroup("groupA@JDONodeQueryAuthorizationTest.org");
    groupB = createGroup("groupB@JDONodeQueryAuthorizationTest.org");
    // Create users in each group
    usersInGroupA = new HashMap<String, UserInfo>();
    for (int i = 0; i < 10; i++) {
        // Create all of the users
        String userId = "userInA" + i + "@JDONodeQueryAuthorizationTest.org";
        UserInfo info = createUser(userId, false);
        info.getGroups().add(groupA);
        usersInGroupA.put(userId, info);
    }
    // Create group b users
    usersInGroupB = new HashMap<String, UserInfo>();
    for (int i = 0; i < 7; i++) {
        // Create all of the users
        String userId = "userInB" + i + "@JDONodeQueryAuthorizationTest.org";
        UserInfo info = createUser(userId, false);
        info.getGroups().add(groupB);
        usersInGroupB.put(userId, info);
    }
    // Create users in both groups
    usersInBothGroups = new HashMap<String, UserInfo>();
    for (int i = 0; i < 7; i++) {
        // Create all of the users
        String userId = "userInBothA&B" + i + "@JDONodeQueryAuthorizationTest.org";
        UserInfo info = createUser(userId, false);
        info.getGroups().add(groupB);
        info.getGroups().add(groupA);
        usersInBothGroups.put(userId, info);
    }
    // Now create the two projects
    // Project A
    projectA = NodeTestUtils.createNew("projectA", creatorUserGroupId);
    projectA.setNodeType(EntityType.project.name());
    String id = nodeDao.createNew(projectA);
    nodesToDelete.add(id);
    projectA = nodeDao.getNode(id);
    // Create the ACL for this node.
    AccessControlList acl = AccessControlListUtil.createACLToGrantAll(id, adminUser);
    // Make sure group A can read from this node
    ResourceAccess access = new ResourceAccess();
    access.setPrincipalId(Long.parseLong(groupA.getId()));
    access.setAccessType(new HashSet<ACCESS_TYPE>());
    access.getAccessType().add(ACCESS_TYPE.READ);
    acl.getResourceAccess().add(access);
    accessControlListDAO.create(acl);
    // Project B
    projectB = NodeTestUtils.createNew("projectB", creatorUserGroupId);
    projectB.setNodeType(EntityType.project.name());
    id = nodeDao.createNew(projectB);
    nodesToDelete.add(id);
    projectB = nodeDao.getNode(id);
    // Create the ACL for this node.
    acl = AccessControlListUtil.createACLToGrantAll(id, adminUser);
    // Make sure group B can read from this node
    access = new ResourceAccess();
    access.setPrincipalId(Long.parseLong(groupB.getId()));
    access.setAccessType(new HashSet<ACCESS_TYPE>());
    access.getAccessType().add(ACCESS_TYPE.READ);
    acl.getResourceAccess().add(access);
    accessControlListDAO.create(acl);
    // Now add some nodes to each project.
    nodesInProjectA = new HashMap<String, Node>();
    for (int i = 0; i < 25; i++) {
        Node node = NodeTestUtils.createNew("nodeInProjectA" + i, creatorUserGroupId);
        node.setNodeType(EntityType.dataset.name());
        node.setParentId(projectA.getId());
        id = nodeDao.createNew(node);
        // nodesToDelete.add(id);
        node = nodeDao.getNode(id);
        nodesInProjectA.put(node.getId(), node);
    }
    // Now add some nodes to each project.
    nodesInProjectB = new HashMap<String, Node>();
    for (int i = 0; i < 25; i++) {
        Node node = NodeTestUtils.createNew("nodeInProjectB" + i, creatorUserGroupId);
        node.setNodeType(EntityType.dataset.name());
        node.setParentId(projectB.getId());
        id = nodeDao.createNew(node);
        // nodesToDelete.add(id);
        node = nodeDao.getNode(id);
        nodesInProjectB.put(node.getId(), node);
        // Add an attribute to nodes in group B
        NamedAnnotations annos = nodeDao.getAnnotations(id);
        assertNotNull(annos);
        // fieldTypeDao.addNewType(attributeName, FieldType.LONG_ATTRIBUTE);
        annos.getAdditionalAnnotations().addAnnotation(attributeName, new Long(i));
        nodeDao.updateAnnotations(id, annos);
    }
}
Also used : AccessControlList(org.sagebionetworks.repo.model.AccessControlList) ResourceAccess(org.sagebionetworks.repo.model.ResourceAccess) Node(org.sagebionetworks.repo.model.Node) UserInfo(org.sagebionetworks.repo.model.UserInfo) ACCESS_TYPE(org.sagebionetworks.repo.model.ACCESS_TYPE) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations)

Example 2 with NamedAnnotations

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

the class JDONodeQueryDAOSelectTest method createSingleNode.

/**
 * Create a single node.
 * @param name
 * @return
 * @throws NotFoundException
 * @throws DatastoreException
 */
private String createSingleNode(String name) throws NotFoundException, DatastoreException, InvalidModelException {
    Long createdBy = Long.parseLong(userGroupDAO.findGroup(AuthorizationConstants.BOOTSTRAP_USER_GROUP_NAME, false).getId());
    Node root = NodeTestUtils.createNew(name, createdBy);
    String id = nodeDao.createNew(root);
    nodeIds.add(id);
    root = nodeDao.getNode(id);
    root.setVersionComment("Version comment");
    root.setVersionLabel("0.1.0");
    nodeDao.createNewVersion(root);
    // Add annotations to the new version only.
    NamedAnnotations annos = nodeDao.getAnnotations(id);
    annos.getPrimaryAnnotations().addAnnotation(STRING_KEY_PRIMARY, "string value");
    annos.getAdditionalAnnotations().addAnnotation(STRING_KEY_SECONDARY, "string value 2");
    nodeDao.updateAnnotations(id, annos);
    return id;
}
Also used : Node(org.sagebionetworks.repo.model.Node) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations)

Example 3 with NamedAnnotations

use of org.sagebionetworks.repo.model.NamedAnnotations 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 4 with NamedAnnotations

use of org.sagebionetworks.repo.model.NamedAnnotations 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 5 with NamedAnnotations

use of org.sagebionetworks.repo.model.NamedAnnotations 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)

Aggregations

NamedAnnotations (org.sagebionetworks.repo.model.NamedAnnotations)70 Annotations (org.sagebionetworks.repo.model.Annotations)50 Test (org.junit.Test)43 Node (org.sagebionetworks.repo.model.Node)30 ArrayList (java.util.ArrayList)14 List (java.util.List)14 EntityType (org.sagebionetworks.repo.model.EntityType)14 Date (java.util.Date)10 NodeRevisionBackup (org.sagebionetworks.repo.model.NodeRevisionBackup)10 UserInfo (org.sagebionetworks.repo.model.UserInfo)10 HashSet (java.util.HashSet)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 Set (java.util.Set)8 DatastoreException (org.sagebionetworks.repo.model.DatastoreException)7 IOException (java.io.IOException)6 NodeQueryResults (org.sagebionetworks.repo.model.NodeQueryResults)5