Exemplo n.º 1
0
  @Test
  public void testAddMultipleContacts() throws Exception {
    groupService.create(group);
    groupService.addAggregation(committee, group);

    group = groupService.findById(group.getId());
    contactService.addToGroup(topLevel, group);

    Contact anotherContact = new Contact();
    anotherContact.setFirstName("Another");
    anotherContact.setEmail("*****@*****.**");
    contactService.create(anotherContact);

    contactService.addToGroup(anotherContact, group);
    group = groupService.findById(group.getId());
    assertEquals(2, group.getTopLevelMembers().size());

    anotherContact = contactService.findById(anotherContact.getId());
    topLevel = contactService.findById(topLevel.getId());

    assertEquals(1, anotherContact.getGroups().size());
    assertEquals(1, topLevel.getGroups().size());

    groupService.delete(group);

    anotherContact = contactService.findById(anotherContact.getId());
    topLevel = contactService.findById(topLevel.getId());

    assertEquals(0, anotherContact.getGroups().size());
    assertEquals(0, topLevel.getGroups().size());
  }
Exemplo n.º 2
0
  @Test
  public void addUserAdminToGroup() {
    User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER);

    Organization newOrganization = new Organization();
    newOrganization.setName("New Organization");
    organizationService.add(newOrganization);

    Group group = new Group();
    group.setAccessCode(UUID.randomUUID().toString());
    group.setName("New Group");
    group.setOrganization(newOrganization);
    groupService.save(group);
    groupService.getAll();

    GroupUserRequest groupUserRequest =
        requestService.createGroupUserRequest(user, group.getAccessCode());
    requestService.getAll(group.getId());

    boolean isAdded =
        userService.addUserToGroup(
            groupUserRequest.getUser(),
            groupUserRequest.getGroup().getId(),
            UserRole.ROLE_GROUP_ADMIN);
    assertTrue(isAdded);
  }
Exemplo n.º 3
0
  @Test
  @Transactional
  public void testAddContactToGroupAndGroupConstituent() throws Exception {

    groupService.create(group);
    groupService.addAggregation(committee, group);

    Contact contact = new Contact();
    contact.setFirstName("Test Contact");
    contact.setEmail("*****@*****.**");
    contactService.create(contact);

    contactService.addContactToCommittee(contact, committee);
    contactService.addToGroup(contact, group);

    contact = contactService.findById(contact.getId());
    assertTrue(contact.getGroups().contains(group));
    assertTrue(contact.getCommittees().contains(committee));

    committee = committeeService.findById(committee.getId());
    assertTrue(committee.getMembers().contains(contact));

    group = groupService.findById(group.getId());
    assertTrue(group.getTopLevelMembers().contains(contact));
  }
Exemplo n.º 4
0
  @Test
  @Transactional
  public void testRemoveContactFromEventMultipleGroups() throws Exception {

    groupService.create(group);
    groupService.addAggregation(event, group);

    Group secondGroup = new Group();
    secondGroup.setGroupName("Second Group");
    groupService.create(secondGroup);
    groupService.addAggregation(event, secondGroup);

    Contact newContact = new Contact();
    newContact.setFirstName("Fresh Contact");
    newContact.setEmail("Fresh email");
    contactService.create(newContact);

    event = eventService.findById(event.getId());
    contactService.attendEvent(newContact, event);

    newContact = contactService.findById(newContact.getId());
    contactService.unattendEvent(newContact, event);

    event = eventService.findById(event.getId());
    assertFalse(event.getAttendees().contains(newContact));

    newContact = contactService.findById(newContact.getId());
    assertFalse(newContact.getAttendedEvents().contains(event));
  }
Exemplo n.º 5
0
  @Test
  public void testAddAggregation() throws Exception {
    groupService.create(group);
    groupService.addAggregation(committee, group);

    Group fromDb = groupService.findById(group.getId());
    assertEquals(1, fromDb.getAggregations().size());
    Aggregation aggregation = fromDb.getAggregations().iterator().next();
    assertEquals(group.getGroupName(), aggregation.getGroups().iterator().next().getGroupName());
  }
