Search in sources :

Example 71 with WrongAttributeValueException

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);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 72 with WrongAttributeValueException

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!");
    }
}
Also used : Matcher(java.util.regex.Matcher) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 73 with WrongAttributeValueException

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");
}
Also used : ArrayList(java.util.ArrayList) Facility(cz.metacentrum.perun.core.api.Facility) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 74 with WrongAttributeValueException

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);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 75 with WrongAttributeValueException

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);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)135 Attribute (cz.metacentrum.perun.core.api.Attribute)100 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)83 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)82 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)75 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)66 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)54 Matcher (java.util.regex.Matcher)31 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)27 ArrayList (java.util.ArrayList)17 LinkedHashMap (java.util.LinkedHashMap)16 Facility (cz.metacentrum.perun.core.api.Facility)14 Map (java.util.Map)14 Resource (cz.metacentrum.perun.core.api.Resource)12 User (cz.metacentrum.perun.core.api.User)11 Group (cz.metacentrum.perun.core.api.Group)9 Pattern (java.util.regex.Pattern)8 BigDecimal (java.math.BigDecimal)7 List (java.util.List)7 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5