@Override
  public int compareTo(TasksEntry tasksEntry) {
    int value = 0;

    if (getPriority() < tasksEntry.getPriority()) {
      value = -1;
    } else if (getPriority() > tasksEntry.getPriority()) {
      value = 1;
    } else {
      value = 0;
    }

    if (value != 0) {
      return value;
    }

    value = DateUtil.compareTo(getDueDate(), tasksEntry.getDueDate());

    if (value != 0) {
      return value;
    }

    value = DateUtil.compareTo(getCreateDate(), tasksEntry.getCreateDate());

    if (value != 0) {
      return value;
    }

    return 0;
  }
  public void updateAsset(
      long userId, TasksEntry tasksEntry, long[] assetCategoryIds, String[] assetTagNames)
      throws PortalException, SystemException {

    AssetEntryLocalServiceUtil.updateEntry(
        userId,
        tasksEntry.getGroupId(),
        TasksEntry.class.getName(),
        tasksEntry.getTasksEntryId(),
        assetCategoryIds,
        assetTagNames);
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof TasksEntry)) {
      return false;
    }

    TasksEntry tasksEntry = (TasksEntry) obj;

    long primaryKey = tasksEntry.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  @Override
  public void deleteTasksEntry(TasksEntry tasksEntry) throws PortalException, SystemException {

    // Tasks entry

    tasksEntryPersistence.remove(tasksEntry);

    // Asset

    AssetEntryLocalServiceUtil.deleteEntry(
        TasksEntry.class.getName(), tasksEntry.getTasksEntryId());

    // Message boards

    MBMessageLocalServiceUtil.deleteDiscussionMessages(
        TasksEntry.class.getName(), tasksEntry.getTasksEntryId());

    // Social

    SocialActivityLocalServiceUtil.deleteActivities(
        TasksEntry.class.getName(), tasksEntry.getTasksEntryId());
  }
  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;
  }
  public static boolean contains(
      PermissionChecker permissionChecker, TasksEntry tasksEntry, String actionId) {

    if (permissionChecker.getUserId() == tasksEntry.getAssigneeUserId()) {
      return true;
    }

    if (permissionChecker.hasOwnerPermission(
        tasksEntry.getCompanyId(),
        TasksEntry.class.getName(),
        tasksEntry.getTasksEntryId(),
        tasksEntry.getUserId(),
        actionId)) {

      return true;
    }

    return permissionChecker.hasPermission(
        tasksEntry.getGroupId(),
        TasksEntry.class.getName(),
        tasksEntry.getTasksEntryId(),
        actionId);
  }
  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;
  }
  /**
   * 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;
  }