Пример #1
0
  @Override
  public EnergyDataHistoryQueryResult getHistory(
      Enums.HistoryType historyType, Group group, long startTime, long endTime, int interval) {
    User user = getCurrentUser();
    if (group == null || group.getId() == null) {
      logger.debug("No group specified");
      return new EnergyDataHistoryQueryResult();
    }
    // Check group history
    Group userGroup = groupService.getGroup(user, group.getId());
    if (userGroup == null) logger.error("User group is null");

    if (userGroup != null
        && (userGroup.getRole() == Group.Role.OWNER
            || userGroup.getRole() == Group.Role.READONLY)) {
      if (logger.isInfoEnabled())
        logger.info(
            "retrieving "
                + historyType
                + " history for  "
                + group
                + " "
                + startTime
                + "-"
                + endTime);
      EnergyDataHistoryQueryResult result =
          historyService.getHistory(historyType, user, group, startTime, endTime, interval);
      return result;
    }
    logger.warn("Security violation. " + user + " attempted to retrieve history for  " + group);
    return new EnergyDataHistoryQueryResult();
  }
  @Test
  public void testCreateGroupMembership() {
    Account account = new Account();
    account.setGivenName("Anthony");
    account.setSurname("Wolski");
    account.setEmail("*****@*****.**");
    account.setPassword("password");
    account.setUsername("awolski");
    accountService.createAccount(account);

    Group group = new Group();
    group.setName("Test Group");
    accountService.createGroup(group);

    GroupMembership groupMembership = new GroupMembership(account, group);
    accountService.createGroupMembership(groupMembership);

    List<Account> groupAccounts = accountService.getGroupAccounts(group.getId());
    assertEquals(1, groupAccounts.size());

    List<Group> accountGroups = accountService.getAccountGroups(account.getId());
    assertEquals(1, accountGroups.size());

    List<GroupMembership> groupGroupMemberships =
        accountService.getGroupGroupMemberships(group.getId());
    assertEquals(1, groupGroupMemberships.size());

    List<GroupMembership> accountGroupMemberships =
        accountService.getAccountGroupMemberships(account.getId());
    assertEquals(1, accountGroupMemberships.size());
  }
Пример #3
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());
  }
Пример #4
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));
  }
Пример #5
0
  public void removeGroup(Group group) throws InternalErrorException {

    List<String> uniqueUsersIds = new ArrayList<String>();
    uniqueUsersIds = this.getAllUniqueMembersInGroup(group.getId(), group.getVoId());
    for (String s : uniqueUsersIds) {
      Attribute memberOf =
          new BasicAttribute(
              "memberOf",
              "perunGroupId="
                  + group.getId()
                  + ",perunVoId="
                  + group.getVoId()
                  + ","
                  + ldapProperties.getLdapBase());
      ModificationItem memberOfItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOf);
      this.updateUserWithUserId(s, new ModificationItem[] {memberOfItem});
    }

    try {
      ldapTemplate.unbind(
          getGroupDN(String.valueOf(group.getVoId()), String.valueOf(group.getId())));
      log.debug(
          "Entry deleted from LDAP: Group {} from Vo with ID=" + group.getVoId() + ".", group);
    } catch (NameNotFoundException e) {
      throw new InternalErrorException(e);
    }
  }
