Search in sources :

Example 1 with ResourceExistsException

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

the class ResourcesManagerBlImpl method updateResource.

@Override
public Resource updateResource(PerunSession sess, Resource resource) throws ResourceExistsException {
    Facility facility = getFacility(sess, resource);
    Vo vo = getVo(sess, resource);
    try {
        Resource existingResource = getResourcesManagerImpl().getResourceByName(sess, vo, facility, resource.getName());
        // if it is the same resource which is updated but the name stayed the same.
        if (existingResource.getId() == resource.getId()) {
            resource = getResourcesManagerImpl().updateResource(sess, resource);
            getPerunBl().getAuditer().log(sess, new ResourceUpdated(resource));
            return resource;
        }
        // because there is already a resource with this name but with different id.
        throw new ResourceExistsException(existingResource);
    } catch (ResourceNotExistsException e) {
        resource = getResourcesManagerImpl().updateResource(sess, resource);
        getPerunBl().getAuditer().log(sess, new ResourceUpdated(resource));
    }
    return resource;
}
Also used : ResourceExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceExistsException) BanSetForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) BanUpdatedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanUpdatedForResource) BanRemovedForResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanRemovedForResource) Resource(cz.metacentrum.perun.core.api.Resource) ServiceRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceRemovedFromResource) GroupAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource) ServiceAssignedToResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource) GroupRemovedFromResource(cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupRemovedFromResource) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) RichResource(cz.metacentrum.perun.core.api.RichResource) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) Vo(cz.metacentrum.perun.core.api.Vo) Facility(cz.metacentrum.perun.core.api.Facility) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) ResourceUpdated(cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceUpdated)

Aggregations

BanRemovedForResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanRemovedForResource)1 BanSetForResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanSetForResource)1 BanUpdatedForResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.BanUpdatedForResource)1 GroupAssignedToResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource)1 GroupRemovedFromResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupRemovedFromResource)1 ResourceUpdated (cz.metacentrum.perun.audit.events.ResourceManagerEvents.ResourceUpdated)1 ServiceAssignedToResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceAssignedToResource)1 ServiceRemovedFromResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.ServiceRemovedFromResource)1 AssignedResource (cz.metacentrum.perun.core.api.AssignedResource)1 BanOnResource (cz.metacentrum.perun.core.api.BanOnResource)1 EnrichedResource (cz.metacentrum.perun.core.api.EnrichedResource)1 Facility (cz.metacentrum.perun.core.api.Facility)1 Resource (cz.metacentrum.perun.core.api.Resource)1 RichResource (cz.metacentrum.perun.core.api.RichResource)1 Vo (cz.metacentrum.perun.core.api.Vo)1 ResourceExistsException (cz.metacentrum.perun.core.api.exceptions.ResourceExistsException)1 ResourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException)1