Skip to content

Commit

Permalink
loopback-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GregorioMonari committed Mar 7, 2023
1 parent 9463b90 commit a5a2c23
Show file tree
Hide file tree
Showing 1,059 changed files with 261,522 additions and 1,518 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class AwApiUpdateManager {
constructor(jsap_file,awmanager,userinfoconsumer,tasksconsumer){
this.log=new Greglogs();
this.awManager=awmanager;
this.userInfoConsumer=userinfoconsumer;
this.tasksConsumer=tasksconsumer;
this.vpanel=document.getElementById("validation_wrapper");
this.opanel=document.getElementById("validation_obscurer");
this.log=new Greglogs();
this.usergraph="http://www.vaimee.it/my2sec/"+userInfoConsumer.usermail;
//MESSAGES
this.awMessagesProducer=new SynchronousProducer(
Expand Down Expand Up @@ -159,12 +159,19 @@ class AwApiUpdateManager {
console.log(success)

//ON SUCCESS...
await this.awManager.uploadQuery()
await this.awManager.uploadQuery() //dentro di se ora awmanager ha gli eventi
//non mi piace, voglio che ritorni una variabile e che fai il ciclo for prima
//if mongo -> qui invia sia sepa che mongo
//else solo sepa
await this.send_messages_to_sepa()
}

async send_messages_to_mongo(){

}

async send_messages_to_sepa(){
consoleLog(1,"### BUTTON PRESSED, STARTING SEPA UPLOAD ###")
this.log.info("### BUTTON PRESSED, STARTING SEPA UPLOAD ###")
this.change_update_status(3)//activate loading spinner

console.log(" ")
Expand Down Expand Up @@ -194,12 +201,12 @@ class AwApiUpdateManager {
msgtimestamp: msgtimestamp,
msgvalue: this.awManager.eventsRawJson[key]
}
consoleLog(0,"Usergraph: "+data.usergraph)
consoleLog(0,"Source: "+data.source)
consoleLog(0,"Timestamp: "+data.msgtimestamp)
consoleLog(0,"Message: "+data.msgvalue)
this.log.debug("Usergraph: "+data.usergraph)
this.log.debug("Source: "+data.source)
this.log.debug("Timestamp: "+data.msgtimestamp)
this.log.debug("Message: "+data.msgvalue)
response=await this.awManager.sepaClient.SEND_MESSAGE(data)
consoleLog(0,"RESPONSE: "+JSON.stringify(response))
this.log.debug("RESPONSE: "+JSON.stringify(response))
data={}//wipe data
}catch(e){
console.log(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
class AwApiStartStopManager {
constructor(){
class ScanManager extends AwMy2SecClient{
constructor(jsap){
super(jsap);
this.scan_started=false;
this.time_scanned=0;
this.currentSection=0;
this.updatebutton=document.getElementById("update-procedure-button")
this.explorerbutton=document.getElementById("explorer-button")
this.startbutton=document.getElementById("start-stop-innertext")
this.awManager= new AwClient();
}

async start_button(){
async getStatus(){
var start_event=await this.get_producer_event("last_start")
var update_event=await this.get_producer_event("last_update")
var data={
scanStarted:this.scan_started,
timeScanned:time_scanned,
lastStartEvent:start_event.data.last_start,
lastUpdateEvent:update_event.data.last_update
}
//this.log.info_table(data);
return data;
}
async logStatus(){
var data=await this.getStatus();
this.log.info_table(data);
}

async onStartButtonPressed(){
try{
if(!scan_started){
this.currentSection=0;
console.log("Starting scan...")
var res= await this.awManager.startWatchers()
var res= await this.startWatchers()
console.log(res)
await this.awManager.update_start_flag()
await this.update_start_flag()
updatebutton.className="default-button-deactivated"
startbutton.innerHTML=`Stop Scan&nbsp <img class="white-icon" src="Assets/icons/square.svg">`
explorerbutton.className="default-button"
Expand All @@ -25,7 +42,7 @@ class AwApiStartStopManager {
}else{
this.currentSection=0;
console.log("stopping scan...")
var res=await this.awManager.stopWatchers()
var res=await this.stopWatchers()
console.log(res)
updatebutton.className="default-button"
startbutton.innerHTML=`Resume Scan&nbsp <img class="white-icon" src="Assets/icons/play-outline.svg">`
Expand All @@ -41,43 +58,6 @@ class AwApiStartStopManager {
}


//###################
//# START-STOP SCAN #
//###################
//update ia knowledge
var currentSection=0;
var scan_started=false;
var time_scanned=0;
var updatebutton=document.getElementById("update-procedure-button")
var explorerbutton=document.getElementById("explorer-button")
var startbutton=document.getElementById("start-stop-innertext")
async function start_button(){
try{
if(!scan_started){
currentSection=0;
console.log("Starting scan...")
var res= await awManager.startWatchers()
console.log(res)
await awManager.update_start_flag()
updatebutton.className="default-button-deactivated"
startbutton.innerHTML=`Stop Scan&nbsp <img class="white-icon" src="Assets/icons/square.svg">`
explorerbutton.className="default-button"
scan_started=true
timer("ready_status")
}else{
currentSection=0;
console.log("stopping scan...")
var res=await awManager.stopWatchers()
console.log(res)
updatebutton.className="default-button"
startbutton.innerHTML=`Resume Scan&nbsp <img class="white-icon" src="Assets/icons/play-outline.svg">`
scan_started=false
}
}catch(e){
console.log(e)
change_update_status(2)
}
}
async function init_update_button(){
var start_event=await awManager.get_producer_event("last_start")
if(Object.keys(start_event).length===0){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ events_title = document.getElementById("events-title");

class AwManager extends AwProducer{

constructor(){
super()
constructor(jsap){
super(jsap)
this.current_watcher_index=0;
this.tm=new TableManager("validation_body")
this.atm= new ActivityTableManager("validation_body")
Expand Down Expand Up @@ -164,7 +164,7 @@ class AwManager extends AwProducer{
//WRITE DATA INTO THE RAW TABLE
//print_raw_json_to_textarea("raw_events_wrapper",json_object)
//WRITE DATA INTO FORMATTED TABLE
consoleLog(0,json_object.length)
log.debug(json_object.length)
//SE NON E' VUOTO ESEGUI
if(json_object.length!=0){
//console.log(json_object)
Expand Down Expand Up @@ -221,7 +221,7 @@ class AwManager extends AwProducer{
tablerows.appendChild(row);
}
}else{
consoleLog(1,"skipped empty json")
log.info("skipped empty json")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ const JsapApi = Sepajs.Jsap;
//console.log(JSON.stringify(default_jsap))

class AwProducer extends AwMy2SecClient{
constructor(){
super("127.0.0.1:5000")
constructor(jsap){
super(jsap)
//this.mc= new My2secClient()
this.queryBenchClient= new Sepajs.SEPA(default_jsap)
this.sepaClient= new JsapApi(default_jsap)
this.sepa_host_string=jsap.host
this.queryBenchClient= new Sepajs.SEPA(jsap)
this.sepaClient= new JsapApi(jsap)
this.whitelistedWatchers="aw-watcher-working,aw-watcher-afk,aw-watcher-notshutdown,aw-watcher-start-stop"//"aw-watcher-working,aw-watcher-afk,aw-watcher-scan";
this.watchersJson={};
this.eventsRawJson=[];
Expand All @@ -28,10 +29,10 @@ class AwProducer extends AwMy2SecClient{
}

async startTests(){
log.info("testing connections...")
log.debug("log_level set to error to avoid console cluttering")
var temp=log.loglevel
log.loglevel=1
this.log.info("testing connections...")
this.log.debug("log_level set to error to avoid console cluttering")
var temp=this.log.loglevel
this.log.loglevel=1
var results={
"sepa":"",
"aw":"",
Expand All @@ -55,7 +56,7 @@ class AwProducer extends AwMy2SecClient{
results.aw="not-passed"
}
//test my2sec
log.loglevel=temp
this.log.loglevel=temp
return results
}

Expand Down Expand Up @@ -93,10 +94,10 @@ class AwProducer extends AwMy2SecClient{
this.queryBenchClient.query("select ?time where {<http://sepatest/currentTime> <http://sepatest/hasValue> ?time}")
.then((data)=>{
log.info("Connected to SEPA!");
sepa_cbox.innerHTML="Connected to SEPA ("+default_jsap.host /*+":"+jsap.sparql11protocol.port*/ +"<img class='white-icon' src='Assets/icons/wifi.svg'>)"
sepa_cbox.innerHTML="Connected to SEPA ("+this.sepa_host_string /*+":"+jsap.sparql11protocol.port*/ +"<img class='white-icon' src='Assets/icons/wifi.svg'>)"

resolve(data);
document.getElementById("row-2").style.display="flex";
//document.getElementById("row-2").style.display="flex";
});
});
}
Expand Down Expand Up @@ -129,7 +130,6 @@ class AwProducer extends AwMy2SecClient{
console.log(this.start_time_json)
this.eventsRawJson=await this.get_filtered_watchers_events()
for(var key in this.watchersJson){

this.eventsJson[key] = JSON.parse(this.eventsRawJson[key]);
this.eventsRawJson[key]=this.eventsRawJson[key].replace(/\\/g,"\\\\");//BUGFIX
this.eventsRawJson[key]=this.eventsRawJson[key].replace(/\"/g,"\\\"");//BUGFIX
Expand Down Expand Up @@ -259,17 +259,17 @@ class AwProducer extends AwMy2SecClient{
}
//alert(number_of_filtered_watchers)
if(filtering_active==1){
consoleLog(0,"FILTERED WATCHERS!")
log.debug("FILTERED WATCHERS!")
//OVERRIDE GLOBAL VARIABLE
watchers_json=filtered_watchers_json;
}else{
consoleLog(2,"USING UNFILTERED WATCHERS, MAY LEAD TO INSTABILITY")
log.warning("USING UNFILTERED WATCHERS, MAY LEAD TO INSTABILITY")
}
//consoleLog(0,JSON.stringify(watchers_json));
//alert("ciao")
//[0.1] CREATE AW PRODUCER BUCKET IF IT DOES NOT EXISTS
if(aw_producer_exists==0){
consoleLog(0,"FIRST RUN, CREATING AW PRODUCER")
log.debug("FIRST RUN, CREATING AW PRODUCER")
await this.create_producer_bucket();
}
//RETURN WATCHERS JSON OBJECT
Expand Down Expand Up @@ -309,7 +309,7 @@ class AwProducer extends AwMy2SecClient{
}else{

//GET ALL EVENTS
consoleLog(1,"first run, fetching all events")
log.info("first run, fetching all events")
end_time = get_current_timestamp();//FIX BUG ON FIRST START
for(key in this.watchersJson){
try{
Expand Down Expand Up @@ -365,10 +365,10 @@ class AwProducer extends AwMy2SecClient{
function update_sepa_message(jsonMessage,watcher_client,watcher_hostname){
//var string="insert {<http://dld.arces.unibo.it/ontology/greg/messaggion"+String(counter)+"> <valore> '''"+JSON.stringify(jsonMessage)+"'''} where{}"
var string="insert { _:b <hasValue> '''"+JSON.stringify(jsonMessage)+"'''; <hasClient> '''"+watcher_client+"'''; <hasHost> '''"+watcher_hostname+"'''} where{}"
consoleLog(0,string)
log.debug(string)
client.update(string)
.then(()=>{
consoleLog(1,"update_sepa_message: "+watcher_client +" EVENTS UPLOADED CORRECTLY!")
log.info("update_sepa_message: "+watcher_client +" EVENTS UPLOADED CORRECTLY!")
});

}
Expand All @@ -378,10 +378,10 @@ function update_user_sepa_message(jsonMessage,watcher_client,username){
//var string="insert {<http://dld.arces.unibo.it/ontology/greg/messaggion"+String(counter)+"> <valore> '''"+JSON.stringify(jsonMessage)+"'''} where{}"
return new Promise(resolve=>{
var string="insert { graph <http://www.vaimee.it/"+username+"> {_:b <http://www.vaimee.it/ontology/sw#messageValue> '''"+jsonMessage+"'''}} where{}"
consoleLog(0,string)
log.debug(string)
client.update(string)
.then(()=>{
consoleLog(1,"update_sepa_message: "+watcher_client +" EVENTS UPLOADED CORRECTLY!")
log.info("update_sepa_message: "+watcher_client +" EVENTS UPLOADED CORRECTLY!")
resolve("updated");

});
Expand All @@ -394,10 +394,10 @@ function update_user_timed_sepa_message(jsonMessage,watcher_client,username,time
//var string="insert {<http://dld.arces.unibo.it/ontology/greg/messaggion"+String(counter)+"> <valore> '''"+JSON.stringify(jsonMessage)+"'''} where{}"
return new Promise(resolve=>{
var string="insert { graph <http://www.vaimee.it/my2sec/"+username+"> {_:b <http://www.vaimee.it/ontology/sw#messageValue> '''"+jsonMessage+"''' ; <http://www.vaimee.it/ontology/sw#messageSource> <http://www.vaimee.it/sources/"+watcher_client+"> ; <http://www.w3.org/2006/time#inXSDDateTimeStamp> '''"+timestamp+"'''}} where{}"
consoleLog(0,string)
log.debug(string)
client.update(string)
.then(()=>{
consoleLog(1,"update_sepa_message: "+watcher_client +" EVENTS UPLOADED CORRECTLY!")
log.info("update_sepa_message: "+watcher_client +" EVENTS UPLOADED CORRECTLY!")
resolve("updated");

});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class TasksConsumer{
constructor(email){
this.queryBenchClient= new Sepajs.SEPA(default_jsap)
this.sepaClient= new JsapApi(default_jsap)
constructor(jsap,email){
var log=new Greglogs();
this.queryBenchClient= new Sepajs.SEPA(jsap)
this.sepaClient= new JsapApi(jsap)
this.sub;
this.tasksCache=[]
this.email=email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class UserInfoConsumer {
constructor(usermail){
this.sepaConsumer= new Sepajs.SEPA(default_jsap)
constructor(jsap,usermail){
var log=new Greglogs();
this.sepaConsumer= new Sepajs.SEPA(jsap)
this.userName="";
this.usermail=usermail;
//log.info("New UserInfoConsumer created!")
Expand All @@ -19,12 +20,11 @@ class UserInfoConsumer {
}

logspan_subEventsCount(element){
consoleLog(1,"SUBSCRIBING TO EVENTS COUNT")
log.debug("SUBSCRIBING TO EVENTS COUNT")
var counter_el=document.getElementById(element);
const sub = this.sepaConsumer.subscribe("select (COUNT(?nodeid) AS ?nevents) where { graph <http://www.vaimee.it/my2sec/"+this.usermail+"> {?nodeid <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.vaimee.it/ontology/sw#Event> }} ")
//[0]ON SUBSCRIBE
sub.on("subscribed",console.log)
//g.consoleLog(1,"#### LISTENING TO NOTIFICATIONS ###\n")
//[1]ON NOTIFICATION
sub.on("notification", not => {
var bindings=this.extract_bindings(not);
Expand Down
Loading

0 comments on commit a5a2c23

Please sign in to comment.