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;
}
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;
}
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);
}
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);
}
}
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);
}
}
Aggregations