protected B2BPermissionData populateB2BPermissionDataFromForm(
      final B2BPermissionForm b2BPermissionForm) throws ParseException {
    final B2BPermissionData b2BPermissionData = new B2BPermissionData();
    b2BPermissionData.setOriginalCode(b2BPermissionForm.getOriginalCode());
    final String permissionCode = b2BPermissionForm.getCode();
    if (StringUtils.isNotEmpty(permissionCode)) {
      b2BPermissionData.setCode(permissionCode);
    } else {
      b2BPermissionData.setCode(assignPermissionName(b2BPermissionForm));
    }
    final B2BPermissionTypeData b2BPermissionTypeData =
        b2BPermissionForm.getB2BPermissionTypeData();
    b2BPermissionData.setB2BPermissionTypeData(b2BPermissionTypeData);
    final CurrencyData currencyData = new CurrencyData();
    currencyData.setIsocode(b2BPermissionForm.getCurrency());
    b2BPermissionData.setCurrency(currencyData);

    b2BPermissionData.setUnit(
        companyB2BCommerceFacade.getUnitForUid(b2BPermissionForm.getParentUnitName()));
    final String permissionTimespan = b2BPermissionForm.getTimeSpan();
    if (StringUtils.isNotEmpty(permissionTimespan)) {
      b2BPermissionData.setPeriodRange(B2BPeriodRange.valueOf(b2BPermissionForm.getTimeSpan()));
    }
    final String monetaryValue = b2BPermissionForm.getValue();
    if (StringUtils.isNotEmpty(monetaryValue)) {
      b2BPermissionData.setValue(
          Double.valueOf(formatFactory.createNumberFormat().parse(monetaryValue).doubleValue()));
    }
    return b2BPermissionData;
  }
  protected String assignPermissionName(final B2BPermissionForm b2BPermissionForm) {
    final StringBuilder permissionCode = new StringBuilder();
    final String permissionType = b2BPermissionForm.getB2BPermissionTypeData().getCode();

    if (!B2BPermissionTypeEnum.B2BBUDGETEXCEEDEDPERMISSION.equals(
        B2BPermissionTypeEnum.valueOf(permissionType))) {
      final String currency = b2BPermissionForm.getCurrency();
      permissionCode.append((StringUtils.isNotEmpty(currency) ? currency : ""));
      permissionCode.append(SINGLE_WHITEPSACE);
      permissionCode.append(b2BPermissionForm.getValue());
      permissionCode.append(SINGLE_WHITEPSACE);
      permissionCode.append(
          getMessageSource()
              .getMessage(
                  "text.company.managePermissions.assignName.per",
                  null,
                  getI18nService().getCurrentLocale()));
      permissionCode.append(SINGLE_WHITEPSACE);
      final String timespan = b2BPermissionForm.getTimeSpan();
      permissionCode.append(
          (StringUtils.isNotEmpty(timespan)
              ? timespan
              : getMessageSource()
                  .getMessage(
                      "text.company.managePermissions.assignName.order",
                      null,
                      getI18nService().getCurrentLocale())));
    } else {
      permissionCode.append(
          getMessageSource()
              .getMessage(
                  "text.company.managePermissions.assignName.budget",
                  null,
                  getI18nService().getCurrentLocale()));
      permissionCode.append(SINGLE_WHITEPSACE);
      permissionCode.append(b2BPermissionForm.getParentUnitName());
    }

    b2BPermissionForm.setCode(permissionCode.toString());
    return permissionCode.toString();
  }