コード例 #1
0
  @Before
  public void setup() {
    Visibility visibility = new Visibility("");
    Authorizations authorizations = new InMemoryAuthorizations();
    InMemoryGraphConfiguration config = new InMemoryGraphConfiguration(new HashMap());
    idGenerator = new QueueIdGenerator();
    graph = new InMemoryGraph(config, idGenerator, new DefaultSearchIndex(config.getConfig()));
    authorizationRepository = new InMemoryAuthorizationRepository();

    Configuration lumifyConfiguration =
        new HashMapConfigurationLoader(new HashMap()).createConfiguration();
    InMemoryUserRepository userRepository =
        new InMemoryUserRepository(lumifyConfiguration, userListenerUtil);
    user1 = (InMemoryUser) userRepository.addUser("user2", "user2", null, "none", new String[0]);
    graph.addVertex(user1.getUserId(), visibility, authorizations);

    user2 = (InMemoryUser) userRepository.addUser("user2", "user2", null, "none", new String[0]);
    graph.addVertex(user2.getUserId(), visibility, authorizations);

    when(ontologyRepository.getConceptByIRI(eq(OntologyRepository.ROOT_CONCEPT_IRI)))
        .thenReturn(rootConcept);

    when(ontologyRepository.getOrCreateConcept(
            (Concept) isNull(),
            eq(WorkspaceRepository.WORKSPACE_CONCEPT_NAME),
            anyString(),
            (java.io.File) anyObject()))
        .thenReturn(workspaceConcept);
    when(workspaceConcept.getTitle()).thenReturn(WorkspaceRepository.WORKSPACE_CONCEPT_NAME);

    when(workspaceToEntityRelationship.getIRI()).thenReturn("workspaceToEntityRelationshipId");
    when(ontologyRepository.getOrCreateRelationshipType(
            eq(workspaceConcept),
            eq(rootConcept),
            eq(WorkspaceRepository.WORKSPACE_TO_ENTITY_RELATIONSHIP_NAME),
            anyString()))
        .thenReturn(workspaceToEntityRelationship);

    when(workspaceToUserRelationship.getIRI()).thenReturn("workspaceToUserRelationshipId");
    when(ontologyRepository.getOrCreateRelationshipType(
            eq(workspaceConcept),
            eq(rootConcept),
            eq(WorkspaceRepository.WORKSPACE_TO_USER_RELATIONSHIP_NAME),
            anyString()))
        .thenReturn(workspaceToUserRelationship);

    workspaceRepository =
        new SecureGraphWorkspaceRepository(
            ontologyRepository, graph, userRepository, authorizationRepository, workspaceDiff);

    String entity1VertexId = "entity1Id";
    entity1Vertex =
        graph.addVertex(
            entity1VertexId, new LumifyVisibility().getVisibility(), new InMemoryAuthorizations());
  }
コード例 #2
0
  @Test
  public void testEntities() {
    int startingVertexCount = graph.getAllVertices().size();
    int startingEdgeCount = graph.getAllEdges().size();

    String workspaceId = "testWorkspaceId";
    idGenerator.push(workspaceId);
    idGenerator.push(workspaceId + "_to_" + user1.getUserId());

    Workspace workspace = workspaceRepository.add("workspace1", user1);
    assertEquals(
        startingVertexCount + 1, graph.getAllVertices().size()); // +1 = the workspace vertex
    assertEquals(
        startingEdgeCount + 1,
        graph.getAllEdges().size()); // +1 = the edges between workspaces and users

    try {
      workspaceRepository.updateEntityOnWorkspace(
          workspace, entity1Vertex.getId(), true, 100, 100, user2);
      fail("user2 should not have write access to workspace");
    } catch (LumifyAccessDeniedException ex) {
      assertEquals(user2, ex.getUser());
      assertEquals(workspace.getId(), ex.getResourceId());
    }

    idGenerator.push(workspaceId + "_to_" + entity1Vertex.getId());
    workspaceRepository.updateEntityOnWorkspace(
        workspace, entity1Vertex.getId(), true, 100, 200, user1);
    assertEquals(
        startingVertexCount + 1, graph.getAllVertices().size()); // +1 = the workspace vertex
    assertEquals(
        startingEdgeCount + 2,
        graph.getAllEdges().size()); // +2 = the edges between workspaces, users, and entities

    workspaceRepository.updateEntityOnWorkspace(
        workspace, entity1Vertex.getId(), true, 200, 300, user1);
    assertEquals(
        startingVertexCount + 1, graph.getAllVertices().size()); // +1 = the workspace vertex
    assertEquals(
        startingEdgeCount + 2,
        graph.getAllEdges().size()); // +2 = the edges between workspaces, users, and entities

    List<WorkspaceEntity> entities = workspaceRepository.findEntities(workspace, user1);
    assertEquals(1, entities.size());
    assertEquals(entity1Vertex.getId(), entities.get(0).getEntityVertexId());
    assertEquals(200, entities.get(0).getGraphPositionX().intValue());
    assertEquals(300, entities.get(0).getGraphPositionY().intValue());

    try {
      workspaceRepository.findEntities(workspace, user2);
      fail("user2 should not have read access to workspace");
    } catch (LumifyAccessDeniedException ex) {
      assertEquals(user2, ex.getUser());
      assertEquals(workspace.getId(), ex.getResourceId());
    }

    try {
      workspaceRepository.softDeleteEntityFromWorkspace(workspace, entity1Vertex.getId(), user2);
      fail("user2 should not have write access to workspace");
    } catch (LumifyAccessDeniedException ex) {
      assertEquals(user2, ex.getUser());
      assertEquals(workspace.getId(), ex.getResourceId());
    }

    workspaceRepository.softDeleteEntityFromWorkspace(workspace, entity1Vertex.getId(), user1);
    assertEquals(
        startingVertexCount + 1, graph.getAllVertices().size()); // +1 = the workspace vertex
    Map<String, InMemoryEdge> edgesAfterDelete = graph.getAllEdges();
    assertEquals(
        startingEdgeCount + 2, edgesAfterDelete.size()); // +1 = the edges between workspaces, users
    boolean foundRemovedEdge = false;
    for (InMemoryEdge edge : edgesAfterDelete.values()) {
      if (edge.getLabel().equals(workspaceToEntityRelationship.getIRI())) {
        assertEquals(
            false, WorkspaceLumifyProperties.WORKSPACE_TO_ENTITY_VISIBLE.getPropertyValue(edge));
        foundRemovedEdge = true;
      }
    }
    assertTrue(foundRemovedEdge);
  }