Пример #6
0
  /**
   * Retrieves whole application object from DB (authz in parent methods)
   *
   * @param sess PerunSession for Authz and to resolve User
   * @param vo VO to get application for
   * @param group Group
   * @return application object / null if not exists
   */
  private Application getLatestApplication(
      PerunSession sess, Vo vo, Group group, Application.AppType type) {
    try {

      if (sess.getPerunPrincipal().getUser() != null) {

        if (group != null) {

          return jdbc.queryForObject(
              RegistrarManagerImpl.APP_SELECT
                  + " where a.id=(select max(id) from application where vo_id=? and group_id=? and apptype=? and user_id=? )",
              RegistrarManagerImpl.APP_MAPPER,
              vo.getId(),
              group.getId(),
              String.valueOf(type),
              sess.getPerunPrincipal().getUserId());

        } else {

          return jdbc.queryForObject(
              RegistrarManagerImpl.APP_SELECT
                  + " where a.id=(select max(id) from application where vo_id=? and apptype=? and user_id=? )",
              RegistrarManagerImpl.APP_MAPPER,
              vo.getId(),
              String.valueOf(type),
              sess.getPerunPrincipal().getUserId());
        }

      } else {

        if (group != null) {

          return jdbc.queryForObject(
              RegistrarManagerImpl.APP_SELECT
                  + " where a.id=(select max(id) from application where vo_id=? and group_id=? and apptype=? and created_by=? and extsourcename=? )",
              RegistrarManagerImpl.APP_MAPPER,
              vo.getId(),
              group.getId(),
              String.valueOf(type),
              sess.getPerunPrincipal().getActor(),
              sess.getPerunPrincipal().getExtSourceName());

        } else {

          return jdbc.queryForObject(
              RegistrarManagerImpl.APP_SELECT
                  + " where a.id=(select max(id) from application where vo_id=? and apptype=? and created_by=? and extsourcename=? )",
              RegistrarManagerImpl.APP_MAPPER,
              vo.getId(),
              String.valueOf(type),
              sess.getPerunPrincipal().getActor(),
              sess.getPerunPrincipal().getExtSourceName());
        }
      }

    } catch (EmptyResultDataAccessException ex) {
      return null;
    }
  }
Пример #7
0
  public void removeFromGroup(Group group) {
    if (groupMap == null || groups == null) {
      return;
    }

    Group storedGroup = groupMap.get(group.getId());
    if (group != null) {
      groups.remove(storedGroup);
      groupMap.remove(storedGroup.getId());
    }
  }
Пример #8
0
  public void addToGroup(Group group) {
    if (groupMap == null) {
      groupMap = new HashMap<String, Group>();
    }
    if (groups == null) {
      groups = new ArrayList<Group>();
    }

    if (groupMap.get(group.getId()) == null) {
      groupMap.put(group.getId(), group);
      groups.add(group);
    }
  }
Пример #9
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));
  }
Пример #10
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));
  }
Пример #11
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);
  }
Пример #12
0
 public void removeMemberFromGroup(Member member, Group group) throws InternalErrorException {
   // Remove member from group
   Attribute uniqueMember =
       new BasicAttribute(
           "uniqueMember",
           "perunUserId=" + member.getUserId() + ",ou=People," + ldapProperties.getLdapBase());
   ModificationItem uniqueMemberItem =
       new ModificationItem(DirContext.REMOVE_ATTRIBUTE, uniqueMember);
   this.updateGroup(group, new ModificationItem[] {uniqueMemberItem});
   // Remove member from vo if this group is membersGroup
   if (group.getName().equals(VosManager.MEMBERS_GROUP) && group.getParentGroupId() == null) {
     // Remove info from vo
     this.updateVo(group.getVoId(), new ModificationItem[] {uniqueMemberItem});
     // Remove also information from user
     Attribute memberOfPerunVo =
         new BasicAttribute("memberOfPerunVo", String.valueOf(group.getVoId()));
     ModificationItem memberOfPerunVoItem =
         new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOfPerunVo);
     this.updateUserWithUserId(
         String.valueOf(member.getUserId()), new ModificationItem[] {memberOfPerunVoItem});
   }
   // Remove group info from member
   Attribute memberOf =
       new BasicAttribute(
           "memberOf",
           "perunGroupId="
               + group.getId()
               + ",perunVoId="
               + group.getVoId()
               + ","
               + ldapProperties.getLdapBase());
   ModificationItem memberOfItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOf);
   this.updateUserWithUserId(
       String.valueOf(member.getUserId()), new ModificationItem[] {memberOfItem});
 }
Пример #13
0
  public void setGroups(List<Group> groups) {
    this.groups = groups;

    groupMap = new HashMap<String, Group>();
    for (Group group : groups) {
      groupMap.put(group.getId(), group);
    }
  }
Пример #14
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());
  }
