Search in sources :

Example 1 with ItemTexts

use of cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts in project perun by CESNET.

the class RegistrarManagerImpl method getFormItemById.

@Override
public ApplicationFormItem getFormItemById(int id) {
    ApplicationFormItem item;
    item = jdbc.queryForObject(FORM_ITEM_SELECT + " where id=?", ITEM_MAPPER, id);
    if (item != null) {
        List<ItemTexts> texts = jdbc.query(FORM_ITEM_TEXTS_SELECT + " where item_id=?", ITEM_TEXTS_MAPPER, item.getId());
        for (ItemTexts itemTexts : texts) {
            item.getI18n().put(itemTexts.getLocale(), itemTexts);
        }
        List<AppType> appTypes = jdbc.query(APP_TYPE_SELECT + " where item_id=?", APP_TYPE_MAPPER, item.getId());
        item.setApplicationTypes(appTypes);
    }
    return item;
}
Also used : ApplicationFormItem(cz.metacentrum.perun.registrar.model.ApplicationFormItem) ItemTexts(cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts) AppType(cz.metacentrum.perun.registrar.model.Application.AppType)

Example 2 with ItemTexts

use of cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts in project perun by CESNET.

the class RegistrarManagerImpl method getFormItems.

@Override
public List<ApplicationFormItem> getFormItems(PerunSession sess, ApplicationForm form, AppType appType) throws PerunException {
    // authz
    if (form.getGroup() == null) {
        if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo()) && !AuthzResolver.isAuthorized(sess, Role.VOOBSERVER, form.getVo())) {
            throw new PrivilegeException("getFormItems");
        }
    } else {
        if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo()) && !AuthzResolver.isAuthorized(sess, Role.VOOBSERVER, form.getVo()) && !AuthzResolver.isAuthorized(sess, Role.TOPGROUPCREATOR, form.getVo()) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, form.getGroup())) {
            throw new PrivilegeException("getFormItems");
        }
    }
    List<ApplicationFormItem> items;
    if (appType == null) {
        items = jdbc.query(FORM_ITEM_SELECT + " where form_id=? order by ordnum asc", ITEM_MAPPER, form.getId());
    } else {
        items = jdbc.query(FORM_ITEM_SELECT + " i,application_form_item_apptypes t where form_id=? and i.id=t.item_id and t.apptype=? order by ordnum asc", ITEM_MAPPER, form.getId(), appType.toString());
    }
    for (ApplicationFormItem item : items) {
        List<ItemTexts> texts = jdbc.query(FORM_ITEM_TEXTS_SELECT + " where item_id=?", ITEM_TEXTS_MAPPER, item.getId());
        for (ItemTexts itemTexts : texts) {
            item.getI18n().put(itemTexts.getLocale(), itemTexts);
        }
        List<AppType> appTypes = jdbc.query(APP_TYPE_SELECT + " where item_id=?", APP_TYPE_MAPPER, item.getId());
        item.setApplicationTypes(appTypes);
    }
    return items;
}
Also used : ApplicationFormItem(cz.metacentrum.perun.registrar.model.ApplicationFormItem) ItemTexts(cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts) AppType(cz.metacentrum.perun.registrar.model.Application.AppType)

Example 3 with ItemTexts

use of cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts in project perun by CESNET.

the class RegistrarManagerImpl method updateFormItemTexts.

@Override
public void updateFormItemTexts(PerunSession sess, ApplicationFormItem item, Locale locale) {
    ItemTexts texts = item.getTexts(locale);
    jdbc.update("update application_form_item_texts set label=?,options=?,help=?,error_message=? where item_id=? and locale=?", texts.getLabel(), texts.getOptions(), texts.getHelp(), texts.getErrorMessage(), item.getId(), locale.getLanguage());
}
Also used : ItemTexts(cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts)

Example 4 with ItemTexts

use of cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts in project perun by CESNET.

the class RegistrarManagerImpl method updateFormItems.

@Override
@Transactional(rollbackFor = Exception.class)
public int updateFormItems(PerunSession sess, ApplicationForm form, List<ApplicationFormItem> items) throws PrivilegeException, InternalErrorException {
    if (form.getGroup() == null) {
        // VO application
        if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo())) {
            throw new PrivilegeException(sess, "updateFormItems");
        }
    } else {
        if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, form.getVo()) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, form.getGroup())) {
            throw new PrivilegeException(sess, "updateFormItems");
        }
    }
    if (items == null) {
        throw new NullPointerException("ApplicationFormItems to update can't be null");
    }
    int finalResult = 0;
    for (ApplicationFormItem item : items) {
        // is item to create ? => create
        if (item.getId() == 0 && !item.isForDelete()) {
            if (addFormItem(sess, form, item) != null) {
                finalResult++;
            }
            continue;
        }
        // is item for deletion ? => delete on cascade
        if (item.isForDelete()) {
            finalResult += jdbc.update("delete from application_form_items where id=?", item.getId());
            // continue to next item
            continue;
        }
        // else update form item
        int result = jdbc.update("update application_form_items set ordnum=?,shortname=?,required=?,type=?,fed_attr=?,dst_attr=?,regex=? where id=?", item.getOrdnum(), item.getShortname(), item.isRequired() ? "1" : "0", item.getType().toString(), item.getFederationAttribute(), item.getPerunDestinationAttribute(), item.getRegex(), item.getId());
        finalResult += result;
        if (result == 0) {
            // skip whole set if not found for update
            continue;
        }
        // update form item texts (easy way = delete and new insert)
        // delete
        jdbc.update("delete from application_form_item_texts where item_id=?", item.getId());
        // insert new
        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 (?,?,?,?,?,?)", item.getId(), locale.getLanguage(), itemTexts.getLabel(), itemTexts.getOptions(), itemTexts.getHelp(), itemTexts.getErrorMessage());
        }
        // update form item app types (easy way = delete and new insert)
        // delete
        jdbc.update("delete from application_form_item_apptypes where item_id=?", item.getId());
        // insert new
        for (AppType appType : item.getApplicationTypes()) {
            jdbc.update("insert into application_form_item_apptypes (item_id,apptype) values (?,?)", item.getId(), appType.toString());
        }
    }
    perun.getAuditer().log(sess, "Application form ID=" + form.getId() + " voID=" + form.getVo().getId() + ((form.getGroup() != null) ? (" groupID=" + form.getGroup().getId()) : "") + " has had its items updated.");
    // return number of updated rows
    return finalResult;
}
Also used : ApplicationFormItem(cz.metacentrum.perun.registrar.model.ApplicationFormItem) ItemTexts(cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts) AppType(cz.metacentrum.perun.registrar.model.Application.AppType) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with ItemTexts

use of cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts 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

ItemTexts (cz.metacentrum.perun.registrar.model.ApplicationFormItem.ItemTexts)5 AppType (cz.metacentrum.perun.registrar.model.Application.AppType)4 ApplicationFormItem (cz.metacentrum.perun.registrar.model.ApplicationFormItem)3 Transactional (org.springframework.transaction.annotation.Transactional)2