Commit 406501e0 authored by ReemyHasan's avatar ReemyHasan

add Rethink Functions

parent e0c31d51
......@@ -44,7 +44,7 @@ public class SnmpListener implements CommandResponder {
}
public void startTrapListener() {
try {
TransportMapping<?> transport = new DefaultUdpTransportMapping(new UdpAddress("192.168.26.46/1625"));
TransportMapping<?> transport = new DefaultUdpTransportMapping(new UdpAddress("192.168.25.254/1625"));
System.out.println("Listening to SNMP Trap");
Snmp snmp = new Snmp(transport);
snmp.addCommandResponder(this);
......
......@@ -19,7 +19,7 @@ public class WebSocketConfig implements WebSocketConfigurer {
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
System.out.println(webSocketPath);
// System.out.println(webSocketPath);
registry.addHandler(socket_server, webSocketPath).setAllowedOrigins("*");
}
}
//package com.example.WebApplication.controller;
//
//import com.example.WebApplication.controller.SocketTextHandler;
//import com.example.WebApplication.entities.RethinkChange;
//import com.example.WebApplication.services.RethinkDBService;
//import com.rethinkdb.net.Cursor;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.CommandLineRunner;
//import org.springframework.web.bind.annotation.CrossOrigin;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.IOException;
//
//@RestController
//@RequestMapping("/api/rethink")
//public class RethinkController {
//
// @Override
// public void run(String... args) throws Exception {
// Cursor<RethinkChange> changeCursor = rethinkDBService.subscribe();
// System.out.println("I am Subscribing");
// //List<RethinkChange> result = new ArrayList<>();
// for (RethinkChange change : changeCursor){
//// System.out.println("Something Changed ");
//// System.out.println(change);
//// result.add(change);
// try {
// socket_server.broadcast(change);
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// }
//
// }
//}
package com.example.WebApplication.controller;
import com.example.WebApplication.controller.SocketTextHandler;
import com.example.WebApplication.entities.RethinkChange;
import com.example.WebApplication.services.RethinkDBService;
import com.rethinkdb.net.Cursor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api/rethink")
@CrossOrigin(origins = {"http://localhost:3000"})
public class RethinkController {
@Autowired
private RethinkDBService rethinkDBService;
@PostMapping("/delete")
public void delete(@RequestBody String id){
rethinkDBService.deleteById(id);
}
@GetMapping("/data")
public ResponseEntity<List<Map<String, Object>>> getData() {
List<Map<String, Object>> result = rethinkDBService.getData();
System.out.println(result);
if (result != null) {
return ResponseEntity.ok(result);
} else {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
}
......@@ -25,8 +25,6 @@ import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
@Component
@RestController
@RequestMapping("/api/rethink")
public class SocketTextHandler extends TextWebSocketHandler implements CommandLineRunner {
private List<WebSocketSession> sessions = new CopyOnWriteArrayList<>();
......@@ -98,8 +96,8 @@ public class SocketTextHandler extends TextWebSocketHandler implements CommandLi
public void run(String... args) throws Exception {
Cursor<RethinkChange> changeCursor = rethinkDBService.subscribe();
System.out.println("I am Subscribing");
System.out.println(changeCursor.getClass());
System.out.println(changeCursor);
// System.out.println(changeCursor.getClass());
// System.out.println(changeCursor);
//List<RethinkChange> result = new ArrayList<>();
for (RethinkChange change : changeCursor){
System.out.println("Something Changed ");
......@@ -112,8 +110,4 @@ public class SocketTextHandler extends TextWebSocketHandler implements CommandLi
}
}
@PostMapping("/delete")
public void delete(@RequestBody String id){
rethinkDBService.deleteById(id);
}
}
......@@ -34,10 +34,10 @@ public class RethinkDBService{
String jsonString = objectMapper.writeValueAsString(rethinkTrap);
JsonNode jsonNode = objectMapper.readTree(jsonString);
Map<String,EnrichedTrap> document = objectMapper.convertValue(jsonNode, Map.class);
System.out.println(jsonString);
System.out.println(jsonNode);
System.out.println(document);
System.out.println("I am here reem " + connectionFactory.getDbName() + " " + connectionFactory.getDbTableName());
// System.out.println(jsonString);
// System.out.println(jsonNode);
// System.out.println(document);
// System.out.println("I am here reem " + connectionFactory.getDbName() + " " + connectionFactory.getDbTableName());
r.db(connectionFactory.getDbName()).table(connectionFactory.getDbTableName()).insert(document).run(connectionFactory.getConnection());
System.out.println("I am here now reem");
} catch (Exception e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment