',
47 | 'toString': 'reknow-principal-researchers@hiit.fi',
48 | 'tags': ['email', 'reknow'],
49 | #'ccString': [],
50 | #'attachments': [],
51 | #'rawMessage': '' # the full raw message here...
52 | }
53 | }
54 |
55 | r = requests.post(server_url + '/data/event',
56 | data=json.dumps(payload),
57 | headers={'content-type': 'application/json'},
58 | auth=(server_username, server_password),
59 | timeout=10)
60 |
61 | print('DiMe returns:', json.dumps(r.json(), indent=2))
62 |
--------------------------------------------------------------------------------
/scripts/event-spamming.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import threading
4 | import time
5 | import requests
6 | import socket
7 | import json
8 |
9 | #------------------------------------------------------------------------------
10 |
11 | server_url = 'http://localhost:8080/api'
12 | server_username = 'testuser'
13 | server_password = 'testuser123'
14 |
15 | #------------------------------------------------------------------------------
16 |
17 | class PostingThread(threading.Thread):
18 | def __init__(self, payload):
19 | threading.Thread.__init__(self)
20 | self.payload = payload
21 |
22 | def run(self):
23 | print('Sleeping 1 sec ...')
24 | time.sleep(1)
25 | r = requests.post(server_url + '/data/event',
26 | data=json.dumps(self.payload),
27 | headers={'content-type': 'application/json'},
28 | auth=(server_username, server_password),
29 | timeout=10)
30 |
31 | # Set all the standard event fields
32 | payload = {
33 | '@type': 'SearchEvent',
34 | 'actor': 'event-spamming.py',
35 | 'origin': socket.gethostbyaddr(socket.gethostname())[0],
36 | 'type': 'http://www.hiit.fi/ontologies/dime/#ExampleSearchEvent',
37 | 'start': time.strftime("%Y-%m-%dT%H:%M:%S%z", time.localtime()),
38 | 'appId': 'Oocheth5muQuu8jathah3EewTheiReo0veryrandomindeed'
39 | }
40 |
41 | threads = []
42 | for i in range(1):
43 | p = payload.copy()
44 | p['query'] = 'dummy search new {}'.format(i)
45 | threads.append(PostingThread(p))
46 |
47 | for t in threads:
48 | t.start()
49 |
50 | print('Sleeping 5 secs ...')
51 | time.sleep(5)
52 | r = requests.get(server_url + '/data/events?appid=' + payload['appId'],
53 | headers={'content-type': 'application/json'},
54 | auth=(server_username, server_password),
55 | timeout=10)
56 |
57 | print('DiMe returns:', json.dumps(r.json(), indent=2))
58 | print('Items: ', len(r.json()))
59 |
--------------------------------------------------------------------------------
/scripts/filter-example.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import socket
6 | import time
7 | import json
8 |
9 | #------------------------------------------------------------------------------
10 |
11 | server_url = 'http://localhost:8080/api'
12 | server_username = 'testuser'
13 | server_password = 'testuser123'
14 |
15 | #------------------------------------------------------------------------------
16 |
17 | r = requests.post(server_url + '/ping')
18 |
19 | if r.status_code != requests.codes.ok:
20 | print('No connection to DiMe server!')
21 | sys.exit(1)
22 |
23 | print('DiMe returns:', json.dumps(r.json(), indent=2))
24 |
25 | r = requests.get(server_url + '/data/informationelements?' + sys.argv[1],
26 | headers={'content-type': 'application/json'},
27 | auth=(server_username, server_password),
28 | timeout=10)
29 |
30 | print('DiMe returns:', json.dumps(r.json(), indent=2))
31 |
--------------------------------------------------------------------------------
/scripts/fitbit/README.md:
--------------------------------------------------------------------------------
1 | First, install the requirements using `pip`, for example using `virtualenv`:
2 |
3 | virtualenv env
4 | source env/bin/activate
5 | pip install -r requirements.txt
6 |
7 | (If you find that there are still some requirements missing, please add them to requirements.txt.)
8 |
9 | Next, you need to create a fresh configuration file and fetch the OAuth2 API keys:
10 |
11 | cp fitbit.cfg.example fitbit.cfg
12 | ./gather_keys_oauth2.py
13 |
14 | Open the file `upload.py` in your favourite text editor and check the variables at the start of the file, at least the DiMe username and password. Finally, run it to import your Fitbit events into DiMe:
15 |
16 | ./upload.py
17 |
18 | Currently the script takes the steps at 15 minute intervals, but this can be changed by altering the variables. It also takes the values just for today. See the Python fitbit library's API for how to other things:
19 |
--------------------------------------------------------------------------------
/scripts/fitbit/fitbit.cfg.example:
--------------------------------------------------------------------------------
1 | [oauth2]
2 | client_id = 227SBD
3 | client_secret = 374b60ed8d4c54af12fd10e92412f42a
4 |
--------------------------------------------------------------------------------
/scripts/fitbit/requirements.txt:
--------------------------------------------------------------------------------
1 | cherrypy
2 | fitbit
3 | pytz
4 |
--------------------------------------------------------------------------------
/scripts/funf-example.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import socket
6 | import time
7 | import json
8 |
9 | #------------------------------------------------------------------------------
10 |
11 | server_url = 'http://localhost:8080/api'
12 | server_username = 'testuser'
13 | server_password = 'testuser123'
14 |
15 | #------------------------------------------------------------------------------
16 |
17 | payload = {
18 | '@type': 'FunfEvent',
19 | 'appId': 'foobar1234',
20 | 'actor': 'TestMobileLogger',
21 | 'origin': socket.gethostbyaddr(socket.gethostname())[0],
22 | 'start': time.strftime("%Y-%m-%dT%H:%M:%S%z", time.localtime()),
23 | 'probeName': 'WifiProbe',
24 | 'funfValue': '{"some": "json", "here": "ok"}'
25 | }
26 |
27 | print('Uploading: ', json.dumps(payload, indent=2))
28 |
29 | r = requests.post(server_url + '/data/event',
30 | data=json.dumps(payload),
31 | headers={'content-type': 'application/json'},
32 | auth=(server_username, server_password),
33 | timeout=10)
34 |
35 | print('DiMe returns:', json.dumps(r.json(), indent=2))
36 |
--------------------------------------------------------------------------------
/scripts/generate_activities.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import datetime
4 | import dime
5 | import json
6 | import requests
7 | import time
8 |
9 | from numpy.random import choice
10 |
11 |
12 | #------------------------------------------------------------------------------
13 |
14 | class DiMeConnection:
15 | def __init__(self, url, username, uid=None):
16 | self.url = url
17 | self.username = username
18 | self.uid = uid
19 | self.password = dime.password(self.username)
20 |
21 | def ping(self, verbose=True):
22 | r = requests.post(self.url + '/ping')
23 |
24 | if r.status_code != requests.codes.ok:
25 | if verbose:
26 | print('No connection to DiMe server!', file=sys.stderr)
27 | return None
28 | else:
29 | if verbose:
30 | print('Connected to DiMe: {} @ {}, version {}.'.
31 | format(self.username, self.url, r.json()['version']),
32 | file=sys.stderr)
33 | return r.json()
34 |
35 | def post(self, url):
36 | print("POST", url)
37 | r = requests.post(self.url + url, headers={'content-type': 'application/json'},
38 | auth=(self.username, self.password), timeout=10)
39 | return r
40 |
41 | def get(self, url):
42 | print("GET", url)
43 | r = requests.get(self.url + url, headers={'content-type': 'application/json'},
44 | auth=(self.username, self.password), timeout=10)
45 | return r
46 |
47 | #------------------------------------------------------------------------------
48 |
49 | def remove_fields(res, *fields):
50 | for f in fields:
51 | if f in res:
52 | del res[f]
53 | #------------------------------------------------------------------------------
54 |
55 | dime = DiMeConnection('http://localhost:8081/api', 'mvsjober')
56 |
57 | day = "2017-06-09"
58 | req = '/data/events?after={0}T00:00:00&before={0}T23:59:59&orderBy=start&desc=false'.format(day)
59 | print(req)
60 | events = dime.get(req).json()
61 |
62 | activities = ["Re:Know", "Admin", "Focus area", "Misc"]
63 |
64 | act_events = []
65 | act_start = None
66 | prev_end = None
67 |
68 | for e in events:
69 | start = e['start']
70 | end = e['end']
71 |
72 | if act_start is None:
73 | act_start = start
74 |
75 | desc = ''
76 | if 'targettedResource' in e:
77 | res = e['targettedResource']
78 | if 'title' in res:
79 | desc = res['title']
80 |
81 | if 'plainTextContent' in res and len(res['plainTextContent']) > 0:
82 | res['plainTextContent'] = '[removed]'
83 |
84 | if 'uri' in res and len(res['uri']) > 0:
85 | res['plainTextContent'] = 'http://example.com'
86 |
87 | remove_fields(res, 'frequentTerms', 'title', 'tags', 'html', 'hyperLinks', 'imgURLs', 'metaTags', 'id', 'user', 'profileIds', 'timeCreated', 'timeModified')
88 |
89 | if prev_end is not None:
90 | diff = start-prev_end
91 | if diff > 5*60*1000: # five minutes
92 | act_events.append({
93 | '@type': 'ActivityEvent',
94 | 'actor': 'generate_activities.py',
95 | 'origin': 'localhost',
96 | 'type': 'http://www.hiit.fi/ontologies/dime/#ActivityEvent',
97 | 'start': act_start,
98 | 'end': prev_end,
99 | 'activity': choice(activities, 1, p=[0.5, 0.2, 0.2, 0.1])[0]
100 | })
101 | act_start = start
102 |
103 |
104 | print(e['@type'], ':', start, '->', end)
105 | print(desc)
106 |
107 | prev_end = end
108 | del e['id']
109 | del e['user']
110 | del e['timeCreated']
111 | del e['timeModified']
112 | del e['profileIds']
113 |
114 | with open('demo_activities.json', 'w') as fp:
115 | json.dump(act_events, fp, indent=2)
116 |
117 | with open('demo_events.json', 'w') as fp:
118 | json.dump(events, fp, indent=2)
119 |
--------------------------------------------------------------------------------
/scripts/get-all.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import socket
6 | import time
7 | import json
8 | import dime
9 |
10 | #------------------------------------------------------------------------------
11 |
12 | server_url = 'http://localhost:8080/api'
13 | server_username = 'testuser'
14 | server_password = dime.password(server_username)
15 |
16 | json_filename = 'dime-elements.json'
17 |
18 | #------------------------------------------------------------------------------
19 |
20 | # ping server (not needed, but fun to do :-)
21 | r = requests.post(server_url + '/ping')
22 |
23 | if r.status_code != requests.codes.ok:
24 | print('No connection to DiMe server!')
25 | sys.exit(1)
26 |
27 | params = ""
28 | if len(sys.argv) > 1:
29 | params = "?" + quote_plus("&".join(sys.argv[1:]), safe='&=')
30 |
31 | get_url = server_url + '/data/informationelements' + params
32 | print("GET", get_url)
33 |
34 | r = requests.get(get_url,
35 | headers={'content-type': 'application/json'},
36 | auth=(server_username, server_password),
37 | timeout=10)
38 |
39 | if r.status_code > 299:
40 | print('HTTP Error:', r.status_code)
41 | sys.exit(1)
42 |
43 | j = r.json()
44 |
45 | print("Got {} InformationElements from DiMe.".format(len(j)), file=sys.stderr)
46 |
47 | with open(json_filename, 'w') as fp:
48 | json.dump(j, fp, indent=2)
49 | print("Wrote", json_filename)
50 |
51 | # for elem in j:
52 | # print(elem['id'])
53 |
--------------------------------------------------------------------------------
/scripts/get-events.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import socket
6 | import time
7 | import json
8 | import dime
9 |
10 | #------------------------------------------------------------------------------
11 |
12 | server_url = 'http://localhost:8080/api'
13 | server_username = 'testuser'
14 | server_password = dime.password(server_username)
15 |
16 | json_filename = 'dime-events.json'
17 |
18 | #------------------------------------------------------------------------------
19 |
20 | # ping server (not needed, but fun to do :-)
21 | r = requests.post(server_url + '/ping')
22 |
23 | if r.status_code != requests.codes.ok:
24 | print('No connection to DiMe server!')
25 | sys.exit(1)
26 |
27 | params = ""
28 | if len(sys.argv) > 1:
29 | params = "?" + "&".join(sys.argv[1:])
30 |
31 | request_url = server_url + '/data/events' + params
32 | print('GET', request_url)
33 |
34 | r = requests.get(request_url,
35 | headers={'content-type': 'application/json'},
36 | auth=(server_username, server_password))
37 |
38 | if r.status_code > 299:
39 | print('HTTP Error:', r.status_code)
40 | sys.exit(1)
41 |
42 | j = r.json()
43 |
44 | print("Got {} events from DiMe.".format(len(j)), file=sys.stderr)
45 |
46 | # for elem in j[:2]:
47 | # print(json.dumps(elem, indent=2))
48 |
49 | with open(json_filename, 'w') as fp:
50 | json.dump(j, fp, indent=2)
51 | print("Wrote", json_filename)
52 |
--------------------------------------------------------------------------------
/scripts/get-one.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import socket
6 | import time
7 | import json
8 |
9 | #------------------------------------------------------------------------------
10 |
11 | server_url = 'http://localhost:8080/api'
12 | server_username = 'testuser'
13 | server_password = 'testuser123'
14 |
15 | #------------------------------------------------------------------------------
16 |
17 | r = requests.get(server_url + '/data/informationelement/111',
18 | headers={'content-type': 'application/json'},
19 | auth=(server_username, server_password),
20 | timeout=10)
21 |
22 | if r.status_code != requests.codes.ok:
23 | print('HTTP Error:', r.status_code)
24 | print(json.dumps(r.json(), indent=2))
25 | sys.exit(1)
26 |
27 | print('DiMe returns:', json.dumps(r.json(), indent=2))
28 |
--------------------------------------------------------------------------------
/scripts/google-search-import.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import socket
6 | import time
7 | import json
8 | import os, os.path
9 |
10 | #------------------------------------------------------------------------------
11 |
12 | server_url = 'http://localhost:8080/api'
13 | server_username = 'testuser'
14 | server_password = 'testuser123'
15 |
16 | #------------------------------------------------------------------------------
17 |
18 | count = 0
19 |
20 | #------------------------------------------------------------------------------
21 |
22 | def ping():
23 | r = requests.post(server_url + '/ping')
24 |
25 | if r.status_code != requests.codes.ok:
26 | print('No connection to DiMe server!')
27 | return False
28 | return True
29 |
30 | #------------------------------------------------------------------------------
31 |
32 | def post_item(item, endpoint):
33 | global server_url, server_username, server_password
34 |
35 | # Fill in all the standard event fields
36 | item['actor'] = 'google-search-import.py'
37 | item['origin'] = socket.gethostbyaddr(socket.gethostname())[0]
38 | item['type'] = 'http://www.hiit.fi/ontologies/dime/#GoogleSearchEvent'
39 |
40 | r = requests.post(server_url + endpoint,
41 | data=json.dumps(item),
42 | headers={'content-type': 'application/json'},
43 | auth=(server_username, server_password),
44 | timeout=10)
45 |
46 | if r.status_code != requests.codes.ok:
47 | print ("\nERROR: Post to DiMe failed: "
48 | "error={}, message={}\n".format(r.json()['error'],
49 | r.json()['message']))
50 |
51 | #------------------------------------------------------------------------------
52 |
53 | def process_file(filename):
54 | global count
55 |
56 | print("Processing", filename)
57 | with open(filename, 'r') as fp:
58 | events = json.load(fp)['event']
59 | for event in events:
60 | query = event['query']
61 | timestamp = int(query['id'][0]['timestamp_usec'])
62 |
63 | item = {}
64 | item['@type'] = 'SearchEvent'
65 | item['query'] = query['query_text']
66 | item['start'] = time.strftime("%Y-%m-%dT%H:%M:%S%z",
67 | time.localtime(timestamp/1000000))
68 |
69 | print('QUERY: "{}" at {}'.format(item['query'], item['start']))
70 |
71 | post_item(item, '/data/event')
72 |
73 | count += 1
74 |
75 | #------------------------------------------------------------------------------
76 |
77 | if not ping():
78 | sys.exit(1)
79 |
80 | search_path = sys.argv[1]
81 | for root, _, files in os.walk(search_path):
82 | for f in files:
83 | if f.endswith('.json'):
84 | process_file(os.path.join(root, f))
85 |
86 | print("Imported", count, "items.")
87 |
--------------------------------------------------------------------------------
/scripts/import-mongo.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | ./export-mongo.py -u testuser
3 |
4 | python -mjson.tool dime-events.json > /dev/null && \
5 | python -mjson.tool dime-elements.json > /dev/null && \
6 | curl -H "Content-Type: application/json" -u testuser:testuser123 --data @dime-events.json http://localhost:8080/api/data/events > /dev/null
7 |
--------------------------------------------------------------------------------
/scripts/import_json.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import dime
4 | import json
5 | import sys
6 | import requests
7 |
8 | #------------------------------------------------------------------------------
9 |
10 | class DiMeConnection:
11 | def __init__(self, url, username, uid=None):
12 | self.url = url
13 | self.username = username
14 | self.uid = uid
15 | self.password = dime.password(self.username)
16 |
17 | def ping(self, verbose=True):
18 | r = requests.post(self.url + '/ping')
19 |
20 | if r.status_code != requests.codes.ok:
21 | if verbose:
22 | print('No connection to DiMe server!', file=sys.stderr)
23 | return None
24 | else:
25 | if verbose:
26 | print('Connected to DiMe: {} @ {}, version {}.'.
27 | format(self.username, self.url, r.json()['version']),
28 | file=sys.stderr)
29 | return r.json()
30 |
31 | def post(self, url, data=None):
32 | print("POST", url)
33 | r = requests.post(self.url + url, headers={'content-type': 'application/json'},
34 | data=data, auth=(self.username, self.password), timeout=10)
35 | return r
36 |
37 | def get(self, url):
38 | print("GET", url)
39 | r = requests.get(self.url + url, headers={'content-type': 'application/json'},
40 | auth=(self.username, self.password), timeout=10)
41 | return r
42 |
43 | #------------------------------------------------------------------------------
44 |
45 | with open(sys.argv[1], 'r') as fp:
46 | data = json.loads(fp.read())
47 | dime = DiMeConnection('http://localhost:8081/api', 'demouser')
48 | res=dime.post("/data/events", data=json.dumps(data))
49 | if res.status_code == 200:
50 | print("Uploaded {} events.".format(len(res.json())))
51 | else:
52 | print(res.text)
53 |
54 |
--------------------------------------------------------------------------------
/scripts/jstest.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | JS Test
7 |
8 |
9 | Making HTTP GET request...
10 |
11 |
12 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/scripts/keyword-search-example.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import json
6 |
7 | #------------------------------------------------------------------------------
8 |
9 | server_url = 'http://localhost:8080/api'
10 | server_username = 'testuser'
11 | server_password = 'testuser123'
12 |
13 | #------------------------------------------------------------------------------
14 |
15 | # Define query as a JSON object
16 | query = [
17 | {"weight":0.5, "word":"dime"},
18 | {"weight": 0.1, "word":"reknow"}
19 | ]
20 |
21 | r = requests.post(server_url + '/keywordsearch',
22 | data=json.dumps(query),
23 | headers={'content-type': 'application/json'},
24 | auth=(server_username, server_password),
25 | timeout=10)
26 |
27 | if r.status_code != requests.codes.ok:
28 | print('ErrorNo connection to DiMe server!')
29 | sys.exit(1)
30 |
31 | print('DiMe returns:', json.dumps(r.json(), indent=2))
32 |
--------------------------------------------------------------------------------
/scripts/logger-example.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import socket
6 | import time
7 | import json
8 |
9 | #------------------------------------------------------------------------------
10 |
11 | server_url = 'http://localhost:8080/api'
12 | server_username = 'testuser'
13 | server_password = 'testuser123'
14 |
15 | #------------------------------------------------------------------------------
16 |
17 | r = requests.post(server_url + '/ping')
18 |
19 | if r.status_code != requests.codes.ok:
20 | print('No connection to DiMe server!')
21 | sys.exit(1)
22 |
23 | print('DiMe returns:', json.dumps(r.json(), indent=2))
24 |
25 | # Set all the standard event fields
26 | payload = {
27 | '@type': 'SearchEvent',
28 | 'actor': 'logger-example.py',
29 | 'origin': socket.gethostbyaddr(socket.gethostname())[0],
30 | 'type': 'http://www.hiit.fi/ontologies/dime/#ExampleSearchEvent',
31 | 'start': time.strftime("%Y-%m-%dT%H:%M:%S%z", time.localtime()),
32 | 'duration': 0,
33 | 'query': 'cats',
34 | 'tags': [
35 | { '@type': 'Tag',
36 | 'text': 'tag1',
37 | 'auto': False,
38 | 'actor': 'logger-example.py',
39 | },
40 | { '@type': 'Tag',
41 | 'text': 'tag2',
42 | 'auto': False,
43 | 'weight': 0.1
44 | }
45 | ]
46 | }
47 |
48 | # payload = {
49 | # # this corresponds to the Java event class
50 | # "@type": "DesktopEvent",
51 | # # the program that produced the event, here the web browser
52 | # "actor": "DiMe browser extension",
53 | # # time stamp when the event was started
54 | # "start": "2015-08-11T12:56:53Z",
55 | # # type using the Semantic Desktop ontology
56 | # "type": 'http://www.semanticdesktop.org/ontologies/2010/01/25/nuao/#UsageEvent',
57 | # "targettedResource": {
58 | # "@type": "WebDocument",
59 | # # title of the Web page
60 | # "title": "Join, or Die - Wikipedia, the free encyclopedia",
61 | # # type using the Semantic Desktop ontology
62 | # "isStoredAs": "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#RemoteDataObject",
63 | # # the plain text in the webpage
64 | # "plainTextContent": "From Wikipedia, the free encyclopedia....",
65 | # "mimeType": "text/html",
66 | # # the URI of the web page or document
67 | # "uri": "https://en.wikipedia.org/wiki/Join,_or_Die",
68 | # "type": 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/#HtmlDocument',
69 | # #a list of 8 tags defined by Tag class, the 8 tags are the most frequent terms on the page
70 | # "tags": [{"@type": "Tag", "text": "wikipedia"}],
71 | # #a list of terms in the webpage, ranked by frequency
72 | # "frequentTerms": ["wikipedia", "hurrican"],
73 | # #abstract/excerpt of the page
74 | # "abstract": '',
75 | # #a string of plain HTML with class/id/styles removed
76 | # "HTML": "From Wikipedia, the free encyclopedia
...",
77 | # #a list of imgages in the page
78 | # "imgURLs": [{'url':'http://.../a.jpg', 'text': 'a pic'}],
79 | # #a list of hyperlinks in the page
80 | # "hyperLinks": [{'url': 'http://.../', 'text': 'a link'}],
81 | # #a list of Open Graph protocol http://ogp.me/
82 | # "OpenGraphProtocol": {
83 | # "image": "https://www.facebook.com/images/fb_icon_325x325.png",
84 | # "url": "https://www.facebook.com/",
85 | # "site_name": "Facebook",
86 | # "locale": "en_US"
87 | # },
88 | # #a list of HTML meta tags http://www.w3schools.com/tags/tag_meta.asp
89 | # "MetaTags": [{'name': 'description', 'content': 'Free Web tutorials'}],
90 | # },
91 | # }
92 |
93 | r = requests.post(server_url + '/data/event',
94 | data=json.dumps(payload),
95 | headers={'content-type': 'application/json'},
96 | auth=(server_username, server_password),
97 | timeout=10)
98 |
99 | print('DiMe returns:', json.dumps(r.json(), indent=2))
100 |
--------------------------------------------------------------------------------
/scripts/mongod.conf:
--------------------------------------------------------------------------------
1 | # configuration file /opt/local/etc/mongodb/mongod.conf
2 |
3 | # Store data alongside MongoDB instead of the default, /data/db/
4 | dbpath = /opt/local/var/db/mongodb_data
5 |
6 | # Only accept local connections
7 | bind_ip = 127.0.0.1
8 |
9 | # Running as daemon
10 | fork = true
11 |
12 | # Take log
13 | logpath = /opt/local/var/log/mongodb/mongodb.log
14 | logappend = true
15 |
16 |
--------------------------------------------------------------------------------
/scripts/mongostart.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | sudo mongod -f /opt/local/etc/mongodb/mongod.conf --httpinterface
4 |
5 |
--------------------------------------------------------------------------------
/scripts/mongostop.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | mongostop_func () {
4 | local mongopid=`less /opt/local/var/db/mongodb_data/mongod.lock`;
5 | if [[ $mongopid =~ [[:digit:]] ]]; then
6 | sudo kill -15 $mongopid;
7 | echo mongod process $mongopid terminated;
8 | else
9 | echo mongo process $mongopid not exist;
10 | fi
11 | }
12 |
13 | mongostop_func
14 |
15 |
--------------------------------------------------------------------------------
/scripts/package/README.txt:
--------------------------------------------------------------------------------
1 | Digital Me (DiMe)
2 | =================
3 |
4 | This package contains the executable version of DiMe. If you wish to
5 | access the source code go to .
6 |
7 | Run DiMe
8 | --------
9 |
10 | The only requirement for running DiMe is Java JRE version 1.7 or
11 | above. If you don't have that, you can download it from:
12 |
13 | http://www.oracle.com/technetwork/java/javase/downloads/index.html
14 |
15 | You can run DiMe directly from this directory, just open a terminal
16 | window and change to this directory, and run:
17 |
18 | ./run-dime.sh
19 |
20 | or for Windows systems you can double-click the run-dime.bat file.
21 |
22 | It will take a few seconds to start up, once you see the message
23 | "Started Application in X seconds" you can access your DiMe dashboard
24 | by opening a web browser and going to the address:
25 |
26 |
27 | This is the DiMe server that runs completely on your own computer!
28 |
29 | The first step is to create an account for yourself by clicking on
30 | "Register a new account." After this you can log in. Unfortunately
31 | your DiMe will be empty, so the next step is to start logging, by
32 | installing one of the DiMe loggers. You can find a list here:
33 |
34 |
35 |
36 | Starting DiMe automatically
37 | ---------------------------
38 |
39 | If you want DiMe to start automatically the next time you restart your
40 | computer, you can run the installer script in this directory:
41 |
42 | ./install-autorun.sh
43 |
44 | This will install DiMe into the folder ~/.dime and set up autostarting
45 | for supported operating systems. Currently we support Mac OS X, and
46 | Linux systems running an XDG compliant desktop or systemd.
47 |
48 | After installing autorun you may remove the current directory if you
49 | wish (since DiMe is now installed in ~/.dime).
50 |
51 | Licensing
52 | ---------
53 |
54 | The DiMe core server is Copyright (c) 2015 University of Helsinki
55 |
56 | Permission is hereby granted, free of charge, to any person
57 | obtaining a copy of this software and associated documentation
58 | files (the "Software"), to deal in the Software without
59 | restriction, including without limitation the rights to use,
60 | copy, modify, merge, publish, distribute, sublicense, and/or sell
61 | copies of the Software, and to permit persons to whom the
62 | Software is furnished to do so, subject to the following
63 | conditions:
64 |
65 | The above copyright notice and this permission notice shall be
66 | included in all copies or substantial portions of the Software.
67 |
68 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
69 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
70 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
71 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
72 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
73 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
74 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
75 | OTHER DEALINGS IN THE SOFTWARE.
76 |
77 |
78 |
--------------------------------------------------------------------------------
/scripts/package/install/dime-server.desktop:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Type=Application
3 | Exec=$DIME_INSTALL_DIR/run-dime.sh
4 | Hidden=false
5 | NoDisplay=false
6 | X-GNOME-Autostart-enabled=true
7 | Name=DiMe
8 | Comment=Digital Me server
9 |
--------------------------------------------------------------------------------
/scripts/package/install/dime-server.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Label
6 | fi.hiit.dime.dime-server
7 | Program
8 | $DIME_INSTALL_DIR/run-dime.sh
9 | WorkingDirectory
10 | $DIME_INSTALL_DIR
11 | RunAtLoad
12 |
13 | StandardInPath
14 | /tmp/fi.hiit.dime.dime-server.stdin
15 | StandardOutPath
16 | /tmp/fi.hiit.dime.dime-server.stdout
17 | StandardErrorPath
18 | /tmp/fi.hiit.dime.dime-server.stderr
19 |
20 |
21 |
--------------------------------------------------------------------------------
/scripts/package/install/dime-server.service:
--------------------------------------------------------------------------------
1 | [Unit]
2 | Description=Digital Me server
3 | After=syslog.target network.target
4 |
5 | [Service]
6 | Type=simple
7 | ExecStart=$DIME_INSTALL_DIR/run-dime.sh
8 |
9 | [Install]
10 | WantedBy=default.target
11 |
--------------------------------------------------------------------------------
/scripts/package/run-dime.bat:
--------------------------------------------------------------------------------
1 | if defined JAVA_HOME goto useJavaHome
2 |
3 | set JAVA_EXE=java.exe
4 |
5 | %JAVA_EXE% -version >NUL 2>&1
6 | if "%ERRORLEVEL%" == "0" goto runIt
7 |
8 | :useJavaHome
9 | set JAVA_HOME=%JAVA_HOME:"=%
10 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
11 |
12 | :runIt
13 | "%JAVA_EXE%" -jar dime-server.jar
14 |
--------------------------------------------------------------------------------
/scripts/package/run-dime.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # If you need to change the server port, uncomment the following line
4 | # and change the port number.
5 | #
6 | # export SERVER_PORT=8080
7 |
8 | DIME_INSTALL_DIR=.
9 |
10 | java -jar $DIME_INSTALL_DIR/dime-server.jar
11 |
--------------------------------------------------------------------------------
/scripts/post-leaderboard.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import socket
6 | import time
7 | import json
8 |
9 | #------------------------------------------------------------------------------
10 |
11 | server_url = 'http://localhost:8080/api'
12 | server_username = 'testuser'
13 | server_password = 'testuser123'
14 |
15 | #------------------------------------------------------------------------------
16 |
17 | def print_res(r):
18 | print('DiMe returns [HTTP {}]:'.format(r.status_code))
19 | print(json.dumps(r.json(), indent=2))
20 |
21 | #------------------------------------------------------------------------------
22 |
23 |
24 |
25 | r = requests.post(server_url + '/ping', auth=(server_username, server_password))
26 | print_res(r)
27 |
28 | if r.status_code != requests.codes.ok:
29 | print('No connection to DiMe server!')
30 | sys.exit(1)
31 |
32 | r = requests.post(server_url + '/updateleaderboard',
33 | headers={'content-type': 'application/json'},
34 | auth=(server_username, server_password),
35 | timeout=10)
36 |
37 | print('DiMe returns [HTTP {}]:'.format(r.status_code))
38 | print(json.dumps(r.json(), indent=2))
39 |
--------------------------------------------------------------------------------
/scripts/print_events.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import datetime
4 | import dime
5 | import json
6 | import requests
7 | import time
8 | import sys
9 |
10 | from numpy.random import choice
11 |
12 |
13 | #------------------------------------------------------------------------------
14 |
15 | class DiMeConnection:
16 | def __init__(self, url, username, uid=None):
17 | self.url = url
18 | self.username = username
19 | self.uid = uid
20 | self.password = dime.password(self.username)
21 |
22 | def ping(self, verbose=True):
23 | r = requests.post(self.url + '/ping')
24 |
25 | if r.status_code != requests.codes.ok:
26 | if verbose:
27 | print('No connection to DiMe server!', file=sys.stderr)
28 | return None
29 | else:
30 | if verbose:
31 | print('Connected to DiMe: {} @ {}, version {}.'.
32 | format(self.username, self.url, r.json()['version']),
33 | file=sys.stderr)
34 | return r.json()
35 |
36 | def post(self, url):
37 | print("POST", url)
38 | r = requests.post(self.url + url, headers={'content-type': 'application/json'},
39 | auth=(self.username, self.password), timeout=10)
40 | return r
41 |
42 | def get(self, url):
43 | print("GET", url)
44 | r = requests.get(self.url + url, headers={'content-type': 'application/json'},
45 | auth=(self.username, self.password), timeout=10)
46 | return r
47 |
48 | #------------------------------------------------------------------------------
49 |
50 | dime = DiMeConnection('http://localhost:8081/api', 'demouser')
51 |
52 | req = '/data/events?orderBy=start&desc=false'
53 | events = dime.get(req).json()
54 |
55 | for e in events:
56 | start = datetime.datetime.fromtimestamp(e['start']/1000.0)
57 | end = datetime.datetime.fromtimestamp(e['end']/1000.0)
58 | print(e['@type'], start, end)
59 |
--------------------------------------------------------------------------------
/scripts/search-example.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import socket
6 | import time
7 | import json
8 | import urllib
9 |
10 | #------------------------------------------------------------------------------
11 |
12 | server_url = 'http://localhost:8080/api'
13 | server_username = 'testuser'
14 | server_password = 'testuser123'
15 |
16 | #------------------------------------------------------------------------------
17 |
18 | # ping server (not needed, but fun to do :-)
19 | r = requests.post(server_url + '/ping')
20 |
21 | if r.status_code != requests.codes.ok:
22 | print('No connection to DiMe server!')
23 | sys.exit(1)
24 |
25 | # make search query
26 | query = "dime"
27 | if len(sys.argv) > 1:
28 | query = urllib.parse.quote(' '.join(sys.argv[1:]), safe='&=')
29 |
30 | r = requests.get(server_url + '/search?query={}&limit=10'.format(query),
31 | headers={'content-type': 'application/json'},
32 | auth=(server_username, server_password),
33 | timeout=10)
34 |
35 | if r.status_code != requests.codes.ok:
36 | print('HTTP Error ' + str(r.status_code))
37 |
38 | print('DiMe returns:', json.dumps(r.json(), indent=2))
39 |
--------------------------------------------------------------------------------
/scripts/suggest-event.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import json
6 |
7 | #------------------------------------------------------------------------------
8 |
9 | server_url = 'http://localhost:8080/api'
10 | server_username = 'testuser'
11 | server_password = 'testuser123'
12 |
13 | #------------------------------------------------------------------------------
14 |
15 | r = requests.post(server_url + '/ping')
16 |
17 | if r.status_code != requests.codes.ok:
18 | print('No connection to DiMe server!')
19 | sys.exit(1)
20 |
21 | r = requests.get(server_url + '/profiles',
22 | headers={'content-type': 'application/json'},
23 | auth=(server_username, server_password),
24 | timeout=10)
25 |
26 | profile_id = None
27 | for item in r.json():
28 | if item["name"] == "Test":
29 | profile_id = item["id"]
30 |
31 | if profile_id is None:
32 | print("Unable to find Test profile!")
33 | sys.exit(1)
34 |
35 | payload = {
36 | "informationelement": {
37 | "@type": "InformationElement",
38 | "id": 15773
39 | },
40 | "weight": 0.22,
41 | "actor": "FooAlgorithm"
42 | }
43 |
44 | r = requests.post(server_url + '/profiles/{}/suggestedinformationelements'.format(profile_id),
45 | data=json.dumps(payload),
46 | headers={'content-type': 'application/json'},
47 | auth=(server_username, server_password),
48 | timeout=10)
49 | print(r.status_code)
50 | print('DiMe returns:', json.dumps(r.json(), indent=2))
51 |
--------------------------------------------------------------------------------
/scripts/test-users.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | import socket
6 | import time
7 | import json
8 |
9 | #------------------------------------------------------------------------------
10 |
11 | server_url = 'http://localhost:8080/api'
12 | server_username = 'testuser2'
13 | server_password = 'testuser123'
14 |
15 | #------------------------------------------------------------------------------
16 |
17 | payload = {
18 | "username": server_username,
19 | "password": server_password
20 | }
21 |
22 | # Add user
23 | r = requests.post(server_url + '/users',
24 | data=json.dumps(payload),
25 | headers={'content-type': 'application/json'},
26 | timeout=10)
27 |
28 | if r.status_code != requests.codes.ok:
29 | print('HTTP Error:', r.status_code)
30 | print(json.dumps(r.json(), indent=2))
31 | #sys.exit(1)
32 | else:
33 | print('DiMe returns:', json.dumps(r.json(), indent=2))
34 |
35 | # Check user
36 | r = requests.get(server_url + '/users',
37 | headers={'content-type': 'application/json'},
38 | auth=(server_username, server_password),
39 | timeout=10)
40 |
41 | if r.status_code != requests.codes.ok:
42 | print('HTTP Error:', r.status_code)
43 | print(json.dumps(r.json(), indent=2))
44 | sys.exit(1)
45 |
46 | print('DiMe returns:', json.dumps(r.json(), indent=2))
47 |
48 | user_id = r.json()[0]["id"]
49 | print('USER ID:', user_id)
50 |
51 | # Delete user
52 | r = requests.delete(server_url + '/users/{}'.format(user_id),
53 | headers={'content-type': 'application/json'},
54 | auth=(server_username, server_password),
55 | timeout=10)
56 |
57 | if r.status_code < 200 or r.status_code >= 300:
58 | print('HTTP Error:', r.status_code)
59 | print(json.dumps(r.json(), indent=2))
60 | sys.exit(1)
61 |
62 | print('DiMe returns:', r.status_code)
63 |
--------------------------------------------------------------------------------
/scripts/xdi_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | import sys
5 | # import socket
6 | # import time
7 | import json
8 | import dime
9 | import urllib
10 |
11 | #------------------------------------------------------------------------------
12 |
13 | class DiMeConnection:
14 | def __init__(self, url, username, uid=None):
15 | self.url = url
16 | self.username = username
17 | self.uid = uid
18 | self.password = dime.password(self.username)
19 |
20 | def ping(self, verbose=True):
21 | r = requests.post(self.url + '/ping')
22 |
23 | if r.status_code != requests.codes.ok:
24 | if verbose:
25 | print('No connection to DiMe server!', file=sys.stderr)
26 | return None
27 | else:
28 | if verbose:
29 | print('Connected to DiMe: {} @ {}, version {}.'.
30 | format(self.username, self.url, r.json()['version']),
31 | file=sys.stderr)
32 | return r.json()
33 |
34 | def post(self, url):
35 | print("POST", url)
36 | r = requests.post(self.url + url, headers={'content-type': 'application/json'},
37 | auth=(self.username, self.password), timeout=10)
38 | return r
39 |
40 | def get(self, url):
41 | print("GET", url)
42 | r = requests.get(self.url + url, headers={'content-type': 'application/json'},
43 | auth=(self.username, self.password), timeout=10)
44 | return r
45 |
46 | #------------------------------------------------------------------------------
47 |
48 | dime_a = DiMeConnection('http://localhost:8081/api', 'mvsjober')
49 |
50 | dime_b = DiMeConnection('http://localhost:8082/api', 'bob',
51 | '=!:did:sov:TJrPGZ3e6uWC4xmSZrJPar')
52 |
53 | #------------------------------------------------------------------------------
54 |
55 | if not dime_a.ping() or not dime_b.ping():
56 | sys.exit(1)
57 |
58 | dime_a.post('/requests/send/' + dime_b.uid)
59 |
60 | reqs = dime_b.get('/requests/view').json()
61 | print("Current requests (b):")
62 | print(json.dumps(reqs, indent=2))
63 |
64 | # dime_b.post('/requests/delete?address=' + reqs[0]['address'])
65 | # dime_b.post('/requests/approve/' + reqs[0]['address'])
66 |
67 | # reqs = dime_b.get('/requests/view').json()
68 | # print("Current requests (b) (AFTER):")
69 | # print(reqs)
70 |
71 |
72 | # contracts_a = dime_a.get('/linkcontracts/view').json()
73 | # print("Contracts (a)")
74 | # print(contracts_a)
75 |
76 | # contracts_b = dime_b.get('/linkcontracts/view').json()
77 | # print("Contracts (b)")
78 | # print(contracts_b)
79 |
80 | # if len(contracts_b) > 0:
81 | # address_quoted = urllib.parse.quote_plus(contracts_b[0]['address'])
82 | # #ret = dime_b.post('/linkcontracts/delete?address=' + address_quoted)
83 |
84 | # # contracts_b = dime_b.get('/linkcontracts/view').json()
85 | # # print("Contracts (b) (AFTER)")
86 | # # print(contracts_b)
87 |
88 |
89 | data = dime_a.get('/linkcontracts/data/' + dime_b.uid)
90 | print(json.dumps(data.json(), indent=2))
91 |
92 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/AnswerController.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime;
26 |
27 | //------------------------------------------------------------------------------
28 |
29 | import fi.hiit.dime.answer.*;
30 | import fi.hiit.dime.database.*;
31 | import java.util.Calendar;
32 | import java.util.Date;
33 | import java.util.ArrayList;
34 | import java.util.List;
35 | import org.springframework.beans.factory.annotation.Autowired;
36 | import org.springframework.http.HttpStatus;
37 | import org.springframework.http.ResponseEntity;
38 | import org.springframework.web.bind.annotation.RequestBody;
39 | import org.springframework.web.bind.annotation.RequestMapping;
40 | import org.springframework.web.bind.annotation.RequestMethod;
41 | import org.springframework.web.bind.annotation.RequestParam;
42 | import org.springframework.web.bind.annotation.RestController;
43 |
44 | //------------------------------------------------------------------------------
45 |
46 | @RestController
47 | @RequestMapping("/api/answer")
48 | public class AnswerController {
49 | private final EventDAO eventDAO;
50 |
51 | @Autowired
52 | AnswerController(EventDAO eventDAO) {
53 | this.eventDAO = eventDAO;
54 | }
55 |
56 | // @RequestMapping(value="/eventhist", method = RequestMethod.GET)
57 | // public ResponseEntity>
58 | // eventHist(@RequestParam(defaultValue="false") String perc,
59 | // @RequestParam(defaultValue="actor") String groupBy) {
60 |
61 | // List answer = new ArrayList();
62 |
63 | // // Set calendar to tomorrow at 00:00:00
64 | // Calendar cal = Calendar.getInstance();
65 | // cal.add(Calendar.DAY_OF_MONTH, 1);
66 | // cal.set(Calendar.HOUR, 0);
67 | // cal.set(Calendar.MINUTE, 0);
68 | // cal.set(Calendar.SECOND, 0);
69 | // cal.set(Calendar.MILLISECOND, 0);
70 |
71 | // for (int i=0; i<10; i++) {
72 | // Date toDate = cal.getTime();
73 | // cal.add(Calendar.DAY_OF_MONTH, -1);
74 | // Date fromDate = cal.getTime();
75 |
76 | // List results = eventDAO.eventHist(groupBy, fromDate,
77 | // toDate,
78 | // !perc.equals("false"));
79 |
80 | // answer.add(new EventHistAnswer(fromDate, results));
81 | // }
82 |
83 | // return new ResponseEntity>(answer, HttpStatus.OK);
84 | // }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/Application.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime;
26 |
27 | //------------------------------------------------------------------------------
28 |
29 | import fi.hiit.dime.authentication.CurrentUser;
30 | import org.springframework.boot.SpringApplication;
31 | import org.springframework.boot.autoconfigure.SpringBootApplication;
32 | import org.springframework.security.core.Authentication;
33 | import org.springframework.web.bind.annotation.ControllerAdvice;
34 | import org.springframework.web.bind.annotation.ModelAttribute;
35 | import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice;
36 |
37 | //------------------------------------------------------------------------------
38 |
39 | @SpringBootApplication
40 | public class Application {
41 |
42 | @ControllerAdvice
43 | static class JsonpAdvice extends AbstractJsonpResponseBodyAdvice {
44 | public JsonpAdvice() {
45 | super("callback");
46 | }
47 | }
48 |
49 | @ControllerAdvice
50 | static class CurrentUserControllerAdvice {
51 | @ModelAttribute("currentUser")
52 | public CurrentUser getCurrentUser(Authentication authentication) {
53 | return (authentication == null) ? null :
54 | (CurrentUser)authentication.getPrincipal();
55 | }
56 | }
57 |
58 | public static void main(String[] args) {
59 | SpringApplication.run(Application.class, args);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/AuthorizedController.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime;
26 |
27 | import fi.hiit.dime.authentication.CurrentUser;
28 | import fi.hiit.dime.authentication.User;
29 |
30 | import org.springframework.security.core.Authentication;
31 | import org.springframework.web.bind.annotation.ResponseStatus;
32 | import org.springframework.http.HttpStatus;
33 |
34 | import javax.servlet.http.HttpServletRequest;
35 |
36 | /**
37 | * Base class for controllers that need user authentication.
38 | *
39 | * @author Mats Sjöberg, mats.sjoberg@helsinki.fi
40 | */
41 | public class AuthorizedController {
42 | protected User getUser(Authentication auth) {
43 | if (auth == null)
44 | return null;
45 |
46 | CurrentUser currentUser = (CurrentUser)auth.getPrincipal();
47 | return currentUser.getUser();
48 | }
49 |
50 | @ResponseStatus(value=HttpStatus.UNAUTHORIZED)
51 | public class NotAuthorizedException extends Exception {
52 | public NotAuthorizedException(String msg) {
53 | super(msg);
54 | }
55 | }
56 |
57 | @ResponseStatus(value=HttpStatus.BAD_REQUEST)
58 | public class BadRequestException extends Exception {
59 | public BadRequestException(String msg) {
60 | super(msg);
61 | }
62 | }
63 |
64 | @ResponseStatus(value=HttpStatus.NOT_FOUND)
65 | public class NotFoundException extends Exception {
66 | public NotFoundException(String msg) {
67 | super(msg);
68 | }
69 | }
70 |
71 | public boolean isLocalhost(HttpServletRequest req) {
72 | String addr = req.getRemoteAddr();
73 | return addr.equals("0:0:0:0:0:0:0:1") ||
74 | addr.equals("127.0.0.1") ||
75 | addr.startsWith("172.17."); // Docker
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/DiMeProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime;
26 |
27 | import org.springframework.boot.context.properties.ConfigurationProperties;
28 | import org.springframework.stereotype.Component;
29 |
30 | @ConfigurationProperties(ignoreUnknownFields = false,
31 | prefix = "dime")
32 | @Component
33 | public class DiMeProperties {
34 | private String luceneIndexPath;
35 | public void setLuceneIndexPath(String s) { luceneIndexPath = s; }
36 | public String getLuceneIndexPath() { return luceneIndexPath; }
37 |
38 | private String luceneAnalyzer = "Standard";
39 | public void setLuceneAnalyzer(String s) {
40 | luceneAnalyzer = s; //.replaceAll("Analyzer$", "");
41 | }
42 | public String getLuceneAnalyzer() { return luceneAnalyzer; }
43 |
44 | private String[] corsAllowOrigin = null;
45 | public void setCorsAllowOrigin(String[] s) { corsAllowOrigin = s; }
46 | public String[] getCorsAllowOrigin() { return corsAllowOrigin; }
47 |
48 | private String leaderboardEndpoint = "https://dimeproxy.hiit.fi/dime-leaderboards/api/event";
49 | public void setLeaderboardEndpoint(String s) { leaderboardEndpoint = s; }
50 | public String getLeaderboardEndpoint() { return leaderboardEndpoint; }
51 |
52 | private String peoplefinderEndpoint = "https://peoplefinder.danubetech.com/xdi/graph";
53 | public void setPeoplefinderEndpoint(String s) { peoplefinderEndpoint = s; }
54 | public String getPeoplefinderEndpoint() { return peoplefinderEndpoint; }
55 |
56 | private String trustanchorEndpoint = "http://localhost:8000/";
57 | public void setTrustanchorEndpoint(String s) { trustanchorEndpoint = s; }
58 | public String getTrustanchorEndpoint() { return trustanchorEndpoint; }
59 |
60 | private String baseUri = "http://localhost:8080/";
61 | public void setBaseUri(String s) { baseUri = s; }
62 | public String getBaseUri() { return baseUri; }
63 |
64 | private String sovrinPoolConfig;
65 | public void setSovrinPoolConfig(String s) { sovrinPoolConfig = s; }
66 | public String getSovrinPoolConfig() { return sovrinPoolConfig; }
67 |
68 | private boolean sovrinSelfRegisteringDID = false;
69 | public void setSovrinSelfRegisteringDID(boolean b) { sovrinSelfRegisteringDID = b; }
70 | public boolean getSovrinSelfRegisteringDID() { return sovrinSelfRegisteringDID; }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/Makefile:
--------------------------------------------------------------------------------
1 | all: build
2 |
3 | %::
4 | @make $@ -C ../../../../../../
5 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/WebSecurityConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime;
26 |
27 | import org.springframework.beans.factory.annotation.Autowired;
28 | import org.springframework.context.annotation.Configuration;
29 | import org.springframework.core.annotation.Order;
30 | import org.springframework.http.HttpMethod;
31 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
32 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
33 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
34 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
35 | import org.springframework.security.core.userdetails.UserDetailsService;
36 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
37 |
38 | @EnableWebSecurity
39 | public class WebSecurityConfig {
40 | @Autowired
41 | private UserDetailsService userDetailsService;
42 |
43 | @Autowired
44 | protected void configureGlobal(AuthenticationManagerBuilder auth)
45 | throws Exception
46 | {
47 | auth.userDetailsService(userDetailsService)
48 | .passwordEncoder(new BCryptPasswordEncoder());
49 | }
50 |
51 |
52 | @Configuration
53 | public static class ApiWebSecurityConfigurationAdapter
54 | extends WebSecurityConfigurerAdapter
55 | {
56 | @Override
57 | protected void configure(HttpSecurity http) throws Exception {
58 | http.antMatcher("/api/**")
59 | .authorizeRequests()
60 | .antMatchers("/api/ping").permitAll()
61 | .antMatchers(HttpMethod.POST, "/api/users").permitAll()
62 | .antMatchers(HttpMethod.OPTIONS, "/api/**").permitAll()
63 | .anyRequest().fullyAuthenticated()
64 | .and()
65 | .httpBasic()
66 | .and()
67 | .csrf().disable();
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/XdiController.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime;
26 |
27 | import java.io.IOException;
28 |
29 | import javax.servlet.http.HttpServletRequest;
30 | import javax.servlet.http.HttpServletResponse;
31 |
32 | import org.springframework.beans.factory.annotation.Autowired;
33 | import org.springframework.stereotype.Controller;
34 | import org.springframework.web.bind.annotation.RequestMapping;
35 |
36 | import fi.hiit.dime.xdi.XdiService;
37 | import xdi2.transport.impl.http.HttpTransportRequest;
38 | import xdi2.transport.impl.http.HttpTransportResponse;
39 | import xdi2.transport.impl.http.impl.servlet.ServletHttpTransportRequest;
40 | import xdi2.transport.impl.http.impl.servlet.ServletHttpTransportResponse;
41 |
42 | @Controller
43 | @RequestMapping("/xdi")
44 | public class XdiController {
45 |
46 | private final XdiService xdiService;
47 |
48 | @Autowired
49 | public XdiController(XdiService xdiService) {
50 |
51 | this.xdiService = xdiService;
52 | }
53 |
54 | @RequestMapping("/**")
55 | public void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
56 |
57 | httpServletRequest.setCharacterEncoding("UTF-8");
58 | httpServletResponse.setCharacterEncoding("UTF-8");
59 |
60 | // execute the transport
61 |
62 | HttpTransportRequest request = ServletHttpTransportRequest.fromHttpServletRequest(httpServletRequest, "/xdi");
63 | HttpTransportResponse response = ServletHttpTransportResponse.fromHttpServletResponse(httpServletResponse);
64 |
65 | this.xdiService.getHttpTransport().execute(request, response);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/answer/EventHistAnswer.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.answer;
26 |
27 | //------------------------------------------------------------------------------
28 |
29 | import fi.hiit.dime.database.EventCount;
30 | import java.util.Date;
31 | import java.util.List;
32 |
33 | //------------------------------------------------------------------------------
34 |
35 | public class EventHistAnswer {
36 | public Date date;
37 | public List hist;
38 |
39 | public EventHistAnswer(Date date, List hist) {
40 | this.date = date;
41 | this.hist = hist;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/answer/Makefile:
--------------------------------------------------------------------------------
1 | all: build
2 |
3 | %::
4 | @make $@ -C ../
5 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/authentication/CurrentUser.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.authentication;
26 |
27 | import org.springframework.security.core.authority.AuthorityUtils;
28 |
29 | public class CurrentUser extends
30 | org.springframework.security.core.userdetails.User
31 | {
32 |
33 | private User user;
34 |
35 | public CurrentUser(User user) {
36 | super(user.username, user.passwordHash,
37 | AuthorityUtils.createAuthorityList(user.role.toString()));
38 | this.user = user;
39 | }
40 |
41 | public User getUser() {
42 | return user;
43 | }
44 |
45 | public Long getId() {
46 | return user.getId();
47 | }
48 |
49 | public Role getRole() {
50 | return user.role;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/authentication/CurrentUserDetailsService.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.authentication;
26 |
27 | import org.springframework.beans.factory.annotation.Autowired;
28 | import org.springframework.security.core.userdetails.UserDetailsService;
29 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
30 | import org.springframework.stereotype.Service;
31 |
32 | @Service
33 | public class CurrentUserDetailsService implements UserDetailsService {
34 | private final UserService userService;
35 |
36 | @Autowired
37 | public CurrentUserDetailsService(UserService userService) {
38 | this.userService = userService;
39 | }
40 |
41 | @Override
42 | public CurrentUser loadUserByUsername(String username)
43 | throws UsernameNotFoundException {
44 | String notFoundError = String.format("User with username=%s was not found",
45 | username);
46 |
47 | User user = userService.getUserByUsername(username);
48 | if (user == null)
49 | throw new UsernameNotFoundException(notFoundError);
50 | return new CurrentUser(user);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/authentication/CurrentUserService.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.authentication;
26 |
27 | public interface CurrentUserService {
28 | boolean canAccessUser(CurrentUser currentUser, String userId);
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/authentication/CurrentUserServiceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.authentication;
26 |
27 | import fi.hiit.dime.authentication.Role;
28 |
29 | import org.springframework.stereotype.Service;
30 |
31 | @Service
32 | public class CurrentUserServiceImpl implements CurrentUserService {
33 |
34 | @Override
35 | public boolean canAccessUser(CurrentUser currentUser, String username) {
36 | return currentUser != null &&
37 | (currentUser.getRole() == Role.ADMIN ||
38 | currentUser.getUsername().equals(username));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/authentication/Makefile:
--------------------------------------------------------------------------------
1 | all: build
2 |
3 | %::
4 | @make $@ -C ../
5 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/authentication/Role.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | //------------------------------------------------------------------------------
26 |
27 | package fi.hiit.dime.authentication;
28 |
29 | //------------------------------------------------------------------------------
30 |
31 | public enum Role {
32 | USER, ADMIN
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/authentication/User.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.authentication;
26 |
27 | import fi.hiit.dime.data.*;
28 |
29 | import com.fasterxml.jackson.annotation.JsonIgnore;
30 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
31 | import com.fasterxml.jackson.annotation.JsonInclude;
32 | import org.hibernate.annotations.GenericGenerator;
33 | import org.springframework.data.annotation.Id;
34 | import org.springframework.data.jpa.domain.AbstractPersistable;
35 |
36 | import java.util.Date;
37 | import java.util.Set;
38 |
39 | import javax.persistence.Column;
40 | import javax.persistence.Entity;
41 | import javax.persistence.GeneratedValue;
42 | import javax.persistence.Transient;
43 |
44 | /**
45 | Class for storing users and associated information for this DiMe.
46 | */
47 | @JsonInclude(value=JsonInclude.Include.NON_NULL)
48 | @JsonIgnoreProperties({"hibernateLazyInitializer", "handler", "new"})
49 | @Entity
50 | public class User extends AbstractPersistable {
51 | public static User makeUser(Long id) {
52 | User user = new User();
53 | user.setId(id);
54 | return user;
55 | }
56 |
57 | /** Unique username */
58 | public String username;
59 |
60 | /** Password, just used for initial setting of password. Not
61 | stored in the database! */
62 | @Transient public String password;
63 |
64 | /** Hash of password (never store the actual password!) */
65 | @JsonIgnore public String passwordHash;
66 |
67 | /** Email */
68 | public String email;
69 |
70 | /** Date and time when the user was registered */
71 | public Date time_registered;
72 |
73 | /** Date and time when the user last logged in */
74 | public Date time_login;
75 |
76 | /** User role, e.g. user or admin. */
77 | public Role role;
78 |
79 | /** Unique user ID, used for identification in external services. */
80 | public String userId;
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/authentication/UserService.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.authentication;
26 |
27 | import fi.hiit.dime.authentication.User;
28 |
29 | import java.util.Collection;
30 |
31 | /**
32 | * Higher-level interface to accessing users.
33 | */
34 | public interface UserService {
35 | class CannotCreateUserException extends Exception {
36 | public CannotCreateUserException(String msg) {
37 | super(msg);
38 | }
39 | }
40 |
41 | /**
42 | * Return user by user id.
43 | *
44 | * @param id User id
45 | * @return User with the given id
46 | */
47 | User getUserById(Long id);
48 |
49 | /**
50 | * Return user by username.
51 | *
52 | * @param username The username
53 | * @return User with the given username
54 | */
55 | User getUserByUsername(String username);
56 |
57 | /**
58 | * Return a list of all users.
59 | * @return List of users.
60 | */
61 | Collection getAllUsers();
62 |
63 | /**
64 | * Create a new user.
65 | *
66 | * @param user The user to create
67 | * @return The created user
68 | */
69 | User create(User user, String password) throws CannotCreateUserException;
70 |
71 | /**
72 | * Update existing user.
73 | *
74 | * @param user The user to update
75 | * @return The updated user
76 | */
77 | User update(User user, String password) throws CannotCreateUserException;
78 |
79 | /**
80 | * Remove user and all related events and informationelements
81 | *
82 | * @param id User id of the user to be removed
83 | * @return True if a user was successfully removed
84 | */
85 | boolean removeAllForUserId(Long id);
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/ActivityEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Entity;
28 |
29 | @Entity
30 | public class ActivityEvent extends Event {
31 | public String activity;
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/BookmarkEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Entity;
28 | import javax.persistence.FetchType;
29 | import javax.persistence.JoinColumn;
30 | import javax.persistence.ManyToOne;
31 |
32 | /**
33 | An event representing adding or removing a bookmark by the user,
34 | e.g. bookmarking a document for reading it later.
35 | */
36 | @Entity
37 | public class BookmarkEvent extends ResourcedEvent {
38 |
39 | /**
40 | A related event, e.g. the SearchEvent that introduced the
41 | document.
42 | */
43 | @ManyToOne(fetch = FetchType.EAGER)
44 | @JoinColumn(name = "related_event_id")
45 | public Event relatedEvent;
46 |
47 | /**
48 | Whether the bookmark was added or removed.
49 | */
50 | public Boolean add;
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/CalendarEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import java.util.Date;
28 | import java.util.List;
29 |
30 | import javax.persistence.Entity;
31 | import javax.persistence.Column;
32 | import javax.persistence.JoinColumn;
33 | import javax.persistence.JoinTable;
34 | import javax.persistence.ManyToMany;
35 | import javax.persistence.CascadeType;
36 |
37 | /**
38 | An event generated from the user's calendar.
39 | */
40 | @Entity
41 | public class CalendarEvent extends Event {
42 | /**
43 | The name (or title) of the event.
44 | */
45 | public String name;
46 |
47 | /**
48 | The name of the calendar where this event appeared (e.g. work, personal, etc).
49 | */
50 | public String calendar;
51 |
52 | /**
53 | * Notes associated with the event.
54 | */
55 | @Column(columnDefinition="longtext")
56 | public String notes;
57 |
58 | /**
59 | * In case detailed location is not available, this field stores the location as a string.
60 | */
61 | public String locString;
62 |
63 | /**
64 | * Participants (or invitees) who took part.
65 | */
66 | @ManyToMany(cascade=CascadeType.ALL)
67 | @JoinTable(name="calendarevent_participants",
68 | joinColumns={@JoinColumn(name="calendarevent_id", referencedColumnName="id")},
69 | inverseJoinColumns={@JoinColumn(name="person_id", referencedColumnName="id")})
70 | public List participants;
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/DesktopEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Entity;
28 |
29 | /**
30 | A desktop event, such as opening a document in the computer
31 | graphical environment.
32 | */
33 | @Entity
34 | public class DesktopEvent extends ResourcedEvent {
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/DiMeDataRelation.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import fi.hiit.dime.authentication.User;
28 |
29 | import com.fasterxml.jackson.annotation.*;
30 | import org.springframework.data.jpa.domain.AbstractPersistable;
31 |
32 | import javax.persistence.MappedSuperclass;
33 | import javax.persistence.Transient;
34 |
35 | /**
36 | General class representing a relation to a DiMeData object.
37 | */
38 | @JsonInclude(value=JsonInclude.Include.NON_NULL)
39 | @JsonIgnoreProperties({"hibernateLazyInitializer", "handler", "new", "data"})
40 | @MappedSuperclass
41 | public abstract class DiMeDataRelation extends AbstractPersistable {
42 | public DiMeDataRelation() {
43 | }
44 |
45 | /** Get the related data.
46 | * @return the data object
47 | */
48 | @Transient
49 | public abstract T getData();
50 |
51 | /** Set the related data.
52 | * @param data The data object to assign to the relation
53 | */
54 | public abstract void setData(T data);
55 |
56 | /** The weight of the relationship, e.g. probability of being related. */
57 | public Double weight;
58 |
59 | /** Application that generated the relation. */
60 | public String actor;
61 |
62 | /** Set to true if it has been explicitly valided by the user. */
63 | public Boolean validated;
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/Document.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Entity;
28 |
29 | /** Class representing a document, e.g. PDF or word-processing document.
30 | */
31 | @Entity
32 | public class Document extends InformationElement {
33 | /** Mime type of the document, see:
34 | https://en.wikipedia.org/wiki/MIME#Content-Type
35 | */
36 | public String mimeType;
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/Event.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import java.util.Calendar;
28 | import java.util.Date;
29 |
30 | import javax.persistence.Column;
31 | import javax.persistence.Embedded;
32 | import javax.persistence.Entity;
33 | import javax.persistence.FetchType;
34 | import javax.persistence.Inheritance;
35 | import javax.persistence.InheritanceType;
36 | import javax.persistence.JoinColumn;
37 |
38 | /**
39 | Abstract class for all events.
40 | */
41 | @Entity
42 | @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
43 | public abstract class Event extends DiMeData {
44 | /** The program that produced the event, e.g. "Firefox".
45 | */
46 | public String actor;
47 |
48 | /** Typically the host name of the computer where the event was generated.
49 | */
50 | public String origin;
51 |
52 | /** Place where the event happened.
53 | */
54 | @Embedded
55 | public Location location;
56 |
57 | /** Time stamp when the event was started. Format example: 2015-08-11T12:56:53Z
58 | */
59 | public Date start;
60 |
61 | /** Time stamp when the event ended - DiMe can fill this if duration was supplied.
62 | */
63 | public Date end;
64 |
65 | /** Duration of event in seconds - DiMe can fill this if end time was supplied.
66 | */
67 | public double duration;
68 |
69 | /** Make sure start, end and duration times are consistent.
70 | */
71 | @Override
72 | public void autoFill() {
73 | Calendar cal = Calendar.getInstance();
74 | int dur = (int)(duration*1000.0);
75 |
76 | if (start == null && end != null) {
77 | cal.setTime(end);
78 | cal.add(Calendar.MILLISECOND, -dur);
79 | start = cal.getTime();
80 | } else if (start != null && end == null) {
81 | cal.setTime(start);
82 | cal.add(Calendar.MILLISECOND, dur);
83 | end = cal.getTime();
84 | } else if (start != null && !start.equals(end)) {
85 | duration = (end.getTime() - start.getTime())/1000.0;
86 | }
87 | super.autoFill();
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/EventRelation.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Entity;
28 | import javax.persistence.FetchType;
29 | import javax.persistence.JoinColumn;
30 | import javax.persistence.ManyToOne;
31 | import javax.persistence.Inheritance;
32 | import javax.persistence.InheritanceType;
33 |
34 | /**
35 | Class representing a relation to an Event.
36 | */
37 | @Entity
38 | @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
39 | public class EventRelation extends DiMeDataRelation {
40 | public EventRelation(Event event, double weight, String actor, boolean validated) {
41 | this.event = event;
42 | this.weight = weight;
43 | this.actor = actor;
44 | this.validated = validated;
45 | }
46 |
47 | public EventRelation(Event event, double weight, String actor) {
48 | this(event, weight, actor, false);
49 | }
50 |
51 | public EventRelation() {
52 | this(null, 0.0, "", false);
53 | }
54 |
55 | @Override
56 | public Event getData() {
57 | return this.event;
58 | }
59 |
60 | @Override
61 | public void setData(Event event) {
62 | this.event = event;
63 | }
64 |
65 | /** The related event. */
66 | @ManyToOne(fetch = FetchType.EAGER)
67 | @JoinColumn(name = "event_id")
68 | public Event event;
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/FeedbackEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Entity;
28 | import javax.persistence.FetchType;
29 | import javax.persistence.JoinColumn;
30 | import javax.persistence.ManyToOne;
31 |
32 | /**
33 | An event representing an explicit feedback by the user, e.g.
34 | ranking a document as relevant.
35 | */
36 | @Entity
37 | public class FeedbackEvent extends ResourcedEvent {
38 |
39 | /**
40 | A related event, e.g. the SearchEvent that introduced the
41 | document.
42 | */
43 | @ManyToOne(fetch = FetchType.EAGER)
44 | @JoinColumn(name = "related_event_id")
45 | public Event relatedEvent;
46 |
47 | /**
48 | The feedback value, e.g. the relevance of the document.
49 | */
50 | public Double value;
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/FunfEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Column;
28 | import javax.persistence.Entity;
29 |
30 | /**
31 | Class representing Funf probe events
32 | */
33 | @Entity
34 | public class FunfEvent extends Event {
35 | /** Name of funf probe, e.g. "WifiProbe" */
36 | public String probeName;
37 |
38 | /** The raw data value of the funf probe. Typically a JSON object
39 | to be interpreted separately. */
40 | @Column(columnDefinition="longtext")
41 | public String funfValue;
42 |
43 | /** Automatically update the type according to probeName
44 | */
45 | @Override
46 | public void autoFill() {
47 | if (probeName != null && !probeName.isEmpty())
48 | type = "http://www.hiit.fi/ontologies/dime/#" + probeName;
49 |
50 | super.autoFill();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/HealthTrackerEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Entity;
28 |
29 | /**
30 | An event from a health tracker such as FitBit.
31 | */
32 | @Entity
33 | public class HealthTrackerEvent extends PhysicalEvent {
34 | /** Name of the tracker device, e.g. "Charge HR" */
35 | public String device;
36 |
37 | /** Type of activity, e.g. steps. */
38 | public String activityType;
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/HtmlMetaTag.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Embeddable;
28 |
29 | /**
30 | Class to represent an HTML Meta tag in a WebDocument.
31 | */
32 | @Embeddable
33 | public class HtmlMetaTag {
34 | public HtmlMetaTag() {}
35 |
36 | public HtmlMetaTag(String name, String content) {
37 | this.name = name;
38 | this.content = content;
39 | }
40 |
41 | /** Name of the meta tag.
42 | */
43 | public String name;
44 |
45 | /** Content of the meta tag.
46 | */
47 | public String content;
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/HyperLink.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Embeddable;
28 |
29 | /** Class to represent a hyper link in a WebDocument. */
30 | @Embeddable
31 | public class HyperLink {
32 | public HyperLink() {}
33 |
34 | public HyperLink(String url, String text) {
35 | this.url = url;
36 | this.text = text;
37 | }
38 |
39 | /** Url of the hyper link. */
40 | public String url;
41 |
42 | /** Text of the hyper link. */
43 | public String text;
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/InformationElementRelation.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Entity;
28 | import javax.persistence.FetchType;
29 | import javax.persistence.JoinColumn;
30 | import javax.persistence.ManyToOne;
31 | import javax.persistence.Inheritance;
32 | import javax.persistence.InheritanceType;
33 |
34 | /**
35 | Class representing a relation to an InformationElement.
36 | */
37 | @Entity
38 | @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
39 | public class InformationElementRelation extends DiMeDataRelation {
40 | public InformationElementRelation(InformationElement elem, double weight, String actor,
41 | boolean validated) {
42 | this.informationElement = elem;
43 | this.weight = weight;
44 | this.actor = actor;
45 | this.validated = validated;
46 | }
47 |
48 | public InformationElementRelation(InformationElement elem, double weight, String actor) {
49 | this(elem, weight, actor, false);
50 | }
51 |
52 | public InformationElementRelation() {
53 | this(null, 0.0, "", false);
54 | }
55 |
56 | @Override
57 | public InformationElement getData() {
58 | return this.informationElement;
59 | }
60 |
61 | @Override
62 | public void setData(InformationElement elem) {
63 | this.informationElement = elem;
64 | }
65 |
66 | /** The related information element. */
67 | @ManyToOne(fetch = FetchType.EAGER)
68 | @JoinColumn(name = "element_id")
69 | public InformationElement informationElement;
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/IntentModelEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import java.util.Map;
28 |
29 | import javax.persistence.ElementCollection;
30 | import javax.persistence.Entity;
31 | import javax.persistence.FetchType;
32 | import javax.persistence.JoinColumn;
33 | import javax.persistence.ManyToOne;
34 |
35 | /**
36 | An intent model expressed as a list of weighted keywords.
37 | */
38 | @Entity
39 | public class IntentModelEvent extends Event {
40 | /**
41 | A related event, e.g. the SearchEvent that started the search.
42 | */
43 | @ManyToOne(fetch = FetchType.EAGER)
44 | @JoinColumn(name = "related_event_id")
45 | public Event relatedEvent;
46 |
47 | @ElementCollection
48 | public Map model;
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/IntentModelFeedbackEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import java.util.Map;
28 |
29 | import javax.persistence.CascadeType;
30 | import javax.persistence.ElementCollection;
31 | import javax.persistence.Entity;
32 | import javax.persistence.FetchType;
33 | import javax.persistence.JoinColumn;
34 | import javax.persistence.ManyToOne;
35 |
36 | /**
37 | Represents the feedback to a profile and the intent that it
38 | represented at the time of the feedback
39 | */
40 | @Entity
41 | public class IntentModelFeedbackEvent extends Event {
42 | @ManyToOne(fetch = FetchType.EAGER, cascade=CascadeType.MERGE)
43 | @JoinColumn(name = "related_profile_id")
44 | public Profile relatedProfile;
45 |
46 | @ElementCollection
47 | public Map intent;
48 |
49 | public Double weight;
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/Location.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Embeddable;
28 |
29 | /**
30 | Class representing a location on the planet Earth (usually).
31 | */
32 | @Embeddable
33 | public class Location {
34 | /** Latitude in degrees
35 | */
36 | public Double latitude;
37 |
38 | /** Longitude in degrees
39 | */
40 | public Double longitude;
41 |
42 | /** Altitude in metres.
43 | */
44 | public Double altitude;
45 |
46 | /** Horizontal accuracy, in metres.
47 | */
48 | public Double horizAccuracy;
49 |
50 | /** Vertical accuracy, in metres.
51 | */
52 | public Double vertAccuracy;
53 |
54 | /** Bearing in degrees, east of north (0: north, 90: east, 180: south, 270: west).
55 | */
56 | public Double bearing;
57 |
58 | /** Speed in metres per second
59 | */
60 | public Double speed;
61 |
62 | /** A (relatively) long line of text that quickly describes the location to a human.
63 | * Example: "Country: Finland, Locality: Helsinki, Neighborhood: Kumpula, Steet: Gadolininkatu
64 | */
65 | public String descriptionLine;
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/Makefile:
--------------------------------------------------------------------------------
1 | all: build
2 |
3 | %::
4 | @make $@ -C ../
5 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/Message.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import java.util.Date;
28 | import java.util.List;
29 |
30 | import javax.persistence.CascadeType;
31 | import javax.persistence.Column;
32 | import javax.persistence.Entity;
33 | import javax.persistence.JoinColumn;
34 | import javax.persistence.JoinTable;
35 | import javax.persistence.ManyToMany;
36 | import javax.persistence.ManyToOne;
37 | import javax.persistence.OneToMany;
38 |
39 | /**
40 | Class representing an electronic message, such as an email.
41 | */
42 | @Entity
43 | public class Message extends InformationElement {
44 | public Date date;
45 |
46 | @Column(columnDefinition="text")
47 | public String subject;
48 |
49 | @Column(columnDefinition="text")
50 | public String fromString;
51 |
52 | @ManyToOne(cascade=CascadeType.ALL)
53 | @JoinColumn(name="from_id")
54 | public Person from;
55 |
56 | @Column(columnDefinition="text")
57 | public String toString;
58 |
59 | @ManyToMany(cascade=CascadeType.ALL)
60 | @JoinTable(name="message_to",
61 | joinColumns={@JoinColumn(name="message_id", referencedColumnName="id")},
62 | inverseJoinColumns={@JoinColumn(name="person_id", referencedColumnName="id")})
63 | public List to;
64 |
65 | @Column(columnDefinition="text")
66 | public String ccString;
67 |
68 | @ManyToMany(cascade=CascadeType.ALL)
69 | @JoinTable(name="message_cc",
70 | joinColumns={@JoinColumn(name="message_id", referencedColumnName="id")},
71 | inverseJoinColumns={@JoinColumn(name="person_id", referencedColumnName="id")})
72 | public List cc;
73 |
74 | @OneToMany(cascade=CascadeType.ALL)
75 | @JoinColumn(name="message_id", referencedColumnName="id")
76 | public List attachments;
77 |
78 | @Column(columnDefinition="text")
79 | public String rawMessage;
80 |
81 | @Override
82 | public void autoFill() {
83 | if (subject != null && subject.length() > 0 &&
84 | !plainTextContent.startsWith(subject))
85 | plainTextContent = subject + "\n\n" + plainTextContent;
86 | super.autoFill();
87 | if (title == null)
88 | title = subject;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/MessageEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Entity;
28 |
29 | @Entity
30 | public class MessageEvent extends ResourcedEvent {
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/OpenGraphProtocol.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import com.fasterxml.jackson.annotation.JsonProperty;
28 |
29 | import javax.persistence.Embeddable;
30 |
31 | /** Class to represent a OpenGraphProtocol data in a WebDocument. */
32 | @Embeddable
33 | public class OpenGraphProtocol {
34 | public OpenGraphProtocol() {}
35 |
36 | public String image;
37 |
38 | public String url;
39 |
40 | @JsonProperty("site_name")
41 | public String siteName;
42 |
43 | public String locale;
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/PageEyeData.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import com.fasterxml.jackson.annotation.*;
28 | import org.springframework.data.jpa.domain.AbstractPersistable;
29 |
30 | import javax.persistence.ElementCollection;
31 | import javax.persistence.Entity;
32 |
33 | import java.util.List;
34 |
35 | /**
36 | Class representing points read on a specific page (in page space coordinates).
37 | */
38 | @JsonInclude(value=JsonInclude.Include.NON_NULL)
39 | @JsonIgnoreProperties({"hibernateLazyInitializer", "handler", "new"})
40 | @Entity
41 | public class PageEyeData extends AbstractPersistable {
42 | /** Horizontal (x) coordinates
43 | */
44 | @ElementCollection(targetClass = Double.class)
45 | public List Xs;
46 |
47 | /** Vertical (y) coordinatess.
48 | */
49 | @ElementCollection(targetClass = Double.class)
50 | public List Ys;
51 |
52 | /** Pupil size.
53 | */
54 | @ElementCollection(targetClass = Double.class)
55 | public List Ps;
56 |
57 | /** Times of fixation start in microseconds.
58 | */
59 | @ElementCollection(targetClass = Long.class)
60 | public List startTimes;
61 |
62 | /** Times of fixation end in microseconds.
63 | */
64 | @ElementCollection(targetClass = Long.class)
65 | public List endTimes;
66 |
67 | /** Fixation durations in microseconds.
68 | */
69 | @ElementCollection(targetClass = Long.class)
70 | public List durations;
71 |
72 | /** Page index for this block of data.
73 | */
74 | public int pageIndex;
75 |
76 | /** The scale factor (zoom level) used when these data were collected (1 = 100% size, 2 = 200%, etc).
77 | */
78 | public Double scaleFactor;
79 |
80 | /** Unix time (note: milliseconds) indicating when this chunk of data was created (when the first chunk of fixations was received).
81 | */
82 | public Long unixt;
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/Person.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import com.fasterxml.jackson.annotation.*;
28 | import org.springframework.data.jpa.domain.AbstractPersistable;
29 |
30 | import java.util.List;
31 |
32 | import javax.persistence.ElementCollection;
33 | import javax.persistence.Entity;
34 |
35 | @JsonInclude(value=JsonInclude.Include.NON_NULL)
36 | @JsonIgnoreProperties({"hibernateLazyInitializer", "handler", "new"})
37 | @Entity
38 | public class Person extends AbstractPersistable {
39 | public String firstName;
40 | public String lastName;
41 |
42 | @ElementCollection(targetClass = String.class)
43 | public List middleNames; // middle names or middle initials, if any
44 |
45 | public String emailAccount; // e.g. "foo.bar@hiit.fi"
46 | public String dimeAccount; // e.g. "foobar@dime.hiit.fi"
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/PhysicalEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Entity;
28 |
29 | /**
30 | An event representing a physical measurement in time, or time
31 | interval (e.g. 1 minute average).
32 | */
33 | @Entity
34 | public class PhysicalEvent extends Event {
35 | /**
36 | The value of a physical measurement.
37 | */
38 | public Double value;
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/Point.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Embeddable;
28 |
29 | /**
30 | Class representing a point in a two-dimensional space.
31 | */
32 | @Embeddable
33 | public class Point {
34 | // Yes, this is needed :-)
35 | public Point() {}
36 |
37 | public Point(double x, double y) {
38 | this.x = x;
39 | this.y = y;
40 | }
41 |
42 | /** Horizontal (x) coordinate
43 | */
44 | public double x;
45 |
46 | /** Vertical (y) coordinate.
47 | */
48 | public double y;
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/Range.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Embeddable;
28 |
29 | /**
30 | Class representing a range of floating point values.
31 | */
32 | @Embeddable
33 | public class Range {
34 | /** The minimum value.
35 | */
36 | public double min;
37 |
38 | /** The maximum value.
39 | */
40 | public double max;
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/ReadingTag.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import java.util.Date;
28 | import java.util.List;
29 |
30 | import com.fasterxml.jackson.annotation.*;
31 |
32 | import org.springframework.data.jpa.domain.AbstractPersistable;
33 |
34 | import javax.persistence.Column;
35 | import javax.persistence.OneToMany;
36 | import javax.persistence.JoinColumn;
37 | import javax.persistence.CascadeType;
38 | import javax.persistence.Entity;
39 |
40 | /**
41 | Class representing a tag for some text within a document (represented by rects).
42 | */
43 | @Entity
44 | public class ReadingTag extends Tag {
45 |
46 | /** A list of rectangles representing where the relevant (tagged) text is located.
47 | */
48 | @OneToMany(cascade=CascadeType.ALL)
49 | @JoinColumn(name="tag_id", referencedColumnName="id")
50 | public List rects;
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/ResourcedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.CascadeType;
28 | import javax.persistence.Entity;
29 | import javax.persistence.FetchType;
30 | import javax.persistence.JoinColumn;
31 | import javax.persistence.ManyToOne;
32 |
33 | /**
34 | Abstract class representing events that link to an
35 | InformationElement.
36 | */
37 | @Entity
38 | public abstract class ResourcedEvent extends Event {
39 | /**
40 | The InformationElement object that is targetted by this event.
41 | */
42 | @ManyToOne(fetch = FetchType.EAGER) //, cascade=CascadeType.ALL)
43 | @JoinColumn(name = "resource_id")
44 | public InformationElement targettedResource;
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/ScientificDocument.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import java.util.List;
28 |
29 | import javax.persistence.CascadeType;
30 | import javax.persistence.Column;
31 | import javax.persistence.ElementCollection;
32 | import javax.persistence.Entity;
33 | import javax.persistence.JoinColumn;
34 | import javax.persistence.OneToMany;
35 |
36 | @Entity
37 | public class ScientificDocument extends Document {
38 | @OneToMany(cascade=CascadeType.ALL)
39 | @JoinColumn(name="document_id", referencedColumnName="id")
40 | public List authors;
41 |
42 | @Column(columnDefinition="text")
43 | public String booktitle;
44 |
45 | @ElementCollection(targetClass = String.class)
46 | public List keywords;
47 |
48 | public int firstPage;
49 | public int lastPage;
50 | public int year;
51 | public String address;
52 | public String publisher;
53 | public int volume;
54 | public String doi;
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/SearchEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import fi.hiit.dime.search.WeightedKeyword;
28 |
29 | import java.util.Date;
30 | import java.util.List;
31 |
32 | import javax.persistence.Entity;
33 | import javax.persistence.Transient;
34 |
35 | /**
36 | A search event, i.e. the user doing a text query.
37 | */
38 | @Entity
39 | public class SearchEvent extends Event {
40 | /**
41 | The text of the query.
42 | */
43 | public String query;
44 |
45 | @Transient
46 | public List queryTerms;
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/Size.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import javax.persistence.Embeddable;
28 |
29 | /**
30 | Class representing a size in a two dimensional space.
31 | */
32 | @Embeddable
33 | public class Size {
34 | // Yes, this is needed :-)
35 | public Size() {}
36 |
37 | public Size(double w, double h) {
38 | width = w;
39 | height = h;
40 | }
41 |
42 | /** Width of this item.
43 | */
44 | public Double width;
45 |
46 | /** Height of this item.
47 | */
48 | public Double height;
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/SummaryReadingEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import java.util.List;
28 |
29 | import javax.persistence.ElementCollection;
30 | import javax.persistence.Entity;
31 |
32 | /**
33 | A summary reading event.
34 | Summary reading events contain more "refined" data, while non-summary reading events contain more detail.
35 | Summary reading events can contain united (non-floating) rectangles (but can contain floating rectangles).
36 | Non-summary reading events contain floating rectangles only.
37 |
38 | Also see https://github.com/HIIT/PeyeDF/wiki/Data-Format/.
39 | */
40 | @Entity
41 | public class SummaryReadingEvent extends ReadingEvent {
42 |
43 | /** Proportion of document which was displayed in viewports.
44 | * Probably seen by the user, but not guaranteed to have been read.
45 | */
46 | public Double proportionSeen;
47 |
48 | /** Proportion of document which was read
49 | */
50 | public Double proportionRead;
51 |
52 | /** Proportion of document which was marked as "interesting"
53 | */
54 | public Double proportionInteresting;
55 |
56 | /** Proportion of document which was marked as "critical"
57 | */
58 | public Double proportionCritical;
59 |
60 | /** Total time spent reading for the whole session (seconds)
61 | */
62 | public Double readingTime;
63 |
64 | /** List of strings that were searched for, found and selected by user, during this reading session.
65 | */
66 | @ElementCollection(targetClass = String.class)
67 | public List foundStrings;
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/data/WebDocument.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.data;
26 |
27 | import com.fasterxml.jackson.annotation.JsonProperty;
28 |
29 | import java.util.List;
30 |
31 | import javax.persistence.Column;
32 | import javax.persistence.ElementCollection;
33 | import javax.persistence.Embedded;
34 | import javax.persistence.Entity;
35 |
36 | @Entity
37 | public class WebDocument extends Document {
38 | @ElementCollection(targetClass = String.class)
39 | public List frequentTerms;
40 |
41 | @JsonProperty("abstract")
42 | public String abstractText;
43 |
44 | @Column(columnDefinition="longtext")
45 | public String html;
46 |
47 | @ElementCollection(targetClass = HyperLink.class)
48 | public List imgURLs;
49 |
50 | @ElementCollection(targetClass = HyperLink.class)
51 | public List hyperLinks;
52 |
53 | @Embedded
54 | public OpenGraphProtocol openGraphProtocol;
55 |
56 | @ElementCollection(targetClass = HtmlMetaTag.class)
57 | public List metaTags;
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/database/EventCount.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.database;
26 |
27 | import fi.hiit.dime.data.Event;
28 |
29 | public class EventCount {
30 | public String value;
31 | public long count;
32 | public double perc;
33 |
34 | public EventCount(String value, long count) {
35 | this.value = value;
36 | this.count = count;
37 | }
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/database/EventDAO.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.database;
26 |
27 | import fi.hiit.dime.authentication.User;
28 | import fi.hiit.dime.data.Event;
29 | import fi.hiit.dime.data.InformationElement;
30 | import fi.hiit.dime.data.IntentModelFeedbackEvent;
31 | import fi.hiit.dime.data.Profile;
32 | import fi.hiit.dime.data.ResourcedEvent;
33 |
34 | import org.slf4j.Logger;
35 | import org.slf4j.LoggerFactory;
36 | import org.springframework.data.domain.PageRequest;
37 | import org.springframework.stereotype.Service;
38 | import org.springframework.transaction.annotation.Transactional;
39 |
40 | import java.util.Date;
41 | import java.util.Iterator;
42 | import java.util.List;
43 |
44 | @Service
45 | public class EventDAO extends DiMeDAO {
46 | private static final Logger LOG = LoggerFactory.getLogger(EventDAO.class);
47 |
48 | @Transactional(readOnly = true)
49 | public List findByElement(InformationElement elem, User user) {
50 | return repo.findByTargettedResourceAndUser(elem, user);
51 | }
52 |
53 | @Transactional(readOnly = true)
54 | public List findByRelatedProfile(Profile profile,
55 | User user) {
56 | return repo.findByRelatedProfileAndUser(profile, user);
57 | }
58 |
59 | @Transactional(readOnly = true)
60 | public List eventsForUser(Long userId, int limit) {
61 | return repo.findByUserOrderByStartDesc(User.makeUser(userId),
62 | new PageRequest(0, limit));
63 | }
64 |
65 | @Transactional(readOnly = true)
66 | public List eventsSince(Long userId, Date since) {
67 | return repo.findByUserAndTimeModifiedIsAfterOrderByStartDesc(User.makeUser(userId), since);
68 | }
69 |
70 | public List getActorHistogram(Long userId) {
71 | List hist = repo.actorHistogram(User.makeUser(userId));
72 |
73 | // filter list a bit ...
74 | long totCount = 0;
75 | for (Iterator it = hist.iterator(); it.hasNext(); ) {
76 | EventCount ec = it.next();
77 | if (ec.value == null || ec.count == 0)
78 | it.remove();
79 | else
80 | totCount += ec.count;
81 | }
82 |
83 | for (EventCount ec : hist)
84 | ec.perc = ec.count/(double)totCount*100.0;
85 |
86 | return hist;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/database/InformationElementDAO.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.database;
26 |
27 | import fi.hiit.dime.authentication.User;
28 | import fi.hiit.dime.data.InformationElement;
29 | import fi.hiit.dime.data.ResourcedEvent;
30 |
31 | import org.springframework.beans.factory.annotation.Autowired;
32 | import org.springframework.data.domain.PageRequest;
33 | import org.springframework.stereotype.Service;
34 | import org.springframework.transaction.annotation.Transactional;
35 |
36 | import java.util.List;
37 |
38 | @Service
39 | public class InformationElementDAO
40 | extends DiMeDAO {
41 |
42 | @Autowired
43 | private EventDAO eventDAO;
44 |
45 | /**
46 | Return all InformationElement objects in database.
47 |
48 | @param id User id
49 | @return List of all InformationElement objects for user
50 | */
51 | @Transactional(readOnly = true)
52 | public List elementsForUser(Long id, int limit) {
53 | return repo.findByUserOrderByTimeModifiedDesc(User.makeUser(id),
54 | new PageRequest(0, limit));
55 | }
56 |
57 |
58 | /**
59 | Removes a single item.
60 |
61 | @param id Item id
62 | @param user User
63 | @return True if it was deleted, false otherwise.
64 | */
65 | @Override
66 | @Transactional
67 | public boolean remove(Long id, User user) {
68 | InformationElement elem = findById(id, user);
69 |
70 | List events = eventDAO.findByElement(elem, user);
71 |
72 | for (ResourcedEvent e : events) {
73 | eventDAO.remove(e.getId(), user);
74 | }
75 |
76 | return super.remove(id, user);
77 | }
78 |
79 | }
80 |
81 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/database/Makefile:
--------------------------------------------------------------------------------
1 | all: build
2 |
3 | %::
4 | @make $@ -C ../
5 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/database/ProfileRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.database;
26 |
27 | import fi.hiit.dime.data.Profile;
28 | import fi.hiit.dime.authentication.User;
29 |
30 | import org.springframework.data.repository.CrudRepository;
31 |
32 | import java.util.List;
33 |
34 | import javax.persistence.EntityManager;
35 | import javax.persistence.PersistenceContext;
36 |
37 | // interface ProfileRepositoryCustom {
38 | // public Profile replace(Profile oldProfile, Profile newProfile);
39 | // }
40 |
41 | // abstract class ProfileRepositoryImpl implements ProfileRepositoryCustom {
42 | // @PersistenceContext
43 | // protected EntityManager entityManager;
44 |
45 | // @Override
46 | // public Profile replace(Profile oldProfile, Profile newProfile) {
47 | // newProfile.copyIdFrom(oldProfile);
48 | // return entityManager.merge(newProfile);
49 | // }
50 | // }
51 |
52 | public interface ProfileRepository extends CrudRepository {
53 | // ProfileRepositoryCustom {
54 | Profile findOne(Long id);
55 |
56 | Profile findOneByIdAndUser(Long id, User user);
57 |
58 | List findByUser(User user);
59 |
60 | Long deleteByUser(User user);
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/database/UserDAO.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.database;
26 |
27 |
28 | import fi.hiit.dime.authentication.User;
29 |
30 | import org.springframework.beans.factory.annotation.Autowired;
31 | import org.springframework.stereotype.Repository;
32 |
33 | import java.util.List;
34 | import java.util.UUID;
35 |
36 | /**
37 | * Data access object for managing User objects.
38 | *
39 | * @author Mats Sjöberg (mats.sjoberg@helsinki.fi)
40 | */
41 | @Repository
42 | public class UserDAO {
43 |
44 | @Autowired
45 | private UserRepository repo;
46 |
47 | public User save(User obj) {
48 | return repo.save(obj);
49 | }
50 |
51 | private void ensureUserId(User user) {
52 | if (user != null && user.userId == null) {
53 | user.userId = UUID.randomUUID().toString();
54 | save(user);
55 | }
56 | }
57 |
58 | public User findById(Long id) {
59 | User user = repo.findOne(id);
60 | ensureUserId(user);
61 | return user;
62 | }
63 |
64 | public User findByUsername(String username) {
65 | User user = repo.findOneByUsername(username);
66 | ensureUserId(user);
67 | return user;
68 | }
69 |
70 | public List findAll() {
71 | List users = repo.findAll();
72 | for (User user : users)
73 | ensureUserId(user);
74 | return users;
75 | }
76 |
77 | public void remove(Long id) {
78 | repo.delete(id);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/database/UserRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.database;
26 |
27 |
28 | import fi.hiit.dime.authentication.User;
29 |
30 | import org.springframework.data.repository.CrudRepository;
31 |
32 | import java.util.List;
33 |
34 | /**
35 | * Data access object for managing User objects.
36 | *
37 | * @author Mats Sjöberg (mats.sjoberg@helsinki.fi)
38 | */
39 | public interface UserRepository extends CrudRepository {
40 | User findOne(Long id);
41 |
42 | User findOneByUsername(String username);
43 |
44 | List findAll();
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/search/KeywordSearchQuery.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.search;
26 |
27 | import java.util.ArrayList;
28 | import java.util.Arrays;
29 | import java.util.List;
30 |
31 | //------------------------------------------------------------------------------
32 |
33 | public class KeywordSearchQuery extends SearchQuery {
34 | public List weightedKeywords;
35 |
36 | public KeywordSearchQuery() {
37 | weightedKeywords = new ArrayList();
38 | }
39 |
40 | public KeywordSearchQuery(WeightedKeyword[] query) {
41 | this.weightedKeywords = Arrays.asList(query);
42 | }
43 |
44 | public void add(String term, float weight) {
45 | weightedKeywords.add(new WeightedKeyword(term, weight));
46 | }
47 |
48 | @Override
49 | public boolean isEmpty() {
50 | return weightedKeywords == null || weightedKeywords.size() == 0;
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | StringBuilder s = new StringBuilder();
56 | for (WeightedKeyword kw : weightedKeywords)
57 | s.append(String.format("%s (%f) ", kw.term, kw.weight));
58 | return s.toString();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/search/Makefile:
--------------------------------------------------------------------------------
1 | all: build
2 |
3 | %::
4 | @make $@ -C ../
5 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/search/SearchQuery.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.search;
26 |
27 | //------------------------------------------------------------------------------
28 |
29 | abstract public class SearchQuery {
30 | abstract public boolean isEmpty();
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/search/SearchResults.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.search;
26 |
27 | import fi.hiit.dime.authentication.User;
28 | import fi.hiit.dime.data.DiMeData;
29 |
30 | import com.fasterxml.jackson.annotation.JsonInclude;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | /** Class for containing search results and metadata. Similar to JSON
36 | "response" part of Solr.
37 | */
38 | @JsonInclude(value=JsonInclude.Include.NON_NULL)
39 | public class SearchResults {
40 | private long numFound;
41 |
42 | private List docs;
43 |
44 | public List queryTerms;
45 |
46 | public String message;
47 |
48 | public SearchResults() {
49 | this.docs = new ArrayList();
50 | }
51 |
52 | public SearchResults(String message) {
53 | this.docs = new ArrayList();
54 | this.message = message;
55 | }
56 |
57 | /** Add a single DiMeData object to the results.
58 | */
59 | public long add(DiMeData obj) {
60 | docs.add(obj);
61 | numFound = docs.size();
62 | return numFound;
63 | }
64 |
65 | /** Get the list of results.
66 | */
67 | public List getDocs() { return docs; }
68 |
69 | /** Set the list of results to given list of DiMeData objects.
70 | */
71 | public void setDocs(List docs) {
72 | this.docs = docs;
73 | numFound = docs.size();
74 | }
75 |
76 | /** Get number of results.
77 | */
78 | public long getNumFound() { return numFound; }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/search/TextSearchQuery.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.search;
26 |
27 | //------------------------------------------------------------------------------
28 |
29 | public class TextSearchQuery extends SearchQuery {
30 | public String query;
31 |
32 | public TextSearchQuery() {
33 | this.query = "";
34 | }
35 |
36 | public TextSearchQuery(String query) {
37 | this.query = query;
38 | }
39 |
40 | // getter and setter to make Thymeleaf believe this is a "bean"
41 | public String getQuery() { return query; }
42 | public void setQuery(String query) { this.query = query; }
43 |
44 | @Override
45 | public boolean isEmpty() {
46 | return query.isEmpty();
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return this.query;
52 | }
53 | }
54 |
55 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/search/WeightedKeyword.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.search;
26 |
27 | //------------------------------------------------------------------------------
28 |
29 | public class WeightedKeyword implements Comparable {
30 | public String term;
31 |
32 | public float weight;
33 |
34 | public WeightedKeyword() {}
35 |
36 | public WeightedKeyword(String term, float weight) {
37 | this.term = term;
38 | this.weight = weight;
39 | }
40 |
41 | @Override
42 | public boolean equals(Object obj) {
43 | WeightedKeyword other = (WeightedKeyword)obj;
44 | if (other != null)
45 | return this.term.equals(other.term) && this.weight == other.weight;
46 | return false;
47 | }
48 |
49 | @Override
50 | public int compareTo(WeightedKeyword other) {
51 | return (int)Math.signum(this.weight - other.weight);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/sovrin/Makefile:
--------------------------------------------------------------------------------
1 | all: build
2 |
3 | %::
4 | @make $@ -C ../
5 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/util/Makefile:
--------------------------------------------------------------------------------
1 | all: build
2 |
3 | %::
4 | @make $@ -C ../
5 |
--------------------------------------------------------------------------------
/src/main/java/fi/hiit/dime/util/RandomPassword.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.util;
26 |
27 | //------------------------------------------------------------------------------
28 |
29 | import java.security.SecureRandom;
30 |
31 | //------------------------------------------------------------------------------
32 |
33 | public class RandomPassword {
34 | private SecureRandom mRand;
35 |
36 | private final static String chars_alpha =
37 | "abcdefghijklmnopqrstuvwxyz" +
38 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
39 |
40 | private final static String chars_numeric =
41 | "01234567890";
42 |
43 | private final static String chars_symbols =
44 | "_,.;:!#%&/()={}[]?+^<>*";
45 |
46 | public RandomPassword() {
47 | mRand = new SecureRandom();
48 | // FIXME: implement handling of seed
49 | }
50 |
51 | public String getPassword(int length, boolean numeric, boolean symbols) {
52 | StringBuilder chars = new StringBuilder(chars_alpha);
53 | if (numeric)
54 | chars.append(chars_numeric);
55 | if (symbols)
56 | chars.append(chars_symbols);
57 |
58 | StringBuilder p = new StringBuilder(length);
59 | int l = chars.length();
60 |
61 | for (int i=0; i
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HIIT/dime-server/28ba45bf4339724a05f6ae3d63b17049d61f751f/src/main/resources/static/favicon.ico
--------------------------------------------------------------------------------
/src/test/java/fi/hiit/dime/DiMeDataTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2016 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime;
26 |
27 | import fi.hiit.dime.data.Document;
28 | import fi.hiit.dime.data.Tag;
29 |
30 | import org.junit.Test;
31 | import org.junit.runner.RunWith;
32 | import org.springframework.boot.test.SpringApplicationConfiguration;
33 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
34 | import static org.junit.Assert.*;
35 |
36 | import java.util.List;
37 |
38 | /**
39 | * @author Mats Sjöberg (mats.sjoberg@helsinki.fi)
40 | */
41 | @SpringApplicationConfiguration(classes = Application.class)
42 | @RunWith(SpringJUnit4ClassRunner.class)
43 | public class DiMeDataTest {
44 | @Test
45 | public void testTags() throws Exception {
46 | Document doc1 = new Document();
47 | doc1.uri = "http://www.example.com/hello.txt";
48 | doc1.plainTextContent = "Hello, world";
49 | doc1.mimeType = "text/plain";
50 |
51 | assertFalse(doc1.hasTags());
52 |
53 | doc1.addTag(new Tag("foo"));
54 | doc1.addTag(new Tag("foo", true));
55 |
56 | doc1.addTag(new Tag("foo", "actor1"));
57 | doc1.addTag(new Tag("foo", true, "actor1"));
58 |
59 | assertTrue(doc1.hasTags());
60 | assertTrue(doc1.hasMatchingTag("foo"));
61 | assertTrue(doc1.hasMatchingTag(new Tag("foo", false, "actor1")));
62 | assertFalse(doc1.hasMatchingTag(new Tag("foo", "actor2")));
63 |
64 | Tag tag1 = doc1.getTag(new Tag("foo"));
65 | assertEquals(null, tag1.actor);
66 | assertTrue(tag1.auto);
67 |
68 | List matchingTags = doc1.getMatchingTags(new Tag("foo"));
69 | assertEquals(2, matchingTags.size());
70 | assertEquals(null, matchingTags.get(0).actor);
71 | assertEquals("actor1", matchingTags.get(1).actor);
72 | assertTrue(matchingTags.get(0).auto);
73 | assertTrue(matchingTags.get(1).auto);
74 |
75 | List matchingTagsWithActor =
76 | doc1.getMatchingTags(new Tag("foo", "actor1"));
77 | assertEquals(1, matchingTagsWithActor.size());
78 | assertEquals("actor1", matchingTagsWithActor.get(0).actor);
79 | assertTrue(matchingTagsWithActor.get(0).auto);
80 |
81 | List noMatchingTags =
82 | doc1.getMatchingTags(new Tag("foo", "actor2"));
83 | assertEquals(0, noMatchingTags.size());
84 |
85 | // Document doc2 = new Document();
86 | // doc2.uri = "http://www.example.com/hello2.txt";
87 | // doc2.plainTextContent = "Hello, world too";
88 | // doc2.mimeType = "text/plain";
89 |
90 | int removedNoneCount = doc1.removeMatchingTags(new Tag("foo", "actor2"));
91 | assertEquals(0, removedNoneCount);
92 | assertEquals(2, doc1.tags.size());
93 |
94 | int removedAllCount = doc1.removeMatchingTags(new Tag("foo"));
95 | assertEquals(2, removedAllCount);
96 | assertEquals(0, doc1.tags.size());
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/test/java/fi/hiit/dime/Makefile:
--------------------------------------------------------------------------------
1 | all: build
2 |
3 | %::
4 | @make $@ -C ../../../../../../
5 |
--------------------------------------------------------------------------------
/src/test/java/fi/hiit/dime/util/RandomPasswordTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015-2017 University of Helsinki
3 |
4 | Permission is hereby granted, free of charge, to any person
5 | obtaining a copy of this software and associated documentation files
6 | (the "Software"), to deal in the Software without restriction,
7 | including without limitation the rights to use, copy, modify, merge,
8 | publish, distribute, sublicense, and/or sell copies of the Software,
9 | and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | */
24 |
25 | package fi.hiit.dime.util;
26 |
27 | //------------------------------------------------------------------------------
28 |
29 | import static org.junit.Assert.*;
30 | import org.junit.Before;
31 | import org.junit.Test;
32 |
33 | //------------------------------------------------------------------------------
34 |
35 | public class RandomPasswordTest {
36 | private RandomPassword rand;
37 |
38 | @Before
39 | public void setup() {
40 | rand = new RandomPassword();
41 | }
42 |
43 | @Test
44 | public void testLength() {
45 | for (int i=1; i<30; i++) {
46 | String p1 = rand.getPassword(i, true, true);
47 | String p2 = rand.getPassword(i, false, true);
48 | String p3 = rand.getPassword(i, true, false);
49 | String p4 = rand.getPassword(i, false, false);
50 |
51 | System.out.println("p1 = " + p1);
52 | System.out.println("p2 = " + p2);
53 | System.out.println("p3 = " + p3);
54 | System.out.println("p4 = " + p4);
55 |
56 | assertEquals(p1.length(), i);
57 | assertEquals(p2.length(), i);
58 | assertEquals(p3.length(), i);
59 | assertEquals(p4.length(), i);
60 | }
61 | }
62 |
63 | //FIXME: test contents
64 | }
65 |
--------------------------------------------------------------------------------
/trustnet-demo.txt:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Start Sovrin pool
3 | docker run -d --ip="10.0.0.2" --net=indy_pool_network indy_pool
4 |
5 | # Register our trust anchor
6 | sovrin
7 | connect test
8 | new key with seed 424242424242MyTestTrustAnchor424
9 | new key with seed 000000000000000000000000Trustee1
10 | send NYM dest=CzvneMT45XwY5eTAVQedLF role=TRUST_ANCHOR verkey=~XgrExLytAX7t2gfJGLXStB
11 |
12 | # Start trust anchor service
13 | cd ~/dev/trustanchor-service/
14 | ./runserver.sh
15 |
16 |
17 | ################################################################################
18 | # Reset XDI state
19 | cd ~/dev/dime-server
20 | rm xdi2*.xdi
21 |
22 | # Start DiMe on 8080
23 | ./gradlew bootRun
24 |
25 | # Start DiMe on 8082
26 | SPRING_PROFILES_ACTIVE=second ./gradlew bootRun
27 |
28 |
29 | ################################################################################
30 | # Start people finder service
31 | cd ~/dev/dime-people-finder/
32 | rm graph.xdi # clean up
33 | mvn jetty:run
34 |
35 |
36 | ################################################################################
37 |
38 | DiMe:8082:
39 | - remove DID
40 | - register DID
41 | - send to People Finder
42 |
43 | DiMe:8080:
44 | - remove DID
45 |
--------------------------------------------------------------------------------