Exemplo n.º 6
0
  @Test
  public void testCreateGroupFromCommittee() throws Exception {
    String id = groupService.create(group);
    groupService.addAggregation(committee, group);

    Group fromDb = groupService.findById(id);
    assertEquals(group.getGroupName(), fromDb.getGroupName());
    Aggregation aggregation = fromDb.getAggregations().iterator().next();
    assertNotNull(aggregation);
    assertEquals(
        committee.getAggregationMembers().size(), aggregation.getAggregationMembers().size());
  }
Exemplo n.º 7
0
  @Test
  public void testRemoveContactFromGroup() throws Exception {
    groupService.create(group);
    groupService.addAggregation(committee, group);
    contactService.addToGroup(topLevel, group);

    assertEquals(1, group.getTopLevelMembers().size());

    contactService.removeFromGroup(topLevel, group);

    Group fromDb = groupService.findById(group.getId());
    assertEquals(0, fromDb.getTopLevelMembers().size());

    Contact contactFromDb = contactService.findById(topLevel.getId());
    assertEquals(0, contactFromDb.getGroups().size());
  }
 private Group createGroup(Client client) {
   Group group = new Group();
   group.setName("Test Group" + RandomStringUtils.randomAlphanumeric(9));
   group.setClient(clientService.reload(client));
   groupService.save(group);
   return group;
 }
Exemplo n.º 9
0
  @Test
  public void addUserToGroupTest() {
    User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER);

    Group newGroup = new Group();
    newGroup.setName("New Group");
    groupService.add(newGroup);

    groupService.getAll();

    userService.addUserToGroup(user, newGroup.getId(), UserRole.ROLE_GROUP_USER);
    List<Group> groups = userService.getGroups(user);
    assertTrue(groups.size() == 2);
    assertTrue(userService.isUserInGroup(user, newGroup));
    assertTrue(userService.isUserInGroup(user, newGroup, UserRole.ROLE_GROUP_USER));
  }
Exemplo n.º 10
0
 @After
 public void tearDown() {
   groupService.deleteAll();
   organizationService.deleteAll();
   committeeService.deleteAll();
   eventService.deleteAll();
   contactService.deleteAll();
 }
Exemplo n.º 11
0
  private Group createGroup(Organization organization) {
    Group group = new Group();
    group.setAccessCode(UUID.randomUUID().toString());
    group.setName("Test Group");
    group.setOrganization(organization);
    groupService.save(group);

    return group;
  }
Exemplo n.º 12
0
  @Test
  public void testRemoveContactFromAggregation() throws Exception {
    groupService.create(group);
    groupService.addAggregation(committee, group);

    group = groupService.findById(group.getId());
    assertEquals(
        committee.getMembers().size(),
        group.getAggregations().iterator().next().getAggregationMembers().size());

    contactService.removeContactFromCommittee(first, committee);

    committee = committeeService.findById(committee.getId());
    group = groupService.findById(group.getId());
    assertEquals(
        committee.getMembers().size(),
        group.getAggregations().iterator().next().getAggregationMembers().size());
  }
