Beispiel #1
0
  /**
   * Adds a link.
   *
   * @param owner the owning Entity
   * @param pathIn the path (url, filepath, or entity key)
   * @param linkType the link type
   * @throws Exception the exception
   */
  public void addLink(KeyedEntity<?> owner, String pathIn, LinkType linkType) throws Exception {
    String path = pathIn;
    if (owner == null) {
      Errmsg.getErrorHandler().notice(Resource.getResourceString("att_owner_null"));
      return;
    }

    if (linkType == LinkType.ATTACHMENT) {

      String atfolder = attachmentFolder();
      if (atfolder == null) throw new Exception("attachments not supported");

      // need to copy file and create new path
      File orig = new File(path);
      String fname = orig.getName();
      String newpath = atfolder + "/" + fname;

      int i = 1;
      while (true) {
        File newfile = new File(newpath);
        if (!newfile.exists()) break;

        fname = Integer.toString(i) + orig.getName();
        newpath = atfolder + "/" + fname;
        i++;
      }

      copyFile(path, newpath);
      path = fname;
    }

    Link at = newLink();
    at.setKey(-1);
    at.setOwnerKey(new Integer(owner.getKey()));
    LinkType type = typemap.get(owner.getClass());
    if (type == null) throw new Exception("illegal link owner type");
    at.setOwnerType(type.toString());
    at.setPath(path);
    at.setLinkType(linkType.toString());
    saveLink(at);

    // * modification for backtrace/2way link

    if (linkType == LinkType.ADDRESS
        || linkType == LinkType.APPOINTMENT
        || linkType == LinkType.PROJECT
        || linkType == LinkType.TASK) {
      Link at2way = newLink();
      at2way.setKey(-1);
      at2way.setOwnerKey(new Integer(at.getPath()));
      at2way.setOwnerType(at.getLinkType());
      at2way.setPath(at.getOwnerKey().toString());
      at2way.setLinkType(at.getOwnerType());
      saveLink(at2way);
    }
    // end of modification

  }
Beispiel #2
0
 /* (non-Javadoc)
  * @see net.sf.borg.model.db.jdbc.JdbcBeanDB#createFrom(java.sql.ResultSet)
  */
 @Override
 Link createFrom(ResultSet r) throws SQLException {
   Link att = new Link();
   att.setKey(r.getInt("id"));
   att.setLinkType(r.getString("linktype"));
   att.setOwnerKey(new Integer(r.getInt("ownerkey")));
   att.setOwnerType(r.getString("ownertype"));
   att.setPath(r.getString("path"));
   return att;
 }