Search in sources :

Example 1 with Node

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

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

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

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

the class JDONodeQueryDAOImplTest method testFilterOnMultiplePrimary.

@Test
public void testFilterOnMultiplePrimary() throws Exception {
    BasicQuery query = new BasicQuery();
    query.setFrom(EntityType.dataset.name());
    List<Expression> filters = new ArrayList<Expression>();
    Long filterCreator = createdBy;
    String filterName = "dsName0";
    Expression expression = new Expression(new CompoundId("dataset", "createdByPrincipalId"), Comparator.EQUALS, filterCreator);
    Expression expression2 = new Expression(new CompoundId("dataset", "name"), Comparator.EQUALS, filterName);
    filters.add(expression);
    filters.add(expression2);
    query.setFilters(filters);
    NodeQueryResults results = nodeQueryDao.executeQuery(query, mockUserInfo);
    assertNotNull(results);
    // Only one data has the name so the filter should limit to it.
    assertEquals(1, results.getTotalNumberOfResults());
    List<String> list = results.getResultIds();
    assertNotNull(list);
    assertEquals(1, list.size());
    String id = list.get(0);
    Node node = nodeDao.getNode(id);
    assertEquals(filterName, node.getName());
    assertEquals(filterCreator, node.getCreatedByPrincipalId());
}
Also used : BasicQuery(org.sagebionetworks.repo.model.query.BasicQuery) Expression(org.sagebionetworks.repo.model.query.Expression) Node(org.sagebionetworks.repo.model.Node) ArrayList(java.util.ArrayList) NodeQueryResults(org.sagebionetworks.repo.model.NodeQueryResults) CompoundId(org.sagebionetworks.repo.model.query.CompoundId) Test(org.junit.Test)

Example 5 with Node

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

Aggregations

Node (org.sagebionetworks.repo.model.Node)159 Test (org.junit.Test)109 NamedAnnotations (org.sagebionetworks.repo.model.NamedAnnotations)31 Date (java.util.Date)24 Annotations (org.sagebionetworks.repo.model.Annotations)23 AccessControlList (org.sagebionetworks.repo.model.AccessControlList)20 Matchers.anyString (org.mockito.Matchers.anyString)18 UserInfo (org.sagebionetworks.repo.model.UserInfo)18 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)16 BasicQuery (org.sagebionetworks.repo.model.query.BasicQuery)12 ACCESS_TYPE (org.sagebionetworks.repo.model.ACCESS_TYPE)11 NodeQueryResults (org.sagebionetworks.repo.model.NodeQueryResults)11 NodeRevisionBackup (org.sagebionetworks.repo.model.NodeRevisionBackup)11 ResourceAccess (org.sagebionetworks.repo.model.ResourceAccess)11 Set (java.util.Set)10 HashMap (java.util.HashMap)9 Reference (org.sagebionetworks.repo.model.Reference)8 Transactional (org.springframework.transaction.annotation.Transactional)8 Before (org.junit.Before)7