/**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static ShoppingCategory toModel(ShoppingCategorySoap soapModel) {
    ShoppingCategory model = new ShoppingCategoryImpl();

    model.setCategoryId(soapModel.getCategoryId());
    model.setGroupId(soapModel.getGroupId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setParentCategoryId(soapModel.getParentCategoryId());
    model.setName(soapModel.getName());
    model.setDescription(soapModel.getDescription());

    return model;
  }
  @Override
  public ShoppingCategory addCategory(
      long userId,
      long parentCategoryId,
      String name,
      String description,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Category

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();
    parentCategoryId = getParentCategoryId(groupId, parentCategoryId);
    Date now = new Date();

    validate(name);

    long categoryId = counterLocalService.increment();

    ShoppingCategory category = shoppingCategoryPersistence.create(categoryId);

    category.setGroupId(groupId);
    category.setCompanyId(user.getCompanyId());
    category.setUserId(user.getUserId());
    category.setUserName(user.getFullName());
    category.setCreateDate(now);
    category.setModifiedDate(now);
    category.setParentCategoryId(parentCategoryId);
    category.setName(name);
    category.setDescription(description);

    shoppingCategoryPersistence.update(category);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

      addCategoryResources(
          category, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      addCategoryResources(
          category, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    return category;
  }
  @Override
  public ShoppingCategory updateCategory(
      long categoryId,
      long parentCategoryId,
      String name,
      String description,
      boolean mergeWithParentCategory,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Merge categories

    ShoppingCategory category = shoppingCategoryPersistence.findByPrimaryKey(categoryId);

    parentCategoryId = getParentCategoryId(category, parentCategoryId);

    if (mergeWithParentCategory
        && (categoryId != parentCategoryId)
        && (parentCategoryId != ShoppingCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)) {

      mergeCategories(category, parentCategoryId);

      return category;
    }

    // Category

    validate(name);

    category.setModifiedDate(new Date());
    category.setParentCategoryId(parentCategoryId);
    category.setName(name);
    category.setDescription(description);

    shoppingCategoryPersistence.update(category);

    return category;
  }