use of cz.metacentrum.perun.notif.entities.PerunNotifPoolMessage in project perun by CESNET.
the class PerunNotifPoolMessageManagerImpl method createPerunNotifPoolMessagesForTemplates.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public List<PerunNotifPoolMessage> createPerunNotifPoolMessagesForTemplates(Map<Integer, List<PerunNotifTemplate>> templatesWithRegexIds, PerunNotifAuditMessage perunAuditMessage) {
List<PerunNotifPoolMessage> result = new ArrayList<PerunNotifPoolMessage>();
// We parse recieved message from auditer to get all objects
// List<PerunBean> retrievedObjects = ParseUtils.parseMessage(perunMessage.getMessage());
List<PerunBean> retrievedObjects = AuditParser.parseLog(perunAuditMessage.getMessage());
// Objects which can be later used when proccessing managerCalls
Map<String, Object> usableObjects = parseRetrievedObjects(retrievedObjects);
usableObjects.put(parseClassName(PerunSession.class.toString()), session);
Map<String, String> retrievedProperties = new HashMap<String, String>();
for (Integer regexId : templatesWithRegexIds.keySet()) {
// We list through every regexId recognized in message
List<PerunNotifTemplate> templates = templatesWithRegexIds.get(regexId);
if ((templates != null) && (!templates.isEmpty())) {
for (PerunNotifTemplate template : templates) {
// We list through every template which uses regexId
Map<String, String> retrievedPrimaryProperties = new HashMap<String, String>();
Set<String> classNames = new HashSet<String>();
classNames.addAll(template.getPrimaryProperties().keySet());
for (String className : classNames) {
if (className != null && !className.equals(METHOD_CLASSNAME)) {
// Listing through all classNames
try {
logger.debug("Resolving class with name: " + className);
Class resolvedClass = Class.forName(className);
Object matchingObject = null;
for (Object myObject : retrievedObjects) {
if (resolvedClass.isAssignableFrom(myObject.getClass())) {
matchingObject = myObject;
logger.debug("Parsed object: " + matchingObject.toString() + " from message recognized for class: " + className);
}
}
if (matchingObject != null) {
if (template.getPrimaryProperties().get(className) != null) {
List<String> methods = template.getPrimaryProperties().get(className);
retrieveProperties(methods, className, retrievedPrimaryProperties, retrievedProperties, matchingObject);
}
} else {
logger.error("No object recognized in objects from message for class: " + className);
}
} catch (ClassNotFoundException ex) {
logger.error("Class from template cannot be resolved: " + className, ex);
}
}
}
if (template.getPrimaryProperties().get(METHOD_CLASSNAME) != null) {
for (String methodName : template.getPrimaryProperties().get(METHOD_CLASSNAME)) {
String value = retrieveMethodProperty(retrievedProperties, methodName, usableObjects);
retrievedPrimaryProperties.put(methodName, value);
}
}
if (retrievedPrimaryProperties != null && !retrievedPrimaryProperties.isEmpty()) {
PerunNotifPoolMessage poolMessage = new PerunNotifPoolMessage();
poolMessage.setCreated(Instant.now());
poolMessage.setKeyAttributes(retrievedPrimaryProperties);
poolMessage.setRegexId(regexId);
poolMessage.setTemplateId(template.getId());
poolMessage.setNotifMessage(perunAuditMessage.getMessage());
result.add(poolMessage);
}
}
} else {
logger.info("No template for regex id: " + regexId + " found.");
}
}
return result;
}
Aggregations