Revision 58059
Added by Dimitris Pierrakos about 4 years ago
modules/dnet-openaire-usage-stats-export/branches/usage-stats-export-v3/src/main/java/eu/dnetlib/usagestats/export/ConnectDB.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package eu.dnetlib.usagestats.export; |
|
7 |
|
|
8 |
/** |
|
9 |
* |
|
10 |
* @author dpie |
|
11 |
*/ |
|
12 |
import java.io.InputStream; |
|
13 |
import java.sql.Connection; |
|
14 |
import java.sql.DriverManager; |
|
15 |
import java.util.Properties; |
|
16 |
import org.apache.log4j.Logger; |
|
17 |
|
|
18 |
public class ConnectDB { |
|
19 |
|
|
20 |
|
|
21 |
public static Connection DB_CONNECTION; |
|
22 |
private final String dbURL; |
|
23 |
private final String dbUsername; |
|
24 |
private final String dbPassword; |
|
25 |
private final Logger log = Logger.getLogger(this.getClass()); |
|
26 |
|
|
27 |
public ConnectDB() throws Exception { |
|
28 |
Properties prop = new Properties(); |
|
29 |
InputStream propertiesInputStream = executeWorkflowNew.class.getClassLoader().getResourceAsStream("usagestats.properties"); |
|
30 |
prop.load(propertiesInputStream); |
|
31 |
|
|
32 |
Class.forName(prop.getProperty("db.driverClassName")); |
|
33 |
this.dbURL = prop.getProperty("db.Url"); |
|
34 |
this.dbUsername = prop.getProperty("db.username"); |
|
35 |
this.dbPassword = prop.getProperty("db.password"); |
|
36 |
this.connectDB(); |
|
37 |
} |
|
38 |
|
|
39 |
private void connectDB() throws Exception { |
|
40 |
try { |
|
41 |
Class.forName("org.postgresql.Driver"); |
|
42 |
DB_CONNECTION = DriverManager.getConnection(dbURL, dbUsername, dbPassword); |
|
43 |
log.info("Opened database successfully"); |
|
44 |
} catch (Exception e) { |
|
45 |
log.error("Connect to db failed: " + e); |
|
46 |
throw new Exception("Failed to connect to db: " + e.toString(), e); |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
} |
modules/dnet-openaire-usage-stats-export/branches/usage-stats-export-v3/src/main/java/eu/dnetlib/usagestats/export/ReadCounterRobotsList.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package eu.dnetlib.usagestats.export; |
|
7 |
|
|
8 |
/** |
|
9 |
* |
|
10 |
* @author dpie |
|
11 |
*/ |
|
12 |
import java.io.BufferedReader; |
|
13 |
import java.io.IOException; |
|
14 |
import java.io.InputStream; |
|
15 |
import java.io.InputStreamReader; |
|
16 |
import java.net.MalformedURLException; |
|
17 |
import java.net.URL; |
|
18 |
import java.nio.charset.Charset; |
|
19 |
import java.util.ArrayList; |
|
20 |
import org.json.JSONException; |
|
21 |
import org.json.simple.JSONArray; |
|
22 |
import org.json.simple.parser.JSONParser; |
|
23 |
import org.json.simple.parser.ParseException; |
|
24 |
|
|
25 |
public class ReadCounterRobotsList { |
|
26 |
|
|
27 |
private ArrayList robotsPatterns = new ArrayList(); |
|
28 |
private String COUNTER_ROBOTS_URL; |
|
29 |
|
|
30 |
public ReadCounterRobotsList(String url) throws IOException, JSONException, ParseException { |
|
31 |
COUNTER_ROBOTS_URL = url; |
|
32 |
robotsPatterns = readRobotsPartners(COUNTER_ROBOTS_URL); |
|
33 |
} |
|
34 |
|
|
35 |
private ArrayList readRobotsPartners(String url) throws MalformedURLException, IOException, ParseException { |
|
36 |
InputStream is = new URL(url).openStream(); |
|
37 |
JSONParser parser = new JSONParser(); |
|
38 |
BufferedReader reader = new BufferedReader(new InputStreamReader(is, Charset.forName("ISO-8859-1"))); |
|
39 |
JSONArray jsonArray = (JSONArray) parser.parse(reader); |
|
40 |
for (Object aJsonArray : jsonArray) { |
|
41 |
org.json.simple.JSONObject jsonObjectRow = (org.json.simple.JSONObject) aJsonArray; |
|
42 |
robotsPatterns.add(jsonObjectRow.get("pattern").toString().replace("\\", "\\\\")); |
|
43 |
} |
|
44 |
return robotsPatterns; |
|
45 |
} |
|
46 |
|
|
47 |
public ArrayList getRobotsPatterns(){ |
|
48 |
return robotsPatterns; |
|
49 |
} |
|
50 |
} |
modules/dnet-openaire-usage-stats-export/branches/usage-stats-export-v3/src/main/java/eu/dnetlib/usagestats/export/executeWorkflow.java | ||
---|---|---|
1 |
/* |
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package eu.dnetlib.usagestats.export; |
|
7 |
|
|
8 |
import java.io.BufferedReader; |
|
9 |
import java.io.File; |
|
10 |
import java.io.FileInputStream; |
|
11 |
import java.io.FileNotFoundException; |
|
12 |
import java.io.FileReader; |
|
13 |
import java.io.IOException; |
|
14 |
import java.io.InputStream; |
|
15 |
import java.sql.Connection; |
|
16 |
import java.sql.DriverManager; |
|
17 |
import java.sql.PreparedStatement; |
|
18 |
import java.sql.ResultSet; |
|
19 |
import java.sql.SQLException; |
|
20 |
import java.util.ArrayList; |
|
21 |
import java.util.Iterator; |
|
22 |
import java.util.Properties; |
|
23 |
import java.util.regex.Matcher; |
|
24 |
import java.util.regex.Pattern; |
|
25 |
|
|
26 |
/** |
|
27 |
* |
|
28 |
* @author dpie |
|
29 |
*/ |
|
30 |
public class executeWorkflow { |
|
31 |
|
|
32 |
public static void main(String args[]) throws ClassNotFoundException, SQLException, Exception { |
|
33 |
UsageStatsExporter usagestatsExport =new UsageStatsExporter(); |
|
34 |
usagestatsExport.export(); |
|
35 |
|
|
36 |
} |
|
37 |
} |
modules/dnet-openaire-usage-stats-export/branches/usage-stats-export-v3/src/main/resources/usagestats.properties | ||
---|---|---|
1 |
#logging.config=log4j.properties |
|
2 |
db.driverClassName=org.postgresql.Driver |
|
3 |
#spring.datasource.url=jdbc:postgresql://88.197.53.70:5432/stats |
|
4 |
#spring.datasource.url=jdbc:postgresql://statsdb-beta.openaire.eu:5432/stats |
|
5 |
db.Url=jdbc:postgresql://88.197.53.70:5432/stats2 |
|
6 |
#db.Url=jdbc:postgresql://statsdb-prod.openaire.eu/stats |
|
7 |
db.username=sqoop |
|
8 |
db.password=sqoop |
|
9 |
matomo.AuthToken=703bd17d845acdaf795e01bb1e0895b9 |
|
10 |
matomo.BaseUrl=analytics.openaire.eu |
|
11 |
repo.LogPath=/Users/dpie/Desktop/Repologs/ |
|
12 |
portal.LogPath=/Users/dpie/Desktop/Portallogs/ |
|
13 |
portal.MatomoID=109 |
|
14 |
COUNTER.robots.Url=https://raw.githubusercontent.com/atmire/COUNTER-Robots/master/COUNTER_Robots_list.json |
|
15 |
IRUS_UK.BaseUrl=https://irus.jisc.ac.uk/api/sushilite/v1_7/ |
|
16 |
#server.compression.enabled=true |
|
17 |
#compression.max_number_of_records=1000 |
|
18 |
#usagestats.redis.hostname=localhost |
|
19 |
#usagestats.redis.port=6379 |
|
20 |
#spring.jackson.serialization.INDENT_OUTPUT=true |
|
21 |
#download.folder=/Users/dpie/DownloadSushiLite |
|
22 |
#sushi-lite.server=http://localhost:8080 |
Also available in: Unified diff
New Workflow