예제 #1
0
 public void delete(int id) {
   Document d = new Document();
   d.setId(id);
   try {
     FileManage criteria = new FileManage();
     criteria.setSource(ParameterModel.DOCUMENT_ENTITY);
     criteria.setFkEntityId(id + "");
     List<FileManage> files = this.getFileManageService().getByExample(criteria, null);
     String lastFileName;
     if (files != null & !files.isEmpty() && files.size() > 0) {
       lastFileName = files.get(files.size() - 1).getPath();
       FileUtils.deleteFile(lastFileName);
       fileManageService.delete(files.get(files.size() - 1));
     }
     criteria.setSource(ParameterModel.DOCUMENT_THUMB_ENTITY);
     files = this.getFileManageService().getByExample(criteria, null);
     if (files != null & !files.isEmpty() && files.size() > 0) {
       lastFileName = files.get(files.size() - 1).getPath();
       FileUtils.deleteFile(lastFileName);
       fileManageService.delete(files.get(files.size() - 1));
     }
   } catch (Exception e) {
   }
   documentService.delete(d);
   documents = documentService.getAll();
   FacesContext.getCurrentInstance()
       .addMessage(
           null,
           new FacesMessage(FacesMessage.SEVERITY_INFO, ParameterModel.STATUS_DELETE_SUCCESS, ""));
 }
예제 #2
0
  public void addUser() {
    try {
      logger.info("addUser");
      UserProfile model = new UserProfile();
      model.setUsername(getUsername());
      model.setDepartment(getDepartment());
      model.setDivision(getDivision());
      model.setFirstName(getFirstName());
      model.setLastName(getLastName());
      model.setSection(getSection());
      model.setUpdatedBy(FacesContext.getCurrentInstance().getExternalContext().getRemoteUser());

      UserRole qcUserRole = new UserRole();
      qcUserRole.setId(1);
      model.setQcUserRole(qcUserRole);
      userProfileService.update(model);
      String f = "";
      try {
        if (getAtt() != null) {
          f = FileUtils.copyFile(getAtt());
          FileManage fModel;
          fModel = new FileManage();
          fModel.setFkEntityId(model.getUsername());
          fModel.setPath(f);
          fModel.setSource(ParameterModel.USER_ENTITY);
          fModel.setType("");
          fModel.setUpdatedBy(
              FacesContext.getCurrentInstance().getExternalContext().getRemoteUser());
          fileManageService.add(fModel);
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
      setUsername("");
      setDepartment("");
      setDivision("");
      setFirstName("");
      setLastName("");
      setSection("");
      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(FacesMessage.SEVERITY_INFO, ParameterModel.STATUS_SAVE_SUCCESS, ""));
    } catch (Exception e) {
      e.printStackTrace();
      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(FacesMessage.SEVERITY_ERROR, ParameterModel.STATUS_SAVE_FAIL, ""));
    }
  }
예제 #3
0
  public void add() {
    logger.info("add");
    Document model = new Document();
    String lastFileName = null;
    try {
      model.setTitle(getTitle());
      DocumentType docType = new DocumentType();
      docType.setId(Integer.parseInt(getDocumentType()));
      model.setDocType(docType);

      model.setUpdatedBy(FacesContext.getCurrentInstance().getExternalContext().getRemoteUser());

      if (getId() == 0) {
        documentService.add(model);
      } else {
        model.setId(getId());
        documentService.update(model);
      }
      try {
        if (file != null) {
          String f = FileUtils.copyFile(file);
          List<FileManage> files;
          FileManage criteria = new FileManage();
          criteria.setSource(ParameterModel.DOCUMENT_ENTITY);

          FileManage fModel = new FileManage();
          fModel.setFkEntityId(model.getId() + "");
          fModel.setPath(f);
          fModel.setSource(ParameterModel.DOCUMENT_ENTITY);

          if (getId() != 0) {
            // check dup
            criteria.setFkEntityId(getId() + "");
            criteria.setWeight(1);
            files = this.getFileManageService().getByExample(criteria, null);
            if (files != null & !files.isEmpty() && files.size() > 0) {
              fModel.setId(files.get(files.size() - 1).getId());
              lastFileName = files.get(files.size() - 1).getPath();
            }
          }

          fModel.setType("");
          fModel.setUpdatedBy(
              FacesContext.getCurrentInstance().getExternalContext().getRemoteUser());
          if (fModel.getId() == 0) fileManageService.add(fModel);
          else {
            fileManageService.update(fModel);
            FileUtils.deleteFile(lastFileName);
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }

      try {
        if (thumb != null) {
          String f = FileUtils.copyFile(thumb);
          List<FileManage> files;
          FileManage criteria = new FileManage();
          criteria.setSource(ParameterModel.DOCUMENT_THUMB_ENTITY);

          FileManage fModel = new FileManage();
          fModel.setFkEntityId(model.getId() + "");
          fModel.setPath(f);
          fModel.setSource(ParameterModel.DOCUMENT_THUMB_ENTITY);

          if (getId() != 0) {
            // check dup
            criteria.setFkEntityId(getId() + "");
            criteria.setWeight(2);
            files = this.getFileManageService().getByExample(criteria, null);
            if (files != null & !files.isEmpty() && files.size() > 0) {
              fModel.setId(files.get(files.size() - 1).getId());
              lastFileName = files.get(files.size() - 1).getPath();
            }
          }

          fModel.setType("");
          fModel.setUpdatedBy(
              FacesContext.getCurrentInstance().getExternalContext().getRemoteUser());
          if (fModel.getId() == 0) fileManageService.add(fModel);
          else {
            fileManageService.update(fModel);
            FileUtils.deleteFile(lastFileName);
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    setId(0);
    setDocumentType("");
    setTitle("");
  }