Exemplo n.º 13
0
  /**
   * This method is called when player leaves the game, which includes just two cases: either player
   * goes back to char selection screen or it's leaving the game [closing client].<br>
   * <br>
   * <b><font color='red'>NOTICE: </font> This method is called only from {@link AionConnection} and
   * {@link CM_QUIT} and must not be called from anywhere else</b>
   *
   * @param player
   */
  public static void playerLoggedOut(final Player player) {
    log.info(
        "Player logged out: "
            + player.getName()
            + " Account: "
            + player.getClientConnection().getAccount().getName());
    player.onLoggedOut();

    // Update prison timer
    if (player.isInPrison()) {
      long prisonTimer = System.currentTimeMillis() - player.getStartPrison();
      prisonTimer = player.getPrisonTimer() - prisonTimer;

      player.setPrisonTimer(prisonTimer);

      log.debug("Update prison timer to " + prisonTimer / 1000 + " seconds !");
    }

    // store current effects
    DAOManager.getDAO(PlayerEffectsDAO.class).storePlayerEffects(player);
    DAOManager.getDAO(ItemCooldownsDAO.class).storeItemCooldowns(player);
    DAOManager.getDAO(PlayerLifeStatsDAO.class).updatePlayerLifeStat(player);
    player.getEffectController().removeAllEffects();

    player.getLifeStats().cancelAllTasks();

    if (player.getLifeStats().isAlreadyDead()) TeleportService.moveToBindLocation(player, false);

    if (DuelService.getInstance().isDueling(player.getObjectId()))
      DuelService.getInstance().loseDuel(player);

    if (player.getSummon() != null) player.getSummon().getController().release(UnsummonType.LOGOUT);

    PunishmentService.stopPrisonTask(player, true);

    player.getCommonData().setOnline(false);
    player.getCommonData().setLastOnline(new Timestamp(System.currentTimeMillis()));

    player.setClientConnection(null);

    if (player.isLegionMember()) LegionService.getInstance().onLogout(player);

    if (player.isInGroup()) GroupService.getInstance().scheduleRemove(player);

    if (player.isInAlliance()) AllianceService.getInstance().onLogout(player);

    player.getController().delete();
    DAOManager.getDAO(PlayerDAO.class).onlinePlayer(player, false);

    if (!GSConfig.DISABLE_CHAT_SERVER) ChatService.onPlayerLogout(player);

    storePlayer(player);
    player.getEquipment().setOwner(null);
  }
Exemplo n.º 14
0
  @Test
  public void testRemoveAggregation() throws Exception {
    String id = groupService.create(group);
    groupService.addAggregation(committee, group);

    Group fromDb = groupService.findById(id);
    assertEquals(1, fromDb.getAggregations().size());
    assertEquals(1, fromDb.getAggregations().iterator().next().getGroups().size());

    Aggregation aggregation = committeeService.findById(committee.getId());
    assertEquals(1, aggregation.getGroups().size());

    groupService.removeAggregation(committee, fromDb);

    fromDb = groupService.findById(id);
    assertEquals(0, fromDb.getAggregations().size());

    aggregation = committeeService.findById(committee.getId());
    assertEquals(0, aggregation.getGroups().size());
  }
Exemplo n.º 15
0
  @Test
  @Transactional
  public void testAddContactToMultipleGroupsMultipleConstituents() throws Exception {

    groupService.create(group);
    groupService.addAggregation(committee, group);
    groupService.addAggregation(event, group);

    Group secondGroup = new Group();
    secondGroup.setGroupName("Second Group");
    groupService.create(secondGroup);
    groupService.addAggregation(committee, secondGroup);
    groupService.addAggregation(event, secondGroup);

    Contact contact = new Contact();
    contact.setFirstName("Test Contact");
    contact.setEmail("*****@*****.**");
    contactService.create(contact);

    contactService.addContactToCommittee(contact, committee);
    contactService.attendEvent(contact, event);
    contactService.addToGroup(contact, group);
    contactService.addToGroup(contact, secondGroup);

    contact = contactService.findById(contact.getId());
    group = groupService.findById(group.getId());
    secondGroup = groupService.findById(secondGroup.getId());
    event = eventService.findById(event.getId());
    committee = committeeService.findById(committee.getId());

    assertTrue(contact.getGroups().contains(group));
    assertTrue(contact.getGroups().contains(secondGroup));
    assertTrue(contact.getCommittees().contains(committee));
    assertTrue(contact.getAttendedEvents().contains(event));

    assertTrue(event.getAttendees().contains(contact));
    assertTrue(event.getGroups().contains(group));
    assertTrue(event.getGroups().contains(secondGroup));

    assertTrue(committee.getMembers().contains(contact));
    assertTrue(committee.getGroups().contains(group));
    assertTrue(committee.getGroups().contains(secondGroup));

    assertTrue(group.getTopLevelMembers().contains(contact));
    assertTrue(group.getAggregations().contains(committee));
    assertTrue(group.getAggregations().contains(event));

    assertTrue(secondGroup.getTopLevelMembers().contains(contact));
    assertTrue(secondGroup.getAggregations().contains(committee));
    assertTrue(secondGroup.getAggregations().contains(event));
  }
