コード例 #1
0
  private InputStream getDownloadContent(boolean isTemplate) throws Exception {
    UserUtil.permissionCheck("view_targetList");
    String fileName = getText("entity.targetList.label") + ".csv";
    fileName = new String(fileName.getBytes(), "ISO8859-1");
    File file = new File(fileName);
    ICsvMapWriter writer = new CsvMapWriter(new FileWriter(file), CsvPreference.EXCEL_PREFERENCE);
    try {
      final String[] header =
          new String[] {
            getText("entity.id.label"),
            getText("entity.name.label"),
            getText("entity.description.label"),
            getText("entity.notes.label"),
            getText("entity.assigned_to_id.label"),
            getText("entity.assigned_to_name.label")
          };
      writer.writeHeader(header);
      if (!isTemplate) {
        String[] ids = seleteIDs.split(",");
        for (int i = 0; i < ids.length; i++) {
          String id = ids[i];
          TargetList targetList = baseService.getEntityById(TargetList.class, Integer.parseInt(id));
          final HashMap<String, ? super Object> data1 = new HashMap<String, Object>();
          data1.put(header[0], targetList.getId());
          data1.put(header[1], CommonUtil.fromNullToEmpty(targetList.getName()));
          data1.put(header[2], CommonUtil.fromNullToEmpty(targetList.getDescription()));
          data1.put(header[3], CommonUtil.fromNullToEmpty(targetList.getNotes()));
          if (targetList.getAssigned_to() != null) {
            data1.put(header[4], targetList.getAssigned_to().getId());
            data1.put(header[5], targetList.getAssigned_to().getName());
          } else {
            data1.put(header[4], "");
            data1.put(header[5], "");
          }
          writer.write(data1, header);
        }
      }
    } catch (Exception e) {
      throw e;
    } finally {
      writer.close();
    }

    InputStream in = new FileInputStream(file);
    this.setFileName(fileName);
    return in;
  }
コード例 #2
0
  private Collection<ChangeLog> changeLog(TargetList originalTargetList, TargetList targetList) {
    Collection<ChangeLog> changeLogs = null;
    if (originalTargetList != null) {
      ActionContext context = ActionContext.getContext();
      Map<String, Object> session = context.getSession();
      String entityName = TargetList.class.getSimpleName();
      Integer recordID = targetList.getId();
      User loginUser = (User) session.get(AuthenticationSuccessListener.LOGIN_USER);
      changeLogs = new ArrayList<ChangeLog>();

      String oldName = CommonUtil.fromNullToEmpty(originalTargetList.getName());
      String newName = CommonUtil.fromNullToEmpty(targetList.getName());
      if (!oldName.equals(newName)) {
        ChangeLog changeLog =
            saveChangeLog(entityName, recordID, "entity.name.label", oldName, newName, loginUser);
        changeLogs.add(changeLog);
      }

      String oldDescription = CommonUtil.fromNullToEmpty(originalTargetList.getDescription());
      String newDescription = CommonUtil.fromNullToEmpty(targetList.getDescription());
      if (!oldDescription.equals(newDescription)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.description.label",
                oldDescription,
                newDescription,
                loginUser);
        changeLogs.add(changeLog);
      }

      String oldNotes = CommonUtil.fromNullToEmpty(originalTargetList.getNotes());
      String newNotes = CommonUtil.fromNullToEmpty(targetList.getNotes());
      if (!oldNotes.equals(newNotes)) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName, recordID, "entity.notes.label", oldNotes, newNotes, loginUser);
        changeLogs.add(changeLog);
      }

      String oldAssignedToName = "";
      User oldAssignedTo = originalTargetList.getAssigned_to();
      if (oldAssignedTo != null) {
        oldAssignedToName = oldAssignedTo.getName();
      }
      String newAssignedToName = "";
      User newAssignedTo = targetList.getAssigned_to();
      if (newAssignedTo != null) {
        newAssignedToName = newAssignedTo.getName();
      }
      if (oldAssignedToName != newAssignedToName) {
        ChangeLog changeLog =
            saveChangeLog(
                entityName,
                recordID,
                "entity.assigned_to.label",
                CommonUtil.fromNullToEmpty(oldAssignedToName),
                CommonUtil.fromNullToEmpty(newAssignedToName),
                loginUser);
        changeLogs.add(changeLog);
      }
    }
    return changeLogs;
  }
コード例 #3
0
  /**
   * Gets the list JSON data.
   *
   * @return list JSON data
   */
  public static void getListJson(
      Iterator<TargetList> targetLists,
      long totalRecords,
      SearchCondition searchCondition,
      boolean isList)
      throws Exception {

    StringBuilder jsonBuilder = new StringBuilder("");
    jsonBuilder.append(getJsonHeader(totalRecords, searchCondition, isList));

    String assignedTo = null;
    while (targetLists.hasNext()) {
      TargetList instance = targetLists.next();
      int id = instance.getId();
      String name = CommonUtil.fromNullToEmpty(instance.getName());
      String description = CommonUtil.fromNullToEmpty(instance.getDescription());
      User user = instance.getAssigned_to();
      if (user != null) {
        assignedTo = user.getName();
      } else {
        assignedTo = "";
      }

      if (isList) {
        User createdBy = instance.getCreated_by();
        String createdByName = "";
        if (createdBy != null) {
          createdByName = CommonUtil.fromNullToEmpty(createdBy.getName());
        }
        User updatedBy = instance.getUpdated_by();
        String updatedByName = "";
        if (updatedBy != null) {
          updatedByName = CommonUtil.fromNullToEmpty(updatedBy.getName());
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(Constant.DATE_TIME_FORMAT);
        Date createdOn = instance.getCreated_on();
        String createdOnName = "";
        if (createdOn != null) {
          createdOnName = dateFormat.format(createdOn);
        }
        Date updatedOn = instance.getUpdated_on();
        String updatedOnName = "";
        if (updatedOn != null) {
          updatedOnName = dateFormat.format(updatedOn);
        }

        jsonBuilder
            .append("{\"cell\":[\"")
            .append(id)
            .append("\",\"")
            .append(name)
            .append("\",\"")
            .append(description)
            .append("\",\"")
            .append(assignedTo)
            .append("\",\"")
            .append(createdByName)
            .append("\",\"")
            .append(updatedByName)
            .append("\",\"")
            .append(createdOnName)
            .append("\",\"")
            .append(updatedOnName)
            .append("\"]}");
      } else {
        jsonBuilder
            .append("{\"id\":\"")
            .append(id)
            .append("\",\"name\":\"")
            .append(name)
            .append("\",\"assigned_to.name\":\"")
            .append(assignedTo)
            .append("\"}");
      }
      if (targetLists.hasNext()) {
        jsonBuilder.append(",");
      }
    }
    jsonBuilder.append("]}");

    // Returns JSON data back to page
    HttpServletResponse response = ServletActionContext.getResponse();
    response.setContentType("text/html;charset=UTF-8");
    response.getWriter().write(jsonBuilder.toString());
  }