use of cz.metacentrum.perun.registrar.model.Application.AppType in project perun by CESNET.
the class RegistrarManagerImpl method addFormItem.
@Transactional
@Override
public ApplicationFormItem addFormItem(PerunSession user, ApplicationForm form, ApplicationFormItem item) throws PrivilegeException, InternalErrorException {
if (form.getGroup() == null) {
// VO application
if (!AuthzResolver.isAuthorized(user, Role.VOADMIN, form.getVo())) {
throw new PrivilegeException(user, "addFormItem");
}
} else {
if (!AuthzResolver.isAuthorized(user, Role.VOADMIN, form.getVo()) && !AuthzResolver.isAuthorized(user, Role.GROUPADMIN, form.getGroup())) {
throw new PrivilegeException(user, "addFormItem");
}
}
// find the ordinal number of the next item
int ordnum = 0;
if (item.getOrdnum() == null || item.getOrdnum() < 0) {
if (jdbc.queryForInt("select count(*) from application_form_items where form_id=?", form.getId()) > 0) {
ordnum = jdbc.queryForInt("select max(ordnum)+1 from application_form_items where form_id=?", form.getId());
}
} else {
// use predefined ordnum
ordnum = item.getOrdnum();
}
int itemId = Utils.getNewId(jdbc, "APPLICATION_FORM_ITEMS_ID_SEQ");
jdbc.update("insert into application_form_items(id,form_id,ordnum,shortname,required,type,fed_attr,dst_attr,regex) values (?,?,?,?,?,?,?,?,?)", itemId, form.getId(), ordnum, item.getShortname(), item.isRequired() ? "1" : "0", item.getType().name(), item.getFederationAttribute(), item.getPerunDestinationAttribute(), item.getRegex());
// create texts
for (Locale locale : item.getI18n().keySet()) {
ItemTexts itemTexts = item.getTexts(locale);
jdbc.update("insert into application_form_item_texts(item_id,locale,label,options,help,error_message) values (?,?,?,?,?,?)", itemId, locale.getLanguage(), itemTexts.getLabel(), itemTexts.getOptions(), itemTexts.getHelp(), itemTexts.getErrorMessage());
}
for (AppType appType : item.getApplicationTypes()) {
jdbc.update("insert into application_form_item_apptypes (item_id,apptype) values (?,?)", itemId, appType.toString());
}
// set new properties back to object & return
item.setOrdnum(ordnum);
item.setId(itemId);
perun.getAuditer().log(user, "Application form item ID=" + form.getId() + " voID=" + form.getVo().getId() + ((form.getGroup() != null) ? (" groupID=" + form.getGroup().getId()) : "") + " has been added");
return item;
}
Aggregations