aboutsummaryrefslogtreecommitdiffstats
path: root/musictrigger
diff options
context:
space:
mode:
authorNelson, Thomas (tn1381) <tn1381@att.com>2018-08-27 19:52:13 +0000
committerNelson, Thomas (tn1381) <tn1381@att.com>2018-08-27 19:52:13 +0000
commitc79755d43c123176515e5cafbba0774a03d297d3 (patch)
tree869472d1d7a9883aaa8a60604c5dad54128bd5ba /musictrigger
parent21b8e51a9318a97363437c9668e3564875c15f8f (diff)
Swagger Update and other updates.
Updates related to callback api Change-Id: I2a4c00e8db4a430c5998e7770389451610f0770a Issue-ID: MUSIC-97 Signed-off-by: Nelson, Thomas (tn1381) <tn1381@att.com>
Diffstat (limited to 'musictrigger')
-rwxr-xr-xmusictrigger/src/MusicTrigger.java38
1 files changed, 30 insertions, 8 deletions
diff --git a/musictrigger/src/MusicTrigger.java b/musictrigger/src/MusicTrigger.java
index d70e41a0..b5894da1 100755
--- a/musictrigger/src/MusicTrigger.java
+++ b/musictrigger/src/MusicTrigger.java
@@ -25,6 +25,11 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.Map;
import javax.ws.rs.core.HttpHeaders;
@@ -68,7 +73,6 @@ public class MusicTrigger implements ITrigger {
boolean isInsert = checkQueryType(partition);
org.json.simple.JSONObject obj = new org.json.simple.JSONObject();
-
String operation = null;
if(isDelete)
operation = "delete";
@@ -76,14 +80,14 @@ public class MusicTrigger implements ITrigger {
operation = "insert";
else
operation = "update";
- Map<String, String> changeMap = new HashMap<>();
+ Map<String, Object> changeMap = new HashMap<>();
obj.put("operation", operation);
obj.put("keyspace", ksName);
obj.put("table_name", tableName);
obj.put("full_table", ksName+"."+tableName);
obj.put("primary_key", partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey()));
-
+ List<String> updateList = new ArrayList<>();
//obj.put("message_id", partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey()));
if("update".equals(operation)) {
try {
@@ -97,15 +101,29 @@ public class MusicTrigger implements ITrigger {
while(columns.hasNext()){
ColumnDefinition columnDef = columns.next();
Cell cell = cells.next();
- String data = new String(cell.value().array()); // If cell type is text
+
+ String data = null;
+ if(cell.column().type.toString().equals("org.apache.cassandra.db.marshal.UTF8Type")) {
+ logger.info(">> type is String");
+ data = new String(cell.value().array()); // If cell type is text
+ } else if(cell.column().type.toString().equals("org.apache.cassandra.db.marshal.Int32Type")) {
+ //ByteBuffer wrapped = ByteBuffer.wrap(cell.value()); // big-endian by default
+ int num = fromByteArray(cell.value().array());
+ logger.info(">> type is Integer1 :: "+num);
+ data = String.valueOf(num);
+ }
+
logger.info("Inside triggers loop: "+columnDef.name+" : "+data);
- changeMap.put(ksName+"."+tableName+"."+columnDef.name,data);
+ //changeMap.put(ksName+"."+tableName+"."+columnDef.name,data);
+ updateList.add(ksName+"."+tableName+":"+columnDef.name+":"+data);
changeMap.put("field_value",ksName+"."+tableName+":"+columnDef.name+":"+data);
+
}
}
} catch (Exception e) {
}
+ obj.put("updateList", updateList);
} else {
changeMap.put("field_value", ksName+"."+tableName);
}
@@ -121,6 +139,10 @@ public class MusicTrigger implements ITrigger {
return Collections.emptyList();
}
+ private int fromByteArray(byte[] bytes) {
+ return bytes[0] << 24 | (bytes[1] & 0xFF) << 16 | (bytes[2] & 0xFF) << 8 | (bytes[3] & 0xFF);
+ }
+
private boolean checkQueryType(Partition partition) {
UnfilteredRowIterator it = partition.unfilteredIterator();
while (it.hasNext()) {
@@ -149,12 +171,12 @@ public class MusicTrigger implements ITrigger {
.post(ClientResponse.class, data);
if(response.getStatus() != 200){
- System.out.println("Exception...");
+ System.out.println("Exception while notifying MUSIC...");
}
- response.getHeaders().put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON));
+ /*response.getHeaders().put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON));
response.bufferEntity();
String x = response.getEntity(String.class);
- System.out.println("Response: "+x);
+ System.out.println("Response: "+x);*/
}