use of cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException in project perun by CESNET.
the class MembersManagerBlImpl method getRichMembersWithAttributesByNames.
@Override
public List<RichMember> getRichMembersWithAttributesByNames(PerunSession sess, Group group, Resource resource, List<String> attrsNames) throws AttributeNotExistsException, GroupResourceMismatchException {
getPerunBl().getAttributesManagerBl().checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
List<Member> members = new ArrayList<>(perunBl.getGroupsManagerBl().getGroupMembers(sess, group));
List<RichMember> richMembers = this.convertMembersToRichMembers(sess, members);
List<AttributeDefinition> attrsDef = new ArrayList<>();
for (String atrrName : attrsNames) {
AttributeDefinition attrDef = perunBl.getAttributesManagerBl().getAttributeDefinition(sess, atrrName);
attrsDef.add(attrDef);
}
List<RichMember> richMembersWithAttributes;
try {
richMembersWithAttributes = this.convertMembersToRichMembersWithAttributes(sess, group, resource, richMembers, attrsDef);
} catch (MemberResourceMismatchException | MemberGroupMismatchException ex) {
throw new ConsistencyErrorException(ex);
}
return richMembersWithAttributes;
}
use of cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException in project perun by CESNET.
the class urn_perun_member_resource_attribute_def_virt_fileQuotas method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Member member, Resource resource, AttributeDefinition attributeDefinition) {
Attribute attribute = new Attribute(attributeDefinition);
// get resource quotas
Map<String, Pair<BigDecimal, BigDecimal>> resourceTransferedQuotas;
Attribute resourceQuotas;
try {
resourceQuotas = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_defaultFileQuotas);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
if (resourceQuotas == null || resourceQuotas.getValue() == null)
resourceTransferedQuotas = new HashMap<>();
else {
try {
resourceTransferedQuotas = sess.getPerunBl().getModulesUtilsBl().checkAndTransferQuotas(resourceQuotas, resource, null, false);
} catch (WrongAttributeValueException ex) {
throw new ConsistencyErrorException("Quotas on resource " + resource + " are in bad format.", ex);
}
}
// get members quotas
Map<String, Pair<BigDecimal, BigDecimal>> memberTransferedQuotas;
Attribute memberQuotas;
try {
memberQuotas = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, member, resource, A_MR_fileQuotas);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeAssignmentException | MemberResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
if (memberQuotas == null || memberQuotas.getValue() == null)
memberTransferedQuotas = new HashMap<>();
else {
try {
memberTransferedQuotas = sess.getPerunBl().getModulesUtilsBl().checkAndTransferQuotas(memberQuotas, resource, member, false);
} catch (WrongAttributeValueException ex) {
throw new ConsistencyErrorException("Quotas on resource " + resource + " for member " + member + " are in bad format.", ex);
}
}
// get members quotas override
Map<String, Pair<BigDecimal, BigDecimal>> memberTransferedQuotasOverride;
Attribute memberQuotasOverride;
try {
memberQuotasOverride = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, member, resource, A_MR_fileQuotasOverride);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeAssignmentException | MemberResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
if (memberQuotasOverride == null || memberQuotasOverride.getValue() == null)
memberTransferedQuotasOverride = new HashMap<>();
else {
try {
memberTransferedQuotasOverride = sess.getPerunBl().getModulesUtilsBl().checkAndTransferQuotas(memberQuotasOverride, resource, member, false);
} catch (WrongAttributeValueException ex) {
throw new ConsistencyErrorException("Override quotas on resource " + resource + " for member " + member + " are in bad format.", ex);
}
}
// Merge quotas for member on resource
Map<String, Pair<BigDecimal, BigDecimal>> finalMemberResourceQuotas = sess.getPerunBl().getModulesUtilsBl().mergeMemberAndResourceTransferredQuotas(resourceTransferedQuotas, memberTransferedQuotas, memberTransferedQuotasOverride);
// set final value to attribute
attribute.setValue(sess.getPerunBl().getModulesUtilsBl().transferQuotasBackToAttributeValue(finalMemberResourceQuotas, false));
// return attribute
return attribute;
}
use of cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_dataQuotas method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, Facility facility, AttributeDefinition attributeDefinition) {
Attribute attribute = new Attribute(attributeDefinition);
// merge attribute settings for every allowed resource
List<Map<String, Pair<BigDecimal, BigDecimal>>> mergedMemberResourceQuotas = new ArrayList<>();
List<Resource> allowedResources = sess.getPerunBl().getResourcesManagerBl().getAllowedResources(sess, facility, user);
for (Resource resource : allowedResources) {
// get allowed member of this user on this resource (using his VO)
Vo membersVo;
try {
membersVo = sess.getPerunBl().getVosManagerBl().getVoById(sess, resource.getVoId());
} catch (VoNotExistsException ex) {
throw new ConsistencyErrorException("Vo should exists, because resource with this id exists " + resource);
}
Member memberOnResource;
try {
memberOnResource = sess.getPerunBl().getMembersManagerBl().getMemberByUser(sess, membersVo, user);
} catch (MemberNotExistsException ex) {
throw new ConsistencyErrorException("User should have member in this VO, because he was listed in allowed assigned resources " + user + ", " + membersVo + " , " + resource);
}
// Get member-resource final counted quotas for the member on the resource
Map<String, Pair<BigDecimal, BigDecimal>> memberResourceFinalDataQuotas;
Attribute memberResourceFinalDataQuotasAttribute;
try {
memberResourceFinalDataQuotasAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, memberOnResource, resource, A_MR_V_dataQuotas);
} catch (MemberResourceMismatchException | WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
if (memberResourceFinalDataQuotasAttribute == null || memberResourceFinalDataQuotasAttribute.getValue() == null)
memberResourceFinalDataQuotas = new LinkedHashMap<>();
else {
try {
memberResourceFinalDataQuotas = sess.getPerunBl().getModulesUtilsBl().checkAndTransferQuotas(memberResourceFinalDataQuotasAttribute, resource, memberOnResource, true);
} catch (WrongAttributeValueException ex) {
throw new ConsistencyErrorException("Final counted quotas on " + resource + " for member " + memberOnResource + " are in bad format.", ex);
}
}
// Add merged quotas to the big map by resources
mergedMemberResourceQuotas.add(memberResourceFinalDataQuotas);
}
// now we have all resource and member merged quotas, so we need to create 1 transfered map with sum of values
Map<String, Pair<BigDecimal, BigDecimal>> finalTransferredQuotas = sess.getPerunBl().getModulesUtilsBl().countUserFacilityQuotas(mergedMemberResourceQuotas);
// transfer map back to attribute value
attribute.setValue(sess.getPerunBl().getModulesUtilsBl().transferQuotasBackToAttributeValue(finalTransferredQuotas, true));
// return attribute
return attribute;
}
use of cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_fileQuotas method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, Facility facility, AttributeDefinition attributeDefinition) {
Attribute attribute = new Attribute(attributeDefinition);
// merge attribute settings for every allowed resource
List<Map<String, Pair<BigDecimal, BigDecimal>>> mergedMemberResourceQuotas = new ArrayList<>();
List<Resource> allowedResources = sess.getPerunBl().getResourcesManagerBl().getAllowedResources(sess, facility, user);
for (Resource resource : allowedResources) {
// get allowed member of this user on this resource (using his VO)
Vo membersVo;
try {
membersVo = sess.getPerunBl().getVosManagerBl().getVoById(sess, resource.getVoId());
} catch (VoNotExistsException ex) {
throw new ConsistencyErrorException("Vo should exists, because resource with this id exists " + resource);
}
Member memberOnResource;
try {
memberOnResource = sess.getPerunBl().getMembersManagerBl().getMemberByUser(sess, membersVo, user);
} catch (MemberNotExistsException ex) {
throw new ConsistencyErrorException("User should have member in this VO, because he was listed in allowed assigned resources " + user + ", " + membersVo + " , " + resource);
}
// Get member-resource final counted quotas for the member on the resource
Map<String, Pair<BigDecimal, BigDecimal>> memberResourceFinalFileQuotas;
Attribute memberResourceFinalFileQuotasAttribute;
try {
memberResourceFinalFileQuotasAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, memberOnResource, resource, A_MR_V_fileQuotas);
} catch (MemberResourceMismatchException | WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
if (memberResourceFinalFileQuotasAttribute == null || memberResourceFinalFileQuotasAttribute.getValue() == null)
memberResourceFinalFileQuotas = new LinkedHashMap<>();
else {
try {
memberResourceFinalFileQuotas = sess.getPerunBl().getModulesUtilsBl().checkAndTransferQuotas(memberResourceFinalFileQuotasAttribute, resource, memberOnResource, false);
} catch (WrongAttributeValueException ex) {
throw new ConsistencyErrorException("Final counted quotas on " + resource + " for member " + memberOnResource + " are in bad format.", ex);
}
}
// Add merged quotas to the big map by resources
mergedMemberResourceQuotas.add(memberResourceFinalFileQuotas);
}
// now we have all resource and member merged quotas, so we need to create 1 transfered map with sum of values
Map<String, Pair<BigDecimal, BigDecimal>> finalTransferredQuotas = sess.getPerunBl().getModulesUtilsBl().countUserFacilityQuotas(mergedMemberResourceQuotas);
// transfer map back to attribute value
attribute.setValue(sess.getPerunBl().getModulesUtilsBl().transferQuotasBackToAttributeValue(finalTransferredQuotas, false));
// return attribute
return attribute;
}
use of cz.metacentrum.perun.core.api.exceptions.MemberResourceMismatchException in project perun by CESNET.
the class AttributesManagerBlImpl method doTheMagic.
@Override
public void doTheMagic(PerunSession sess, Member member, boolean trueMagic) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, member);
for (Resource resource : resources) {
Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
List<Attribute> requiredAttributes;
try {
requiredAttributes = getResourceRequiredAttributes(sess, resource, facility, resource, user, member);
} catch (MemberResourceMismatchException ex) {
throw new ConsistencyErrorException(ex);
}
boolean allOk = false;
AttributeDefinition lastWrongAttribute = null;
int safetyCounter = 0;
do {
try {
setRequiredAttributes(sess, facility, resource, user, member, requiredAttributes);
allOk = true;
} catch (AttributeNotExistsException | MemberResourceMismatchException | WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
if (!trueMagic)
throw ex;
AttributeDefinition wrongAttributeDefinition = ex.getAttribute();
if (wrongAttributeDefinition == null)
throw new ConsistencyErrorException("WrongAttributeValueException doesn't have set the wrong attribute.", ex);
if (wrongAttributeDefinition.equals(lastWrongAttribute))
throw new WrongAttributeValueException("Method doTheMagic can't fix this attribute value", ex);
lastWrongAttribute = wrongAttributeDefinition;
findAndSetValueInList(requiredAttributes, wrongAttributeDefinition, null);
} catch (WrongReferenceAttributeValueException ex) {
if (!trueMagic)
throw ex;
AttributeDefinition wrongAttributeDefinition = ex.getReferenceAttribute();
if (wrongAttributeDefinition == null)
throw new ConsistencyErrorException("WrongReferenceAttributeValueException doesn't have set reference attribute.", ex);
if (wrongAttributeDefinition.equals(lastWrongAttribute))
throw new WrongReferenceAttributeValueException("Method doTheMagic can't fix this attribute value", ex);
lastWrongAttribute = wrongAttributeDefinition;
if (!findAndSetValueInList(requiredAttributes, wrongAttributeDefinition, null)) {
// this attribute can't be fixed here
throw ex;
}
}
safetyCounter++;
if (safetyCounter == 50)
throw new InternalErrorException("Method doTheMagic possibly stays in infinite loop.");
} while (trueMagic && !allOk);
}
}
Aggregations