Search in sources :

Example 1 with WrongAttributeAssignmentException

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

the class Auditer method flush.

/**
	 * Imidiately flushes stored message for last top-level transaction into the log
	 *
	 */
public void flush() {
    List<List<List<AuditerMessage>>> topLevelTransactions = getTopLevelTransactions();
    if (topLevelTransactions.isEmpty()) {
        log.trace("No messages to flush");
        return;
    }
    List<List<AuditerMessage>> transactionChain = topLevelTransactions.get(topLevelTransactions.size() - 1);
    if (transactionChain.isEmpty()) {
        log.trace("No messages to flush");
        topLevelTransactions.remove(topLevelTransactions.size() - 1);
        return;
    }
    if (transactionChain.size() != 1) {
        log.error("There should be only one list of messages while flushing representing the most outer transaction.");
    }
    List<AuditerMessage> messages = transactionChain.get(0);
    topLevelTransactions.remove(topLevelTransactions.size() - 1);
    if (topLevelTransactions.isEmpty()) {
        TransactionSynchronizationManager.unbindResourceIfPossible(this);
    }
    log.trace("Audit messages was flushed for current transaction.");
    synchronized (LOCK_DB_TABLE_AUDITER_LOG) {
        storeMessagesToDb(messages);
    }
    for (AuditerMessage message : messages) {
        for (VirtualAttributesModuleImplApi virtAttrModuleImplApi : registeredAttributesModules) {
            List<String> resolvingMessages = new ArrayList<String>();
            try {
                resolvingMessages.addAll(virtAttrModuleImplApi.resolveVirtualAttributeValueChange((PerunSessionImpl) message.getOriginaterPerunSession(), message.getMessage()));
            } catch (InternalErrorException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            } catch (WrongAttributeAssignmentException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            } catch (WrongReferenceAttributeValueException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            } catch (AttributeNotExistsException ex) {
                log.error("Error when auditer trying to resolve messages in modules.", ex);
            }
            if (!resolvingMessages.isEmpty()) {
                List<AuditerMessage> resolvingAuditerMessages = new ArrayList<>();
                for (String msg : resolvingMessages) {
                    resolvingAuditerMessages.add(new AuditerMessage(message.getOriginaterPerunSession(), msg));
                }
                storeMessagesToDb(resolvingAuditerMessages);
            }
        }
    }
}
Also used : VirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.VirtualAttributesModuleImplApi) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with WrongAttributeAssignmentException

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

the class urn_perun_group_attribute_def_def_unixGID_namespace method changedAttributeHook.

