Fabio Sinibaldi 2018-07-23 16:34:20 +00:00
parent dccb83467a
commit 7dcddb56ed
2 changed files with 30 additions and 17 deletions

View File

@ -15,9 +15,9 @@ import org.gcube.accounting.accounting.summary.access.model.ScopeDescriptor;
public class SimpleTest {
public static void main(String[] args) throws ParameterException, Exception {
TokenSetter.set("/gcube/devNext/NextNext");
AccountingDao dao=AccountingDao.get();
// AccountingDao dao=AccountingDao.get(new DummyContextTreeProvider());
TokenSetter.set("/d4science.research-infrastructures.eu");
// AccountingDao dao=AccountingDao.get();
AccountingDao dao=AccountingDao.get(new DummyContextTreeProvider());
ScopeDescriptor desc=dao.getTree(null);
@ -26,7 +26,7 @@ public class SimpleTest {
// Date from=new Date(1514764800000l);
Date from=new GregorianCalendar(2018,0,1).getTime();
Date from=new GregorianCalendar(2017,0,1).getTime();
Date to=new GregorianCalendar(2018,7,1).getTime();
// Date to=from;
@ -34,7 +34,7 @@ public class SimpleTest {
scan(desc,from,to,dao);
System.out.println(Queries.asIDSet(desc));
}
@ -42,10 +42,10 @@ public class SimpleTest {
System.out.println("**********************************************************************************************************");
System.out.println(desc);
System.out.println(dao.getReportByScope(desc, from, to, MeasureResolution.MONTHLY));
if(desc.hasChildren()) {
for(ScopeDescriptor child:desc.getChildren())
scan(child,from,to,dao);
}
// if(desc.hasChildren()) {
// for(ScopeDescriptor child:desc.getChildren())
// scan(child,from,to,dao);
// }
}

View File

@ -1,7 +1,5 @@
package org.gcube.data.access.accounting.summary.access.utils;
import static org.gcube.accounting.accounting.summary.access.impl.DBStructure.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
@ -12,6 +10,9 @@ import java.util.Date;
import java.util.HashMap;
import org.gcube.accounting.accounting.summary.access.impl.DBStructure.CONTEXTS;
import org.gcube.accounting.accounting.summary.access.impl.DBStructure.DIMENSIONS;
import org.gcube.accounting.accounting.summary.access.impl.DBStructure.Measure;
import org.postgresql.util.PSQLException;
public class Importer {
private static Connection getSourceConn() throws SQLException, ClassNotFoundException {
@ -29,12 +30,18 @@ public class Importer {
}
private static Connection getDestinationConn() throws SQLException, ClassNotFoundException{
//DEV OLD DB
String user="analytics_b_dev_u";
String password ="78cb625303be21b";
String url ="jdbc:postgresql://postgresql-srv-dev.d4science.org:5432/analytics_b_dev";
// //DEV OLD DB
// String user="analytics_b_dev_u";
// String password ="78cb625303be21b";
// String url ="jdbc:postgresql://postgresql-srv-dev.d4science.org:5432/analytics_b_dev";
//
// PRODUCTION OLD DB
String user="analytics_board_u";
String password ="b52b64ab07ea0b5";
String url ="jdbc:postgresql://postgresql-srv.d4science.org:5432/analytics_board";
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(url, user, password);
conn.setAutoCommit(false);
@ -84,7 +91,7 @@ public class Importer {
Statement sourceStmt=sourceConn.createStatement();
ResultSet sourceRS=sourceStmt.executeQuery("Select monthly_measure.id as id, monthly_measure.measure as measure, monthly_measure.day as day,context.dname as context, context.name as context_label, measure_type.name as dimension"
+ " from monthly_measure inner join context on monthly_measure.context_id=context.id "
+ " inner join measure_type on monthly_measure.measure_type_id=measure_type.id order by id");
+ " inner join measure_type on monthly_measure.measure_type_id=measure_type.id where context.dname is not null AND monthly_measure.measure>0 order by id");
// LOAD PRE EXISTING CONTEXTS
HashMap<String,String> insertedContexts=new HashMap<>();
@ -113,6 +120,7 @@ public class Importer {
long startime=System.currentTimeMillis();
while(sourceRS.next()){
try {
Long measure = sourceRS.getLong("measure");
String context = sourceRS.getString("context");
String contextLabel= sourceRS.getString("context_label");
@ -152,6 +160,11 @@ public class Importer {
counter++;
if(counter%1000==0)
System.out.println(String.format("Inserted %1$s rows [%2$s dims, %3$s contexts]", counter, insertedDimensions.size(),insertedContexts.size()));
}catch(PSQLException e) {
System.out.println("Problematic Row ID "+sourceRS.getLong("id"));
throw e;
}
}
System.out.println("Committing..");