/**
   * Move All Sor Records from one person to another.
   *
   * @param fromPerson person losing sor records.
   * @param toPerson person receiving sor records.
   * @return Result of move. Validation errors if they occurred or the Person receiving sor records.
   */
  public boolean moveAllSystemOfRecordPerson(Person fromPerson, Person toPerson) {
    // get the list of sor person records that will be moving.
    List<SorPerson> sorPersonList = personRepository.getSoRRecordsForPerson(fromPerson);

    // move each sorRecord
    for (final SorPerson sorPerson : sorPersonList) {
      moveSystemOfRecordPerson(fromPerson, toPerson, sorPerson);
    }

    Set<? extends Identifier> oldIdentifiers = fromPerson.getIdentifiers();
    Set<? extends IdCard> oldIdCards = fromPerson.getIdCards();

    this.personRepository.deletePerson(fromPerson);
    logger.info("moveAllSystemOfRecordPerson: Deleted From Person");
    for (Identifier identifier : oldIdentifiers) {

      if (toPerson.getIdentifiersByType().get(identifier.getType().getName()) == null) {
        Identifier oldIdentifierAttachedTotoPerson =
            toPerson.addIdentifier(identifier.getType(), identifier.getValue());
        /// if type of this identifier don't exist then add this identifier as primary and not
        // deleted

        oldIdentifierAttachedTotoPerson.setDeleted(false);
        oldIdentifierAttachedTotoPerson.setPrimary(true);
      }
      // and if this exist then add this identifier as deleted and no primary
      else {
        Identifier oldIdentifierAttachedTotoPerson =
            toPerson.addIdentifier(identifier.getType(), identifier.getValue());
        /// if type of this identifier don't exist then add this identifier as primary and not
        // deleted

        oldIdentifierAttachedTotoPerson.setDeleted(true);
        oldIdentifierAttachedTotoPerson.setPrimary(false);
        ;
      }
    }
    for (IdCard oldIdCard : oldIdCards) {
      if (toPerson.getPrimaryIdCard() == null) {
        toPerson.addIDCard(oldIdCard);
      } else {
        if (oldIdCard.isPrimary()) oldIdCard.setPrimary(false);
        toPerson.addIDCard(oldIdCard);
      }
    }

    this.personRepository.savePerson(toPerson);

    return true;
  }
Beispiel #2
0
  /*
   * evaluate the given expression.
   */
  public Object evaluate(Expression e) {
    if (e == null) {
      return null;
    }

    if (debug) {
      System.out.println("Evaluating expression: " + e);
    }

    if (e instanceof Literal) {
      return ((Literal) e).getValue();
    }

    if (e instanceof Identifier) {
      Identifier id = (Identifier) e;
      if (map.containsKey(id.getName())) {
        return map.get(id.getName());
      } else {
        // cache the data values for coherency of the values over
        // the life of this expression executer.
        Monitor m = (Monitor) id.getValue();
        Object v = m.getValue();
        map.put(id.getName(), v);
        return v;
      }
    }

    Expression l = e.getLeft();
    Expression r = e.getRight();

    Operator op = e.getOperator();

    if (op == null) {
      return evaluate(l);
    } else {
      Double lval = new Double(((Number) evaluate(l)).doubleValue());
      Double rval = new Double(((Number) evaluate(r)).doubleValue());
      double result = op.eval(lval.doubleValue(), rval.doubleValue());
      if (debug) {
        System.out.println("Performed Operation: " + lval + op + rval + " = " + result);
      }
      return new Double(result);
    }
  }