@Override
  public void updateUsername(String externalId, String username) {
    InternalAuthDAO internalAuthDAO = DAOFactory.getInstance().getInternalAuthDAO();

    InternalAuth internalAuth = internalAuthDAO.findById(NumberUtils.createLong(externalId));
    internalAuthDAO.updateUsername(internalAuth, username);
  }
  public void process(JSONRequestContext jsonRequestContext) {
    ResourceDAO resourceDAO = DAOFactory.getInstance().getResourceDAO();
    ResourceCategoryDAO resourceCategoryDAO = DAOFactory.getInstance().getResourceCategoryDAO();
    WorkResourceDAO workResourceDAO = DAOFactory.getInstance().getWorkResourceDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();

    String name = jsonRequestContext.getRequest().getParameter("name");
    Long resourceId =
        NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("resource"));
    Double hourlyCost =
        NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("hourlyCost"));
    Double costPerUse =
        NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("costPerUse"));
    Long version = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("version"));
    String tagsText = jsonRequestContext.getString("tags");

    Set<Tag> tagEntities = new HashSet<Tag>();
    if (!StringUtils.isBlank(tagsText)) {
      List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
      for (String tag : tags) {
        if (!StringUtils.isBlank(tag)) {
          Tag tagEntity = tagDAO.findByText(tag.trim());
          if (tagEntity == null) tagEntity = tagDAO.create(tag);
          tagEntities.add(tagEntity);
        }
      }
    }

    WorkResource workResource = workResourceDAO.findById(resourceId);
    if (!version.equals(workResource.getVersion()))
      throw new SmvcRuntimeException(
          PyramusStatusCode.CONCURRENT_MODIFICATION,
          Messages.getInstance()
              .getText(
                  jsonRequestContext.getRequest().getLocale(),
                  "generic.errors.concurrentModification"));

    ResourceCategory resourceCategory =
        resourceCategoryDAO.findById(
            NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("category")));

    workResourceDAO.update(workResource, name, resourceCategory, costPerUse, hourlyCost);
    resourceDAO.setResourceTags(workResource, tagEntities);

    jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
  }
  /**
   * Returns the username of a user corresponding to the given identifier, or <code>null</code> if
   * not found.
   *
   * @param externalId The user identifier
   * @return The username of the user corresponding to the given identifier, or <code>null</code> if
   *     not found
   */
  public String getUsername(String externalId) {
    InternalAuthDAO internalAuthDAO = DAOFactory.getInstance().getInternalAuthDAO();

    Long internalAuthId = NumberUtils.createLong(externalId);
    if (internalAuthId != null && internalAuthId > 0) {
      InternalAuth internalAuth = internalAuthDAO.findById(internalAuthId);
      return internalAuth == null ? null : internalAuth.getUsername();
    }

    return null;
  }
  @Override
  public void updatePassword(String externalId, String password) {
    InternalAuthDAO internalAuthDAO = DAOFactory.getInstance().getInternalAuthDAO();

    try {
      InternalAuth internalAuth = internalAuthDAO.findById(NumberUtils.createLong(externalId));

      String newPasswordEncoded = EncodingUtils.md5EncodeString(password);
      internalAuthDAO.updatePassword(internalAuth, newPasswordEncoded);
    } catch (UnsupportedEncodingException e) {
      throw new SmvcRuntimeException(e);
    } catch (NoSuchAlgorithmException e) {
      throw new SmvcRuntimeException(e);
    }
  }
 public static Long getIdFromSlug(String slug) {
   return NumberUtils.createLong(StringUtils.substringAfterLast(slug, "@"));
 }