示例#1
0
  /**
   * Determines if the two entries can be linked
   *
   * @param entry parent in link hierarchy
   * @param link child in link hierarchy
   * @return true if the two entries can be linked in the hierarchy specified
   */
  private boolean canLink(Entry entry, Entry link) {
    if (entry == null || link == null || entry.getId() == link.getId()) return false;

    if (link.getLinkedEntries().contains(entry)) return false;

    EntryType linkedType = EntryType.nameToType(link.getRecordType());
    EntryType type = EntryType.nameToType(entry.getRecordType());
    if (type == null || linkedType == null) return false;

    switch (type) {
      case PLASMID:
        if (linkedType != type && linkedType != EntryType.PART) return false;
        break;

      case PART:
        if (linkedType != type) return false;
        break;

      case STRAIN:
        if (linkedType != type && linkedType != EntryType.PLASMID && linkedType != EntryType.PART)
          return false;
        break;

      case ARABIDOPSIS:
        if (linkedType != type && linkedType != EntryType.PART) return false;
        break;
    }

    return true;
  }
 /**
  * Find value for a specific key. If multiple instances of this node exist, the first one is
  * taken.
  *
  * @param name Key
  * @return Value, may be null
  */
 public EntryType lookup(String name) {
   for (EntryType entry : entries) {
     if (entry.getId().equals(name)) {
       return entry;
     }
   }
   return null;
 }
 @Override
 public String toString() {
   String ret = "";
   for (EntryType entry : entries) {
     ret += entry.getId() + ", ";
   }
   return ret;
 }
 public void insertEntry(EntryType entry) {
   if (lookup(entry.getId(), entry.getParams()) == null) {
     entries.add(entry);
   } else {
     throw new SemanticException(
         entry.getId()
             + " is already registered in this symbolTable. "
             + "You may want to update instead. 3"
             + lookup(entry.getId(), entry.getParams())
             + ":"
             + entry);
   }
 }
 /**
  * Updates the entry associated with name. If it is not contained yet it gets added, otherwise the
  * current value will be overridden.
  *
  * @param entry
  */
 public void updateEntry(EntryType entry) throws SemanticException {
   try {
     entries.set(lookupIndex(entry.getId()), entry);
   } catch (SemanticException e) {
     insertEntry(entry);
   }
 }
 /** @return */
 private LinkedHashMap<String, List<String>> getDataStrings() {
   LinkedHashMap<String, List<String>> dataToWrite = new LinkedHashMap<String, List<String>>();
   for (EntryType type : EntryType.values()) {
     if (!data.containsKey(type)) {
       continue;
     }
     List<String> linesToWrite = new ArrayList<String>();
     LinkedHashMap<String, ConfigEntry> typeMappings = data.get(type);
     for (String key : typeMappings.keySet()) {
       ConfigEntry entry = typeMappings.get(key);
       String entryString = safelyGetSaveString(entry);
       linesToWrite.add(String.format("%s %s", key, entryString));
     }
     dataToWrite.put(type.toString(), linesToWrite);
   }
   return dataToWrite;
 }
 /**
  * This is basically the method to look for function definitions.
  *
  * @param name function name
  * @param params function parameter
  * @return The Entry for this method
  */
 public EntryType lookup(String name, List<EntryType> params) {
   EntryType ret = null;
   for (EntryType entry : entries) {
     if (entry.getId().equals(name)) {
       boolean found = true;
       if (entry.getParams().size() == params.size()) {
         for (int i = 0; i < params.size(); i++) {
           if (!entry.getParams().get(i).equals(params.get(i))) {
             found = false;
           }
         }
       } else {
         found = false;
       }
       if (found) ret = entry;
     }
   }
   return ret;
 }
 protected void maintainVersion() {
   if (shouldUpdate()) {
     if (isOutOfDate()) {
       // we need to update from the default, overriding any out-dated keys
       loader.updateFromResource();
       for (EntryType type : EntryType.values()) {
         LinkedHashMap<String, ConfigEntry> mappings = loader.getMappings(type);
         data.put(type, mappings);
       }
     }
   }
   setDateStamp();
 }
 protected void putAllOfType(EntryType type, Map<String, ? extends Object> map) {
   synchronized (data) {
     LinkedHashMap<String, ConfigEntry> mappings = data.get(type);
     Class<?> classForCast = type.getDataClass();
     for (String key : map.keySet()) {
       Object obj = map.get(key);
       if (obj != null && classForCast.isInstance(obj)) {
         ConfigEntry entry = new ConfigEntry(type, obj);
         mappings.put(key, entry);
       }
     }
   }
 }