@Override
public void changedAttributeHook(PerunSessionImpl session, Group group, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    String gidNamespace = attribute.getFriendlyNameParameter();
    //get attribute with usedGids for update
    //IMPORTANT: for update lock row in table of attr values, be careful when using
    Attribute usedGids;
    try {
        usedGids = session.getPerunBl().getAttributesManagerBl().getEntitylessAttributeForUpdate(session, gidNamespace, A_E_usedGids);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    }
    //Get Map of gids (if there is no value, use empty map
    Map<String, String> usedGidsValue = new LinkedHashMap<>();
    if (usedGids.getValue() != null)
        usedGidsValue = (Map<String, String>) usedGids.getValue();
    //initial settings
    String key = "G" + group.getId();
    String oldGid = usedGidsValue.get(key);
    //for removing gid
    if (attribute.getValue() == null) {
        //remove record from map
        if (oldGid != null) {
            usedGidsValue.remove(key);
            //looking for another oldGid value, if not exists, add depleted record
            if (!usedGidsValue.containsValue(oldGid)) {
                usedGidsValue.put("D" + oldGid, oldGid);
            }
        }
    //for setting gid
    } else {
        String newUnixGid = ((Integer) attribute.getValue()).toString();
        //add new record to map
        usedGidsValue.put(key, newUnixGid);
        //looking for another oldGid value, if not exists, add depleted record
        if (oldGid != null && !usedGidsValue.containsValue(oldGid)) {
            usedGidsValue.put("D" + oldGid, oldGid);
        }
    }
    //set new attribute value for usedGids
    usedGids.setValue(usedGidsValue);
    try {
        session.getPerunBl().getAttributesManagerBl().setAttribute(session, gidNamespace, usedGids);
    } catch (WrongAttributeValueException ex) {
        throw new WrongReferenceAttributeValueException(attribute, usedGids, ex);
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with WrongAttributeAssignmentException

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

the class urn_perun_group_attribute_def_def_unixGroupName_namespace method changedAttributeHook.

@Override
public void changedAttributeHook(PerunSessionImpl session, Group group, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    //Need to know if this is remove or set, if value is null, its remove, otherway it is set
    String groupNameNamespace = attribute.getFriendlyNameParameter();
    try {
        if (attribute.getValue() == null) {
        //This is ok, for now no changes for removing some GroupName of this Group
        } else {
            //First need to find all facilities for the group
            Set<Facility> facilitiesOfGroup = new HashSet<Facility>();
            List<Resource> resourcesOfGroup = session.getPerunBl().getResourcesManagerBl().getAssignedResources(session, group);
            for (Resource r : resourcesOfGroup) {
                facilitiesOfGroup.add(session.getPerunBl().getResourcesManagerBl().getFacility(session, r));
            }
            //Prepare list of gid namespaces of all facilities which have the same groupName namespace like this unixGroupName namespace
            Set<String> gidNamespaces;
            gidNamespaces = session.getPerunBl().getModulesUtilsBl().getSetOfGIDNamespacesWhereFacilitiesHasTheSameGroupNameNamespace(session, new ArrayList<Facility>(facilitiesOfGroup), attribute);
            //If there is any gidNamespace which is need to be set, do it there
            if (!gidNamespaces.isEmpty()) {
                List<Attribute> gidsToSet = new ArrayList<>();
                for (String s : gidNamespaces) {
                    Attribute groupUnixGIDNamespace = session.getPerunBl().getAttributesManagerBl().getAttribute(session, group, A_G_unixGID_namespace + ":" + s);
                    //If attribute is not set, then set it (first fill, then set)
                    if (groupUnixGIDNamespace.getValue() == null) {
                        groupUnixGIDNamespace = session.getPerunBl().getAttributesManagerBl().fillAttribute(session, group, groupUnixGIDNamespace);
                        if (groupUnixGIDNamespace.getValue() == null)
                            throw new WrongReferenceAttributeValueException(attribute, groupUnixGIDNamespace);
                        //Set after fill (without check because all namespaces must be set before check (there can be relation between namespaces)
                        gidsToSet.add(groupUnixGIDNamespace);
                    }
                }
                //set and check if there is some gid to set
                if (!gidsToSet.isEmpty()) {
                    try {
                        session.getPerunBl().getAttributesManagerBl().setAttributes(session, group, gidsToSet);
                    } catch (WrongAttributeValueException e) {
                        throw new WrongReferenceAttributeValueException(attribute, e.getAttribute(), group, null, e.getAttributeHolder(), e.getAttributeHolderSecondary(), "Problem when setting all needed GIDs in hook.", e);
                    }
                }
            }
        }
    } catch (WrongAttributeAssignmentException ex) {
        //TODO: need to add WrongAttributeAssignmentException to header of modules methods
        throw new InternalErrorException(ex);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) Facility(cz.metacentrum.perun.core.api.Facility) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) HashSet(java.util.HashSet)

Example 4 with WrongAttributeAssignmentException

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

the class urn_perun_member_attribute_def_def_mail method changedAttributeHook.

@Override
public void changedAttributeHook(PerunSessionImpl session, Member member, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    User user = session.getPerunBl().getUsersManagerBl().getUserByMember(session, member);
    if (attribute.getValue() != null) {
        Attribute userPreferredMail = null;
        try {
            userPreferredMail = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, A_U_preferredMail);
            if (userPreferredMail.getValue() == null) {
                userPreferredMail.setValue(attribute.getValue());
                session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userPreferredMail);
            }
        } catch (WrongAttributeAssignmentException ex) {
            throw new InternalErrorException(ex);
        } catch (AttributeNotExistsException ex) {
            throw new ConsistencyErrorException(ex);
        } catch (WrongAttributeValueException ex) {
            throw new WrongReferenceAttributeValueException(attribute, userPreferredMail, "Mismatch in checking of member mail and user preferredMail (different checking rules).", ex);
        }
    }
/* This funcionality is not needed now
		//if this mail has been removed, check user preffered mail if the value is still correct, if not set a new one or remove it if no other exists
		User user = session.getPerunBl().getUsersManagerBl().getUserByMember(session, member);
		try {
		Attribute userPreferredMail = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, A_U_preferredMail);
		//TODO: if userPreferredMail is null when memberMail has been removed, its error in consistency, but exception is not solution, need to log it

		//If member mail has been removed
		if(attribute.getValue() == null) {
		try {
		session.getPerunBl().getAttributesManagerBl().checkAttributeValue(session, user, userPreferredMail);
		} catch (WrongAttributeValueException ex) {
		List<Member> membersOfUser = session.getPerunBl().getMembersManagerBl().getMembersByUser(session, user);
		for(Member m: membersOfUser) {
		Attribute memberMail = session.getPerunBl().getAttributesManagerBl().getAttribute(session, member, A_M_mail);
		if(memberMail.getValue() != null) {
		userPreferredMail.setValue(memberMail.getValue());
		session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userPreferredMail);
		break;
		}
		}
		userPreferredMail.setValue(null);
		session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userPreferredMail);

		}
		//if member mail was new set or set to another value
		} else {
		//if userPreferredMail is null, so can save this new value there
		if(userPreferredMail.getValue() == null) {
		userPreferredMail.setValue(attribute.getValue());
		session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userPreferredMail);

		//if userPreferredMail is not null, need to try if the old value is still correct, if not, save new value there
		} else {
		try {
		session.getPerunBl().getAttributesManagerBl().checkAttributeValue(session, user, userPreferredMail);
		} catch (WrongAttributeValueException ex) {
		//old value of userPreferredMail is not correct now, save the new value from member mail there
		userPreferredMail.setValue(attribute.getValue());
		session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, attribute);
		}
		}
		}
		} catch(WrongAttributeAssignmentException ex) {
		throw new InternalErrorException(ex);
		} catch(AttributeNotExistsException ex) {
		throw new ConsistencyErrorException(ex);
		} catch(WrongAttributeValueException ex) {
		throw new WrongReferenceAttributeValueException("There is mismatch between possible format of member mail and userPreferredMail", ex);
		}*/
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 5 with WrongAttributeAssignmentException

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

the class urn_perun_group_resource_attribute_def_virt_unixGID method setAttributeValue.

@Override
public boolean setAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    Attribute unixGIDNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGIDNamespaceAttributeWithNotNullValue(sess, resource);
    try {
        Attribute gidAttribute = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGID-namespace:" + unixGIDNamespaceAttribute.getValue()));
        gidAttribute.setValue(attribute.getValue());
        return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, group, gidAttribute);
    } catch (WrongAttributeValueException ex) {
        throw new InternalErrorException(ex);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)127 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)97 Attribute (cz.metacentrum.perun.core.api.Attribute)95 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)61 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)59 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)55 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)52 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)42 User (cz.metacentrum.perun.core.api.User)31 ArrayList (java.util.ArrayList)31 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)14 Facility (cz.metacentrum.perun.core.api.Facility)14 LinkedHashMap (java.util.LinkedHashMap)11 Member (cz.metacentrum.perun.core.api.Member)10 Map (java.util.Map)9 Group (cz.metacentrum.perun.core.api.Group)8 List (java.util.List)8 Resource (cz.metacentrum.perun.core.api.Resource)7 Vo (cz.metacentrum.perun.core.api.Vo)6 HashMap (java.util.HashMap)6