Пример #15
0
  @Test
  public void canUserEditApplicationTest() {
    // Initial setup
    User user = getUser();
    userService.add(user);
    Organization organization = createOrganization();
    Category category = createCategory(organization);
    organization.getCategories().add(category);
    Application application =
        createApplication(category, "Test Application", AppState.GROUP_PUBLISH);
    Group group = createGroup(organization);
    group.getOwnedApplications().add(application);

    entityManager.flush();

    createUserDomain(user, group.getId(), DomainType.GROUP, UserRole.ROLE_GROUP_ADMIN);
    entityManager.flush();

    assertTrue(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test if org admin can edit application
    user = getUser();
    userService.add(user);
    entityManager.flush();
    createUserDomain(user, organization.getId(), DomainType.ORGANIZATION, UserRole.ROLE_ORG_ADMIN);
    entityManager.flush();
    assertTrue(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test user is org user
    user = getUser();
    userService.add(user);
    entityManager.flush();
    createUserDomain(user, organization.getId(), DomainType.ORGANIZATION, UserRole.ROLE_ORG_USER);
    entityManager.flush();
    assertFalse(userService.canUserEditApplication(user.getId(), application.getId()));

    // Reset
    userService.delete(user.getId());
    ReflectionTestUtils.setField(this, "user", null);
    entityManager.flush();

    // Test user is not part of organization and not group admin
    user = getUser();
    userService.add(user);
    entityManager.flush();
    assertFalse(userService.canUserEditApplication(user.getId(), application.getId()));
  }
Пример #16
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());
  }
Пример #17
0
  public void addGroup(Group group) throws InternalErrorException {
    // Create a set of attributes
    Attributes attributes = new BasicAttributes();

    // Create the objectclass to add
    Attribute objClasses = new BasicAttribute("objectClass");
    objClasses.add("top");
    objClasses.add("perunGroup");

    // Add attributes
    attributes.put(objClasses);
    attributes.put("cn", group.getName());
    attributes.put("perunGroupId", String.valueOf(group.getId()));
    attributes.put(
        "perunUniqueGroupName",
        new String(this.getVoShortName(group.getVoId()) + ":" + group.getName()));
    attributes.put("perunVoId", String.valueOf(group.getVoId()));
    if (group.getDescription() != null && !group.getDescription().isEmpty())
      attributes.put("description", group.getDescription());
    if (group.getParentGroupId() != null) {
      attributes.put(
          "perunParentGroup",
          "perunGroupId="
              + group.getParentGroupId().toString()
              + ",perunVoId="
              + group.getVoId()
              + ","
              + ldapProperties.getLdapBase());
      attributes.put("perunParentGroupId", group.getParentGroupId().toString());
    }

    // Create the entry
    try {
      ldapTemplate.bind(
          getGroupDN(String.valueOf(group.getVoId()), String.valueOf(group.getId())),
          null,
          attributes);
      log.debug(
          "New entry created in LDAP: Group {} in Vo with Id=" + group.getVoId() + ".", group);
    } catch (NameNotFoundException e) {
      throw new InternalErrorException(e);
    }
  }
Пример #18
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());
  }
Пример #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());
  }
Пример #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));
  }
Пример #21
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());
  }
Пример #22
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));
  }
Пример #23
0
 public boolean isAlreadyMember(Member member, Group group) {
   Object o =
       ldapTemplate.lookup(
           getUserDN(String.valueOf(member.getUserId())), new UserMemberOfContextMapper());
   String[] memberOfInformation = (String[]) o;
   if (memberOfInformation != null) {
     for (String s : memberOfInformation) {
       if (s.equals(
           "perunGroupId="
               + group.getId()
               + ",perunVoId="
               + group.getVoId()
               + ","
               + ldapProperties.getLdapBase())) return true;
     }
   }
   return false;
 }