示例#10
0
  private void parseTitle(String bufferContent) {
    String[] marks = {"~ by:", "By"};
    boolean found = false;

    for (int i = 0; i < marks.length; i++) {
      int foundIndex = bufferContent.indexOf(marks[i]);
      if (foundIndex >= 0) {
        if (myAuthor != null) {
          String title = bufferContent.substring(0, foundIndex);
          myItem.Title = title;
          String authorName = bufferContent.substring(foundIndex + marks[i].length());
          myAuthor.Name = authorName.trim();
          myItem.Authors.push(myAuthor);
          myAuthor = null;
        }
        found = true;
        break;
      }
    }

    if (!found) {
      myItem.Title = bufferContent;
    }
  }
示例#11
0
 public boolean loadFromConfig() {
   loader.setForceReload(true);
   boolean changed = false;
   synchronized (data) {
     LinkedHashMap<String, List<String>> oldData = getDataStrings();
     data.clear();
     for (EntryType type : EntryType.values()) {
       LinkedHashMap<String, ConfigEntry> mappings = loader.getMappings(type);
       data.put(type, mappings);
     }
     maintainVersion();
     LinkedHashMap<String, List<String>> newData = getDataStrings();
     changed |= !oldData.equals(newData);
     if (changed) {
       savedDataStrings.clear();
       savedDataStrings.putAll(newData);
     }
   }
   return changed;
 }
示例#12
0
 public <T extends ConfigManager> boolean copyFromManager(T manager) {
   boolean changed = false;
   synchronized (data) {
     LinkedHashMap<String, List<String>> oldData = getDataStrings();
     data.clear();
     for (EntryType type : EntryType.values()) {
       LinkedHashMap<String, ConfigEntry> mappings = new LinkedHashMap<String, ConfigEntry>();
       List<String> keyOrder = new ArrayList<String>();
       for (String key : manager.getKeys(type)) {
         ConfigEntry entry = manager.getEntry(type, key);
         keyOrder.add(key);
         mappings.put(key, entry);
       }
       data.put(type, mappings);
     }
     LinkedHashMap<String, List<String>> newData = getDataStrings();
     changed |= !oldData.equals(newData);
     onCopyFrom(manager);
   }
   return changed;
 }
