/**
   * Unselects the entities
   *
   * @return the SUCCESS result
   */
  public String unselect() throws ServiceException {
    Campaign campaign = null;
    Set<TargetList> targetLists = null;

    if ("Campaign".equals(this.getRelationKey())) {
      campaign =
          campaignService.getEntityById(Campaign.class, Integer.valueOf(this.getRelationValue()));
      targetLists = campaign.getTargetLists();
    }

    if (this.getSeleteIDs() != null) {
      String[] ids = seleteIDs.split(",");
      Collection<TargetList> selectedTargetLists = new ArrayList<TargetList>();
      for (int i = 0; i < ids.length; i++) {
        Integer selectId = Integer.valueOf(ids[i]);
        A:
        for (TargetList targetList : targetLists) {
          if (targetList.getId().intValue() == selectId.intValue()) {
            selectedTargetLists.add(targetList);
            break A;
          }
        }
      }
      targetLists.removeAll(selectedTargetLists);
    }

    if ("Campaign".equals(this.getRelationKey())) {
      campaignService.makePersistent(campaign);
    }
    return SUCCESS;
  }
  /**
   * Imports the entities
   *
   * @return the SUCCESS result
   */
  public String importCSV() throws Exception {
    File file = this.getUpload();
    CsvListReader reader = new CsvListReader(new FileReader(file), CsvPreference.EXCEL_PREFERENCE);
    int failedNum = 0;
    int successfulNum = 0;
    try {
      final String[] header = reader.getCSVHeader(true);

      List<String> line = new ArrayList<String>();
      Map<String, String> failedMsg = new HashMap<String, String>();
      while ((line = reader.read()) != null) {

        Map<String, String> row = new HashMap<String, String>();
        for (int i = 0; i < line.size(); i++) {
          row.put(header[i], line.get(i));
        }

        TargetList targetList = new TargetList();
        try {
          String id = row.get(getText("entity.id.label"));
          if (!CommonUtil.isNullOrEmpty(id)) {
            targetList.setId(Integer.parseInt(id));
          }
          targetList.setName(CommonUtil.fromNullToEmpty(row.get(getText("entity.name.label"))));
          targetList.setDescription(
              CommonUtil.fromNullToEmpty(row.get(getText("entity.description.label"))));
          targetList.setNotes(CommonUtil.fromNullToEmpty(row.get(getText("entity.notes.label"))));
          String assignedToID = row.get(getText("entity.assigned_to_id.label"));
          if (CommonUtil.isNullOrEmpty(assignedToID)) {
            targetList.setAssigned_to(null);
          } else {
            User assignedTo = userService.getEntityById(User.class, Integer.parseInt(assignedToID));
            targetList.setAssigned_to(assignedTo);
          }
          baseService.makePersistent(targetList);
          successfulNum++;
        } catch (Exception e) {
          failedNum++;
          String Name = CommonUtil.fromNullToEmpty(targetList.getName());
          failedMsg.put(Name, e.getMessage());
        }
      }

      this.setFailedMsg(failedMsg);
      this.setFailedNum(failedNum);
      this.setSuccessfulNum(successfulNum);
      this.setTotalNum(successfulNum + failedNum);
    } finally {
      reader.close();
    }
    return SUCCESS;
  }
  /**
   * Selects the entities
   *
   * @return the SUCCESS result
   */
  public String select() throws ServiceException {
    Campaign campaign = null;
    Set<TargetList> targetLists = null;

    if ("Campaign".equals(this.getRelationKey())) {
      campaign =
          campaignService.getEntityById(Campaign.class, Integer.valueOf(this.getRelationValue()));
      targetLists = campaign.getTargetLists();
    }

    if (this.getSeleteIDs() != null) {
      String[] ids = seleteIDs.split(",");
      for (int i = 0; i < ids.length; i++) {
        String selectId = ids[i];
        targetList = baseService.getEntityById(TargetList.class, Integer.valueOf(selectId));
        targetLists.add(targetList);
      }
    }

    if ("Campaign".equals(this.getRelationKey())) {
      campaignService.makePersistent(campaign);
    }
    return SUCCESS;
  }