use of cz.metacentrum.perun.registrar.RegistrarModule in project perun by CESNET.
the class RegistrarManagerImpl method rejectApplication.
@Override
@Transactional(rollbackFor = Exception.class)
public Application rejectApplication(PerunSession sess, int appId, String reason) throws PerunException {
Application app = getApplicationById(appId);
if (app == null)
throw new RegistrarException("Application with ID=" + appId + " doesn't exists.");
// authz
if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, app.getVo())) {
if (app.getGroup() != null) {
if (!AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, app.getGroup())) {
throw new PrivilegeException(sess, "rejectApplication");
}
} else {
throw new PrivilegeException(sess, "rejectApplication");
}
}
// only VERIFIED applications can be rejected
if (AppState.APPROVED.equals(app.getState())) {
throw new RegistrarException("Approved application can't be rejected ! Try to refresh the view to see changes.");
} else if (AppState.REJECTED.equals(app.getState())) {
throw new RegistrarException("Application is already rejected. Try to refresh the view to see changes.");
}
// mark as rejected
int result = jdbc.update("update application set state=?, modified_by=?, modified_at=? where id=?", AppState.REJECTED.toString(), sess.getPerunPrincipal().getActor(), new Date(), appId);
if (result == 0) {
throw new RegistrarException("Application with ID=" + appId + " not found.");
} else if (result > 1) {
throw new ConsistencyErrorException("More than one application is stored under ID=" + appId + ".");
}
// set back as rejected
app.setState(AppState.REJECTED);
log.info("Application {} marked as REJECTED.", appId);
// get all reserved logins
List<Pair<String, String>> logins = jdbc.query("select namespace,login from application_reserved_logins where app_id=?", new RowMapper<Pair<String, String>>() {
@Override
public Pair<String, String> mapRow(ResultSet rs, int arg1) throws SQLException {
return new Pair<String, String>(rs.getString("namespace"), rs.getString("login"));
}
}, appId);
// delete passwords for reserved logins
for (Pair<String, String> login : logins) {
try {
// left = namespace / right = login
usersManager.deletePassword(registrarSession, login.getRight(), login.getLeft());
} catch (LoginNotExistsException ex) {
log.error("[REGISTRAR] Login: {} not exists while deleting passwords in rejected application: {}", login.getLeft(), appId);
}
}
// free any login from reservation when application is rejected
jdbc.update("delete from application_reserved_logins where app_id=?", appId);
// log
perun.getAuditer().log(sess, "{} rejected.", app);
// call registrar module
RegistrarModule module;
if (app.getGroup() != null) {
module = getRegistrarModule(getFormForGroup(app.getGroup()));
} else {
module = getRegistrarModule(getFormForVo(app.getVo()));
}
if (module != null) {
module.rejectApplication(sess, app, reason);
}
// send mail
getMailManager().sendMessage(app, MailType.APP_REJECTED_USER, reason, null);
perun.getAuditer().log(sess, "Application ID=" + app.getId() + " voID=" + app.getVo().getId() + ((app.getGroup() != null) ? (" groupID=" + app.getGroup().getId()) : "") + " has been rejected.");
// return updated application
return app;
}
Aggregations