@Test
  public void removePolicyWithInvitation() {
    // create a map
    final PortfolioStructureMap map =
        epFrontendManager.createAndPersistPortfolioDefaultMap(
            ident1, "Remove policies", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // save a list of policies
    final List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
    // invitation
    final Invitation invitation = securityManager.createAndPersistInvitation();
    invitation.setFirstName("John");
    invitation.setLastName("Doe");
    invitation.setMail("*****@*****.**");
    final EPMapPolicy invitationPolicy = new EPMapPolicy();
    invitationPolicy.setType(Type.invitation);
    invitationPolicy.setInvitation(invitation);
    policies.add(invitationPolicy);
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();

    // remove the policy
    policies.clear();
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();

    // check if the policies and the invitation are deleted
    final List<EPMapPolicy> deletedPolicies = epFrontendManager.getMapPolicies(map);
    assertNotNull(deletedPolicies);
    assertTrue(deletedPolicies.isEmpty());
  }
  @Test
  public void allUserPolicies() {
    // create a map
    final PortfolioStructureMap map =
        epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Policies", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // check visiblity (is owner)
    assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
    // check visibility (no policy)
    assertFalse(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
    // check not visible (no policy)
    assertFalse(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));

    // add all user policy
    final EPMapPolicy userPolicy = new EPMapPolicy();
    userPolicy.setType(Type.allusers);
    epFrontendManager.updateMapPolicies(map, Collections.singletonList(userPolicy));
    dbInstance.commitAndCloseSession();

    // one policy
    final List<EPMapPolicy> policies1 = epFrontendManager.getMapPolicies(map);
    assertEquals(1, policies1.size());

    // check visiblity (is owner)
    assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
    // check visibility (is user)
    assertTrue(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
    // check not visible (is user)
    assertTrue(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));
  }
  @Test
  public void mergeTwoUserPolicies() {
    // create a map
    final PortfolioStructureMap map =
        epFrontendManager.createAndPersistPortfolioDefaultMap(
            ident1, "Remove policies", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // save a list of policies
    final List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();
    // first user policy
    final EPMapPolicy userPolicy1 = new EPMapPolicy();
    userPolicy1.setType(Type.user);
    userPolicy1.getIdentities().add(ident2);
    userPolicy1.getIdentities().add(ident3);
    policies.add(userPolicy1);
    // second user policy
    final EPMapPolicy userPolicy2 = new EPMapPolicy();
    userPolicy2.setType(Type.user);
    userPolicy2.getIdentities().add(ident1);
    policies.add(userPolicy2);
    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();

    // check if the policies are correctly merged
    final List<EPMapPolicy> mergedPolicies = epFrontendManager.getMapPolicies(map);
    assertNotNull(mergedPolicies);
    assertEquals(1, mergedPolicies.size());

    final EPMapPolicy mergedPolicy = mergedPolicies.get(0);
    final List<Identity> identities = mergedPolicy.getIdentities();
    assertEquals(3, identities.size());

    int count1, count2, count3;
    count1 = count2 = count3 = 0;
    for (final Identity identity : identities) {
      if (identity.equalsByPersistableKey(ident1)) {
        count1++;
      } else if (identity.equalsByPersistableKey(ident2)) {
        count2++;
      } else if (identity.equalsByPersistableKey(ident3)) {
        count3++;
      }
    }
    assertEquals(1, count1);
    assertEquals(1, count2);
    assertEquals(1, count3);
  }
  @Test
  public void allMapPolicies() {
    // create a map
    final PortfolioStructureMap map =
        epFrontendManager.createAndPersistPortfolioDefaultMap(ident1, "Policies", "Description");
    final PortfolioStructure page1 =
        epFrontendManager.createAndPersistPortfolioPage(map, "Page policies", "Page description");
    assertNotNull(page1);
    dbInstance.commitAndCloseSession();

    // save a list of policies
    final List<EPMapPolicy> policies = new ArrayList<EPMapPolicy>();

    // user policy
    final EPMapPolicy userPolicy = new EPMapPolicy();
    userPolicy.setType(Type.user);
    userPolicy.getIdentities().add(ident2);
    userPolicy.getIdentities().add(ident3);
    policies.add(userPolicy);

    // invitation
    final Invitation invitation = securityManager.createAndPersistInvitation();
    invitation.setFirstName("John");
    invitation.setLastName("Doe");
    invitation.setMail("*****@*****.**");
    final EPMapPolicy invitationPolicy = new EPMapPolicy();
    invitationPolicy.setType(Type.invitation);
    invitationPolicy.setInvitation(invitation);
    policies.add(invitationPolicy);

    epFrontendManager.updateMapPolicies(map, policies);
    dbInstance.commitAndCloseSession();

    // check visiblity (is owner)
    assertTrue(epFrontendManager.isMapVisible(ident1, map.getOlatResource()));
    // check visibility (is in policy)
    assertTrue(epFrontendManager.isMapVisible(ident2, map.getOlatResource()));
    // check visible (is in policy)
    assertTrue(epFrontendManager.isMapVisible(ident3, map.getOlatResource()));

    // retrieved policies
    final List<EPMapPolicy> savedPolicies = epFrontendManager.getMapPolicies(map);
    assertTrue(!savedPolicies.isEmpty());
  }
Esempio n. 5
0
  private void internalTestCreateManyMaps(int mapAmount) {
    long start = System.currentTimeMillis();
    // prepare some artefacts to link to maps later
    ArrayList<AbstractArtefact> artefacts = new ArrayList<AbstractArtefact>(10);
    for (int i = 1; i < 11; i++) {
      artefacts.add(createAndFillArtefact(i));
    }

    for (int k = 1; k < mapAmount; k++) {
      PortfolioStructureMap map =
          epFrontendManager.createAndPersistPortfolioDefaultMap(
              ident1, "a test map number " + k, LOREM_STRING_512);
      // attach sites and structures to it
      ArrayList<PortfolioStructure> structs = new ArrayList<PortfolioStructure>();
      PortfolioStructure page1 =
          epFrontendManager.createAndPersistPortfolioPage(
              map, "test page1 for map " + k, LOREM_STRING_512);
      structs.add(page1);
      PortfolioStructure struct11 =
          epFrontendManager.createAndPersistPortfolioStructureElement(
              page1, "struct1 in page1 for map" + k, LOREM_STRING_512);
      structs.add(struct11);
      PortfolioStructure struct12 =
          epFrontendManager.createAndPersistPortfolioStructureElement(
              page1, "struct2 in page1 for map" + k, LOREM_STRING_512);
      structs.add(struct12);
      PortfolioStructure page2 =
          epFrontendManager.createAndPersistPortfolioPage(
              map, "test page2 for map " + k, LOREM_STRING_512);
      structs.add(page2);
      PortfolioStructure struct21 =
          epFrontendManager.createAndPersistPortfolioStructureElement(
              page2, "struct1 in page2 for map" + k, LOREM_STRING_512);
      structs.add(struct21);
      PortfolioStructure struct22 =
          epFrontendManager.createAndPersistPortfolioStructureElement(
              page2, "struct2 in page2 for map" + k, LOREM_STRING_512);
      structs.add(struct22);

      // attach different artefacts to several places in map
      int l = 1;
      for (Iterator<PortfolioStructure> iterator = structs.iterator(); iterator.hasNext(); ) {
        PortfolioStructure portfolioStructure = iterator.next();
        epFrontendManager.addArtefactToStructure(ident1, artefacts.get(l), portfolioStructure);
        // add two artefacts
        if (l % 2 == 0) {
          epFrontendManager.addArtefactToStructure(
              ident1, artefacts.get(l + 1), portfolioStructure);
        }
        l++;
      } // for attach

      // share the map with all users
      EPMapPolicy userPolicy = new EPMapPolicy();
      userPolicy.setType(Type.allusers);
      epFrontendManager.updateMapPolicies(map, Collections.singletonList(userPolicy));
      dbInstance.commitAndCloseSession();
    } // for maps
    long now = System.currentTimeMillis();
    logger.info(
        "created "
            + mapAmount
            + " maps, attached artefacts and shared maps to public in: "
            + (now - start)
            + " ms.");

    // load all maps
    start = System.currentTimeMillis();
    List<PortfolioStructure> publicMaps =
        epFrontendManager.getStructureElementsFromOthers(
            ident2, null, ElementType.STRUCTURED_MAP, ElementType.DEFAULT_MAP);
    now = System.currentTimeMillis();
    logger.info("got all public maps in: " + (now - start) + " ms.");

    // simulate queries done in EPMultipleMapController for all public maps:
    start = System.currentTimeMillis();
    long sharedQ = 0;
    long countArtefactQ = 0;
    long countChildQ = 0;
    long qstart = 0;
    int j = 0;
    Runtime r = Runtime.getRuntime();
    for (PortfolioStructure map : publicMaps) {
      j++;
      qstart = System.currentTimeMillis();
      epFrontendManager.isMapShared((PortfolioStructureMap) map);
      sharedQ += System.currentTimeMillis() - qstart;
      qstart = System.currentTimeMillis();
      epFrontendManager.countArtefactsInMap((PortfolioStructureMap) map);
      countArtefactQ += System.currentTimeMillis() - qstart;
      // lookup structured maps: if received from a template, would also do a lookup on repository
      // entry!
      //			EPTargetResource resource = structMap.getTargetResource();
      //			RepositoryEntry repoEntry =
      // RepositoryManager.getInstance().lookupRepositoryEntry(resource.getOLATResourceable(),
      // false);
      qstart = System.currentTimeMillis();
      epFrontendManager.countStructureChildren(map);
      countChildQ += System.currentTimeMillis() - qstart;

      if (j % 100 == 0) {
        showStatsForStep(j, start, sharedQ, countArtefactQ, countChildQ, r);
      }
    }
    logger.info("============= get overall stats ==============");
    showStatsForStep(mapAmount, start, sharedQ, countArtefactQ, countChildQ, r);
  }