use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class AttributesManagerBlImpl method getResourceRequiredAttributes.
@Override
public List<Attribute> getResourceRequiredAttributes(PerunSession sess, Resource resourceToGetServicesFrom, Member member, Resource resource, boolean workWithUserAttributes) throws MemberResourceMismatchException {
this.checkMemberIsFromTheSameVoLikeResource(sess, member, resource);
List<Attribute> attributes = new ArrayList<>(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, member, resource));
if (workWithUserAttributes) {
User user;
Facility facility;
try {
user = getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId());
facility = getPerunBl().getFacilitiesManagerBl().getFacilityById(sess, resource.getFacilityId());
} catch (UserNotExistsException e) {
throw new ConsistencyErrorException("Member has non-existent user.", e);
} catch (FacilityNotExistsException e) {
throw new ConsistencyErrorException("Resource has non-existent facility.", e);
}
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, facility, user));
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, user));
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, member));
}
return attributes;
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class AttributesManagerBlImpl method getAttributes.
@Override
public List<Attribute> getAttributes(PerunSession sess, Resource resource, Group group, Member member, List<String> attrNames) throws GroupResourceMismatchException, MemberResourceMismatchException, MemberGroupMismatchException {
List<Attribute> attributes = new ArrayList<>();
if (attrNames.isEmpty())
return attributes;
Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
List<String> groupAndGroupResourceAttrNames = new ArrayList<>();
List<String> memberGroupAttrNames = new ArrayList<>();
List<String> memberResourceAttrNames = new ArrayList<>();
List<String> facilityAttrNames = new ArrayList<>();
List<String> resourceAttrNames = new ArrayList<>();
// sort attribute names by namespaces
for (String attrName : attrNames) {
if (attrName.startsWith(NS_GROUP_ATTR)) {
groupAndGroupResourceAttrNames.add(attrName);
} else if (attrName.startsWith(NS_GROUP_RESOURCE_ATTR)) {
groupAndGroupResourceAttrNames.add(attrName);
} else if (attrName.startsWith(NS_MEMBER_GROUP_ATTR)) {
memberGroupAttrNames.add(attrName);
} else if (attrName.startsWith(NS_RESOURCE_ATTR)) {
resourceAttrNames.add(attrName);
} else if (attrName.startsWith(NS_MEMBER_RESOURCE_ATTR)) {
memberResourceAttrNames.add(attrName);
} else if (attrName.startsWith(NS_USER_ATTR)) {
memberResourceAttrNames.add(attrName);
} else if (attrName.startsWith(NS_MEMBER_ATTR)) {
memberResourceAttrNames.add(attrName);
} else if (attrName.startsWith(NS_FACILITY_ATTR)) {
facilityAttrNames.add(attrName);
} else if (attrName.startsWith(NS_USER_FACILITY_ATTR)) {
memberResourceAttrNames.add(attrName);
} else {
throw new ConsistencyErrorException("One of asked attribute names is not from supported namespace : " + attrName);
}
}
// return all group and group_resource attributes
if (!groupAndGroupResourceAttrNames.isEmpty())
attributes.addAll(this.getAttributes(sess, resource, group, groupAndGroupResourceAttrNames, true));
// return all member_group attributes
if (!memberGroupAttrNames.isEmpty())
attributes.addAll(this.getAttributes(sess, member, group, memberGroupAttrNames, false));
// return all user, member, member-resource and user-facility attributes
if (!memberResourceAttrNames.isEmpty())
attributes.addAll(this.getAttributes(sess, member, resource, memberResourceAttrNames, true));
// return all resource attributes
if (!resourceAttrNames.isEmpty())
attributes.addAll(this.getAttributes(sess, resource, resourceAttrNames));
// return all facility attributes
if (!facilityAttrNames.isEmpty())
attributes.addAll(this.getAttributes(sess, facility, facilityAttrNames));
return attributes;
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllUserFacilityAttributes.
@Override
public void removeAllUserFacilityAttributes(PerunSession sess, User user) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
List<RichAttribute<User, Facility>> userFacilitiesAttributes = getAttributesManagerImpl().getAllUserFacilityRichAttributes(sess, user);
// remove all non-virtual attributes
if (getAttributesManagerImpl().removeAllUserFacilityAttributes(sess, user)) {
getPerunBl().getAuditer().log(sess, new AllUserFacilityAttributesRemovedForFacilitiesAndUser(user));
}
log.info("{} removed all attributes from user {} on all facilities.", sess.getLogId(), user.getId());
for (RichAttribute<User, Facility> richAttribute : userFacilitiesAttributes) {
try {
checkAttributeSemantics(sess, richAttribute.getSecondaryHolder(), richAttribute.getPrimaryHolder(), new Attribute(richAttribute.getAttribute()));
checkAttributeDependencies(sess, richAttribute);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
}
for (RichAttribute<User, Facility> attribute : userFacilitiesAttributes) {
getAttributesManagerImpl().changedAttributeHook(sess, attribute.getSecondaryHolder(), attribute.getPrimaryHolder(), new Attribute(attribute.getAttribute()));
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
@Override
public void removeAllAttributes(PerunSession sess, Member member) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
List<Attribute> attributes = getAttributes(sess, member);
if (getAttributesManagerImpl().removeAllAttributes(sess, member)) {
getPerunBl().getAuditer().log(sess, new AllAttributesRemovedForMember(member));
}
log.info("{} removed all attributes from member {}.", sess.getLogId(), member.getId());
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesSemantics(sess, member, attributes);
checkAttributesDependencies(sess, member, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : attributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, member, new Attribute(attribute));
} catch (WrongReferenceAttributeValueException ex) {
throw new InternalErrorException(ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
@Override
public void removeAllAttributes(PerunSession sess, Host host) throws WrongAttributeValueException {
List<Attribute> attributes = getAttributes(sess, host);
if (getAttributesManagerImpl().removeAllAttributes(sess, host)) {
getPerunBl().getAuditer().log(sess, new AllAttributesRemovedForHost(host));
}
log.info("{} removed all attributes from host {}.", sess.getLogId(), host.getId());
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesSemantics(sess, host, attributes);
checkAttributesDependencies(sess, host, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongReferenceAttributeValueException ex) {
throw new WrongAttributeValueException(ex);
}
for (Attribute attribute : attributes) {
getAttributesManagerImpl().changedAttributeHook(sess, host, new Attribute(attribute));
}
}
Aggregations