use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
public void removeAllAttributes(PerunSession sess, Facility facility, User user) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
List<Attribute> attributes = getAttributes(sess, facility, user);
//remove all non-virtual attributes
getAttributesManagerImpl().removeAllAttributes(sess, facility, user);
//remove all virtual attributes
List<Attribute> virtualAttributes = getVirtualAttributes(sess, facility, user);
for (Attribute attribute : virtualAttributes) {
getAttributesManagerImpl().removeVirtualAttribute(sess, facility, user, attribute);
}
attributes.addAll(virtualAttributes);
getPerunBl().getAuditer().log(sess, "All attributes removed for {} and {}", facility, user);
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesValue(sess, facility, user, attributes);
this.checkAttributesDependencies(sess, facility, user, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : attributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, facility, user, new Attribute(attribute));
} catch (WrongAttributeValueException ex) {
//TODO better exception here
throw new InternalErrorException(ex);
} catch (WrongReferenceAttributeValueException ex) {
//TODO better exception here
throw new InternalErrorException(ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException in project perun by CESNET.
the class urn_perun_entityless_attribute_def_def_usedGids method checkAttributeValue.
public void checkAttributeValue(PerunSessionImpl perunSession, String key, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
//If this attribute value is null, it means there is no GIDS depleted or used.
if (attribute.getValue() == null)
return;
Map<String, String> map = (Map<String, String>) attribute.getValue();
//If there are no keys in map, it means the same like null value
if (map.isEmpty())
return;
Set<String> mapKeys = map.keySet();
for (String mapKey : mapKeys) {
//Test key
if (mapKey == null)
throw new WrongAttributeValueException(attribute, key, "Key in usedGids can't be null.");
Matcher keyMatcher = keyPattern.matcher(mapKey);
if (!keyMatcher.matches())
throw new WrongAttributeValueException(attribute, key, "Key in usedGids can be only in format 'Rx', 'Gx', 'Dx' where 'x' is positive integer.");
//Test value
String value = map.get(key);
if (value == null)
throw new WrongAttributeValueException(attribute, key, "Value is usedGids can't be null.");
Matcher valueMatcher = valuePattern.matcher(value);
if (!valueMatcher.matches())
throw new WrongAttributeValueException(attribute, key, "Key in usedGids can be only positive integer.");
}
//If group or resource has some gid, this gid can't be depleted at the same time!
for (String mapKey : mapKeys) {
String value = map.get(mapKey);
if (map.containsKey("D" + value))
throw new WrongAttributeValueException(attribute, key, "This gid can't be depleted and used at the same time!");
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException in project perun by CESNET.
the class urn_perun_facility_attribute_def_def_pbsServer method checkAttributeValue.
public void checkAttributeValue(PerunSessionImpl perunSession, Facility facility, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
String pbsServer = null;
if (attribute.getValue() != null) {
pbsServer = (String) attribute.getValue();
} else {
throw new WrongAttributeValueException(attribute, "PbsServer cannot be null.");
}
//TODO better method for searching Facility by querry in DB
List<Facility> allFacilities = new ArrayList<Facility>();
allFacilities = perunSession.getPerunBl().getFacilitiesManagerBl().getFacilities(perunSession);
boolean success = false;
for (Facility f : allFacilities) {
if (f.getName().equals(pbsServer)) {
success = true;
break;
}
}
if (!success)
throw new WrongAttributeValueException(attribute, "There is no such facility with the same name like this pbsServer");
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException in project perun by CESNET.
the class ModulesUtilsEntryIntegrationTest method checkReservedNames.
@Test
public void checkReservedNames() throws Exception {
System.out.println(CLASS_NAME + "checkReservedNames");
String goodName = "cokoliv";
String badName = "sys";
Attribute attr = new Attribute();
attr.setValue(goodName);
modulesUtilsBl.checkReservedUnixGroupNames(attr);
attr.setValue(badName);
boolean ok = false;
try {
modulesUtilsBl.checkReservedUnixGroupNames(attr);
ok = false;
} catch (WrongAttributeValueException ex) {
ok = true;
}
assertTrue(ok);
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException in project perun by CESNET.
the class ModulesUtilsEntryIntegrationTest method checkIfGIDIsWithinRange.
@Test
public void checkIfGIDIsWithinRange() throws Exception {
System.out.println(CLASS_NAME + "checkIfGIDIsWithinRange");
Attribute minGID = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_ENTITYLESS_ATTR_DEF + ":namespace-minGID"));
Attribute maxGID = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_ENTITYLESS_ATTR_DEF + ":namespace-maxGID"));
minGID.setValue(100000);
maxGID.setValue(100500);
perun.getAttributesManagerBl().setAttribute(sess, namespace, minGID);
perun.getAttributesManagerBl().setAttribute(sess, namespace, maxGID);
List<Attribute> attributes = setUpGroupNamesAndGIDForGroupAndResource();
int i = 0;
for (Attribute a : attributes) {
if (a.getFriendlyName().startsWith("unixGID-namespace")) {
if (i == 0)
a.setValue(2000);
else
a.setValue(100005);
try {
modulesUtilsBl.checkIfGIDIsWithinRange((PerunSessionImpl) sess, a);
} catch (WrongAttributeValueException ex) {
i++;
}
}
}
assertEquals(1, i);
}
Aggregations