Exemplo n.º 16
0
  @Test
  public void testDeleteGroup() throws Exception {
    groupService.create(group);
    groupService.addAggregation(committee, group);

    group = groupService.findById(group.getId());
    contactService.addToGroup(topLevel, group);

    groupService.delete(group);

    Group groupFromDb = groupService.findById(group.getId());
    assertNull(groupFromDb);
    Aggregation fromDb = committeeService.findById(committee.getId());
    assertNotNull(fromDb);
    assertEquals(0, fromDb.getGroups().size());
    assertEquals(committee.getAggregationMembers().size(), fromDb.getAggregationMembers().size());

    Contact topLevelFromDb = contactService.findById(topLevel.getId());
    assertNotNull(topLevelFromDb);
    assertEquals(0, topLevelFromDb.getGroups().size());
  }
Exemplo n.º 17
0
  @Test
  @Transactional
  public void testAddContactToOrganizationMultipleGroups() throws Exception {

    groupService.create(group);
    groupService.addAggregation(organization, group);

    Group secondGroup = new Group();
    secondGroup.setGroupName("Second Group");
    groupService.create(secondGroup);
    groupService.addAggregation(organization, secondGroup);

    Contact newContact = new Contact();
    newContact.setFirstName("Fresh Contact");
    newContact.setEmail("Fresh email");
    contactService.create(newContact);

    contactService.addContactToOrganization(newContact, organization);

    newContact = contactService.findById(newContact.getId());
    assertTrue(newContact.getOrganizations().contains(organization));

    group = groupService.findById(group.getId());
    assertTrue(group.getAggregations().contains(organization));

    secondGroup = groupService.findById(secondGroup.getId());
    assertTrue(secondGroup.getAggregations().contains(organization));

    organization = organizationService.findById(organization.getId());
    assertTrue(organization.getMembers().contains(newContact));
  }
Exemplo n.º 18
0
  /**
   * saveNew
   *
   * <p>Saves the information then displays a page with the given information
   *
   * <pre>
   * Version	Date		Developer				Description
   * 0.1		26/04/2012	Genevieve Turner (GT)	Initial
   * 0.8		20/06/2012	Genevieve Turner (GT)	Updated so that page retrieval is now using a map
   * 0.15		20/08/2012	Genevieve Turner (GT)	Updated to use permissionService rather than aclService
   * 0.23		12/11/2012	Genevieve Turner (GT)	Added the request id
   * 0.25		02/01/2012	Genevieve Turner (GT)	Updated to enforce records requriing an ownerGroup, type and name/title
   * </pre>
   *
   * @param layout The layout to display the page
   * @param tmplt The template that determines the fields on the screen
   * @param form Contains the parameters from the request
   * @param rid The request id
   * @return Returns the viewable for the jsp file to pick up.
   * @throws JAXBException
   * @throws FedoraClientException
   */
  @Override
  public FedoraObject saveNew(String tmplt, Map<String, List<String>> form, Long rid)
      throws FedoraClientException, JAXBException {
    FedoraObject fedoraObject = null;
    ViewTransform viewTransform = new ViewTransform();

    List<String> messages = new ArrayList<String>();
    if (form.get("ownerGroup") == null
        || form.get("ownerGroup").size() == 0
        || form.get("ownerGroup").get(0).trim().equals("")) {
      messages.add("No Group Affiliation");
    }
    if (form.get("type") == null
        || form.get("type").size() == 0
        || form.get("type").get(0).trim().equals("")) {
      messages.add("No item type has been set");
    }
    if ((form.get("name") == null
            || form.get("name").size() == 0
            || form.get("name").get(0).trim().equals(""))
        && (form.get("lastName") == null
            || form.get("lastName").size() == 0
            || form.get("lastName").get(0).trim().equals(""))) {
      messages.add("No name/title has been set");
    }

    if (messages.size() == 0) {
      // Check if the user has access to the ownerGroup
      String ownerGroup = form.get("ownerGroup").get(0);
      Long ownerGroupId = new Long(ownerGroup);
      List<Groups> groups = groupService.getCreateGroups();
      boolean groupFound = false;
      for (Groups group : groups) {
        if (group.getId().equals(ownerGroupId)) {
          groupFound = true;
          break;
        }
      }
      if (groupFound == false) {
        throw new AccessDeniedException(
            format("You do not have permissions to create in group {0}", ownerGroup));
      }
    } else {
      throw new ValidateException(messages);
    }

    fedoraObject = viewTransform.saveData(tmplt, null, form, rid);
    permissionService.saveObjectPermissions(fedoraObject);

    return fedoraObject;
  }
