1.0.3
This commit is contained in:
parent
9a42faef00
commit
ad7f439605
|
@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
Implemented list, list by type
|
||||
Fixed : commit transaction when safelyCommit project
|
||||
Fixed : exception encapsulation in DB initialization
|
||||
|
||||
## [v1.0.2] - 2020-11-4
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.apache.commons.csv.CSVRecord;
|
|||
import org.gcube.application.geoportal.model.Configuration;
|
||||
import org.gcube.application.geoportal.model.db.DBConstants;
|
||||
import org.gcube.application.geoportal.model.db.PostgisTable;
|
||||
import org.gcube.application.geoportal.model.fault.ConfigurationException;
|
||||
import org.gcube.application.geoportal.model.fault.InvalidRecordException;
|
||||
import org.gcube.application.geoportal.storage.PostgisDBManager;
|
||||
import org.gcube.application.geoportal.storage.PostgisDBManagerI;
|
||||
|
@ -65,7 +66,7 @@ public class Uploader {
|
|||
|
||||
// Expectcs CSV nome,anno,regione,xcentroid,ycentroid,csv,shp,nome_csv,poligono,punti,linee
|
||||
// I.E {nome=Acquacadda Nuxis, anno=2019, regione=Sardegna, xcentroid=8.751, ycentroid=39.179, csv=TRUE, shp=TRUE, nome_csv=AcquacaddaNuxis_poligoni, poligono=TRUE, punti=FALSE, linee=FALSE}
|
||||
public void insertConcessioni(File CSVFile,Boolean centroidsOnly) throws FileNotFoundException, IOException, SQLException {
|
||||
public void insertConcessioni(File CSVFile,Boolean centroidsOnly) throws FileNotFoundException, IOException, SQLException, ConfigurationException {
|
||||
log.info("Connecting to postgresDB.. ");
|
||||
log.info("Parsing file "+CSVFile.getAbsolutePath());
|
||||
File exportedFolder=new File(CSVFile.getParent()+File.separator+"esportazioni");
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.EntityTransaction;
|
||||
|
@ -29,6 +28,7 @@ import org.gcube.application.geoportal.model.db.DatabaseConnection;
|
|||
import org.gcube.application.geoportal.model.db.PostgisTable;
|
||||
import org.gcube.application.geoportal.model.db.PostgisTable.Field;
|
||||
import org.gcube.application.geoportal.model.db.PostgisTable.FieldType;
|
||||
import org.gcube.application.geoportal.model.fault.ConfigurationException;
|
||||
import org.gcube.application.geoportal.model.fault.PersistenceException;
|
||||
import org.gcube.application.geoportal.model.fault.PublishException;
|
||||
import org.gcube.application.geoportal.model.fault.SDIInteractionException;
|
||||
|
@ -91,7 +91,7 @@ public abstract class AbstractRecordManager<T extends Record> {
|
|||
|
||||
}catch(Throwable t) {
|
||||
if(defaultProvider==null)
|
||||
throw new RuntimeException("NO INTERNAL DADATABASE. Please contact VRE Manager (Required SE [platform : postgresq, 'GNA-DB' flag : internal-db])");
|
||||
throw new RuntimeException("NO INTERNAL DADATABASE. Please contact VRE Manager (Required SE [platform : postgresq, 'GNA-DB' flag : internal-db])",t);
|
||||
else {
|
||||
log.warn("Found default provider. This should happen only in test phase.");
|
||||
emf=defaultProvider.getFactory();
|
||||
|
@ -327,6 +327,9 @@ public abstract class AbstractRecordManager<T extends Record> {
|
|||
}catch(SDIInteractionException e) {
|
||||
log.warn("Unable to publish Centroid Layer for record type "+getRecord().getRecordType(),e);
|
||||
throw new PublishException("Unable to publish centroid.",e, null);
|
||||
} catch (ConfigurationException e) {
|
||||
log.warn("Unable to contact centroids db "+getRecord().getRecordType(),e);
|
||||
throw new PublishException("Unable to publish centroid.",e, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.application.geoportal.model.db;
|
||||
|
||||
import org.gcube.application.geoportal.model.fault.ConfigurationException;
|
||||
import org.gcube.application.geoportal.utils.ISUtils;
|
||||
|
||||
import lombok.Getter;
|
||||
|
@ -19,7 +20,7 @@ public class DatabaseConnection {
|
|||
Concessioni,Mosi,Mopr
|
||||
}
|
||||
|
||||
public static DatabaseConnection get(TYPE type) {
|
||||
public static DatabaseConnection get(TYPE type) throws ConfigurationException {
|
||||
return ISUtils.queryForDB("postgis", type.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package org.gcube.application.geoportal.model.fault;
|
||||
|
||||
public class ConfigurationException extends Exception {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3810929853461018566L;
|
||||
|
||||
public ConfigurationException() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ConfigurationException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ConfigurationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ConfigurationException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public ConfigurationException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package org.gcube.application.geoportal.model.vre;
|
||||
|
||||
import org.gcube.application.geoportal.model.fault.ConfigurationException;
|
||||
import org.gcube.application.geoportal.utils.ISUtils;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.data.transfer.library.utils.ScopeUtils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class SudoOperator {
|
||||
|
||||
private String token;
|
||||
private String backupToken;
|
||||
private String caller;
|
||||
|
||||
public SudoOperator() throws ConfigurationException {
|
||||
this.token=ISUtils.getToken();
|
||||
this.backupToken=SecurityTokenProvider.instance.get();
|
||||
this.caller=ScopeUtils.getCurrentCaller();
|
||||
log.warn("Created SUDO operator by "+caller);
|
||||
}
|
||||
|
||||
public void sudo() {
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
log.warn("Starting SUDO operation by "+ScopeUtils.getCurrentCaller());
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
SecurityTokenProvider.instance.set(backupToken);
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import org.gcube.application.geoportal.model.db.DatabaseConnection;
|
|||
import org.gcube.application.geoportal.model.db.DatabaseConnection.TYPE;
|
||||
import org.gcube.application.geoportal.model.db.PostgisTable;
|
||||
import org.gcube.application.geoportal.model.db.PostgisTable.Field;
|
||||
import org.gcube.application.geoportal.model.fault.ConfigurationException;
|
||||
import org.gcube.application.geoportal.model.fault.DataParsingException;
|
||||
import org.gcube.application.geoportal.model.gis.BBOX;
|
||||
import org.gcube.application.geoportal.utils.DBUtils;
|
||||
|
@ -22,7 +23,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
public class PostgisDBManager implements PostgisDBManagerI {
|
||||
|
||||
@Synchronized
|
||||
public static PostgisDBManager get() throws SQLException {
|
||||
public static PostgisDBManager get() throws SQLException, ConfigurationException {
|
||||
if(config==null) {
|
||||
log.debug("Looking for Default Configuration.. ");
|
||||
DatabaseConnection defaultConfiguration=DatabaseConnection.get(TYPE.Concessioni);
|
||||
|
@ -31,7 +32,7 @@ public class PostgisDBManager implements PostgisDBManagerI {
|
|||
}
|
||||
return new PostgisDBManager();
|
||||
}
|
||||
public static PostgisDBManagerI get(boolean autocommit) throws SQLException {
|
||||
public static PostgisDBManagerI get(boolean autocommit) throws SQLException, ConfigurationException {
|
||||
PostgisDBManager toReturn=get();
|
||||
toReturn.conn.setAutoCommit(autocommit);
|
||||
return toReturn;
|
||||
|
|
|
@ -38,7 +38,7 @@ public class WorkspaceManager {
|
|||
return sgClient;
|
||||
}
|
||||
|
||||
private FolderContainer getApplicationBaseFolder() throws StorageHubException {
|
||||
public FolderContainer getApplicationBaseFolder() throws StorageHubException {
|
||||
if(appBase==null) {
|
||||
StorageHubClient client=getSGClient();
|
||||
FolderContainer vre=client.openVREFolder();
|
||||
|
|
|
@ -3,7 +3,10 @@ package org.gcube.application.geoportal.utils;
|
|||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.application.geoportal.model.db.DatabaseConnection;
|
||||
import org.gcube.application.geoportal.model.fault.ConfigurationException;
|
||||
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
|
@ -12,7 +15,7 @@ import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|||
|
||||
public class ISUtils {
|
||||
|
||||
public static DatabaseConnection queryForDB(String platform,String flag) {
|
||||
public static DatabaseConnection queryForDB(String platform,String flag) throws ConfigurationException {
|
||||
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
|
||||
|
@ -22,14 +25,41 @@ public class ISUtils {
|
|||
.setResult("$resource/Profile/AccessPoint");
|
||||
|
||||
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
||||
|
||||
AccessPoint point=client.submit(query).get(0);
|
||||
List<AccessPoint> found=client.submit(query);
|
||||
if(found.size()>1) {
|
||||
throw new ConfigurationException("Multiple SE found ["+found.size()+"] for platform : "+platform+" flag : "+flag);
|
||||
}else if (found.isEmpty()){
|
||||
throw new ConfigurationException("No SE found for platform : "+platform+" flag : "+flag);
|
||||
}
|
||||
AccessPoint point=found.get(0);
|
||||
|
||||
|
||||
return new DatabaseConnection(point.username(),decryptString(point.password()),point.address());
|
||||
|
||||
}
|
||||
|
||||
public static String getToken() throws ConfigurationException {
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
|
||||
query.addCondition("$resource/Profile/Category/text() eq 'Application'")
|
||||
.addCondition("$resource/Profile/Name/text() eq 'GNA-APP'")
|
||||
.setResult("$resource/Profile/AccessPoint");
|
||||
|
||||
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
||||
|
||||
List<AccessPoint> found= client.submit(query);
|
||||
if(found.size()>1) {
|
||||
throw new ConfigurationException("Multiple Token SE found ["+found.size()+"] for Category : Application name : GNA-APP");
|
||||
}else if (found.isEmpty()){
|
||||
throw new ConfigurationException("No Token SE found ["+found.size()+"] for Category : Application name : GNA-APP");
|
||||
}
|
||||
|
||||
AccessPoint point=found.get(0);
|
||||
return decryptString(point.password());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String decryptString(String toDecrypt){
|
||||
try{
|
||||
return StringEncrypter.getEncrypter().decrypt(toDecrypt);
|
||||
|
|
|
@ -4,16 +4,24 @@ package org.gcube.application.geoportal;
|
|||
import org.gcube.application.geoportal.managers.ConcessioneManager;
|
||||
import org.gcube.application.geoportal.managers.ManagerFactory;
|
||||
import org.gcube.application.geoportal.model.concessioni.Concessione;
|
||||
import org.gcube.application.geoportal.model.fault.ConfigurationException;
|
||||
import org.gcube.application.geoportal.model.fault.PersistenceException;
|
||||
import org.gcube.application.geoportal.model.fault.PublishException;
|
||||
import org.gcube.application.geoportal.model.fault.ValidationException;
|
||||
import org.gcube.application.geoportal.storage.WorkspaceManager;
|
||||
import org.gcube.application.geoportal.utils.ISUtils;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.data.transfer.library.utils.ScopeUtils;
|
||||
|
||||
public class CheckContextConfiguration {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TokenSetter.set("/gcube/devNext/NextNext");
|
||||
TokenSetter.set("/pred4s/preprod/preVRE");
|
||||
public static void main(String[] args) throws ConfigurationException, StorageHubException {
|
||||
TokenSetter.set("/gcube/devNext/NextNext");
|
||||
// TokenSetter.set("/pred4s/preprod/preVRE");
|
||||
|
||||
// TokenSetter.set("/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype");
|
||||
|
||||
// System.out.println("Checking for internal .. ");
|
||||
// ConcessioneManager manager=ManagerFactory.getByRecord(new Concessione());
|
||||
// try {
|
||||
|
@ -24,11 +32,37 @@ public class CheckContextConfiguration {
|
|||
// }finally {
|
||||
// manager.shutdown();
|
||||
// }
|
||||
|
||||
|
||||
// Checking token validity
|
||||
// only from 1.0.3
|
||||
// System.out.println("Checking for token ");
|
||||
// String token = ISUtils.getToken();
|
||||
// System.out.println("Token Found ");
|
||||
//
|
||||
// String toRestore= (SecurityTokenProvider.instance.get());
|
||||
// System.out.println("Current Identity : "+ScopeUtils.getCurrentCaller());
|
||||
// SecurityTokenProvider.instance.set(token);
|
||||
// System.out.println("Current Identity : "+ScopeUtils.getCurrentCaller());
|
||||
//
|
||||
// SecurityTokenProvider.instance.set(toRestore);
|
||||
// System.out.println("Current Identity : "+ScopeUtils.getCurrentCaller());
|
||||
//
|
||||
//
|
||||
System.out.println(ISUtils.queryForDB("postgresql", "internal-db"));
|
||||
System.out.println("Checking for postgis .. ");
|
||||
System.out.println(ISUtils.queryForDB("postgis", "Concessioni"));
|
||||
|
||||
|
||||
|
||||
System.out.println("Base folder path : "+new WorkspaceManager(null).getApplicationBaseFolder().get().getPath());
|
||||
|
||||
|
||||
System.out.println("Inspecting internal DB ");
|
||||
System.out.println("Found "+ManagerFactory.getList().size()+" records");
|
||||
|
||||
|
||||
|
||||
// INIT APP
|
||||
// INTERNAL DB // ******* IS ******** SE platform : "postgresql" AP."GNA_DB"="internal-db"
|
||||
// WORKSPACE ROOT FOLDER
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.Map;
|
|||
|
||||
import org.gcube.application.geoportal.model.db.DBInteractionException;
|
||||
import org.gcube.application.geoportal.model.db.DatabaseConnection;
|
||||
import org.gcube.application.geoportal.model.fault.ConfigurationException;
|
||||
import org.gcube.application.geoportal.model.fault.DataParsingException;
|
||||
import org.gcube.application.geoportal.model.fault.GeoPackageInteractionException;
|
||||
import org.gcube.application.geoportal.storage.PostgisDBManager;
|
||||
|
@ -30,7 +31,7 @@ public class UploadGpkgTable {
|
|||
+ "--TABLENAME";
|
||||
|
||||
|
||||
public static void main(String[] args) throws SQLException, IOException, GeoPackageInteractionException, DBInteractionException, DataParsingException {
|
||||
public static void main(String[] args) throws SQLException, IOException, GeoPackageInteractionException, DBInteractionException, DataParsingException, ConfigurationException {
|
||||
|
||||
if(args.length<1) {
|
||||
System.out.println(USAGE);
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.io.FileInputStream;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gcube.application.geoportal.managers.AbstractRecordManager;
|
||||
import org.gcube.application.geoportal.managers.ConcessioneManager;
|
||||
import org.gcube.application.geoportal.managers.ManagerFactory;
|
||||
import org.gcube.application.geoportal.model.InputStreamDescriptor;
|
||||
|
@ -54,6 +55,8 @@ public class UseCases {
|
|||
}catch(Throwable t) {
|
||||
System.err.println("ALERT "+t.getMessage());
|
||||
throw t;
|
||||
}finally {
|
||||
AbstractRecordManager.shutdown();
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,7 +65,6 @@ public class UseCases {
|
|||
|
||||
public static Concessione registerNewConcessione() throws FileNotFoundException, IOException{
|
||||
ConcessioneManager manager=null;
|
||||
try {
|
||||
//Preparo l'istanza del modello con i vari campi compilati e senza gli allegati
|
||||
Concessione conc=TestModel.prepareEmptyConcessione();
|
||||
|
||||
|
@ -138,20 +140,13 @@ public class UseCases {
|
|||
return registered;
|
||||
//--- FINALLY --/
|
||||
|
||||
}finally{
|
||||
manager.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void readConcessione(long id) {
|
||||
|
||||
ConcessioneManager manager=ManagerFactory.getByRecordID(id);
|
||||
try{
|
||||
System.out.println(manager.getRecord());
|
||||
}finally {
|
||||
manager.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package org.gcube.application.geoportal;
|
||||
|
||||
import org.gcube.application.geoportal.utils.Workspace;
|
||||
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.ItemContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.ListResolver;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
|
||||
public class WSTests {
|
||||
|
||||
public static void main(String[] args) throws StorageHubException {
|
||||
TokenSetter.set("/gcube/devNext/NextNext");
|
||||
|
||||
StorageHubClient client=Workspace.getClient();
|
||||
String id="9e397c1f-0b52-4b59-b247-e5ef301978ed";
|
||||
|
||||
ItemContainer item=client.open(id).asItem();
|
||||
System.out.println(item.get().getPath());
|
||||
// switch(item.getType()) {
|
||||
// case FILE :
|
||||
// FileContainer file=(FileContainer) item;
|
||||
// file.getAnchestors();
|
||||
// }
|
||||
System.out.println(path(item));
|
||||
|
||||
}
|
||||
|
||||
public static String path(ItemContainer item) throws StorageHubException {
|
||||
StringBuilder builder=new StringBuilder();
|
||||
ListResolver resolver=item.getAnchestors();
|
||||
for(Item i:resolver.getItems()) {
|
||||
builder.append(i.getName()+" ID : "+i.getId()+"\n");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue