public TasksEntry updateTasksEntryStatus(
      long tasksEntryId, long resolverUserId, int status, ServiceContext serviceContext)
      throws PortalException, SystemException {

    Date now = new Date();

    TasksEntry tasksEntry = tasksEntryPersistence.findByPrimaryKey(tasksEntryId);

    tasksEntry.setModifiedDate(now);

    if (status == TasksEntryConstants.STATUS_RESOLVED) {
      tasksEntry.setResolverUserId(resolverUserId);
      tasksEntry.setFinishDate(now);
    } else {
      tasksEntry.setResolverUserId(0);
      tasksEntry.setFinishDate(null);
    }

    tasksEntry.setStatus(status);

    tasksEntryPersistence.update(tasksEntry, false);

    return tasksEntry;
  }
  /**
   * 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 TasksEntry toModel(TasksEntrySoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    TasksEntry model = new TasksEntryImpl();

    model.setTasksEntryId(soapModel.getTasksEntryId());
    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.setTitle(soapModel.getTitle());
    model.setPriority(soapModel.getPriority());
    model.setAssigneeUserId(soapModel.getAssigneeUserId());
    model.setResolverUserId(soapModel.getResolverUserId());
    model.setDueDate(soapModel.getDueDate());
    model.setFinishDate(soapModel.getFinishDate());
    model.setStatus(soapModel.getStatus());

    return model;
  }
  public TasksEntry addTasksEntry(
      long userId,
      String title,
      int priority,
      long assigneeUserId,
      int dueDateMonth,
      int dueDateDay,
      int dueDateYear,
      int dueDateHour,
      int dueDateMinute,
      boolean neverDue,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Tasks entry

    User user = UserLocalServiceUtil.getUserById(userId);
    long groupId = serviceContext.getScopeGroupId();
    Date now = new Date();

    Date dueDate = null;

    if (!neverDue) {
      dueDate =
          PortalUtil.getDate(
              dueDateMonth,
              dueDateDay,
              dueDateYear,
              dueDateHour,
              dueDateMinute,
              user.getTimeZone(),
              new TasksEntryDueDateException());
    }

    long tasksEntryId = CounterLocalServiceUtil.increment();

    TasksEntry tasksEntry = tasksEntryPersistence.create(tasksEntryId);

    tasksEntry.setGroupId(groupId);
    tasksEntry.setCompanyId(user.getCompanyId());
    tasksEntry.setUserId(user.getUserId());
    tasksEntry.setUserName(user.getFullName());
    tasksEntry.setCreateDate(now);
    tasksEntry.setModifiedDate(now);
    tasksEntry.setTitle(title);
    tasksEntry.setPriority(priority);
    tasksEntry.setAssigneeUserId(assigneeUserId);
    tasksEntry.setDueDate(dueDate);
    tasksEntry.setStatus(TasksEntryConstants.STATUS_OPEN);

    tasksEntryPersistence.update(tasksEntry, false);

    // Asset

    updateAsset(
        userId,
        tasksEntry,
        serviceContext.getAssetCategoryIds(),
        serviceContext.getAssetTagNames());

    // Social

    SocialActivityLocalServiceUtil.addActivity(
        userId,
        groupId,
        TasksEntry.class.getName(),
        tasksEntryId,
        TasksActivityKeys.ADD_ENTRY,
        StringPool.BLANK,
        assigneeUserId);

    return tasksEntry;
  }
  public TasksEntry updateTasksEntry(
      long tasksEntryId,
      String title,
      int priority,
      long assigneeUserId,
      long resolverUserId,
      int dueDateMonth,
      int dueDateDay,
      int dueDateYear,
      int dueDateHour,
      int dueDateMinute,
      boolean neverDue,
      int status,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Tasks entry

    Date now = new Date();

    TasksEntry tasksEntry = tasksEntryPersistence.findByPrimaryKey(tasksEntryId);

    User user = UserLocalServiceUtil.getUserById(tasksEntry.getUserId());

    Date dueDate = null;

    if (!neverDue) {
      dueDate =
          PortalUtil.getDate(
              dueDateMonth,
              dueDateDay,
              dueDateYear,
              dueDateHour,
              dueDateMinute,
              user.getTimeZone(),
              new TasksEntryDueDateException());
    }

    tasksEntry.setModifiedDate(now);
    tasksEntry.setTitle(title);
    tasksEntry.setPriority(priority);
    tasksEntry.setAssigneeUserId(assigneeUserId);
    tasksEntry.setDueDate(dueDate);

    if (status == TasksEntryConstants.STATUS_RESOLVED) {
      tasksEntry.setResolverUserId(resolverUserId);
      tasksEntry.setFinishDate(now);
    } else {
      tasksEntry.setResolverUserId(0);
      tasksEntry.setFinishDate(null);
    }

    tasksEntry.setStatus(status);

    tasksEntryPersistence.update(tasksEntry, false);

    // Asset

    updateAsset(
        tasksEntry.getUserId(),
        tasksEntry,
        serviceContext.getAssetCategoryIds(),
        serviceContext.getAssetTagNames());

    // Social

    int activity = TasksActivityKeys.UPDATE_ENTRY;

    if (status == TasksEntryConstants.STATUS_RESOLVED) {
      activity = TasksActivityKeys.RESOLVE_ENTRY;
    } else if (status == TasksEntryConstants.STATUS_REOPENED) {
      activity = TasksActivityKeys.REOPEN_ENTRY;
    }

    SocialActivityLocalServiceUtil.addActivity(
        serviceContext.getUserId(),
        tasksEntry.getGroupId(),
        TasksEntry.class.getName(),
        tasksEntryId,
        activity,
        StringPool.BLANK,
        assigneeUserId);

    return tasksEntry;
  }