/*
   * (non-Javadoc)
   *
   * @see
   * org.adorsys.platform.domain.service.ApplicationInitService#initUserAccount
   * (org.adorsys.platform.domain.PlatformUser)
   */
  @Override
  public boolean initUserAccount() {
    try {
      if (UserAccount.countUserAccounts() < 1) {
        Set<RoleNames> roleNames = this.constructRoleNames(RoleNames.ADMIN, RoleNames.DRUGSTORE);
        UserAccount userAccount =
            new UserAccount(
                "gakam",
                "test123",
                DateUtils.addYears(new Date(), 20),
                DateUtils.addYears(new Date(), 1),
                false,
                roleNames);
        userAccount.setPlatformUser(PlatformUser.findPlatformUser(Long.valueOf(1)));
        userAccount.persistUserAndSendMessage(userAccount);
      }
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }

    try {
      if (UserAccount.countUserAccounts() == 1) {
        Set<RoleNames> roleNames = this.constructRoleNames(RoleNames.ADMIN, RoleNames.PROVIDER);
        UserAccount userAccount2 =
            new UserAccount(
                "hsimo",
                "test123",
                DateUtils.addYears(new Date(), 20),
                DateUtils.addYears(new Date(), 1),
                false,
                roleNames);
        userAccount2.setPlatformUser(PlatformUser.findPlatformUser(Long.valueOf(2)));
        userAccount2.persistUserAndSendMessage(userAccount2);
      }
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }
 /**
  * 获取新的日期 + 年份
  *
  * @param date1 the date1
  * @param year the year
  * @return the date
  */
 public static Date addYears(Date date1, int year) {
   return DateUtils.addYears(date1, year);
 }
  private String getFormatDate(String infmt, String date, String outfmt) throws ParseException {
    if (date == null || date.length() <= 0) {
      return "";
    }
    if (date.length() == 1) {
      Date today = Calendar.getInstance().getTime();
      return DateFormatUtils.format(today, outfmt);
    } else {
      int plus = date.indexOf('+');
      int minus = date.indexOf('-');
      if (plus > 0 || minus > 0) {
        Date today = Calendar.getInstance().getTime();
        String type = date.substring(0, 1);
        String sign = date.substring(1, 2);
        int amount = 0;
        try {
          amount = Integer.parseInt(date.substring(2));
        } catch (NumberFormatException e) {
          LOG.error("Exception", e);
          return null;
        }
        if (("+").equals(sign)) {
          if (("D").equals(type)) {
            return DateFormatUtils.format(DateUtils.addDays(today, amount), outfmt);
          } else if (("M").equals(type)) {
            return DateFormatUtils.format(DateUtils.addMonths(today, amount), outfmt);
          } else if (("Y").equals(type)) {
            return DateFormatUtils.format(DateUtils.addYears(today, amount), outfmt);
          }
        } else if (("-").equals(sign)) {
          if (("D").equals(type)) {
            return DateFormatUtils.format(DateUtils.addDays(today, -amount), outfmt);
          } else if (("M").equals(type)) {
            return DateFormatUtils.format(DateUtils.addMonths(today, -amount), outfmt);
          } else if (("Y").equals(type)) {
            return DateFormatUtils.format(DateUtils.addYears(today, -amount), outfmt);
          }
        } else {
          return null;
        }
      }
    }

    // date 형식이  infmt 에 맞지 않다면 date 를 infmt 에 맞추어줌.
    StringBuilder sDate = new StringBuilder(date);
    int len = date.length();

    if (("yyyyMMddHHmm").equals(infmt) && len < 12) {
      for (int i = len; i < 12; i++) {
        sDate.append("0");
      }
    } else if (("yyyyMMddHHmmss").equals(infmt) && len < 14) {
      for (int i = len; i < 14; i++) {
        sDate.append("0");
      }
    }

    SimpleDateFormat sdf = new SimpleDateFormat(infmt);
    Date d = sdf.parse(sDate.toString());
    sdf.applyPattern(outfmt);

    return sdf.format(d);
  }