Search in sources :

Example 96 with InternalErrorException

use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.

the class ExtSourceVOOT method getGroupSubjects.

@Override
public List<Map<String, String>> getGroupSubjects(Map<String, String> attributes) throws InternalErrorException {
    List<Map<String, String>> subjects = new ArrayList<>();
    try {
        String queryForGroup = attributes.get(GroupsManager.GROUPMEMBERSQUERY_ATTRNAME);
        if (queryForGroup == null) {
            throw new InternalErrorException("Attribute " + GroupsManager.GROUPMEMBERSEXTSOURCE_ATTRNAME + " can't be null.");
        }
        prepareEnvironment();
        List<Map<String, String>> parsedResult = getUsersFromRemoteGroup(queryForGroup);
        for (Map map : parsedResult) {
            if (map != null) {
                subjects.add(map);
            }
        }
    } catch (IOException ex) {
        log.error("IOException in getGroupSubjects() method while obtaining" + "users from VOOT external source by group name", ex);
    }
    return subjects;
}
Also used : ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 97 with InternalErrorException

use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.

the class ExtSourceXML method convertNodeToMap.

/**
	 * Get XML node and convert all values by "xmlMapping" attribute to Map<String,String>
	 * In map there are "name=value" data.
	 *
	 * Attribute xmlMapping is from file perun-extSource.xml
	 *
	 * @param node node for converting
	 * @return Map<String,String> like <name,value>
	 * @throws InternalErrorException
	 */
protected Map<String, String> convertNodeToMap(Node node) throws InternalErrorException {
    Map<String, String> nodeInMap = new HashMap<String, String>();
    //If node is empty, return null
    if (node == null)
        return null;
    String mapping = getAttributes().get("xmlMapping");
    String[] mappingArray = mapping.split(",\n");
    for (int i = 0; i < mappingArray.length; i++) {
        String attr = mappingArray[i].trim();
        int index = attr.indexOf("=");
        if (index <= 0)
            throw new InternalErrorException("There is no text in xmlMapping attribute or there is no '=' character.");
        String name = attr.substring(0, index);
        String value = attr.substring(index + 1);
        if (value.startsWith("#")) {
            value = value.substring(1);
            String[] regexAndXpath = value.split("#");
            if (regexAndXpath.length != 2)
                throw new InternalErrorException("There is not only 2 parts (regex and XpathExpression). There are " + regexAndXpath.length + " parts.");
            value = extractValueByRegex(getValueFromXpath(node, regexAndXpath[1]), regexAndXpath[0]);
        } else {
            value = getValueFromXpath(node, value);
        }
        nodeInMap.put(name.trim(), value.trim());
    }
    return nodeInMap;
}
Also used : HashMap(java.util.HashMap) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 98 with InternalErrorException

use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.

the class ExtSourceXML method getGroupSubjects.

public List<Map<String, String>> getGroupSubjects(Map<String, String> attributes) throws InternalErrorException, ExtSourceUnsupportedOperationException {
    // Get the query for the group subjects
    String queryForGroup = attributes.get(GroupsManager.GROUPMEMBERSQUERY_ATTRNAME);
    //If there is no query for group, throw exception
    if (queryForGroup == null)
        throw new InternalErrorException("Attribute " + GroupsManager.GROUPMEMBERSEXTSOURCE_ATTRNAME + " can't be null.");
    //Get file or uri of xml
    prepareEnvironment();
    return xpathParsing(queryForGroup, 0);
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 99 with InternalErrorException

use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.

the class FacilitiesManagerImpl method removeAllGroupContacts.

@Override
public void removeAllGroupContacts(PerunSession sess, Group group) throws InternalErrorException {
    try {
        jdbc.update("delete from facility_contacts where group_id=?", group.getId());
        log.info("All group's {} facilities contacts deleted.", group);
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 100 with InternalErrorException

use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.

the class FacilitiesManagerImpl method removeFacilityContact.

@Override
public void removeFacilityContact(PerunSession sess, Facility facility, String name, Owner owner) throws InternalErrorException {
    try {
        jdbc.update("delete from facility_contacts where facility_id=? and owner_id=? and name=?", facility.getId(), owner.getId(), name);
        log.info("Facility contact deleted. Facility: {}, ContactName: {}, Owner: " + owner, facility, name);
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)376 Attribute (cz.metacentrum.perun.core.api.Attribute)119 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)104 ArrayList (java.util.ArrayList)94 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)89 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)78 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)68 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)67 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)44 User (cz.metacentrum.perun.core.api.User)37 Group (cz.metacentrum.perun.core.api.Group)36 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)33 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)33 HashMap (java.util.HashMap)30 IOException (java.io.IOException)28 Member (cz.metacentrum.perun.core.api.Member)24 Map (java.util.Map)24 Facility (cz.metacentrum.perun.core.api.Facility)23 List (java.util.List)23 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)22