Exemplo n.º 1
0
 /**
  * Replace variables of the form [Patient.Name] in the script with their respective values for the
  * current call
  *
  * @param script the script
  * @param params all Variables to replace
  * @return the parsed Script
  */
 private static String parse(String script, PersistentObject... params) {
   if (params == null) {
     params = new PersistentObject[0];
   }
   Matcher matcher = varPattern.matcher(script);
   // Suche Variablen der Form [Patient.Alter]
   StringBuffer sb = new StringBuffer();
   while (matcher.find()) {
     boolean bMatched = false;
     String var = matcher.group().replaceAll("[\\[\\]]", StringTool.leer);
     String[] fields = var.split("\\.");
     if (fields.length > 1) {
       String fqname = "ch.elexis.data." + fields[0];
       for (PersistentObject o : params) {
         if (o.getClass().getName().equals(fqname)) {
           String repl = o.get(fields[1]);
           repl = repl.replace('\\', '/');
           repl = repl.replace('\"', ' ');
           repl = repl.replace('\n', ' ');
           repl = repl.replace('\r', ' ');
           matcher.appendReplacement(sb, "\"" + repl + "\"");
           bMatched = true;
         }
       }
     }
     if (!bMatched) {
       matcher.appendReplacement(sb, "\"\"");
     }
   }
   matcher.appendTail(sb);
   return sb.toString();
 }
Exemplo n.º 2
0
  @Test
  public void testExecuteOnDBConnection() throws IOException {
    Query<Organisation> query = new Query<Organisation>(Organisation.class);
    query.clear();
    query.add(Organisation.FLD_NAME1, "=", "orgname2");

    // create a new DBConnection
    DBConnection connection = new DBConnection();
    connection.setDBConnectString("jdbc:h2:mem:test_query_mem");
    connection.setDBUser("sa");
    connection.setDBPassword("");
    assertTrue(connection.connect());
    initElexisDatabase(connection);

    List<Organisation> result = query.execute(connection);
    assertEquals(0, result.size());

    DBConnection initialConnection = PersistentObject.getDefaultConnection();

    // change default connection of PersistenObject and create an Organization
    PersistentObject.connect(connection);
    new Organisation("orgname2", "orgzusatz1");

    result = query.execute(connection);
    assertEquals(1, result.size());

    // cleanup new connection and reset to initial connection
    PersistentObject.disconnect();
    PersistentObject.connect(initialConnection);
  }
Exemplo n.º 3
0
  /**
   * Adds a new object to the organization.
   *
   * @param object object to be added to the organization
   * @exception AccessRightsException if an access rights exception occurs
   * @exception EntryAlreadyExistsException if the entry already exists
   * @exception UMSException Fail to add the object
   * @supported.api
   */
  public void addChild(PersistentObject object)
      throws AccessRightsException, EntryAlreadyExistsException, UMSException {
    Principal principal = getPrincipal();

    if (principal == null) {
      String msg = i18n.getString(IUMSConstants.BAD_PRINCIPAL_HDL);
      throw new IllegalArgumentException(msg);
    } else if (object == null) {
      String msg = i18n.getString(IUMSConstants.BAD_OBJ_TO_ADD);
      throw new IllegalArgumentException(msg);
    }

    if (object instanceof User) {
      String pcId = getPeopleContainer((User) object);
      if (pcId != null) {
        PeopleContainer pc = new PeopleContainer(getPrincipal(), new Guid(pcId));
        pc.addUser((User) object);
      } else {
        // no match and no default value found
        // For now, the user will be addedd to the organization.
        // May want to add to the default people
        // container(ou=People) instead.
        super.addChild(object);
      }

    } else {

      super.addChild(object);
    }
  }
Exemplo n.º 4
0
 /**
  * Returns index of the object a <code>List</code> object of <code>PersistentObject</code>s that
  * contains an encoded key (<code>getEncodedKey()</code>).
  *
  * @param list <code>List</code> of objects to search.
  * @param encodedKey key obtained via <code>getEncodedKey()</code>.
  * @return index of object on list or <code>-1</code> if not found.
  * @see net.sf.jrf.domain.PersistentObject#getEncodedKey()
  * @see #findByKey(List,String)
  */
 public static int findIndexByKey(List list, String encodedKey) {
   for (int i = 0; i < list.size(); i++) {
     PersistentObject p = (PersistentObject) list.get(i);
     if (p.getEncodedKey().equals(encodedKey)) {
       return i;
     }
   }
   return -1;
 }
 /**
  * Helper-Funktion, die Objekte eines beliebigen abgeleiteten Typs mit beliebigen Feldvorgaben
  * erstellen kann.
  *
  * @param typ Die Klasse des zu erstellenden Objekts
  * @param fields Die initial zu belegenden Felder. ID darf nicht angegeben werden.
  * @param values Die Werte für die Felder
  * @return Das Objekt bei Erfolg, sonst null
  */
 public PersistentObject create(
     Class<? extends PersistentObject> typ, String[] fields, String[] values) {
   PersistentObject template = createTemplate(typ);
   template.create(null);
   if ((template != null) && (template.set(fields, values) == true)) {
     return template;
   }
   return null;
 }
