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;
}
Aggregations