コード例 #1
0
ファイル: LinkModel.java プロジェクト: amirhakim/Ref
 /**
  * Gets the links for an owning entity
  *
  * @param ownerbean the owning entity
  * @return the links
  * @throws Exception the exception
  */
 public Collection<Link> getLinks(KeyedEntity<?> ownerbean) throws Exception {
   LinkDB adb = (LinkDB) db_;
   if (ownerbean == null) return new ArrayList<Link>();
   LinkType type = typemap.get(ownerbean.getClass());
   if (type == null) return new ArrayList<Link>();
   return adb.getLinks(ownerbean.getKey(), type.toString());
 }
コード例 #2
0
ファイル: LinkModel.java プロジェクト: amirhakim/Ref
  /**
   * 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

  }
コード例 #3
0
ファイル: LinkModel.java プロジェクト: amirhakim/Ref
 /**
  * Move links from one object to another
  *
  * @param oldOwner the old owner
  * @param newOwner the new owner
  * @throws Exception the exception
  */
 public void moveLinks(KeyedEntity<?> oldOwner, KeyedEntity<?> newOwner) throws Exception {
   Collection<Link> atts = getLinks(oldOwner);
   Iterator<Link> it = atts.iterator();
   while (it.hasNext()) {
     Link at = it.next();
     at.setOwnerKey(new Integer(newOwner.getKey()));
     LinkType type = typemap.get(newOwner.getClass());
     if (type == null) throw new Exception("illegal link owner type");
     at.setOwnerType(type.toString());
     db_.updateObj(at);
   }
 }