Exemplo n.º 6
0
 /**
  * Scans a list of <code>PersistentObject</code>s and return the object that matches the key or
  * <code>null</code> if not found.
  *
  * @param list list of <code>PersistentObject</code>s to scan.
  * @param encodedKey key to locate correct record on the list.
  * @return key-matching record of <code>null</code> if not found.
  */
 public static PersistentObject getPoInList(List list, String encodedKey) {
   Iterator iter = list.iterator();
   while (iter.hasNext()) {
     PersistentObject p = (PersistentObject) iter.next();
     if (p.getEncodedKey().equals(encodedKey)) {
       return p;
     }
   }
   return null;
 }
Exemplo n.º 7
0
 public synchronized void delete() {
   if (swigCPtr != 0) {
     if (swigCMemOwn) {
       swigCMemOwn = false;
       pjsua2JNI.delete_TransportConfig(swigCPtr);
     }
     swigCPtr = 0;
   }
   super.delete();
 }
Exemplo n.º 8
0
 @Before
 public void setUp() throws Exception {
   if (link != null) {
     PersistentObject.deleteAllTables();
     link.disconnect();
   }
   link = initDB();
   // create a instance of an PersistentObject ex. Organisation to test the query
   new Organisation("orgname", "orgzusatz1");
 }
  /**
   * Create an object of a derived class given a pseudo de-serialization code, e.g. <code>
   * ch.elexis.artikel_ch.data.Medikament::ca8bb5c27bdd67d5f011821</code>. If the object can not be
   * created by the core, all plug-ins contributing a {@link #PersistentObjectFactory()} are
   * queried.
   *
   * @param code the storeToString as shown in the above example
   * @param dbConnection the db connection used by the created PersistenObject, if not defined
   *     default is used
   * @return the de-serialized object, or <code>null</code>
   */
  public PersistentObject createFromString(String code, DBConnection dbConnection) {
    if (code == null) {
      return null;
    }

    String[] ci = code.split(StringConstants.DOUBLECOLON);
    if (ci.length != 2) return null;

    PersistentObject ret = null;
    // try to resolve factory from cache
    PersistentObjectFactory persistentObjectFactory = poFactoryCache.get(ci[0]);
    if (persistentObjectFactory != null) {
      ret = persistentObjectFactory.createFromString(code);
      ret.setDBConnection(dbConnection);
      return ret;
    }

    try {
      Class clazz = Class.forName(ci[0]);
      Method load = clazz.getMethod("load", new Class[] {String.class});
      ret = (PersistentObject) (load.invoke(null, new Object[] {ci[1]}));
      ret.setDBConnection(dbConnection);
      return ret;
    } catch (ClassNotFoundException ex) {
      List<PersistentObjectFactory> contributedFactories =
          Extensions.getClasses(ExtensionPointConstantsData.PERSISTENT_REFERENCE, CLASS);
      for (PersistentObjectFactory po : contributedFactories) {
        ret = po.createFromString(code);
        if (ret != null) {
          // found a responsible factory, cache it
          poFactoryCache.put(ci[0], po);
          ret.setDBConnection(dbConnection);
          return ret;
        }
      }
    } catch (Exception ex) {
      ExHandler.handle(ex);
      return ret;
    }
    return ret;
  }
Exemplo n.º 10
0
 @After
 public void tearDown() throws Exception {
   PersistentObject.deleteAllTables();
   link.exec("DROP ALL OBJECTS");
   link.disconnect();
 }
Exemplo n.º 11
0
 public String toString() {
   return _id + " / " + (_persistent == null ? 0 : _persistent.getId());
 }
Exemplo n.º 12
0
 /**
  * Removes an object from the organization.
  *
  * @param object object to be removed to the organization
  * @exception AccessRightsException if an access rights exception occurs
  * @exception EntryNotFoundException if the entry is not found
  * @exception UMSException Fail to remove the object
  * @supported.api
  */
 public void removeChild(PersistentObject object)
     throws AccessRightsException, EntryNotFoundException, UMSException {
   if (object != null && getPrincipal() != null) {
     super.removeChild(object);
   }
 }
Exemplo n.º 13
0
 public String getUpdateStatement(PersistentObject object) {
   return getStatement(object.getClass(), updateStatements, "update");
 }
Exemplo n.º 14
0
 public String getInsertStatement(PersistentObject object) {
   return getStatement(object.getClass(), insertStatements, "insert");
 }