コード例 #1
0
  public String editPermission(final String permissionCode, final Model model)
      throws CMSItemNotFoundException {
    if (!model.containsAttribute("b2BPermissionForm")) {
      final B2BPermissionData b2BPermissionData =
          b2bCommercePermissionFacade.getPermissionDetails(permissionCode);
      final B2BPermissionForm b2BPermissionForm = new B2BPermissionForm();
      b2BPermissionForm.setCode(b2BPermissionData.getCode());
      b2BPermissionForm.setOriginalCode(b2BPermissionData.getCode());
      b2BPermissionForm.setParentUnitName(b2BPermissionData.getUnit().getUid());
      b2BPermissionForm.setPermissionType(b2BPermissionData.getB2BPermissionTypeData().getName());
      b2BPermissionForm.setB2BPermissionTypeData(b2BPermissionData.getB2BPermissionTypeData());
      if (!(B2BPermissionTypeEnum.B2BBUDGETEXCEEDEDPERMISSION.equals(
          B2BPermissionTypeEnum.valueOf(b2BPermissionData.getB2BPermissionTypeData().getCode())))) {
        b2BPermissionForm.setTimeSpan(b2BPermissionData.getTimeSpan());
        b2BPermissionForm.setValue(
            formatFactory.createNumberFormat().format(b2BPermissionData.getValue()));
        b2BPermissionForm.setCurrency(b2BPermissionData.getCurrency().getIsocode());
      }

      model.addAttribute(b2BPermissionForm);
    }
    storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE));
    setUpMetaDataForContentPage(
        model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE));
    final List<Breadcrumb> breadcrumbs =
        myCompanyBreadcrumbBuilder.createManagePermissionsBreadcrumb();
    breadcrumbs.add(
        new Breadcrumb(
            String.format(MANAGE_PERMISSIONS_EDIT_URL, permissionCode),
            getMessageSource()
                .getMessage(
                    "text.company.managePermissions.edit.page",
                    new Object[] {permissionCode},
                    "Edit Order Threshold {0}",
                    getI18nService().getCurrentLocale()),
            null));
    model.addAttribute("breadcrumbs", breadcrumbs);
    model.addAttribute("metaRobots", "no-index,no-follow");
    return ControllerConstants.Views.Pages.MyCompany.MyCompanyManagePermissionsEditPage;
  }
コード例 #2
0
  public String editPermission(
      final B2BPermissionForm b2BPermissionForm,
      final BindingResult bindingResult,
      final Model model,
      final RedirectAttributes redirectModel)
      throws CMSItemNotFoundException, ParseException {
    b2BPermissionFormValidator.validate(b2BPermissionForm, bindingResult);
    if (bindingResult.hasErrors()) {
      model.addAttribute(b2BPermissionForm);
      GlobalMessages.addErrorMessage(model, "form.global.error");
      return editPermission(b2BPermissionForm.getOriginalCode(), model);
    }

    final B2BPermissionData b2BPermissionData =
        populateB2BPermissionDataFromForm(b2BPermissionForm);
    try {
      b2bCommercePermissionFacade.updatePermissionDetails(b2BPermissionData);
    } catch (final Exception e) {
      LOG.warn("Exception while saving the permission details " + e);
      model.addAttribute(b2BPermissionForm);
      GlobalMessages.addErrorMessage(model, "form.global.error");
      bindingResult.rejectValue("code", "text.company.managePermissions.code.exists.error.title");
      return editPermission(b2BPermissionForm.getOriginalCode(), model);
    }
    storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE));
    setUpMetaDataForContentPage(
        model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE));
    final List<Breadcrumb> breadcrumbs =
        myCompanyBreadcrumbBuilder.createManagePermissionsBreadcrumb();
    breadcrumbs.add(
        new Breadcrumb(
            "/my-company/organization-management/manage-budgets/update",
            getMessageSource()
                .getMessage(
                    "text.company.budget.editPage", null, getI18nService().getCurrentLocale()),
            null));
    model.addAttribute("breadcrumbs", breadcrumbs);

    GlobalMessages.addFlashMessage(
        redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "text.confirmation.permission.updated");
    return String.format(REDIRECT_TO_PERMISSION_DETAILS, urlEncode(b2BPermissionData.getCode()));
  }