use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_UID method getAttributeValue.
/**
* Gets the value of the attribute f:uid-namespace and then finds the value of the attribute u:uid-namespace:[uid-namespace]
*/
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, Facility facility, AttributeDefinition attributeDefinition) {
Attribute attr = new Attribute(attributeDefinition);
Attribute uidAttribute;
try {
// Get the f:uid-namespace attribute
Attribute uidNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":uid-namespace");
if (uidNamespaceAttribute.getValue() != null) {
// Get the u:uid-namespace[uidNamespaceAttribute]
uidAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:" + uidNamespaceAttribute.getValue());
Utils.copyAttributeToVirtualAttributeWithValue(uidAttribute, attr);
} else {
attr.setValue(null);
}
} catch (AttributeNotExistsException | WrongAttributeAssignmentException e) {
throw new ConsistencyErrorException(e);
}
return attr;
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException 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.ConsistencyErrorException 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.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_login method setAttributeValue.
@Override
public boolean setAttributeValue(PerunSessionImpl sess, User user, Facility facility, Attribute attribute) throws WrongReferenceAttributeValueException {
AttributeDefinition userLoginAttributeDefinition;
try {
// Get the f:login-namespace attribute
Attribute loginNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":login-namespace");
if (loginNamespaceAttribute.getValue() == null) {
throw new WrongReferenceAttributeValueException(attribute, loginNamespaceAttribute, user, facility, "Facility need to have nonempty login-namespace attribute.");
}
userLoginAttributeDefinition = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:" + loginNamespaceAttribute.getValue());
} catch (AttributeNotExistsException e) {
throw new InternalErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new ConsistencyErrorException(e);
}
Attribute userLoginAttribute = new Attribute(userLoginAttributeDefinition);
userLoginAttribute.setValue(attribute.getValue());
try {
return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, user, userLoginAttribute);
} catch (WrongAttributeValueException e) {
throw new InternalErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new ConsistencyErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_userCertificatesLimited method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) {
Attribute resultAttribute = new Attribute(attributeDefinition);
List<String> result = new ArrayList<>();
Attribute userCertsAttribute = getUserCertsAttribute(sess, user);
Map<String, String> certs = userCertsAttribute.valueAsMap();
if (certs != null) {
Map<String, String> certsExpiration = ModulesUtilsBlImpl.retrieveCertificatesExpiration(certs);
DateFormat dateFormatInstance = DateFormat.getDateInstance();
Map<String, Long> certsExpirationInMilliSeconds = new HashMap<>();
certsExpiration.forEach((key, value) -> {
try {
certsExpirationInMilliSeconds.put(key, dateFormatInstance.parse(value).getTime());
} catch (ParseException ex) {
throw new ConsistencyErrorException(ex);
}
});
certsExpirationInMilliSeconds.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).limit(10).forEachOrdered(entry -> result.add(certs.get(entry.getKey())));
Utils.copyAttributeToViAttributeWithoutValue(userCertsAttribute, resultAttribute);
}
resultAttribute.setValue(result);
return resultAttribute;
}
Aggregations