Script completed for resynching Mongo -> PostGis -> Geoserver

This commit is contained in:
Francesco Mangiacrapa 2023-03-27 16:41:51 +02:00
parent 026fd35fd6
commit 288756e686
2 changed files with 76 additions and 20 deletions

View File

@ -31,11 +31,18 @@ import org.gcube.common.scope.api.ScopeProvider;
public class ReSyncCentroidsMetadataOnDB {
private static final String CONTEXT = "/gcube/devsec/devVRE";
private static final String TOKEN = ""; // devVRE
// private static final String CONTEXT = "/gcube/devsec/devVRE";
// private static final String TOKEN = ""; // devVRE
// private static final String CONTEXT = "/pred4s/preprod/preVRE";
// private static final String TOKEN = "5c3c7551-870d-4259-bd77-a7e603fe4949-980114272"; //preVRE
private static final String CONTEXT = "/d4science.research-infrastructures.eu/D4OS/GNA";
private static final String TOKEN = ""; //GNA
// GEOPORTAL
private static final String PROFILE_ID = "profiledConcessioni";
private static String PROFILE_ID = "profiledConcessioni";
//private static final String PROFILE_ID = "concessioni-estere";
private static final String JSON_KEY_DATA_FINE_PROGETTO = "dataFineProgetto";
private static final String JSON_KEY_DATA_INIZIO_PROGETTO = "dataInizioProgetto";
private static final String JSON_KEY_INTRODUZIONE = "introduzione";
@ -43,13 +50,19 @@ public class ReSyncCentroidsMetadataOnDB {
// DB
private static final String platformName = "postgis";
private static final String category = "Database";
private static final String resourceName = "GNA-POSTGIS-DB";
//private static final String resourceName = "GNA-POSTGIS-DB"; //devVRE
//private static final String resourceName = "Geoserver-t postgis"; //preVRE
private static final String resourceName = "GNA-postgis"; //GNA
private static final String TABLE_COLUMN_DATA_FINE_PROGETTO = "data_fine_progetto";
private static final String TABLE_COLUMN_DATA_INIZIO_PROGETTO = "data_inizio_progetto";
private static final String TABLE_COLUMN_DESCRIZIONE = "descrizione";
private static ProjectsCaller client = null;
public static final boolean READ_ONLY_MODE = true;
/**
* Gets the client.
*
@ -64,13 +77,31 @@ public class ReSyncCentroidsMetadataOnDB {
}
public static void main(String[] args) {
System.out.println("READ_ONLY_MODE ENABLED: "+READ_ONLY_MODE);
System.out.println("CONTEXT IS: "+CONTEXT);
System.out.println("PROFILE_ID: "+PROFILE_ID);
initGeoportalClient();
//preVRE
// String tableName = "profiledconcessioni_internal__prevre_centroids";
// tableName = "profiledconcessioni_prevre_centroids";
// tableName = "concessioni_estere_prevre_centroids";
// tableName = "concessioni_estere_internal__prevre_centroids";
//GNA
// PROFILE_ID = "concessioni-estere";
// String tableName = "concessioni_estere_internal__gna_centroids";
// tableName = "concessioni_estere_gna_centroids";
PROFILE_ID = "profiledConcessioni";
String tableName = "profiledconcessioni_internal__gna_centroids";
tableName = "profiledconcessioni_gna_centroids";
String tableName = "profiledconcessioni_internal__devvre_centroids";
tableName = "profiledconcessioni_devvre_centroids";
long startTime = System.currentTimeMillis();
try {
RuntimeResourceReader rrr = new RuntimeResourceReader(CONTEXT, resourceName, platformName, category, null);
ServiceEndpointBean se = rrr.getListSE().get(0);
@ -85,8 +116,8 @@ public class ReSyncCentroidsMetadataOnDB {
// MUST BE DONE JUST ONCE
try {
// renameColumnTable(dbConnection, tableName, "anno", TABLE_COLUMN_DATA_INIZIO_PROGETTO);
// renameColumnTable(dbConnection, tableName, "date_scavo", TABLE_COLUMN_DATA_FINE_PROGETTO);
renameColumnTable(dbConnection, tableName, "anno", TABLE_COLUMN_DATA_INIZIO_PROGETTO);
renameColumnTable(dbConnection, tableName, "date_scavo", TABLE_COLUMN_DATA_FINE_PROGETTO);
// addColumnTable(dbConnection, tableName, "gna_url", "TEXT"); //Could be a
// VARCHAR(2048). Is it manageable by service?
} catch (Exception e) {
@ -101,8 +132,10 @@ public class ReSyncCentroidsMetadataOnDB {
// List<ResultDocumentDV> listPublishedProjectsIntoService =
// getListProjectsDVFiltered();
int counter = 1;
for (String projectId : listProjectIdsIntoDB) {
Project project = null;
System.out.println("\n\n################ "+counter+" of "+listProjectIdsIntoDB.size()+ ") Reading the project id: " + projectId);
try {
project = client.getProjectByID(PROFILE_ID, projectId);
} catch (Exception e) {
@ -113,7 +146,7 @@ public class ReSyncCentroidsMetadataOnDB {
if (project == null)
continue;
System.out.println("\n###Trying to update Centroid TABLE for project id: " + projectId);
System.out.println("\n###### Trying to update Centroid TABLE for project id: " + projectId);
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
@ -126,9 +159,14 @@ public class ReSyncCentroidsMetadataOnDB {
hashMap.put(TABLE_COLUMN_DESCRIZIONE, projectMap.get(JSON_KEY_INTRODUZIONE) + "");
updateTable(dbConnection, tableName, "projectId='" + projectId + "'", hashMap);
System.out.println("###UPDATED project id: " + projectId);
Thread.sleep(500);
System.out.println("################ Update completed for: " + projectId);
} catch (Exception e) {
System.err.println("Error on updating the table for the project id: " + projectId);
}
counter++;
}
@ -136,6 +174,12 @@ public class ReSyncCentroidsMetadataOnDB {
// TODO Auto-generated catch block
e.printStackTrace();
}
long endTime = System.currentTimeMillis();
System.out.println("\n\nSCRIPT END at: "+endTime);
double toSec = (endTime-startTime)/1000;
System.out.println("SCRIPT TERMINATED in "+toSec + "sec");
}
@ -215,8 +259,10 @@ public class ReSyncCentroidsMetadataOnDB {
System.out.println("Executing: " + alterTableString);
try {
con.setAutoCommit(false);
con.createStatement().execute(alterTableString);
con.commit();
if (!READ_ONLY_MODE) {
con.createStatement().execute(alterTableString);
con.commit();
}
} catch (SQLException e) {
e.printStackTrace();
if (con != null) {
@ -242,8 +288,10 @@ public class ReSyncCentroidsMetadataOnDB {
try {
con.setAutoCommit(false);
con.createStatement().execute(alterTableString);
con.commit();
if (!READ_ONLY_MODE) {
con.createStatement().execute(alterTableString);
con.commit();
}
} catch (SQLException e) {
e.printStackTrace();
if (con != null) {
@ -291,8 +339,10 @@ public class ReSyncCentroidsMetadataOnDB {
con.setAutoCommit(false);
System.out.println("Executing: " + updatePS.toString());
updatePS.executeUpdate();
con.commit();
if (!READ_ONLY_MODE) {
updatePS.executeUpdate();
con.commit();
}
} catch (SQLException e) {
e.printStackTrace();
if (con != null) {

View File

@ -143,15 +143,21 @@ public class RuntimeResourceReader {
*/
public static void main(String[] args) {
String scope = "/gcube/devsec/devVRE";
//String scope = "/gcube/devsec/devVRE";
//String scope = "/pred4s/preprod/preVRE";
String scope = "/d4science.research-infrastructures.eu/D4OS/GNA";
String platformName = "GeoServer";
String category = "Gis";
// String platformName = "postgis";
// String category = "Database";
// scope = "/pred4s/preprod/preVRE";
RuntimeResourceReader reader;
try {
ScopeProvider.instance.set(scope);
reader = new RuntimeResourceReader(scope, null, "postgis", "Database", null);
reader = new RuntimeResourceReader(scope, null, platformName, category, null);
for (ServiceEndpointBean seb : reader.getListSE()) {
System.out.println("Found: " + seb);
@ -175,7 +181,7 @@ public class RuntimeResourceReader {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}