Exemplo n.º 19
0
  @Test
  public void testCreateGroupFromMultipleAggregations() throws Exception {
    String id = groupService.create(group);
    groupService.addAggregation(committee, group);
    group = groupService.findById(group.getId());
    groupService.addAggregation(organization, group);
    group = groupService.findById(group.getId());
    groupService.addAggregation(event, group);
    group = groupService.findById(group.getId());
    contactService.addToGroup(topLevel, group);

    Group fromDb = groupService.findById(id);
    assertEquals(group.getGroupName(), fromDb.getGroupName());
    assertEquals(3, group.getAggregations().size());
    Set<Contact> allAggregationMembers = new HashSet<>();
    for (Aggregation aggregation : group.getAggregations()) {
      for (Contact c : aggregation.getAggregationMembers()) {
        allAggregationMembers.add(c);
      }
    }
    assertEquals(2, allAggregationMembers.size());
    assertEquals(1, group.getTopLevelMembers().size());
  }
Exemplo n.º 20
0
  @Test
  @Transactional
  public void testAddEventMultipleGroups() throws Exception {

    groupService.create(group);
    groupService.addAggregation(event, group);
    groupService.addAggregation(committee, group);

    Group secondGroup = new Group();
    secondGroup.setGroupName("Second Group");
    groupService.create(secondGroup);
    groupService.addAggregation(event, secondGroup);
    groupService.addAggregation(organization, secondGroup);

    event = eventService.findById(event.getId());
    assertTrue(event.getGroups().contains(group));
    assertTrue(event.getGroups().contains(secondGroup));

    group = groupService.findById(group.getId());
    assertTrue(group.getAggregations().contains(event));

    secondGroup = groupService.findById(secondGroup.getId());
    assertTrue(secondGroup.getAggregations().contains(event));
  }
