Search in sources :

Example 1 with Status

use of cz.metacentrum.perun.core.api.Status in project perun by CESNET.

the class MembersManagerBlImpl method validateMember.

public Member validateMember(PerunSession sess, Member member) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    if (this.haveStatus(sess, member, Status.VALID)) {
        log.debug("Trying to validate member who is already valid. " + member);
        return member;
    }
    Status oldStatus = member.getStatus();
    getMembersManagerImpl().setStatus(sess, member, Status.VALID);
    member.setStatus(Status.VALID);
    getPerunBl().getAuditer().log(sess, "{} validated.", member);
    if (oldStatus.equals(Status.INVALID) || oldStatus.equals(Status.DISABLED)) {
        try {
            getPerunBl().getAttributesManagerBl().doTheMagic(sess, member);
        } catch (WrongAttributeAssignmentException ex) {
            throw new InternalErrorException(ex);
        }
    }
    return member;
}
Also used : Status(cz.metacentrum.perun.core.api.Status) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 2 with Status

use of cz.metacentrum.perun.core.api.Status in project perun by CESNET.

the class GroupsManagerImpl method getGroupMembers.

public List<Member> getGroupMembers(PerunSession sess, Group group, List<Status> statuses, boolean excludeStatus) throws InternalErrorException {
    try {
        MapSqlParameterSource parameters = new MapSqlParameterSource();
        List<Integer> statusesCodes = new ArrayList<Integer>();
        for (Status status : statuses) {
            statusesCodes.add(status.getCode());
        }
        parameters.addValue("statuses", statusesCodes);
        parameters.addValue("group_id", group.getId());
        if (excludeStatus) {
            // Exclude members with one of the status
            return this.namedParameterJdbcTemplate.query("select " + MembersManagerImpl.groupsMembersMappingSelectQuery + " from groups_members join members on members.id=groups_members.member_id " + "where groups_members.group_id=:group_id and members.status" + Compatibility.castToInteger() + " not in (:statuses)", parameters, MembersManagerImpl.MEMBER_MAPPER);
        } else {
            // Include members with one of the status
            return this.namedParameterJdbcTemplate.query("select " + MembersManagerImpl.groupsMembersMappingSelectQuery + " from groups_members join members on members.id=groups_members.member_id " + "where groups_members.group_id=:group_id and members.status" + Compatibility.castToInteger() + " in (:statuses)", parameters, MembersManagerImpl.MEMBER_MAPPER);
        }
    } catch (EmptyResultDataAccessException e) {
        return new ArrayList<Member>();
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : Status(cz.metacentrum.perun.core.api.Status) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ArrayList(java.util.ArrayList) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Member(cz.metacentrum.perun.core.api.Member)

Example 3 with Status

use of cz.metacentrum.perun.core.api.Status in project perun by CESNET.

the class MembersManagerBlImpl method getOnlyRichMembersWithAllowedStatuses.

/**
	 * Return list of RichMembers with allowed statuses contains in list of allowedStatuses.
	 * If allowedStatuses is empty or null, get richMembers with all statuses.
	 *
	 * @param sess
	 * @param richMembers
	 * @param allowedStatuses
	 * @return list of allowed richMembers
	 * @throws InternalErrorException
	 */
private List<RichMember> getOnlyRichMembersWithAllowedStatuses(PerunSession sess, List<RichMember> richMembers, List<String> allowedStatuses) throws InternalErrorException {
    List<RichMember> allowedRichMembers = new ArrayList<RichMember>();
    if (richMembers == null || richMembers.isEmpty())
        return allowedRichMembers;
    if (allowedStatuses == null || allowedStatuses.isEmpty())
        return richMembers;
    //Covert statuses to objects Status
    List<Status> statuses = new ArrayList<Status>();
    for (String status : allowedStatuses) {
        statuses.add(Status.valueOf(status));
    }
    for (RichMember rm : richMembers) {
        if (statuses.contains(rm.getStatus()))
            allowedRichMembers.add(rm);
    }
    return allowedRichMembers;
}
Also used : Status(cz.metacentrum.perun.core.api.Status) ArrayList(java.util.ArrayList) RichMember(cz.metacentrum.perun.core.api.RichMember)

Aggregations

Status (cz.metacentrum.perun.core.api.Status)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 ArrayList (java.util.ArrayList)2 Member (cz.metacentrum.perun.core.api.Member)1 RichMember (cz.metacentrum.perun.core.api.RichMember)1 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)1 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1