Пример #24
0
  @Test
  public void isUserInDomainTest() {
    User user = getUser(UserRole.ROLE_ORG_USER, UserRole.ROLE_GROUP_USER);

    List<Group> groups = userService.getGroups(user);
    for (Group group : groups) {
      boolean isInDomain =
          userService.isUserInDomain(
              user, group.getId(), DomainType.GROUP, UserRole.ROLE_GROUP_USER);
      assertTrue(isInDomain);
    }

    List<Organization> organizations = userService.getOrganizations(user);
    for (Organization organization : organizations) {
      boolean isInDomain =
          userService.isUserInDomain(
              user, organization.getId(), DomainType.ORGANIZATION, UserRole.ROLE_ORG_USER);
      assertTrue(isInDomain);
    }
  }
  /**
   * Creates a notification to a Group coordinator signaling that a user wants to join their group
   *
   * <p>- Requires a groupId request parameter for the GET
   *
   * @param req The HTTP Request
   * @param res The HTTP Response
   */
  public void inviteAction(HttpServletRequest req, HttpServletResponse res) {
    // Ensure there is a cookie for the session user
    if (AccountController.redirectIfNoCookie(req, res)) return;

    Map<String, Object> viewData = new HashMap<String, Object>();

    int groupId = Integer.parseInt(req.getParameter("groupId"));

    try {

      // Get the session user
      HttpSession session = req.getSession();
      Session userSession = (Session) session.getAttribute("userSession");
      User user = userSession.getUser();

      // Get the coordinator for the group
      GroupManager groupMan = new GroupManager();
      Group group = groupMan.get(groupId);
      User coordinator = groupMan.getCoordinator(groupId);

      // Send a notification to the coordinator for them to permit access to the group
      NotificationManager notificationMan = new NotificationManager();
      Notification notification =
          new Notification(
              coordinator.getId(),
              coordinator,
              groupId,
              group,
              user.getFullName() + " wants to join your group " + group.getGroupName(),
              "/home/notifications?addUserId=" + user.getId() + "&groupId=" + group.getId());
      notificationMan.createNotification(notification);

      redirectToLocal(req, res, "/home/dashboard");
      return;

    } catch (Exception e) {
      redirectToLocal(req, res, "/home/dashboard");
    }
  }
Пример #26
0
  private User getUser(UserRole organizationUserRole, UserRole groupUserRole) {
    User user = getUser();

    Role orgRole = null;
    if (organizationUserRole != null) {
      orgRole = roleService.getRoleByAuthority(organizationUserRole.name());
      user.getRoles().add(orgRole);
    }
    Role groupRole = null;
    if (groupUserRole != null) {
      groupRole = roleService.getRoleByAuthority(groupUserRole.name());
      user.getRoles().add(groupRole);
    }

    Organization organization = createOrganization();

    Application application =
        createApplication(
            organization.getCategories().get(0), "Test Application", AppState.GROUP_PUBLISH);
    Application application2 =
        createApplication(
            organization.getCategories().get(0),
            "Test Application 2",
            AppState.ORGANIZATION_PUBLISH);

    Group group = createGroup(organization);

    group.getOwnedApplications().add(application);
    group.getOwnedApplications().add(application2);

    organization.getGroups().add(group);

    userService.save(user);

    organizationService.getAll();

    if (groupRole != null) {
      UserDomain userDomainGroup = new UserDomain();
      userDomainGroup.setUser(user);
      userDomainGroup.setDomainId(group.getId());
      userDomainGroup.setDomainType(DomainType.GROUP);
      userDomainGroup.setRole(groupRole);
      userDomainGroup.setDomainId(group.getId());

      user.getUserDomains().add(userDomainGroup);
    }

    if (orgRole != null) {
      UserDomain userDomainOrg = new UserDomain();
      userDomainOrg.setUser(user);
      userDomainOrg.setDomainId(group.getId());
      userDomainOrg.setDomainType(DomainType.ORGANIZATION);
      userDomainOrg.setRole(orgRole);
      userDomainOrg.setDomainId(organization.getId());

      user.getUserDomains().add(userDomainOrg);
    }

    userService.save(user);

    entityManager.flush();

    return user;
  }
Пример #27
0
 /**
  * This method allows an application admin to revoke a permission from a group.
  *
  * @param grp The group to revoke the permission from.
  * @param role The role that is being revoked from the group.
  * @param pg The protection group in which the permission is being revoked
  * @throws RemoteException
  * @throws CSMInternalFault
  * @throws AccessDeniedFault
  * @throws CSMTransactionFault
  */
 public void revokePermission(Group grp, Role role, ProtectionGroup pg)
     throws RemoteException, CSMInternalFault, AccessDeniedFault, CSMTransactionFault {
   this.revokePermission(grp.getId(), role.getId(), pg.getId());
 }
Пример #28
0
  public GroupHistory SetGroupHistory(Group g) {
    GroupHistory gh = new GroupHistory();

    gh.name = g.getName();
    gh.name_en = g.getName_en();
    gh.route = g.getRoute();
    gh.depart_date = g.getDepart_date();
    gh.ticket_url = g.getTicket_url();
    gh.status = g.getStatus();
    gh.max_point = g.getMax_point();
    gh.pickup_info = g.getPickup_info();
    gh.traffic_hotel_info = g.getTraffic_hotel_info();
    gh.profit_ready = g.getProfit_ready();
    gh.profit = g.getProfit();
    gh.guide_ready = g.getGuide_ready();
    gh.caution_ready = g.getCaution_ready();
    gh.caution = g.getCaution();
    gh.guide1 = g.getGuide1();
    gh.guide2 = g.getGuide2();
    gh.multi_days = g.getMulti_days();
    gh.voucher_match = g.getVoucher_match();
    gh.seats = g.getSeats();
    gh.seats_reserved = g.getSeats_reserved();
    gh.seats_taken = g.getSeats_taken();
    gh.price = g.getPrice();
    gh.vip_price = g.getVip_price();

    gh.external_indicator = g.getExternal_indicator();
    gh.external_indicator_en = g.getExternal_indicator_en();

    gh.internalBookable = g.getInternalBookable();
    gh.externalBookable = g.getExternalBookable();
    gh.internalView = g.getInternalView();
    gh.externalView = g.getExternalView();
    gh.ext_groupon = g.getExt_groupon();
    gh.int_groupon = g.getInt_groupon();
    gh.seats_groupon_min = g.getSeats_groupon_min();
    gh.seats_groupon = g.getSeats_groupon();
    gh.seats_taken_groupon = g.getSeats_taken_groupon();
    gh.seats_reserved_groupon = g.getSeats_reserved_groupon();
    gh.group_price = g.getGroup_price();
    gh.group_vip_price = g.getGroup_vip_price();
    gh.groupon_end_time = g.getGroupon_end_time();

    // seckill group feature
    gh.ext_seckill = g.getExt_seckill();
    gh.int_seckill = g.getInt_seckill();
    gh.seats_seckill = g.getSeats_seckill();
    gh.seats_taken_seckill = g.getSeats_taken_seckill();
    gh.seats_reserved_seckill = g.getSeats_reserved_seckill();
    gh.seckill_price = g.getSeckill_price();
    gh.seckill_vip_price = g.getSeckill_vip_price();
    gh.seckill_start_time = g.getSeckill_start_time();
    gh.seckill_end_time = g.getSeckill_end_time();

    gh.go_img_1 = g.getGo_img_1();
    gh.go_img_2 = g.getGo_img_2();
    gh.sk_img_1 = g.getSk_img_1();
    gh.sk_img_2 = g.getSk_img_2();

    gh.voucher_applied = g.getVoucher_applied();

    gh.priority = g.getPriority();

    gh.group_id = g.getId();
    Calendar realtime = Calendar.getInstance();
    ;
    gh.audit_time = realtime;

    return gh;
  }
Пример #29
0
 /**
  * This method allows an application admin to get a list of permissions granted to a group.
  *
  * @param group The group in which to get the permissions granted.
  * @return The permissions granted to the group.
  * @throws RemoteException
  * @throws CSMInternalFault
  * @throws AccessDeniedFault
  * @throws CSMTransactionFault
  */
 public List<Permission> getPermissions(Group grp)
     throws RemoteException, CSMInternalFault, AccessDeniedFault, CSMTransactionFault {
   return getPermissions(grp.getId());
 }
Пример #30
0
  @RequestMapping(value = "/view-news.jsp", method = RequestMethod.GET)
  public ModelAndView showNews(
      @RequestParam(value = "month", required = false) Integer month,
      @RequestParam(value = "year", required = false) Integer year,
      @RequestParam(value = "section", required = false) Integer sectionid,
      @RequestParam(value = "group", required = false) Integer groupid,
      @RequestParam(value = "tag", required = false) String tag,
      @RequestParam(value = "offset", required = false) Integer offset,
      HttpServletResponse response)
      throws Exception {
    Connection db = null;

    Map<String, Object> params = new HashMap<String, Object>();

    try {
      if (month == null) {
        response.setDateHeader("Expires", System.currentTimeMillis() + 60 * 1000);
        response.setDateHeader("Last-Modified", System.currentTimeMillis());
      } else {
        long expires = System.currentTimeMillis() + 30 * 24 * 60 * 60 * 1000L;

        if (year == null) {
          throw new ServletParameterMissingException("year");
        }

        params.put("year", year);
        params.put("month", month);

        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month - 1, 1);
        calendar.add(Calendar.MONTH, 1);

        long lastmod = calendar.getTimeInMillis();

        if (lastmod < System.currentTimeMillis()) {
          response.setDateHeader("Expires", expires);
          response.setDateHeader("Last-Modified", lastmod);
        } else {
          response.setDateHeader("Expires", System.currentTimeMillis() + 60 * 1000);
          response.setDateHeader("Last-Modified", System.currentTimeMillis());
        }
      }

      db = LorDataSource.getConnection();

      Section section = null;

      if (sectionid != null) {
        section = new Section(db, sectionid);

        params.put("section", section);
      }

      Group group = null;

      if (groupid != null) {
        group = new Group(db, groupid);

        if (group.getSectionId() != sectionid) {
          throw new ScriptErrorException(
              "группа #" + groupid + " не принадлежит разделу #" + sectionid);
        }

        params.put("group", group);
      }

      if (tag != null) {
        Tags.checkTag(tag);
        params.put("tag", tag);
      }

      if (section == null && tag == null) {
        throw new ServletParameterException("section or tag required");
      }

      String navtitle;
      if (section != null) {
        navtitle = section.getName();
      } else {
        navtitle = tag;
      }

      if (group != null) {
        navtitle =
            "<a href=\"view-news.jsp?section="
                + section.getId()
                + "\">"
                + section.getName()
                + "</a> - "
                + group.getTitle();
      }

      String ptitle;

      if (month == null) {
        if (section != null) {
          ptitle = section.getName();
          if (group != null) {
            ptitle += " - " + group.getTitle();
          }

          if (tag != null) {
            ptitle += " - " + tag;
          }
        } else {
          ptitle = tag;
        }
      } else {
        ptitle = "Архив: " + section.getName();

        if (group != null) {
          ptitle += " - " + group.getTitle();
        }

        if (tag != null) {
          ptitle += " - " + tag;
        }

        ptitle += ", " + year + ", " + DateUtil.getMonth(month);
        navtitle += " - Архив " + year + ", " + DateUtil.getMonth(month);
      }

      params.put("ptitle", ptitle);
      params.put("navtitle", navtitle);

      NewsViewer newsViewer = new NewsViewer();

      if (section != null) {
        newsViewer.addSection(sectionid);
      }

      if (group != null) {
        newsViewer.setGroup(group.getId());
      }

      if (tag != null) {
        newsViewer.setTag(tag);
      }

      offset = fixOffset(offset);

      if (month != null) {
        newsViewer.setDatelimit(
            "postdate>='"
                + year
                + '-'
                + month
                + "-01'::timestamp AND (postdate<'"
                + year
                + '-'
                + month
                + "-01'::timestamp+'1 month'::interval)");
      } else if (tag == null) {
        if (section.isPremoderated()) {
          newsViewer.setDatelimit("(commitdate>(CURRENT_TIMESTAMP-'6 month'::interval))");
        } else {
          newsViewer.setDatelimit("(postdate>(CURRENT_TIMESTAMP-'6 month'::interval))");
        }

        newsViewer.setLimit("LIMIT 20" + (offset > 0 ? (" OFFSET " + offset) : ""));
      } else {
        newsViewer.setLimit("LIMIT 20" + (offset > 0 ? (" OFFSET " + offset) : ""));
      }

      params.put("messages", newsViewer.getMessagesCached(db));

      params.put("offsetNavigation", month == null);
      params.put("offset", offset);

      if (section != null) {
        String rssLink = "section-rss.jsp?section=" + section.getId();
        if (group != null) {
          rssLink += "&group=" + group.getId();
        }

        params.put("rssLink", rssLink);
      }

      return new ModelAndView("view-news", params);
    } finally {
      if (db != null) {
        db.close();
      }
    }
  }