#22461 #1
|
@ -3,39 +3,36 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
# Changelog for org.gcube.application.geoportal-service
|
||||
|
||||
## [v1.0.8-SNAPSHOT] 2021-09-20
|
||||
Logging
|
||||
Fixes [#22193](https://support.d4science.org/issues/22193)
|
||||
- Logging
|
||||
- Fixes [#22193](https://support.d4science.org/issues/22193)
|
||||
- Fixes [#22280](https://support.d4science.org/issues/22280)
|
||||
|
||||
## [v1.0.6] 2021-09-20
|
||||
Refactored repositories
|
||||
Fixes #22193
|
||||
Fixes #22217
|
||||
- Refactored repositories
|
||||
- Fixes #22193
|
||||
- Fixes #22217
|
||||
|
||||
## [v1.0.5-SNAPSHOT] 2021-07-23
|
||||
Upgrade to gcube-smartgears-bom 2.1.0
|
||||
Fix register postgis table layer
|
||||
Added PostgisIndexRecordManager
|
||||
- Upgrade to gcube-smartgears-bom 2.1.0
|
||||
- Fix register postgis table layer
|
||||
- Added PostgisIndexRecordManager
|
||||
|
||||
## [v1.0.4] 2020-11-11
|
||||
Mongo integration with Concessione
|
||||
Project interface
|
||||
TempFile management
|
||||
WorkspaceContent and publication for Concessioni-over-mongo
|
||||
- Mongo integration with Concessione
|
||||
- Project interface
|
||||
- TempFile management
|
||||
- WorkspaceContent and publication for Concessioni-over-mongo
|
||||
|
||||
## [v1.0.3] 2020-11-11
|
||||
Fixed HTTP method
|
||||
- Fixed HTTP method
|
||||
|
||||
## [v1.0.2] 2020-11-11
|
||||
Delete method
|
||||
Excluded upper bound release gCube 5
|
||||
- Delete method
|
||||
- Excluded upper bound release gCube 5
|
||||
|
||||
|
||||
## [v1.0.1] 2020-11-11
|
||||
|
||||
Project interface
|
||||
- Project interface
|
||||
|
||||
## [v1.0.0] 2020-11-11
|
||||
|
||||
First release
|
||||
|
||||
|
||||
- First release
|
|
@ -24,6 +24,7 @@ import org.gcube.application.geoportal.service.engine.WorkspaceManager.FolderOpt
|
|||
import org.gcube.application.geoportal.service.engine.postgis.PostgisIndex;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.*;
|
||||
import org.gcube.application.geoportal.service.utils.Serialization;
|
||||
import org.gcube.application.geoportal.service.utils.UserUtils;
|
||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.data.transfer.library.faults.RemoteServiceException;
|
||||
|
@ -33,6 +34,7 @@ import java.io.InputStream;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -48,7 +50,7 @@ public class ConcessioniMongoManager extends MongoManager{
|
|||
super();
|
||||
}
|
||||
private static final String collectionName="legacyConcessioni";
|
||||
private static final String DB_NAME="gna_dev";
|
||||
//private static final String DB_NAME="gna_dev";
|
||||
|
||||
|
||||
private MongoDatabase db=null;
|
||||
|
@ -78,12 +80,19 @@ public class ConcessioniMongoManager extends MongoManager{
|
|||
}
|
||||
|
||||
|
||||
// *** PUBLIC METHODS
|
||||
|
||||
|
||||
|
||||
|
||||
/****************************** PUBLIC METHODS ***********************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Concessione registerNew(Concessione toRegister) throws IOException {
|
||||
log.trace("Going to register {} ",toRegister);
|
||||
toRegister.setDefaults();
|
||||
toRegister=onUpdate(toRegister);
|
||||
log.trace("Concessione with defaults is {}",toRegister);
|
||||
ObjectId id=insert(asDocument(toRegister), collectionName);
|
||||
|
||||
|
@ -99,7 +108,7 @@ public class ConcessioniMongoManager extends MongoManager{
|
|||
|
||||
public Concessione replace(Concessione toRegister) throws IOException {
|
||||
log.trace("Replacing {} ",toRegister);
|
||||
toRegister.setDefaults();
|
||||
toRegister=onUpdate(toRegister);
|
||||
return asConcessione(replace(asDocument(toRegister),collectionName));
|
||||
}
|
||||
|
||||
|
@ -176,6 +185,7 @@ public class ConcessioniMongoManager extends MongoManager{
|
|||
delete(asId(id), collectionName);
|
||||
}catch(DeletionException e) {
|
||||
//storing updated - partially deleted
|
||||
concessione=onUpdate(concessione);
|
||||
replace(asDocument(concessione), collectionName);
|
||||
throw e;
|
||||
}
|
||||
|
@ -193,15 +203,17 @@ public class ConcessioniMongoManager extends MongoManager{
|
|||
log.debug("Removed from centroids "+toReturn.getMongo_id());
|
||||
toReturn = unpublish(toReturn);
|
||||
log.debug("Concessione after unpublishing is "+toReturn);
|
||||
toReturn = onUpdate(toReturn);
|
||||
|
||||
return asConcessione(replace(asDocument(toReturn),collectionName));
|
||||
}catch(Throwable t){
|
||||
throw new DeletionException("Unable to unpublish "+id,t);
|
||||
}
|
||||
}
|
||||
|
||||
public Concessione publish(String id) throws JsonProcessingException, IOException, InvalidStateException{
|
||||
public Concessione publish(String id) throws IOException{
|
||||
Concessione toReturn=asConcessione(getById(asId(id),collectionName));
|
||||
toReturn.setDefaults();
|
||||
toReturn=onUpdate(toReturn);
|
||||
toReturn.validate();
|
||||
|
||||
// MATERIALIZE LAYERS
|
||||
|
@ -216,35 +228,6 @@ public class ConcessioniMongoManager extends MongoManager{
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static Concessione removeContent(Concessione concessione) throws DeletionException {
|
||||
if(concessione.getFolderId()==null) {
|
||||
log.debug("No content for " + concessione.getMongo_id());
|
||||
return concessione;
|
||||
}
|
||||
try {
|
||||
log.debug("Removing content for " + concessione.getMongo_id());
|
||||
WorkspaceManager manager = new WorkspaceManager();
|
||||
manager.removeFolderById(concessione.getFolderId());
|
||||
|
||||
//Removing references from Object
|
||||
concessione.setFolderId(null);
|
||||
ArrayList<AssociatedContent> list = new ArrayList<>();
|
||||
list.add(concessione.getPosizionamentoScavo());
|
||||
list.addAll(concessione.getPianteFineScavo());
|
||||
list.addAll(concessione.getImmaginiRappresentative());
|
||||
list.addAll(concessione.getGenericContent());
|
||||
for (AssociatedContent c : list) {
|
||||
c.getActualContent().clear();
|
||||
}
|
||||
return concessione;
|
||||
}catch(Throwable t){
|
||||
throw new DeletionException("Unable to delete from WS ",t);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Concessione unregisterFileset(String id, String toClearPath) throws Exception {
|
||||
log.info("Clearing Fileset at {} for {} ",toClearPath,id);
|
||||
try {
|
||||
|
@ -263,8 +246,7 @@ public class ConcessioniMongoManager extends MongoManager{
|
|||
}
|
||||
toClearContent.getActualContent().clear();
|
||||
|
||||
log.debug("Updating dafults for {} ",c);
|
||||
c.setDefaults();
|
||||
c=onUpdate(c);
|
||||
return asConcessione(replace(asDocument(c),collectionName));
|
||||
|
||||
}catch(Exception e) {
|
||||
|
@ -293,14 +275,39 @@ public class ConcessioniMongoManager extends MongoManager{
|
|||
AssociatedContent section=c.getContentByPath(destinationPath);
|
||||
log.debug("Found section {} for path {}",section,destinationPath);
|
||||
store(section,files,ws,storage,baseFolder);
|
||||
log.debug("Updating dafults for {} ",c);
|
||||
c.setDefaults();
|
||||
|
||||
c=onUpdate(c);
|
||||
return asConcessione(replace(asDocument(c),collectionName));
|
||||
}catch(Exception e) {
|
||||
throw new Exception("Unable to save file.",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************** STATIC ROUTINES *******************************/
|
||||
|
||||
|
||||
/**
|
||||
Sets Accounting data and Defaults
|
||||
*/
|
||||
private static Concessione onUpdate(Concessione c){
|
||||
log.debug("Updating Account data for {} ",c);
|
||||
|
||||
// SET ACCOUNTING
|
||||
c.setLastUpdateTime(LocalDateTime.now());
|
||||
try{
|
||||
c.setLastUpdateUser(UserUtils.getCurrent().getUser().getId());
|
||||
}catch(Throwable t){
|
||||
log.warn("Unable to get User details ",t);
|
||||
}
|
||||
|
||||
log.debug("Updating defaults for {}",c);
|
||||
// Set Defaults
|
||||
c.setDefaults();
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
private static Concessione index(Concessione record) {
|
||||
log.info("Indexing {} ",record.getId());
|
||||
ValidationReport report= new ValidationReport("Index Report ");
|
||||
|
@ -474,4 +481,31 @@ public class ConcessioniMongoManager extends MongoManager{
|
|||
content.setMongo_id(asString(new ObjectId()));
|
||||
}
|
||||
|
||||
|
||||
private static Concessione removeContent(Concessione concessione) throws DeletionException {
|
||||
if(concessione.getFolderId()==null) {
|
||||
log.debug("No content for " + concessione.getMongo_id());
|
||||
return concessione;
|
||||
}
|
||||
try {
|
||||
log.debug("Removing content for " + concessione.getMongo_id());
|
||||
WorkspaceManager manager = new WorkspaceManager();
|
||||
manager.removeFolderById(concessione.getFolderId());
|
||||
|
||||
//Removing references from Object
|
||||
concessione.setFolderId(null);
|
||||
ArrayList<AssociatedContent> list = new ArrayList<>();
|
||||
list.add(concessione.getPosizionamentoScavo());
|
||||
list.addAll(concessione.getPianteFineScavo());
|
||||
list.addAll(concessione.getImmaginiRappresentative());
|
||||
list.addAll(concessione.getGenericContent());
|
||||
for (AssociatedContent c : list) {
|
||||
c.getActualContent().clear();
|
||||
}
|
||||
return concessione;
|
||||
}catch(Throwable t){
|
||||
throw new DeletionException("Unable to delete from WS ",t);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@ import lombok.RequiredArgsConstructor;
|
|||
import lombok.Setter;
|
||||
import lombok.Synchronized;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.application.geoportal.common.utils.ContextUtils;
|
||||
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
|
||||
import org.gcube.application.geoportal.service.utils.ContextUtils;
|
||||
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.TemporalAmount;
|
||||
|
@ -26,7 +27,7 @@ public abstract class AbstractScopedMap<T> implements Engine<T>{
|
|||
private String name;
|
||||
@Synchronized
|
||||
public T getObject() throws ConfigurationException {
|
||||
String currentScope=ContextUtils.getCurrentScope();
|
||||
String currentScope= ContextUtils.getCurrentScope();
|
||||
log.debug(name+" : obtaining object for context "+currentScope);
|
||||
|
||||
TTLObject<T> found=scopeMap.get(currentScope);
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package org.gcube.application.geoportal.service.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
@Slf4j
|
||||
public class ContextUtils {
|
||||
|
||||
public static String getCurrentScope(){
|
||||
try{
|
||||
String token=SecurityTokenProvider.instance.get();
|
||||
log.debug("Token is : "+token);
|
||||
if(token==null) throw new Exception("Security Token is null");
|
||||
AuthorizationEntry entry = authorizationService().get(token);
|
||||
return entry.getContext();
|
||||
}catch(Exception e ){
|
||||
log.debug("Unable to resolve token, checking scope provider..",e);
|
||||
return ScopeProvider.instance.get();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCurrentCaller(){
|
||||
try{
|
||||
String token=SecurityTokenProvider.instance.get();
|
||||
log.debug("Token is : "+token);
|
||||
if(token==null) throw new Exception("Security Token is null");
|
||||
AuthorizationEntry entry = authorizationService().get(token);
|
||||
return entry.getClientInfo().getId();
|
||||
}catch(Exception e ){
|
||||
log.debug("Unable to resolve token, checking scope provider..",e);
|
||||
return "Unidentified data-transfer user";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package org.gcube.application.geoportal.service.utils;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
||||
@Slf4j
|
||||
public class UserUtils {
|
||||
|
||||
public static User getCurrent() throws SecurityException {
|
||||
String context=ScopeProvider.instance.get();
|
||||
if(context==null) throw new SecurityException("Cannot determine context");
|
||||
|
||||
log.debug("Context is {}, checking tokens..",context);
|
||||
|
||||
ClientInfo client = null;
|
||||
try{
|
||||
AuthorizationProvider.instance.get().getClient();
|
||||
}catch(Throwable e) {
|
||||
log.warn("Unable to get client info ",e);
|
||||
}
|
||||
User toReturn = new User(client, AccessTokenProvider.instance.get(),SecurityTokenProvider.instance.get(),context);
|
||||
|
||||
log.info("Current User is {} ",toReturn);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public static class User {
|
||||
private ClientInfo user;
|
||||
private String uma_token;
|
||||
|
||||
private String gcube_token;
|
||||
|
||||
private String context;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("User [user=");
|
||||
builder.append(user);
|
||||
builder.append(", uma_token=");
|
||||
builder.append(uma_token==null?uma_token:"***");
|
||||
|
||||
builder.append(", gcube_token=");
|
||||
builder.append(gcube_token==null?gcube_token:"***");
|
||||
|
||||
builder.append(", context=");
|
||||
builder.append(context);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue