2021-09-20 16:47:35 +02:00
|
|
|
|
package org.gcube.application.geoportal.service.engine.mongo;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2021-10-06 12:49:58 +02:00
|
|
|
|
import org.apache.commons.io.IOUtils;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
import org.bson.Document;
|
|
|
|
|
import org.bson.types.ObjectId;
|
2021-09-27 15:23:03 +02:00
|
|
|
|
import org.gcube.application.geoportal.common.faults.PathException;
|
|
|
|
|
import org.gcube.application.geoportal.common.faults.StorageException;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.*;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus;
|
2022-02-04 17:45:47 +01:00
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
2022-01-27 15:02:53 +01:00
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.TempFile;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
import org.gcube.application.geoportal.common.utils.Files;
|
2021-09-27 15:23:03 +02:00
|
|
|
|
import org.gcube.application.geoportal.common.utils.StorageUtils;
|
2022-02-18 15:34:22 +01:00
|
|
|
|
import org.gcube.application.cms.implementations.ImplementationProvider;
|
2021-10-01 17:42:23 +02:00
|
|
|
|
import org.gcube.application.geoportal.service.engine.materialization.SDIManager;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
import org.gcube.application.geoportal.service.engine.WorkspaceManager;
|
|
|
|
|
import org.gcube.application.geoportal.service.engine.WorkspaceManager.FileOptions;
|
|
|
|
|
import org.gcube.application.geoportal.service.engine.WorkspaceManager.FolderOptions;
|
|
|
|
|
import org.gcube.application.geoportal.service.engine.postgis.PostgisIndex;
|
|
|
|
|
import org.gcube.application.geoportal.service.model.internal.faults.*;
|
2022-02-01 15:24:39 +01:00
|
|
|
|
import org.gcube.application.cms.serialization.Serialization;
|
2021-11-15 16:27:21 +01:00
|
|
|
|
import org.gcube.application.geoportal.service.utils.UserUtils;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
2021-09-27 15:23:03 +02:00
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2021-10-06 12:49:58 +02:00
|
|
|
|
import java.io.InputStream;
|
2021-09-27 15:23:03 +02:00
|
|
|
|
import java.net.URL;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class ConcessioniMongoManager extends MongoManager{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ConcessioniMongoManager() throws ConfigurationException {
|
|
|
|
|
super();
|
2022-03-11 16:42:33 +01:00
|
|
|
|
init(collectionName);
|
|
|
|
|
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}
|
|
|
|
|
private static final String collectionName="legacyConcessioni";
|
2021-11-15 16:27:21 +01:00
|
|
|
|
//private static final String DB_NAME="gna_dev";
|
2021-09-20 16:47:35 +02:00
|
|
|
|
|
2022-03-11 16:42:33 +01:00
|
|
|
|
//
|
|
|
|
|
// private MongoDatabase db=null;
|
|
|
|
|
//
|
|
|
|
|
// @Override
|
|
|
|
|
// @Synchronized
|
|
|
|
|
// protected MongoDatabase getDatabase() {
|
|
|
|
|
// if(db==null) {
|
|
|
|
|
// String toUseDB=super.client.getConnection().getDatabase();
|
|
|
|
|
// log.info("Connecting to DB {} ",toUseDB);
|
|
|
|
|
//
|
|
|
|
|
// // TODO MAP OF DATABASES?
|
|
|
|
|
// db=client.getTheClient().getDatabase(toUseDB);
|
|
|
|
|
// }
|
|
|
|
|
// return db;
|
|
|
|
|
// }
|
2021-09-20 16:47:35 +02:00
|
|
|
|
|
|
|
|
|
protected static Document asDocument (Concessione c) throws JsonProcessingException {
|
|
|
|
|
Document toReturn=Document.parse(Serialization.write(c));
|
|
|
|
|
if(c.getMongo_id()!=null&&!c.getMongo_id().isEmpty())
|
|
|
|
|
toReturn.append(ID, asId(c.getMongo_id()));
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static Concessione asConcessione (Document d) throws JsonProcessingException, IOException {
|
|
|
|
|
return Serialization.read(d.toJson(), Concessione.class);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 17:59:06 +01:00
|
|
|
|
@Override
|
|
|
|
|
protected String mongoIDFieldName() {
|
|
|
|
|
return ID;
|
|
|
|
|
}
|
2021-11-15 16:27:21 +01:00
|
|
|
|
|
|
|
|
|
/****************************** PUBLIC METHODS ***********************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-09-20 16:47:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Concessione registerNew(Concessione toRegister) throws IOException {
|
2021-11-12 16:41:25 +01:00
|
|
|
|
log.trace("Going to register {} ",toRegister);
|
2021-11-15 16:27:21 +01:00
|
|
|
|
toRegister=onUpdate(toRegister);
|
2021-11-12 16:41:25 +01:00
|
|
|
|
log.trace("Concessione with defaults is {}",toRegister);
|
2022-03-11 16:42:33 +01:00
|
|
|
|
ObjectId id=insertDoc(asDocument(toRegister));
|
2021-09-20 16:47:35 +02:00
|
|
|
|
|
2021-11-12 16:41:25 +01:00
|
|
|
|
log.trace("Obtained id {}",id);
|
2022-03-11 16:42:33 +01:00
|
|
|
|
Concessione toReturn=asConcessione(getDocById(id));
|
2021-09-20 16:47:35 +02:00
|
|
|
|
toReturn.setMongo_id(asString(id));
|
|
|
|
|
|
2021-11-12 16:41:25 +01:00
|
|
|
|
|
2022-03-11 16:42:33 +01:00
|
|
|
|
toReturn = asConcessione(replaceDoc(asDocument(toReturn),id));
|
2021-11-12 16:41:25 +01:00
|
|
|
|
log.debug("Registered {} ",toReturn);
|
|
|
|
|
return toReturn;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Concessione replace(Concessione toRegister) throws IOException {
|
|
|
|
|
log.trace("Replacing {} ",toRegister);
|
2021-11-15 16:27:21 +01:00
|
|
|
|
toRegister=onUpdate(toRegister);
|
2022-03-11 16:42:33 +01:00
|
|
|
|
return asConcessione(replaceDoc(asDocument(toRegister),new ObjectId(toRegister.getMongo_id())));
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Iterable<Concessione> list(){
|
|
|
|
|
LinkedBlockingQueue queue=new LinkedBlockingQueue<Concessione>();
|
2022-03-11 16:42:33 +01:00
|
|
|
|
iterateDoc(null,null).forEach(
|
2021-09-20 16:47:35 +02:00
|
|
|
|
new Consumer<Document>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void accept(Document d) {
|
|
|
|
|
try {
|
|
|
|
|
queue.put(asConcessione(d));
|
|
|
|
|
}catch(Throwable t) {
|
|
|
|
|
log.error("Unable to read Document as concessione ",t);
|
|
|
|
|
log.debug("Document was "+d.toJson());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return queue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Iterable<Concessione> search(Document filter){
|
|
|
|
|
log.info("Searching concessione for filter {} ",filter);
|
|
|
|
|
LinkedBlockingQueue queue=new LinkedBlockingQueue<Concessione>();
|
2022-03-11 16:42:33 +01:00
|
|
|
|
iterateDoc(filter,null).forEach(
|
2021-09-20 16:47:35 +02:00
|
|
|
|
(Consumer<? super Document>) (Document d)->{try{
|
|
|
|
|
queue.put(asConcessione(d));
|
|
|
|
|
}catch(Throwable t){log.warn("Unable to translate "+d);}});
|
|
|
|
|
log.info("Returned {} elements ",queue.size());
|
|
|
|
|
return queue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Iterable<Document> query(QueryRequest queryRequest){
|
|
|
|
|
log.info("Searching concessione for filter {} ",queryRequest);
|
|
|
|
|
LinkedBlockingQueue queue=new LinkedBlockingQueue<Concessione>();
|
2022-03-11 16:42:33 +01:00
|
|
|
|
queryDoc(queryRequest).forEach(
|
2021-09-20 16:47:35 +02:00
|
|
|
|
(Consumer<? super Document>) (Document d)->{try{
|
|
|
|
|
queue.put(d);
|
|
|
|
|
}catch(Throwable t){log.warn("Unable to translate "+d);}});
|
|
|
|
|
log.info("Returned {} elements ",queue.size());
|
|
|
|
|
return queue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Concessione getById(String id)throws IOException {
|
|
|
|
|
log.debug("Loading by ID "+id);
|
2022-03-11 16:42:33 +01:00
|
|
|
|
return asConcessione(getDocById(asId(id)));
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void deleteById(String id,boolean force) throws DeletionException {
|
|
|
|
|
log.debug("Deleting by ID {}, force {}",id,force);
|
|
|
|
|
try{
|
|
|
|
|
Concessione concessione =unpublish(id);
|
|
|
|
|
try{
|
|
|
|
|
// UNPUBLISH
|
|
|
|
|
|
|
|
|
|
if (!concessione.getReport().getStatus().equals(ValidationStatus.PASSED)&&!force)
|
|
|
|
|
throw new DeletionException("Unable to unpublish "+concessione.getMongo_id());
|
|
|
|
|
//clean WS
|
|
|
|
|
|
|
|
|
|
concessione = removeContent(concessione);
|
|
|
|
|
|
|
|
|
|
if (!concessione.getReport().getStatus().equals(ValidationStatus.PASSED)&&!force)
|
2022-02-02 11:32:19 +01:00
|
|
|
|
throw new DeletionException("Unable to clean "+concessione.getMongo_id());
|
2021-09-20 16:47:35 +02:00
|
|
|
|
|
2022-03-11 16:42:33 +01:00
|
|
|
|
deleteDoc(asId(id));
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}catch(DeletionException e) {
|
|
|
|
|
//storing updated - partially deleted
|
2022-02-02 18:34:32 +01:00
|
|
|
|
log.error("Error while trying to delete",e);
|
2021-11-15 16:27:21 +01:00
|
|
|
|
concessione=onUpdate(concessione);
|
2022-03-11 16:42:33 +01:00
|
|
|
|
replaceDoc(asDocument(concessione),new ObjectId(concessione.getMongo_id()));
|
2021-09-20 16:47:35 +02:00
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}catch(Throwable t){
|
2022-02-02 11:31:25 +01:00
|
|
|
|
log.error("Unable to delete "+id,t);
|
2021-09-20 16:47:35 +02:00
|
|
|
|
throw new DeletionException("Unable to delete "+id,t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Concessione unpublish(String id) throws DeletionException {
|
|
|
|
|
try{
|
2022-03-11 16:42:33 +01:00
|
|
|
|
Concessione toReturn=asConcessione(getDocById(asId(id)));
|
2021-09-20 16:47:35 +02:00
|
|
|
|
removeFromIndex(toReturn);
|
|
|
|
|
log.debug("Removed from centroids "+toReturn.getMongo_id());
|
|
|
|
|
toReturn = unpublish(toReturn);
|
|
|
|
|
log.debug("Concessione after unpublishing is "+toReturn);
|
2021-11-15 16:27:21 +01:00
|
|
|
|
toReturn = onUpdate(toReturn);
|
|
|
|
|
|
2022-03-11 16:42:33 +01:00
|
|
|
|
return asConcessione(replaceDoc(asDocument(toReturn),new ObjectId(toReturn.getMongo_id())));
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}catch(Throwable t){
|
|
|
|
|
throw new DeletionException("Unable to unpublish "+id,t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-15 16:27:21 +01:00
|
|
|
|
public Concessione publish(String id) throws IOException{
|
2022-03-11 16:42:33 +01:00
|
|
|
|
Concessione toReturn=asConcessione(getDocById(asId(id)));
|
2021-11-15 16:27:21 +01:00
|
|
|
|
toReturn=onUpdate(toReturn);
|
2021-09-20 16:47:35 +02:00
|
|
|
|
toReturn.validate();
|
|
|
|
|
|
|
|
|
|
// MATERIALIZE LAYERS
|
|
|
|
|
toReturn=publish(toReturn);
|
|
|
|
|
// replace(asDocument(toReturn),collectionName);
|
|
|
|
|
|
|
|
|
|
// CREATE INDEXES
|
|
|
|
|
toReturn=index(toReturn);
|
|
|
|
|
// replace(asDocument(toReturn),collectionName);
|
|
|
|
|
|
2022-03-11 16:42:33 +01:00
|
|
|
|
return asConcessione(replaceDoc(asDocument(toReturn),new ObjectId(toReturn.getMongo_id())));
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Concessione unregisterFileset(String id, String toClearPath) throws Exception {
|
|
|
|
|
log.info("Clearing Fileset at {} for {} ",toClearPath,id);
|
|
|
|
|
try {
|
|
|
|
|
WorkspaceManager ws=new WorkspaceManager();
|
|
|
|
|
Concessione c = getById(id);
|
|
|
|
|
AssociatedContent toClearContent=c.getContentByPath(toClearPath);
|
|
|
|
|
log.debug("Found content {} for path {}",toClearContent,toClearPath);
|
|
|
|
|
|
|
|
|
|
//checking if published content
|
|
|
|
|
for(PersistedContent persisted : toClearContent.getActualContent()){
|
|
|
|
|
if(persisted instanceof GeoServerContent) throw new Exception ("Cannot clear concessione "+id+" at "+toClearContent+", because it is published.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(PersistedContent persisted : toClearContent.getActualContent()){
|
|
|
|
|
if(persisted instanceof WorkspaceContent) ws.deleteFromWS((WorkspaceContent) persisted);
|
|
|
|
|
}
|
|
|
|
|
toClearContent.getActualContent().clear();
|
|
|
|
|
|
2021-11-15 16:27:21 +01:00
|
|
|
|
c=onUpdate(c);
|
2022-03-11 16:42:33 +01:00
|
|
|
|
return asConcessione(replaceDoc(asDocument(c),new ObjectId(c.getMongo_id())));
|
2021-09-20 16:47:35 +02:00
|
|
|
|
|
|
|
|
|
}catch(Exception e) {
|
|
|
|
|
throw new Exception("Unable to unregister files.",e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Concessione persistContent(String id, String destinationPath, List<TempFile> files) throws Exception{
|
|
|
|
|
log.info("Persisting {} files for path {} in concessione ",files.size(),destinationPath,id);
|
|
|
|
|
try{
|
|
|
|
|
Concessione c = getById(id);
|
2022-04-27 19:36:10 +02:00
|
|
|
|
StorageUtils storage=ImplementationProvider.get().getProvidedObjectByClass(StorageUtils.class);
|
2021-09-20 16:47:35 +02:00
|
|
|
|
WorkspaceManager ws=new WorkspaceManager();
|
|
|
|
|
//Check Init Base folder
|
|
|
|
|
FolderContainer baseFolder=null;
|
|
|
|
|
if(c.getFolderId()==null) {
|
|
|
|
|
String folderName=Files.fixFilename("mConcessione"+"_"+c.getNome()+"_"+Serialization.FULL_FORMATTER.format(LocalDateTime.now()));
|
|
|
|
|
log.info("Creating folder {} for Concessione ID {} ",folderName,id);
|
|
|
|
|
FolderContainer folder=ws.createFolder(new FolderOptions(folderName, "Base Folder for "+c.getNome(),null));
|
|
|
|
|
c.setFolderId(folder.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.debug("Folder id is : "+c.getFolderId());
|
|
|
|
|
baseFolder=ws.getFolderById(c.getFolderId());
|
|
|
|
|
|
|
|
|
|
AssociatedContent section=c.getContentByPath(destinationPath);
|
|
|
|
|
log.debug("Found section {} for path {}",section,destinationPath);
|
2021-09-27 15:23:03 +02:00
|
|
|
|
store(section,files,ws,storage,baseFolder);
|
2021-11-15 16:27:21 +01:00
|
|
|
|
|
|
|
|
|
c=onUpdate(c);
|
2022-03-11 16:42:33 +01:00
|
|
|
|
return asConcessione(replaceDoc(asDocument(c),new ObjectId(c.getMongo_id())));
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}catch(Exception e) {
|
|
|
|
|
throw new Exception("Unable to save file.",e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-15 16:27:21 +01:00
|
|
|
|
|
|
|
|
|
/************************** 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-09-20 16:47:35 +02:00
|
|
|
|
private static Concessione index(Concessione record) {
|
|
|
|
|
log.info("Indexing {} ",record.getId());
|
|
|
|
|
ValidationReport report= new ValidationReport("Index Report ");
|
|
|
|
|
PostgisIndex index;
|
|
|
|
|
try {
|
|
|
|
|
index = new PostgisIndex();
|
|
|
|
|
index.registerCentroid(record);
|
|
|
|
|
report.addMessage(ValidationStatus.PASSED, "Registered centroid");
|
|
|
|
|
} catch (SDIInteractionException | PublishException | SQLException | ConfigurationException e) {
|
|
|
|
|
log.error("Unable to index {} ",record,e);
|
|
|
|
|
report.addMessage(ValidationStatus.WARNING, "Internal error while indexing.");
|
|
|
|
|
}
|
|
|
|
|
return record;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Concessione removeFromIndex(Concessione record) {
|
|
|
|
|
log.info("Removing from index {} ",record.getMongo_id());
|
|
|
|
|
ValidationReport report= new ValidationReport("Remove From Index Report ");
|
|
|
|
|
PostgisIndex index;
|
|
|
|
|
try {
|
|
|
|
|
index = new PostgisIndex();
|
|
|
|
|
index.removeCentroid(record);
|
|
|
|
|
report.addMessage(ValidationStatus.PASSED, "Removed centroid");
|
|
|
|
|
} catch (SDIInteractionException | SQLException | ConfigurationException e) {
|
2021-10-12 15:43:35 +02:00
|
|
|
|
log.error("Unable to remove from index {} ",record,e);
|
2021-09-20 16:47:35 +02:00
|
|
|
|
report.addMessage(ValidationStatus.WARNING, "Internal error while removing from index.");
|
|
|
|
|
}
|
|
|
|
|
return record;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Concessione publish(Concessione conc) {
|
|
|
|
|
|
|
|
|
|
// CHECK CONDITION BY PROFILE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.debug("Publishing "+conc.getNome());
|
|
|
|
|
|
|
|
|
|
ValidationReport report=new ValidationReport("Publish report");
|
|
|
|
|
try {
|
|
|
|
|
SDIManager sdiManager=new SDIManager();
|
|
|
|
|
ArrayList<AssociatedContent> list=new ArrayList<AssociatedContent>();
|
|
|
|
|
|
|
|
|
|
//Concessione
|
|
|
|
|
String workspace= sdiManager.createWorkspace("gna_conc_"+conc.getMongo_id());
|
|
|
|
|
list.add(conc.getPosizionamentoScavo());
|
|
|
|
|
list.addAll(conc.getPianteFineScavo());
|
|
|
|
|
|
|
|
|
|
for(AssociatedContent c:list) {
|
|
|
|
|
if(c instanceof LayerConcessione) {
|
|
|
|
|
try {
|
|
|
|
|
List<PersistedContent> p=c.getActualContent();
|
|
|
|
|
|
|
|
|
|
GeoServerContent geoserverPersisted=sdiManager.pushShapeLayerFileSet((SDILayerDescriptor)c, workspace, conc.getMongo_id());
|
|
|
|
|
// geoserverPersisted.setAssociated(c);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p.add(geoserverPersisted);
|
|
|
|
|
c.setActualContent(p);
|
|
|
|
|
}catch(SDIInteractionException e) {
|
|
|
|
|
log.warn("Unable to publish layers.",e);
|
|
|
|
|
report.addMessage(ValidationStatus.WARNING, "Layer "+c.getTitolo()+" non pubblicato.");
|
|
|
|
|
}
|
|
|
|
|
report.addMessage(ValidationStatus.PASSED, "Pubblicato layer "+c.getTitolo());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SDIInteractionException e1) {
|
|
|
|
|
report.addMessage(ValidationStatus.WARNING, "Unable to publish layers "+e1.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
conc.setReport(report);
|
|
|
|
|
return conc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final Concessione unpublish(Concessione concessione){
|
|
|
|
|
ValidationReport report=new ValidationReport("Unpublish report");
|
|
|
|
|
try{
|
|
|
|
|
SDIManager sdi=new SDIManager();
|
|
|
|
|
ArrayList<AssociatedContent> list=new ArrayList<AssociatedContent>();
|
|
|
|
|
|
|
|
|
|
list.add(concessione.getPosizionamentoScavo());
|
|
|
|
|
list.addAll(concessione.getPianteFineScavo());
|
|
|
|
|
for(AssociatedContent c:list) {
|
|
|
|
|
if(c instanceof LayerConcessione) {
|
|
|
|
|
List<PersistedContent> contents=c.getActualContent();
|
|
|
|
|
List<PersistedContent> toRemove=new ArrayList<>();
|
|
|
|
|
for(PersistedContent p:contents){
|
|
|
|
|
if(p instanceof GeoServerContent){
|
|
|
|
|
try {
|
|
|
|
|
sdi.deleteContent((GeoServerContent) p);
|
|
|
|
|
toRemove.add(p);
|
2021-10-12 15:43:35 +02:00
|
|
|
|
} catch (Throwable t) {
|
|
|
|
|
report.addMessage(ValidationStatus.WARNING,"Cannot delete "+((GeoServerContent) p).getFeatureType());
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-12 15:43:35 +02:00
|
|
|
|
// Remove GIS coordinates
|
|
|
|
|
((LayerConcessione) c).setLayerID(null);
|
|
|
|
|
((LayerConcessione) c).setBbox(null);
|
|
|
|
|
((LayerConcessione) c).setWmsLink(null);
|
|
|
|
|
((LayerConcessione) c).setWorkspace(null);
|
2021-11-15 14:55:54 +01:00
|
|
|
|
((LayerConcessione) c).setLayerName(null);
|
|
|
|
|
|
2021-10-12 15:43:35 +02:00
|
|
|
|
|
|
|
|
|
//Remove reference to removed content
|
2021-09-20 16:47:35 +02:00
|
|
|
|
c.getActualContent().removeAll(toRemove);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-12 15:43:35 +02:00
|
|
|
|
|
|
|
|
|
concessione.setCentroidLat(null);
|
|
|
|
|
concessione.setCentroidLong(null);
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}catch(SDIInteractionException e){
|
|
|
|
|
report.addMessage(ValidationStatus.WARNING, "Unable to unpublish layers "+e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
concessione.setReport(report);
|
|
|
|
|
return concessione;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-09-27 15:23:03 +02:00
|
|
|
|
private static final void store(AssociatedContent content,List<TempFile> files, WorkspaceManager ws, StorageUtils storage, FolderContainer base) throws StorageHubException, StorageException, PathException {
|
2021-09-20 16:47:35 +02:00
|
|
|
|
FolderContainer sectionParent=null;
|
|
|
|
|
|
|
|
|
|
if(content instanceof RelazioneScavo)
|
|
|
|
|
sectionParent = ws .createFolder(new FolderOptions(
|
|
|
|
|
"relazione","Relazione di scavo : "+content.getTitolo(),base));
|
|
|
|
|
|
2021-09-22 17:46:46 +02:00
|
|
|
|
else if(content instanceof AbstractRelazione)
|
|
|
|
|
sectionParent = ws .createFolder(new FolderOptions(
|
|
|
|
|
"abstract_relazione","Abstract relazione di scavo : "+content.getTitolo(),base));
|
|
|
|
|
|
|
|
|
|
|
2021-09-20 16:47:35 +02:00
|
|
|
|
else if (content instanceof UploadedImage)
|
|
|
|
|
sectionParent = ws .createFolder(new FolderOptions(
|
|
|
|
|
"imgs","Immagini rappresentative : "+content.getTitolo(),base));
|
|
|
|
|
|
|
|
|
|
else if (content instanceof SDILayerDescriptor)
|
|
|
|
|
//SDI Section
|
|
|
|
|
if(content instanceof LayerConcessione)
|
|
|
|
|
sectionParent = ws .createFolder(new FolderOptions(
|
|
|
|
|
content.getTitolo(),"Layer Concessione : "+content.getTitolo(),ws.getSubFolder(base,"layers")));
|
2021-09-27 15:23:03 +02:00
|
|
|
|
else throw new PathException("Invalid SDI Content "+content);
|
2021-09-20 16:47:35 +02:00
|
|
|
|
else if (content instanceof OtherContent )
|
|
|
|
|
sectionParent = ws .createFolder(new FolderOptions(
|
|
|
|
|
content.getTitolo(),"Relazione di scavo : "+content.getTitolo(),ws.getSubFolder(base,"other")));
|
2021-09-27 15:23:03 +02:00
|
|
|
|
else throw new PathException("Invalid Content "+content);
|
2021-09-20 16:47:35 +02:00
|
|
|
|
|
|
|
|
|
content.setActualContent(new ArrayList<PersistedContent>());
|
2021-09-27 15:23:03 +02:00
|
|
|
|
|
2021-09-20 16:47:35 +02:00
|
|
|
|
for(TempFile f : files) {
|
2021-10-06 12:49:58 +02:00
|
|
|
|
InputStream is=null;
|
2021-09-27 15:23:03 +02:00
|
|
|
|
try{
|
|
|
|
|
log.debug("Opening temp file {}",f);
|
|
|
|
|
String fileUrl=storage.getURL(f.getId());
|
|
|
|
|
log.debug("Got URL {} from ID {}",fileUrl,f.getId());
|
2021-10-06 12:49:58 +02:00
|
|
|
|
is=new URL(fileUrl).openStream();
|
|
|
|
|
WorkspaceContent wsContent=ws.storeToWS(new FileOptions(f.getFilename(),is,
|
2021-09-27 15:23:03 +02:00
|
|
|
|
"Imported via GeoPortal", sectionParent));
|
|
|
|
|
log.debug("Registered "+wsContent+" for "+content);
|
|
|
|
|
content.getActualContent().add(wsContent);
|
|
|
|
|
}catch(StorageHubException | IOException e){
|
|
|
|
|
throw new StorageException("Unable to store "+f,e);
|
2021-10-06 12:49:58 +02:00
|
|
|
|
}finally{
|
|
|
|
|
if(is!=null)
|
|
|
|
|
IOUtils.closeQuietly(is);
|
2021-09-27 15:23:03 +02:00
|
|
|
|
}
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}
|
|
|
|
|
content.setMongo_id(asString(new ObjectId()));
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-15 16:27:21 +01:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2021-09-20 16:47:35 +02:00
|
|
|
|
}
|