@Override
  public FriendlyURL saveStagedModel(FriendlyURL friendlyURL) throws PortalException {

    if (friendlyURL.isMain()) {
      FriendlyURL mainFriendlyURL =
          _friendlyURLLocalService.getMainFriendlyURL(
              friendlyURL.getCompanyId(), friendlyURL.getGroupId(),
              friendlyURL.getClassNameId(), friendlyURL.getClassPK());

      if (!mainFriendlyURL.equals(friendlyURL)) {
        mainFriendlyURL.setMain(false);

        _friendlyURLLocalService.updateFriendlyURL(mainFriendlyURL);
      }
    }

    friendlyURL.setUrlTitle(
        _friendlyURLLocalService.getUniqueUrlTitle(
            friendlyURL.getCompanyId(),
            friendlyURL.getGroupId(),
            friendlyURL.getClassNameId(),
            friendlyURL.getClassPK(),
            friendlyURL.getUrlTitle()));

    return _friendlyURLLocalService.updateFriendlyURL(friendlyURL);
  }