Exemplo n.º 21
0
  /**
   * Returns the player with given objId (if such player exists)
   *
   * @param playerObjId
   * @param account
   * @return Player
   */
  public static Player getPlayer(int playerObjId, Account account) {
    Player player = playerCache.get(playerObjId);
    if (player != null) return player;

    /** Player common data and appearance should be already loaded in account */
    PlayerAccountData playerAccountData = account.getPlayerAccountData(playerObjId);
    PlayerCommonData pcd = playerAccountData.getPlayerCommonData();
    PlayerAppearance appearance = playerAccountData.getAppereance();

    player = new Player(new PlayerController(), pcd, appearance);

    LegionMember legionMember = LegionService.getInstance().getLegionMember(player.getObjectId());
    if (legionMember != null) player.setLegionMember(legionMember);

    if (GroupService.getInstance().isGroupMember(playerObjId))
      GroupService.getInstance().setGroup(player);

    if (AllianceService.getInstance().isAllianceMember(playerObjId))
      AllianceService.getInstance().setAlliance(player);

    MacroList macroses = DAOManager.getDAO(PlayerMacrossesDAO.class).restoreMacrosses(playerObjId);
    player.setMacroList(macroses);

    player.setSkillList(DAOManager.getDAO(PlayerSkillListDAO.class).loadSkillList(playerObjId));
    player.setKnownlist(new KnownList(player));
    player.setFriendList(DAOManager.getDAO(FriendListDAO.class).load(player));
    player.setBlockList(DAOManager.getDAO(BlockListDAO.class).load(player));
    player.setTitleList(DAOManager.getDAO(PlayerTitleListDAO.class).loadTitleList(playerObjId));

    DAOManager.getDAO(PlayerSettingsDAO.class).loadSettings(player);
    DAOManager.getDAO(AbyssRankDAO.class).loadAbyssRank(player);
    PlayerStatsData playerStatsData = DataManager.PLAYER_STATS_DATA;
    player.setPlayerStatsTemplate(playerStatsData.getTemplate(player));

    player.setGameStats(new PlayerGameStats(playerStatsData, player));

    Equipment equipment = DAOManager.getDAO(InventoryDAO.class).loadEquipment(player);
    ItemService.loadItemStones(equipment.getEquippedItemsWithoutStigma());
    equipment.setOwner(player);
    player.setEquipment(equipment);

    player.setLifeStats(new PlayerLifeStats(player));
    player.setEffectController(new PlayerEffectController(player));
    player.setFlyController(new FlyController(player));
    player.setReviveController(new ReviveController(player));

    player.setQuestStateList(DAOManager.getDAO(PlayerQuestListDAO.class).load(player));
    player.setRecipeList(DAOManager.getDAO(PlayerRecipesDAO.class).load(player.getObjectId()));

    /** Account warehouse should be already loaded in account */
    Storage accWarehouse = account.getAccountWarehouse();

    player.setStorage(accWarehouse, StorageType.ACCOUNT_WAREHOUSE);

    Storage inventory =
        DAOManager.getDAO(InventoryDAO.class)
            .loadStorage(player, player.getObjectId(), StorageType.CUBE);
    ItemService.loadItemStones(inventory.getStorageItems());

    player.setStorage(inventory, StorageType.CUBE);

    Storage warehouse =
        DAOManager.getDAO(InventoryDAO.class)
            .loadStorage(player, player.getObjectId(), StorageType.REGULAR_WAREHOUSE);
    ItemService.loadItemStones(warehouse.getStorageItems());

    player.setStorage(warehouse, StorageType.REGULAR_WAREHOUSE);

    /** Apply equipment stats (items and manastones were loaded in account) */
    player.getEquipment().onLoadApplyEquipmentStats();

    DAOManager.getDAO(PlayerPunishmentsDAO.class).loadPlayerPunishments(player);

    ItemService.restoreKinah(player);

    // update passive stats after effect controller, stats and equipment are initialized
    player.getController().updatePassiveStats();
    // load saved effects
    DAOManager.getDAO(PlayerEffectsDAO.class).loadPlayerEffects(player);
    // load item cooldowns
    DAOManager.getDAO(ItemCooldownsDAO.class).loadItemCooldowns(player);

    if (player.getCommonData().getTitleId() > 0) {
      TitleChangeListener.onTitleChange(
          player.getGameStats(), player.getCommonData().getTitleId(), true);
    }
    player.getGameStats().recomputeStats();

    DAOManager.getDAO(PlayerLifeStatsDAO.class).loadPlayerLifeStat(player);
    // analyze current instance
    InstanceService.onPlayerLogin(player);

    if (CacheConfig.CACHE_PLAYERS) playerCache.put(playerObjId, player);

    return player;
  }