Search in sources :

Example 1 with FacilityExistsException

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

the class FacilitiesManagerBlImpl method createFacility.

@Override
public Facility createFacility(PerunSession sess, Facility facility) throws FacilityExistsException {
    // check facility name, it can contain only a-zA-Z.0-9_-
    if (!facility.getName().matches("^[ a-zA-Z.0-9_-]+$")) {
        throw new IllegalArgumentException("Wrong facility name, facility name can contain only a-Z0-9.-_ and space characters");
    }
    // check if facility have uniq name
    try {
        this.getFacilityByName(sess, facility.getName());
        throw new FacilityExistsException(facility);
    } catch (FacilityNotExistsException ex) {
    /* OK */
    }
    // create facility
    facility = getFacilitiesManagerImpl().createFacility(sess, facility);
    getPerunBl().getAuditer().log(sess, new FacilityCreated(facility));
    // set creator as Facility manager
    if (sess.getPerunPrincipal().getUser() != null) {
        try {
            AuthzResolverBlImpl.setRole(sess, sess.getPerunPrincipal().getUser(), facility, Role.FACILITYADMIN);
        } catch (AlreadyAdminException ex) {
            throw new ConsistencyErrorException("Add manager to newly created Facility failed because there is particular manager already assigned", ex);
        } catch (RoleCannotBeManagedException e) {
            throw new InternalErrorException(e);
        }
    } else {
        log.warn("Can't set Facility manager during creating of the Facility. User from perunSession is null. {} {}", facility, sess);
    }
    return facility;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) FacilityCreated(cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated) FacilityExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityExistsException) FacilityNotExistsException(cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException) RoleCannotBeManagedException(cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)

Aggregations

FacilityCreated (cz.metacentrum.perun.audit.events.FacilityManagerEvents.FacilityCreated)1 AlreadyAdminException (cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1 FacilityExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityExistsException)1 FacilityNotExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException)1 IllegalArgumentException (cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 RoleCannotBeManagedException (cz.metacentrum.perun.core.api.exceptions.RoleCannotBeManagedException)1