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;
}
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);
}
}
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;
}
Aggregations