diff --git a/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.component.html b/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.component.html
index 6bc4296..52c86a7 100755
--- a/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.component.html
+++ b/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.component.html
@@ -65,6 +65,7 @@
Profile |
Modified |
+ Notified |
Status |
|
@@ -96,6 +97,11 @@
{{profile.name}}
{{profile.datecreated}} |
+
+
+
+ Notified
+ |
{{profile.status}} |
diff --git a/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.component.ts b/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.component.ts
index cd95d5f..a257f66 100755
--- a/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.component.ts
+++ b/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.component.ts
@@ -19,10 +19,12 @@ export class ManageprofilesComponent implements OnInit {
public allUsersProfiles: Array = [];
public statusValues = [
- 'Saved',
+ 'Processing',
'Evaluating',
'On Beta'
];
+
+ public communityId = '';
public isCommunityManager = false;
public userSavedProfiles: Array = [];
@@ -34,6 +36,8 @@ export class ManageprofilesComponent implements OnInit {
currentPage: 1
};
+ public pending = false;
+
constructor(private manageProfilesService: ManageprofilesService, private route: ActivatedRoute, private router: Router) {
}
@@ -41,8 +45,9 @@ export class ManageprofilesComponent implements OnInit {
this.route.queryParams
.subscribe(
params => {
- console.log('queryParams', params['communityId']);
- this.initialServerhandshake(params['communityId']);
+ // console.log('queryParams', params['communityId']);
+ this.communityId = params['communityId'];
+ this.initialServerhandshake(this.communityId);
});
this.isCommunityManager = this.manageProfilesService.isCommunityManager === 'true';
}
@@ -193,6 +198,18 @@ export class ManageprofilesComponent implements OnInit {
.subscribe(res => this.exampleProfiles = res);
}
+ notifyProfile(profile: ProfileMetadata ): void {
+ UIkit.modal.confirm('' +
+ 'A notification will be sent to the OpenAIRE Mining experts, that your profile is in its final version!Are you sure you want to proceed?', {escClose: true}).then(() => {
+ this.pending = true;
+ this.manageProfilesService.notifyProfile(this.communityId, profile.id)
+ .subscribe(res => {
+ profile.notified = 1;
+ this.pending = false;
+ });
+ });
+ }
+
loadExampleProfile(name: string): void {
// clear localstorage values
this.clearLocalStorage();
diff --git a/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.service.ts b/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.service.ts
index 33ab9ac..af509c5 100755
--- a/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.service.ts
+++ b/interactive-mining-angular-frontend/src/app/manageprofiles/manageprofiles.service.ts
@@ -27,6 +27,7 @@ export class ManageprofilesService {
private getExampleProfilesUrl = '/getexampleprofiles';
private loadExampleProfileUrl = '/loadexampleprofile';
private uploadProfileUrl = '/uploadprofile';
+ private notifyProfileUrl = '/notifyforprofile';
constructor(private http: HttpClient) {
this.userId = this.util.getUserId();
@@ -114,4 +115,9 @@ export class ManageprofilesService {
.catch(this.util.handleError);
}
+ notifyProfile(communityId: string, profileId: string): Observable {
+ return this.http.post(this.backendServerAddress + this.notifyProfileUrl, {community: communityId, user: this.userId, id: profileId})
+ .catch(this.util.handleError);
+ }
+
}
diff --git a/interactive-mining-angular-frontend/src/app/manageprofiles/profile-metadata.ts b/interactive-mining-angular-frontend/src/app/manageprofiles/profile-metadata.ts
index 578f3e1..fa15629 100755
--- a/interactive-mining-angular-frontend/src/app/manageprofiles/profile-metadata.ts
+++ b/interactive-mining-angular-frontend/src/app/manageprofiles/profile-metadata.ts
@@ -4,5 +4,6 @@ export class ProfileMetadata {
datecreated: string;
status: string;
matches: string;
+ notified: number;
}
diff --git a/interactive-mining-backend/madoap/src/madserverv3.py b/interactive-mining-backend/madoap/src/madserverv3.py
index 2aa00d7..eba9262 100755
--- a/interactive-mining-backend/madoap/src/madserverv3.py
+++ b/interactive-mining-backend/madoap/src/madserverv3.py
@@ -64,7 +64,8 @@ class Application(tornado.web.Application):
(r"/runmining", RunMiningHandler),
(r"/preparesavedprofile", PrepareSavedProfileHandler),
(r"/saveprofile", SaveProfileToDatabaseHandler),
- (r"/downloadprofile", DownloadProfileHandler)
+ (r"/downloadprofile", DownloadProfileHandler),
+ (r"/notifyforprofile", NotifyHandler)
]
@@ -467,8 +468,8 @@ class GetUsersProfilesHandler(BaseHandler):
except Exception as ints:
print ints
community_id = 'Unkown '+user
- for r in cursor.execute('''SELECT id,name,datecreated,status,matches,docname FROM database order by rowid desc'''):
- users_profiles.append({"user":community_id,"userId":user,"profileId":r[0], "profile": r[1], "datecreated": r[2], "status": r[3], "matches": r[4], "docname": r[5]})
+ for r in cursor.execute('''SELECT id,name,datecreated,status,matches,docname,notified FROM database order by rowid desc'''):
+ users_profiles.append({"user":community_id,"userId":user,"profileId":r[0], "profile": r[1], "datecreated": r[2], "status": r[3], "matches": r[4], "docname": r[5], "notified": r[6] })
data['profiles'] = users_profiles
self.write(json.dumps(data))
self.finish()
@@ -513,7 +514,7 @@ class UpdateProfileStatusHandler(BaseHandler):
cursor=madis.functions.Connection(database_file_name).cursor()
# Write new Profile status to users database
status = request_arguments['status']
- cursor.execute('''UPDATE database set status=? where id=?''', (profile_id,status,), parse=False)
+ cursor.execute('''UPDATE database set status=? where id=?''', (status,profile_id,), parse=False)
cursor.close()
self.write(json.dumps({}))
self.finish()
@@ -560,8 +561,8 @@ class GetUserProfilesHandler(BaseHandler):
# data to be sent
data = {}
user_profiles = []
- for r in cursor.execute('''SELECT id,name,datecreated,status,matches,docname FROM database order by rowid desc'''):
- user_profiles.append({"id":r[0], "name": r[1], "datecreated": r[2], "status": r[3], "matches": r[4], "docname": r[5]})
+ for r in cursor.execute('''SELECT id,name,datecreated,status,matches,docname,notified FROM database order by rowid desc'''):
+ user_profiles.append({"id":r[0], "name": r[1], "datecreated": r[2], "status": r[3], "matches": r[4], "docname": r[5], "notified": r[6]})
data['profiles'] = user_profiles
cursor.close()
self.write(json.dumps(data))
@@ -1603,9 +1604,9 @@ class SaveProfileToDatabaseHandler(BaseHandler):
cursor=madis.functions.Connection(database_file_name).cursor()
user_profiles = []
if old_profile:
- cursor.execute('''UPDATE database SET datecreated=?, status=?, matches=?, docname=?, docsnumber=? WHERE id=?''', (datetime.date.today().strftime("%B %d %Y"),"Ready","8/8",doc_name,docs_number,profile_id), parse=False)
+ cursor.execute('''UPDATE database SET datecreated=?, status=?, matches=?, docname=?, docsnumber=?, notified=? WHERE id=?''', (datetime.date.today().strftime("%B %d %Y"),"Processing","8/8",doc_name,docs_number,0,profile_id), parse=False)
else:
- cursor.execute('''INSERT INTO database VALUES(?,?,?,?,?,?,?)''', (profile_id,profile_name,datetime.date.today().strftime("%B %d %Y"),"Saved","8/8",doc_name,docs_number,), parse=False)
+ cursor.execute('''INSERT INTO database VALUES(?,?,?,?,?,?,?,?)''', (profile_id,profile_name,datetime.date.today().strftime("%B %d %Y"),"Saved","8/8",doc_name,docs_number,0,), parse=False)
cursor.close()
self.write(json.dumps({}))
self.finish()
@@ -1659,6 +1660,66 @@ class DownloadProfileHandler(BaseHandler):
return
+class NotifyHandler(BaseHandler):
+ passwordless=True
+ def set_default_headers(self):
+ self.set_header("Access-Control-Allow-Origin", "*")
+ self.set_header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
+ self.set_header('Access-Control-Allow-Methods', 'POST, OPTIONS')
+ self.set_header('Access-Control-Allow-Credentials', 'true')
+ self.set_header('Content-Type', 'application/oamp')
+ def options(self):
+ # no body
+ self.set_status(204)
+ self.finish()
+ def post(self):
+ try:
+ # get user id from body. Must have
+ request_arguments = json.loads(self.request.body)
+ if 'user' not in request_arguments or request_arguments['user'] == '':
+ self.set_status(400)
+ self.write("Missing user's id argument")
+ return
+ community = request_arguments['community'][:128]
+ user_id = request_arguments['user'][:128]
+ # get data
+ profile_id = request_arguments['id'][:128]
+ # Import smtplib for the actual sending function
+ import smtplib
+ subject = 'New Profile update of Community: {} on profile: {}'.format(community, profile_id)
+ text = 'Hello our great mining team experts of OpenAIRE,\n\nA new profile update of Community {}\non profile named: {}'.format(community, profile_id)
+ message = 'Subject: {}\n\n{}'.format(subject, text)
+ # Send the message via our own SMTP server.
+ s = smtplib.SMTP(msettings.SMTP_HOST, msettings.SMTP_PORT)
+ s.ehlo()
+ s.starttls()
+ s.ehlo()
+ s.login(msettings.SMTP_USERNAME, msettings.SMTP_PASSWORD)
+ s.sendmail(msettings.SMTP_FROM, 'sospioneer2002@gmail.com', message)
+ s.quit()
+
+ # write new profile to database
+ import sys
+ sys.path.append(msettings.MADIS_PATH)
+ import madis
+ # database file name
+ database_file_name = "users_files/OAMiningProfilesDatabase_{0}.db".format(user_id)
+ # get the database cursor
+ cursor=madis.functions.Connection(database_file_name).cursor()
+ user_profiles = []
+ cursor.execute('''UPDATE database SET notified=1 WHERE id=?''', (profile_id,), parse=False)
+ cursor.close()
+
+ self.write(json.dumps({}))
+ self.finish()
+ except Exception as ints:
+ self.set_status(400)
+ self.write("A server error occurred, please contact administrator!")
+ self.finish()
+ print ints
+ return
+
+
def main():
def getqtext(query,params):
query=query.strip('\n \s')
diff --git a/interactive-mining-backend/madoap/src/settings.py b/interactive-mining-backend/madoap/src/settings.py
index bddd8c0..35bed0c 100755
--- a/interactive-mining-backend/madoap/src/settings.py
+++ b/interactive-mining-backend/madoap/src/settings.py
@@ -11,6 +11,14 @@ MADIS_PATH='../../../interactive-mining-3rdparty-madis/madis/src'
DB='static/database.db'
RESET_FIELDS=1
+# SMTP_EMAIL SETTINGS
+SMTP_HOST = 'smtp.gmail.com'
+SMTP_PORT = 587
+SMTP_AUTH = True
+SMTP_FROM = 'openaire.test@gmail.com'
+SMTP_USERNAME = 'openaire.test@gmail.com'
+SMTP_PASSWORD = '...'
+
FLOW_PATH=''
# Change this. Make this unique, and don't share it with anybody.
|