Exemplo n.º 1
0
  /**
   * Finding next sequence id using key
   *
   * @param key
   * @return
   */
  public Long findNextSequenceId(String key) {

    // Building query
    Query query = new Query();
    query.addCriteria(Criteria.where("_id").is(key));

    Sequence sequence = findByQuery(query);

    return sequence.getSequence();
  }
Exemplo n.º 2
0
 public static Sequence promoteSequence(Sequence x) {
   if (BaseSequence.class.isAssignableFrom(x.getClass())) {
     try {
       return new Sequence(x.getFullName(), x.getSequence());
     } catch (SequenceException e) {
       return x;
     }
   } else
     // if it's not a BaseSequence, there isn't anything
     // to 'promote' to! (yet)
     return x;
 }
 @Override
 public Expression visit(Sequence sequence) {
   Sequence result = new Sequence();
   for (Expression exp : sequence.getSequence()) {
     if (exp.getClass() == Choice.class) {
       String name = "seq" + Integer.toString(count);
       count++;
       Nonterminal nt = new Nonterminal(name);
       Expression expr = exp.accept(this);
       newRules.put(nt, expr);
       result.addExpr(nt);
     } else {
       result.addExpr(exp.accept(this));
     }
   }
   return result;
 }
Exemplo n.º 4
0
  /**
   * Updating sequence details
   *
   * @param key
   * @return
   */
  public Long updateSequence(String key) {

    // Building query
    Query query = new Query();
    query.addCriteria(Criteria.where("_id").is(key));

    // Increase Sequence Id by 1
    Update update = new Update();
    update.inc("sequence", 1);

    FindAndModifyOptions options = new FindAndModifyOptions();
    options.returnNew(true);

    Sequence sequence = hamesDataStore.findAndModify(query, update, options, Sequence.class);

    return sequence.getSequence();
  }
Exemplo n.º 5
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;
  }