Search in sources :

Example 6 with AppType

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;
}
Also used : ItemTexts(cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts) AppType(cz.metacentrum.perun.registrar.model.Application.AppType) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AppType (cz.metacentrum.perun.registrar.model.Application.AppType)6 ApplicationFormItem (cz.metacentrum.perun.registrar.model.ApplicationFormItem)4 ItemTexts (cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts)4 Transactional (org.springframework.transaction.annotation.Transactional)3 SQLException (java.sql.SQLException)2 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)2 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)2 RegistrarModule (cz.metacentrum.perun.registrar.RegistrarModule)1 ApplicationForm (cz.metacentrum.perun.registrar.model.ApplicationForm)1 Type (cz.metacentrum.perun.registrar.model.ApplicationFormItem.Type)1 ApplicationFormItemData (cz.metacentrum.perun.registrar.model.ApplicationFormItemData)1 MailType (cz.metacentrum.perun.registrar.model.ApplicationMail.MailType)1