Aems Actions - GitGraf/aems-apilib GitHub Wiki

Query

The AemsQueryAction is used to run a GraphQL-Query against the API.

AemsQueryAction query = new AemsQueryAction(user, EncryptionType.AES);
query.setQuery("INSERT GRAPH-QL QUERY HERE");
String json = query.toJson();

This code example would produce the following JSON output:

{
  "user_id": 10,
  "action": "QUERY",
  "data": "INSERT GRAPH-QL QUERY HERE"
}

Insert

The AemsInsertAction is used to insert single or multiple records into a table. You need to supply the name of the table in which you want to insert. When you finished writing the data of one record, it is important to call action.endWrite().

AemsInsertAction insert = new AemsInsertAction(user, EncryptionType.AES);
insert.setTable("Notifications");                         // In which table are we inserting?

for(NotificationData data : notifications) {
	insert.beginWrite();                             // Let's write a new record (optional)
	insert.write("name", data.getName());            // write(columnName, value)
	insert.write("derivation", data.getDerivation());
	insert.write("annotation", data.getAnnotation());
	insert.endWrite();                               // End of current record (this is required!)
}
String json = insert.toJson();

This code example could produce the following JSON output:

{
  "user_id": 10,
  "action": "INSERT",
  "data": {
    "Notifications": [
      {
        "annotation": "Stromverbrauch weicht 20% ab",
        "name": "Stromwarnung",
        "derivation": 20.0
      },
      {
        "annotation": "Anomalien beim Wasserzähler!",
        "name": "Wasserzähler",
        "derivation": 50.0
      }
    ]
  }
}

Update

The AemsUpdateAction is used to update existing records in the database. Besides the table name you also need to supply the column name which will be used for the WHERE statement. The following code would result in a SQL-Statement like so:
UPDATE Meters SET type = 3 WHERE id = 'AT000001';

AemsUpdateAction update = new AemsUpdateAction(user, EncryptionType.AES);
update.setTable("Meters"); 		// Which table are we updating?
update.setIdColumn("id", "AT000001"); 	// Which column and value should be used for the WHERE statement?
		
update.write("type", 3); 		// UPDATE the meter type column, set it to 3 (whatever that may be)
		
String json = update.toJson();

This code example would produce the following JSON output:

{
  "user_id": 10,
  "action": "UPDATE",
  "data": {
    "id": "AT000001",
    "Meters": [
      {
        "type": 3
      }
    ]
  }
}
⚠️ **GitHub.com Fallback** ⚠️