Search in sources :

Example 71 with InternalErrorException

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

the class EventProcessorImpl method updateVoAttributes.

/**
	 * Update vo's ldap attributes from Map by operation in key.
	 *
	 * Map<LdapOperation, List<Pair<String, String>>> => Map<LdapOperation, List<Pair<attributeName, attributeValue>>>
	 *
	 *
	 * attributeName cant be null and empty String
	 * attributeValue can be null
	 *
	 * Execute all operations on all attributes with (or without value) in 1 task.
	 *
	 * @param mapOfAttributes map of Operation to list of pairs where left is attributeName and right is attributeValue
	 * @param vo cant be null
	 * @throws InternalErrorException if an error occurs
	 */
private void updateVoAttributes(Map<LdapOperation, List<Pair<String, String>>> mapOfAttributes, Vo vo) throws InternalErrorException {
    //User cant be null
    if (vo == null)
        throw new InternalErrorException("Vo is null in method updateVoAttributes");
    //Only 3 types of key are allowed (1,2 or 3) Modification classes
    Set<LdapOperation> keys = mapOfAttributes.keySet();
    //Every Pair in List need to have "attributeName" and may have "attributeValue"
    for (LdapOperation operation : keys) {
        List<Pair<String, String>> listOfAttrs = mapOfAttributes.get(operation);
        for (Pair<String, String> pair : listOfAttrs) {
            if (pair.getLeft() == null || pair.getLeft().equals(""))
                throw new InternalErrorException("Some attributes in map has no name.");
        }
    }
    //If all is correct, can execute operations on attributes
    List<ModificationItem> listOfItemsToModify = new ArrayList<ModificationItem>();
    //For all attributes with operation ADD (1)
    if (mapOfAttributes.containsKey(LdapOperation.ADD_ATTRIBUTE)) {
        List<Pair<String, String>> listOfAddingAttributes = mapOfAttributes.get(LdapOperation.ADD_ATTRIBUTE);
        for (Pair<String, String> pair : listOfAddingAttributes) {
            Attribute attribute;
            if (pair.getRight() != null)
                attribute = new BasicAttribute(pair.getLeft(), pair.getRight());
            else
                attribute = new BasicAttribute(pair.getRight());
            ModificationItem attributeItem = new ModificationItem(LdapOperation.ADD_ATTRIBUTE.getCode(), attribute);
            listOfItemsToModify.add(attributeItem);
        }
    }
    //For all attributes with operation REPLACE (2)
    if (mapOfAttributes.containsKey(LdapOperation.REPLACE_ATTRIBUTE)) {
        List<Pair<String, String>> listOfAddingAttributes = mapOfAttributes.get(LdapOperation.REPLACE_ATTRIBUTE);
        for (Pair<String, String> pair : listOfAddingAttributes) {
            Attribute attribute;
            if (pair.getRight() != null)
                attribute = new BasicAttribute(pair.getLeft(), pair.getRight());
            else
                attribute = new BasicAttribute(pair.getRight());
            ModificationItem attributeItem = new ModificationItem(LdapOperation.REPLACE_ATTRIBUTE.getCode(), attribute);
            listOfItemsToModify.add(attributeItem);
        }
    }
    //For all attributes with operation REMOVE (3)
    if (mapOfAttributes.containsKey(LdapOperation.REMOVE_ATTRIBUTE)) {
        List<Pair<String, String>> listOfAddingAttributes = mapOfAttributes.get(LdapOperation.REMOVE_ATTRIBUTE);
        for (Pair<String, String> pair : listOfAddingAttributes) {
            Attribute attribute;
            if (pair.getRight() != null)
                attribute = new BasicAttribute(pair.getLeft(), pair.getRight());
            else
                attribute = new BasicAttribute(pair.getRight());
            ModificationItem attributeItem = new ModificationItem(LdapOperation.REMOVE_ATTRIBUTE.getCode(), attribute);
            listOfItemsToModify.add(attributeItem);
        }
    }
    //Execute all changes on the notEmpty list of items
    if (!listOfItemsToModify.isEmpty()) {
        ModificationItem[] items = Arrays.copyOf(listOfItemsToModify.toArray(), listOfItemsToModify.toArray().length, ModificationItem[].class);
        ldapConnector.updateVo(vo, items);
    }
}
Also used : LdapOperation(cz.metacentrum.perun.ldapc.beans.LdapOperation) Attribute(javax.naming.directory.Attribute) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 72 with InternalErrorException

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

