Package org.openqreg.bean

Examples of org.openqreg.bean.FileBean


      fsa.setStatus(AjaxWidgetAnswer.STATUS_NOSERVICE);
      return fsa;
    }
    User user = Dispatcher.getInstance().getUser(userId);
    // we have access carry on...
    FileBean fileBean = fsr.getFile();
    Collection<String> fileShareUsers = fsr.getFileShareUsers();
    fsa.setFile(fileBean);
    Connection con = null;
    try {
      try {
        // add default answer text, listboxtexts, guisettings,
        // containers
        addDefaultAnswer(user, fsr, fsa);

        con = DbHandler.getConnection();
        con.setAutoCommit(false);
        fileBean.setUpdatedby(userId);
        fileBean.setTsupdated(new Timestamp(System.currentTimeMillis()));
        fileBean.store(con);

        // service groups
        Collection<FileshareuserBean> col = FileshareuserFinder
            .findByFileid(con, fileBean.getId());
        // loop exsisting FileshareuserBean update or remove based on
        // status
        for (FileshareuserBean fsuBean : col) {
          if (!fileShareUsers.contains(fsuBean.getUserid())) {
            fsuBean.remove(con);
          }
          fileShareUsers.remove(fsuBean.getUserid());
        }
        User fileUser;
        // loop remaining services and create them
        for (String uId : fileShareUsers) {
          FileshareuserBean fsuBean = new FileshareuserBean();
          fsuBean.setFileid(fileBean.getId());
          fsuBean.setUserid(uId);
          fileUser = (User) UserFinderBase
              .findByPrimaryKey(new UserKey(uId));
          if (null != fileUser) {
            //set correct label ending up on switch
            fsuBean.setUserdescription(fileUser.getFirstname()
                + " " + fileUser.getLastname());
          }
          fsuBean.create(con);
        }
        con.commit();
        // sa.setStatus(AjaxWidgetAnswer.STATUS_UPDATED);
        // Dispatcher.getInstance().populateAccessTable();
        // Collection<FileBean> col =
        // FileFinder.findByOwner(user.getId());
        fileBean.setFileShareUserCol(FileshareuserFinder
            .findByFileid(fileBean.getId()));
        // fsa.setServiceGroups(ServicegroupFinder.findByServiceid(fsr
        // .getServiceId()));
        // fsa.setUserGroups(UsergroupFinderBase.findAll());
      } finally {
        if (null != con) {
View Full Code Here


      User user, LoginAnswer loginAnswer, FetchData fetch, String langId)
      throws ServletException, IOException {

    Long fileId = fetch.getValueAsLong("fileId");

    FileBean fileToGet = null;
    try {
      fileToGet = (FileBean) FileFinder.findByPrimaryKey(new FileKey(
          fileId));
    } catch (SQLException e) {
      log.log(Level.ERROR, "giveService() error finding file:", e);

    }

    // if(disp.checkAccess(loginAnswer.getUserId(),"START_PAGE")){
    try {
      if (null != fileToGet
          && null != fileToGet.getService()
          && Dispatcher.getInstance().checkAccess(
              loginAnswer.getUserId(), fileToGet.getService())) {

        // idea, get picture info from db including needed service to
        // see
        // picture, if user has service serv picture, else dont...

        String fileName = fileToGet.getPath() + fileToGet.getName();
        File checkFile = new File(fileName);
        if (checkFile.exists()) {
          File file = new File(fileName);

          // res.setContentType("image/JPEG");
          res.setContentType("application/download");
          res.setHeader("Content-Disposition",
              "attachment; filename=\"" + fileToGet.getName()
                  + "\"");

          // res.setContentType(fileToGet.getContenttype());
          // res.setHeader(arg0, arg1)
          ServletOutputStream servletoutputstream = res
View Full Code Here

              + " <br/>");

        } else {

          // write metadata to db
          FileBean file = new FileBean();
          file.setName(fh.getFileName());
          file.setSize(Integer.valueOf(fh.getFileSize()));
          // file.setContenttype(?);
          file.setPath(fileSharePath);
          file.setOwner(user.getId());
          file.setCreatedby(user.getId());
          file.setService("FILESHARE_DOWNLOAD");
          file.create();

          // fileSharePath from context.xml
          fh.setPath(fileSharePath);
          fh.writeFileToDisk();
          // String answer = XMLImporter.importFile(fh);
View Full Code Here

* @return A populated FileBean
*
* @throws SQLException
*/
protected static FileBean populate(ResultSet rs) throws SQLException {
FileBean valueObject = new FileBean();
valueObject.setId((Long)rs.getObject(1));
valueObject.setName((String)rs.getObject(2));
valueObject.setPath((String)rs.getObject(3));
valueObject.setSize((Integer)rs.getObject(4));
valueObject.setContenttype((String)rs.getObject(5));
valueObject.setDescription((String)rs.getObject(6));
valueObject.setService((String)rs.getObject(7));
valueObject.setOwner((String)rs.getObject(8));
valueObject.setCreatedby((String)rs.getObject(9));
valueObject.setUpdatedby((String)rs.getObject(10));
valueObject.setTscreated((java.sql.Timestamp)rs.getObject(11));
valueObject.setTsupdated((java.sql.Timestamp)rs.getObject(12));
return valueObject;
}
View Full Code Here

* @throws SQLException
*/
public static Collection<FileBean> findAll(Connection con) throws SQLException {
PreparedStatement pStmt = null;
ResultSet rs = null;
FileBean valueObject = null;
Collection<FileBean> col = Collections.synchronizedList(new ArrayList<FileBean>());
try{
pStmt = con.prepareStatement(FIND_ALL_STATEMENT);
rs = pStmt.executeQuery();
while (rs.next()){
valueObject = populate(rs);
valueObject.afterPopulate(con);
col.add(valueObject);
}
return col;
}finally{
if(null!=rs){
View Full Code Here

* @throws SQLException
*/
public static Object findByPrimaryKey(Connection con, PrimaryKey key) throws SQLException {
PreparedStatement pStmt = null;
ResultSet rs = null;
FileBean valueObject = null;
FileKey primaryKey = (FileKey) key;
try{
pStmt = con.prepareStatement(FileBeanBase.SELECT_STATEMENT);
pStmt.setObject(1, primaryKey.getId());
rs = pStmt.executeQuery();
while (rs.next()){
valueObject = populate(rs);
valueObject.afterPopulate(con);
}
return valueObject;
}finally{
if(null!=rs){
rs.close();
View Full Code Here

    // TODO: move the actual work to some other class not in rest package..
    // we have access carry on...
    FileShareAnswer fsa = new FileShareAnswer();

    FileBean fileBean = fsr.getFile();
    // ObjectMapper mapper = new ObjectMapper(); // can reuse, share
    // // globally
    // Map<String, String> json = null;
    // try {
    // json = mapper.readValue(awr.getJson(),
    // // new TypeReference<Map<String, Object>>() {
    // new TypeReference<Map<String, String>>() {
    // });
    //
    // mapper.readValue(node.get("vendor").getTextValue(), Vendor.class);
    //
    // } catch (Exception e) {
    // // TODO Auto-generated catch block
    // e.printStackTrace();
    // }
    //
    // String fileJson = (String) json.get("file");
    // String fileShareUsersJson = (String) json.get("fileShareUsers");
    //
    // // FileBean fileBean = (FileBean) json.get("file");
    // FileBean fileBean = null;
    // Collection<String> fileShareUsers = null;
    // // try {
    // // fileBean = C((Map)json.get("file"),new TypeReference<FileBean>() {
    // // } );
    // // fileShareUsers =
    // mapper.readValue((String)json.get("fileShareUsers"),
    // // new TypeReference<Collection<String>>() {
    // // } );
    // // } catch (IOException e1) {
    // // // TODO Auto-generated catch block
    // // e1.printStackTrace();
    // // }

    Collection<String> fileShareUsers = fsr.getFileShareUsers();
    // Collection<String> fileShareUsers = (Collection<String>)
    // json.get("fileShareUsers");
    fsa.setFile(fileBean);

    Connection con = null;
    try {
      con = DbHandler.getConnection();
      con.setAutoCommit(false);
      fileBean.setUpdatedby(userId);
      fileBean.setTsupdated(new Timestamp(System.currentTimeMillis()));
      fileBean.store(con);

      // service groups
      Collection<FileshareuserBean> col = FileshareuserFinder
          .findByFileid(con, fileBean.getId());
      // loop exsisting FileshareuserBean update or remove based on
      // status
      for (FileshareuserBean fsuBean : col) {
        if (!fileShareUsers.contains(fsuBean.getUserid())) {
          fsuBean.remove(con);
        }
        fileShareUsers.remove(fsuBean.getUserid());
      }
      User fileUser;
      // loop remaining services and create them
      for (String uId : fileShareUsers) {
        FileshareuserBean fsuBean = new FileshareuserBean();
        fsuBean.setFileid(fileBean.getId());
        fsuBean.setUserid(uId);
        fileUser = (User) UserFinderBase.findByPrimaryKey(new UserKey(
            uId));
        if (null != fileUser) {
          // set correct label ending up on switch
          fsuBean.setUserdescription(fileUser.getFirstname() + " "
              + fileUser.getLastname());
        }
        fsuBean.create(con);
      }
      con.commit();
      fileBean.setFileShareUserCol(FileshareuserFinder
          .findByFileid(fileBean.getId()));
    } catch (SQLException sqle) {
      try {
        if (null != con) {
          con.rollback();
        }
      } catch (SQLException e) {
        // getLog().log(Level.ERROR,
        // "createData() error doing rollback: ", e);
      }
    } finally {
      if (null != con) {
        try {
          con.close();
        } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        con = null;
      }
    }

    rw.setLinks(getLinksForObject(userId, fileBean.getId().toString()));

    rw.setSuccess(true);

    rw.setData(fsa);
    return Response.status(Response.Status.OK).entity(rw).build();
View Full Code Here

    Connection con = null;
    try {
      con = DbHandler.getConnection();
      con.setAutoCommit(false);
      FileBean fileBean = (FileBean) FileFinder.findByPrimaryKey(con,
          new FileKey(fileId));

      // service groups
      Collection<FileshareuserBean> col = FileshareuserFinder
          .findByFileid(con, fileBean.getId());
      // loop exsisting FileshareuserBean update or remove based on
      // status
      for (FileshareuserBean fsuBean : col) {
        fsuBean.remove(con);
      }
      fileBean.remove(con);
      con.commit();
    } catch (SQLException sqle) {
      try {
        if (null != con) {
          con.rollback();
View Full Code Here

TOP

Related Classes of org.openqreg.bean.FileBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.