示例#13
0
  protected PartData retrieveEntryDetails(String userId, Entry entry) {
    // user must be able to read if not public entry
    if (!permissionsController.isPubliclyVisible(entry)) authorization.expectRead(userId, entry);

    PartData partData = ModelToInfoFactory.getInfo(entry);
    if (partData == null) return null;
    boolean hasSequence = sequenceDAO.hasSequence(entry.getId());

    partData.setHasSequence(hasSequence);
    boolean hasOriginalSequence = sequenceDAO.hasOriginalSequence(entry.getId());
    partData.setHasOriginalSequence(hasOriginalSequence);

    // permissions
    partData.setCanEdit(authorization.canWriteThoroughCheck(userId, entry));
    partData.setPublicRead(permissionsController.isPubliclyVisible(entry));

    // create audit event if not owner
    // todo : remote access check
    if (userId != null
        && authorization.getOwner(entry) != null
        && !authorization.getOwner(entry).equalsIgnoreCase(userId)) {
      try {
        Audit audit = new Audit();
        audit.setAction(AuditType.READ.getAbbrev());
        audit.setEntry(entry);
        audit.setUserId(userId);
        audit.setLocalUser(true);
        audit.setTime(new Date(System.currentTimeMillis()));
        auditDAO.create(audit);
      } catch (Exception e) {
        Logger.error(e);
      }
    }

    // retrieve more information about linked entries if any (default only contains id)
    if (partData.getLinkedParts() != null) {
      ArrayList<PartData> newLinks = new ArrayList<>();
      for (PartData link : partData.getLinkedParts()) {
        Entry linkedEntry = dao.get(link.getId());
        if (!authorization.canRead(userId, linkedEntry)) continue;

        link = ModelToInfoFactory.createTipView(linkedEntry);
        Sequence sequence = sequenceDAO.getByEntry(linkedEntry);
        if (sequence != null) {
          link.setBasePairCount(sequence.getSequence().length());
          link.setFeatureCount(sequence.getSequenceFeatures().size());
        }

        newLinks.add(link);
      }
      partData.getLinkedParts().clear();
      partData.getLinkedParts().addAll(newLinks);
    }

    // check if there is a parent available
    List<Entry> parents = dao.getParents(entry.getId());
    if (parents == null) return partData;

    for (Entry parent : parents) {
      if (!authorization.canRead(userId, parent)) continue;

      if (parent.getVisibility() != Visibility.OK.getValue()
          && !authorization.canWriteThoroughCheck(userId, entry)) continue;

      EntryType type = EntryType.nameToType(parent.getRecordType());
      PartData parentData = new PartData(type);
      parentData.setId(parent.getId());
      parentData.setName(parent.getName());
      parentData.setVisibility(Visibility.valueToEnum(parent.getVisibility()));
      partData.getParents().add(parentData);
    }

    return partData;
  }
示例#14
0
 public boolean endElementHandler(String ns, String tag, String bufferContent) {
   switch (myState) {
     case START:
       break;
     case RSS:
       if (testTag(TAG_RSS, tag, ns, null)) {
         myState = START;
       }
       break;
     case CHANNEL:
       if (testTag(TAG_CHANNEL, tag, ns, null)) {
         myState = RSS;
       }
       break;
     case C_TITLE:
       if (testTag(TAG_TITLE, tag, ns, null)) {
         myState = CHANNEL;
       }
       break;
     case C_LINK:
       if (testTag(TAG_LINK, tag, ns, null)) {
         myState = CHANNEL;
       }
       break;
     case ITEM:
       if (testTag(TAG_ITEM, tag, ns, null)) {
         myFeedHandler.processFeedEntry(myItem);
         myState = CHANNEL;
       }
     case TITLE:
       if (testTag(TAG_TITLE, tag, ns, null)) {
         parseTitle(bufferContent);
         myState = ITEM;
       }
       break;
     case GUID:
       if (testTag(TAG_GUID, tag, ns, null)) {
         if (myId != null) {
           myId.Uri = bufferContent;
           myItem.Id = myId;
           myId = null;
         }
         myState = ITEM;
       }
       break;
     case DESCRIPTION:
       if (testTag(TAG_DESCRIPTION, tag, ns, null)) {
         myFormattedBuffer.reset(FormattedBuffer.Type.Html);
         myFormattedBuffer.appendText(makeFormat(bufferContent));
         myItem.Summary = myFormattedBuffer.getText();
         myState = ITEM;
       }
       break;
     case CATEGORY:
       if (testTag(TAG_CATEGORY, tag, ns, null)) {
         String[] tokens = bufferContent.split(", ");
         for (String str : tokens) {
           ZLStringMap source = new ZLStringMap();
           source.put(RSSCategory.LABEL, str);
           myCategory = new RSSCategory(source);
           if (myCategory != null) {
             myItem.Categories.push(myCategory);
           }
           myCategory = null;
         }
         myState = ITEM;
       }
       break;
     case PUBDATE:
       if (testTag(TAG_PUBDATE, tag, ns, null)) {
         myState = ITEM;
       }
       break;
     case LINK:
       if (testTag(TAG_LINK, tag, ns, null)) {
         myState = ITEM;
       }
       break;
   }
   return false;
 }
示例#15
0
  public boolean endElementHandler(String ns, String tag, String bufferContent) {
    boolean interruptReading = false;
    switch (myState) {
      case START:
        break;
      case FEED:
        if (ns == XMLNamespaces.Atom && tag == TAG_FEED) {
          if (myFeed != null) {
            interruptReading = myFeedHandler.processFeedMetadata(myFeed, false);
          }
          myFeed = null;
          myFeedHandler.processFeedEnd();
          myState = START;
        }
        break;
      case F_ENTRY:
        if (ns == XMLNamespaces.Atom && tag == TAG_ENTRY) {
          if (myEntry != null) {
            interruptReading = myFeedHandler.processFeedEntry(myEntry);
          }
          myEntry = null;
          myState = FEED;
        }
        break;
      case F_ID:
        if (ns == XMLNamespaces.Atom && tag == TAG_ID) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          if (bufferContent != null && myFeed != null) {
            myId.Uri = bufferContent;
            myFeed.Id = myId;
          }
          myId = null;
          myState = FEED;
        }
        break;
      case F_ICON:
        if (ns == XMLNamespaces.Atom && tag == TAG_ICON) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          if (bufferContent != null && myFeed != null) {
            myIcon.Uri = bufferContent;
            myFeed.Icon = myIcon;
          }
          myIcon = null;
          myState = FEED;
        }
        break;
      case F_LINK:
        if (ns == XMLNamespaces.Atom && tag == TAG_LINK) {
          if (myFeed != null) {
            myFeed.Links.add(myLink);
          }
          myLink = null;
          myState = FEED;
        }
        break;
      case F_CATEGORY:
        if (ns == XMLNamespaces.Atom && tag == TAG_CATEGORY) {
          if (myFeed != null) {
            myFeed.Categories.add(myCategory);
          }
          myCategory = null;
          myState = FEED;
        }
        break;
      case F_TITLE:
        myFormattedBuffer.appendText(bufferContent);
        if (ns == XMLNamespaces.Atom && tag == TAG_TITLE) {
          // TODO:implement ATOMTextConstruct & ATOMTitle
          final CharSequence title = myFormattedBuffer.getText();
          if (myFeed != null) {
            myFeed.Title = title;
          }
          myState = FEED;
        } else {
          myFormattedBuffer.appendEndTag(tag);
        }
        break;
      case F_SUBTITLE:
        myFormattedBuffer.appendText(bufferContent);
        if (ns == XMLNamespaces.Atom && tag == TAG_SUBTITLE) {
          // TODO:implement ATOMTextConstruct & ATOMSubtitle
          final CharSequence subtitle = myFormattedBuffer.getText();
          if (myFeed != null) {
            myFeed.Subtitle = subtitle;
          }
          myState = FEED;
        } else {
          myFormattedBuffer.appendEndTag(tag);
        }
        break;
      case F_UPDATED:
        if (ns == XMLNamespaces.Atom && tag == TAG_UPDATED) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          if (ATOMDateConstruct.parse(bufferContent, myUpdated) && myFeed != null) {
            myFeed.Updated = myUpdated;
          }
          myUpdated = null;
          myState = FEED;
        }
        break;
      case F_AUTHOR:
        if (ns == XMLNamespaces.Atom && tag == TAG_AUTHOR) {
          if (myFeed != null && myAuthor.Name != null) {
            myFeed.Authors.add(myAuthor);
          }
          myAuthor = null;
          myState = FEED;
        }
        break;
      case FA_NAME:
        if (ns == XMLNamespaces.Atom && tag == TAG_NAME) {
          myAuthor.Name = bufferContent;
          myState = F_AUTHOR;
        }
        break;
      case FEA_NAME:
        if (ns == XMLNamespaces.Atom && tag == TAG_NAME) {
          myAuthor.Name = bufferContent;
          myState = FE_AUTHOR;
        }
        break;
      case FA_URI:
        if (ns == XMLNamespaces.Atom && tag == TAG_URI) {
          myAuthor.Uri = bufferContent;
          myState = F_AUTHOR;
        }
        break;
      case FEA_URI:
        if (ns == XMLNamespaces.Atom && tag == TAG_URI) {
          myAuthor.Uri = bufferContent;
          myState = FE_AUTHOR;
        }
        break;
      case FA_EMAIL:
        if (ns == XMLNamespaces.Atom && tag == TAG_EMAIL) {
          myAuthor.Email = bufferContent;
          myState = F_AUTHOR;
        }
        break;
      case FEA_EMAIL:
        if (ns == XMLNamespaces.Atom && tag == TAG_EMAIL) {
          myAuthor.Email = bufferContent;
          myState = FE_AUTHOR;
        }
        break;
      case FE_AUTHOR:
        if (ns == XMLNamespaces.Atom && tag == TAG_AUTHOR) {
          if (myAuthor.Name != null) {
            myEntry.Authors.add(myAuthor);
          }
          myAuthor = null;
          myState = F_ENTRY;
        }
        break;
      case FE_ID:
        if (ns == XMLNamespaces.Atom && tag == TAG_ID) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          if (bufferContent != null) {
            myId.Uri = bufferContent;
            myEntry.Id = myId;
          }
          myId = null;
          myState = F_ENTRY;
        }
        break;
      case FE_CATEGORY:
        if (ns == XMLNamespaces.Atom && tag == TAG_CATEGORY) {
          myEntry.Categories.add(myCategory);
          myCategory = null;
          myState = F_ENTRY;
        }
        break;
      case FE_LINK:
        if (ns == XMLNamespaces.Atom && tag == TAG_LINK) {
          myEntry.Links.add(myLink);
          myLink = null;
          myState = F_ENTRY;
        }
        break;
      case FE_PUBLISHED:
        if (ns == XMLNamespaces.Atom && tag == TAG_PUBLISHED) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          if (ATOMDateConstruct.parse(bufferContent, myPublished)) {
            myEntry.Published = myPublished;
          }
          myPublished = null;
          myState = F_ENTRY;
        }
        break;
      case FE_SUMMARY:
        myFormattedBuffer.appendText(bufferContent);
        if (ns == XMLNamespaces.Atom && tag == TAG_SUMMARY) {
          // TODO:implement ATOMTextConstruct & ATOMSummary
          myEntry.Summary = myFormattedBuffer.getText();
          myState = F_ENTRY;
        } else {
          myFormattedBuffer.appendEndTag(tag);
        }
        break;
      case FE_CONTENT:
        myFormattedBuffer.appendText(bufferContent);
        if (ns == XMLNamespaces.Atom && tag == TAG_CONTENT) {
          // TODO:implement ATOMContent
          myEntry.Content = myFormattedBuffer.getText();
          myState = F_ENTRY;
        } else {
          myFormattedBuffer.appendEndTag(tag);
        }
        break;
      case FE_TITLE:
        myFormattedBuffer.appendText(bufferContent);
        if (ns == XMLNamespaces.Atom && tag == TAG_TITLE) {
          // TODO:implement ATOMTextConstruct & ATOMTitle
          myEntry.Title = myFormattedBuffer.getText();
          myState = F_ENTRY;
        } else {
          myFormattedBuffer.appendEndTag(tag);
        }
        break;
      case FE_UPDATED:
        if (ns == XMLNamespaces.Atom && tag == TAG_UPDATED) {
          // FIXME:uri can be lost:buffer will be truncated, if there are extension tags inside the
          // <id> tag
          try {
            if (ATOMDateConstruct.parse(bufferContent, myUpdated)) {
              myEntry.Updated = myUpdated;
            }
          } catch (Exception e) {
            // this ATOMDateConstruct.parse() throws OOB exception time to time
          }
          myUpdated = null;
          myState = F_ENTRY;
        }
        break;
    }

    return interruptReading;
  }