the class PerunNotifTemplateManagerImpl method updatePerunNotifTemplate.

@Override
public PerunNotifTemplate updatePerunNotifTemplate(PerunNotifTemplate template) throws InternalErrorException {
    PerunNotifTemplate oldTemplate = getPerunNotifTemplateById(template.getId());
    perunNotifTemplateDao.updatePerunNotifTemplateData(template);
    // create rexeges if not exist
    if (template.getMatchingRegexs() != null) {
        for (PerunNotifRegex regex : template.getMatchingRegexs()) {
            if ((regex.getId() == null) || (perunNotifRegexDao.getPerunNotifRegexById(regex.getId()) == null)) {
                perunNotifRegexDao.saveInternals(regex);
            }
            if (!(perunNotifRegexDao.isRegexRelation(template.getId(), regex.getId()))) {
                perunNotifRegexDao.saveTemplateRegexRelation(template.getId(), regex.getId());
            }
        }
    }
    // create receivers if not exist
    if (template.getReceivers() != null) {
        for (PerunNotifReceiver receiver : template.getReceivers()) {
            receiver.setTemplateId(template.getId());
            if ((receiver.getId() == null) || (perunNotifTemplateDao.getPerunNotifReceiverById(receiver.getId()) == null)) {
                perunNotifTemplateDao.createPerunNotifReceiver(receiver);
            }
        }
    }
    // create template messages if not exist
    if (template.getPerunNotifTemplateMessages() != null) {
        for (PerunNotifTemplateMessage message : template.getPerunNotifTemplateMessages()) {
            message.setTemplateId(template.getId());
            PerunNotifTemplateMessage newMessage;
            try {
                newMessage = createPerunNotifTemplateMessage(message);
                message.setId(newMessage.getId());
            } catch (NotifTemplateMessageAlreadyExistsException ex) {
            // template message already exists
            } catch (TemplateMessageSyntaxErrorException ex) {
                throw new InternalErrorException(ex);
            }
        }
    }
    PerunNotifTemplate updatedTemplate = getPerunNotifTemplateById(template.getId());
    allTemplatesById.put(updatedTemplate.getId(), updatedTemplate);
    for (PerunNotifRegex regex : updatedTemplate.getMatchingRegexs()) {
        List<PerunNotifTemplate> list = allTemplatesByRegexId.get(regex.getId());
        if (list == null) {
            list = new ArrayList<PerunNotifTemplate>();
            allTemplatesByRegexId.put(regex.getId(), list);
        }
        boolean updated = false;
        for (PerunNotifTemplate templateToUpdate : list) {
            if (templateToUpdate.getId() == updatedTemplate.getId()) {
                templateToUpdate.update(updatedTemplate);
                updated = true;
            }
        }
        if (!updated) {
            list.add(updatedTemplate);
        }
    }
    return updatedTemplate;
}
Also used : NotifTemplateMessageAlreadyExistsException(cz.metacentrum.perun.notif.exceptions.NotifTemplateMessageAlreadyExistsException) TemplateMessageSyntaxErrorException(cz.metacentrum.perun.notif.exceptions.TemplateMessageSyntaxErrorException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 73 with InternalErrorException

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

the class SchedulingManagerImpl method processPerunAuditMessages.

/**
	 * The method loads perun audit messages from the database and saves them as PerunNotifAudiMessages.
	 */
public void processPerunAuditMessages() throws Exception {
    List<PerunNotifAuditMessage> perunNotifAuditMessages = new ArrayList<PerunNotifAuditMessage>();
    try {
        List<AuditMessage> messages = perun.getAuditMessagesManagerBl().pollConsumerMessagesForParser(consumerName);
        for (AuditMessage message : messages) {
            try {
                PerunNotifAuditMessage perunNotifAuditMessage = perunNotifAuditMessagesManager.saveMessageToPerunAuditerMessage(message.getMsg(), session);
                perunNotifAuditMessages.add(perunNotifAuditMessage);
            } catch (InternalErrorException ex) {
                logger.error("Error during saving message to db. Message: " + message.getMsg());
                throw ex;
            }
        }
    } catch (Exception ex) {
        logger.error("Error during perunNotification process.");
        throw ex;
    }
}
Also used : AuditMessage(cz.metacentrum.perun.core.api.AuditMessage) PerunNotifAuditMessage(cz.metacentrum.perun.notif.entities.PerunNotifAuditMessage) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PerunNotifAuditMessage(cz.metacentrum.perun.notif.entities.PerunNotifAuditMessage) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 74 with InternalErrorException

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

the class TaskStatusManagerImpl method onTaskDestinationError.

@Override
public void onTaskDestinationError(Task task, Destination destination, TaskResult result) {
    if (result != null) {
        try {
            jmsQueueManager.reportFinishedDestination(task, destination, result);
        } catch (JMSException e) {
            log.error("Failed to report finished task " + task.toString() + ": " + e.getMessage());
        }
    }
    if (task.getExecService().getExecServiceType().equals(ExecServiceType.GENERATE)) {
        task.setEndTime(new Date(System.currentTimeMillis()));
        schedulingPool.setTaskStatus(task, cz.metacentrum.perun.taskslib.model.Task.TaskStatus.ERROR);
    } else {
        TaskStatus taskStatus = this.getTaskStatus(task);
        try {
            taskStatus.setDestinationStatus(destination, TaskDestinationStatus.ERROR);
            taskStatus.setDestinationResult(destination, result);
        } catch (InternalErrorException e) {
            log.error("Error setting ERROR status for task " + task.toString() + ": " + e.getMessage());
        }
        if (taskStatus.isTaskFinished()) {
            task.setEndTime(new Date(System.currentTimeMillis()));
            schedulingPool.setTaskStatus(task, taskStatus.getTaskStatus());
        }
    }
}
Also used : JMSException(javax.jms.JMSException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) TaskStatus(cz.metacentrum.perun.engine.scheduling.TaskStatus) Date(java.util.Date)

Example 75 with InternalErrorException

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

the class EventProcessorImpl method updateUserAttribute.

/**
	 * Update ldap attribute with attributeName for the user by value with operation.
	 *
	 *
	 * @param attributeName name of attribute, is mandatory, cant be null
	 * @param attributeValue value of attribute, is not mandatory, can be null
	 * @param operation add, remove or replace (can't be null)
	 * @param user cant be null
	 *
	 * @exception InternalErrorException if an error occurs
	 *
	 */
private void updateUserAttribute(String attributeName, String attributeValue, LdapOperation operation, User user) throws InternalErrorException {
    if (operation == null)
        throw new InternalErrorException("Operation can't be null");
    if (attributeName == null || attributeName.equals(""))
        throw new InternalErrorException("Bad attribute Name in method updateUserAttribute :" + attributeName);
    if (user == null)
        throw new InternalErrorException("User is null in method updateUserAttribute");
    Attribute attribute;
    if (attributeValue != null)
        attribute = new BasicAttribute(attributeName, attributeValue);
    else
        attribute = new BasicAttribute(attributeName);
    ModificationItem attributeItem = new ModificationItem(operation.getCode(), attribute);
    ldapConnector.updateUser(user, new ModificationItem[] { attributeItem });
}
Also used : Attribute(javax.naming.directory.Attribute) 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