Register Fileset

This commit is contained in:
Fabio Sinibaldi 2022-01-27 15:02:53 +01:00
parent 0099e09b1f
commit 0bea1699a1
29 changed files with 425 additions and 153 deletions

View File

@ -84,6 +84,13 @@ public class Serialization {
public static final Document asDocument(Object obj) throws JsonProcessingException {
return Document.parse(mapper.writeValueAsString(obj));
}
public static final Document asDocumentWithId(ProfiledDocument doc) throws JsonProcessingException {
Document toReturn =Document.parse(mapper.writeValueAsString(doc));
if(doc.get_id()!=null)
toReturn.put(ProfiledDocument.ID,new ObjectId(doc.get_id()));
return toReturn;
}
// ***** Serialization Exceptions
@ -92,7 +99,7 @@ public class Serialization {
@Override
public void serialize(ObjectId objectId, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
if (objectId == null) jsonGenerator.writeNull();
else jsonGenerator.writeString(objectId.toHexString());
else jsonGenerator.writeString(objectId.toString());
}
@Override
@ -148,7 +155,7 @@ public class Serialization {
@Override
public void serialize(Semver semver, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
if (semver == null) jsonGenerator.writeNull();
else jsonGenerator.writeString(semver.toString());
else jsonGenerator.writeString(semver.getValue());
}
@Override

View File

@ -1,6 +1,10 @@
package org.gcube.application.cms.concessioni.plugins;
import lombok.extern.slf4j.Slf4j;
import org.bson.BsonDocument;
import org.bson.BsonString;
import org.bson.BsonValue;
import org.bson.Document;
import org.gcube.application.cms.Serialization;
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione;
import org.gcube.application.cms.plugins.LifecycleManager;
@ -11,9 +15,11 @@ import org.gcube.application.cms.plugins.model.PluginDescriptor;
import org.gcube.application.cms.plugins.reports.ExecutionReport;
import org.gcube.application.cms.plugins.reports.InitializationReport;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.document.ComparableVersion;
import org.gcube.application.geoportal.common.model.document.LifecycleInformation;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.document.*;
import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck;
import java.util.List;
@Slf4j
public class ConcessioniLifeCycleManager implements LifecycleManager {
@ -97,7 +103,63 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
private static final ProfiledDocument setDefaults(ProfiledDocument document){
ProfiledConcessione c=Serialization.convert(document,ProfiledConcessione.class);
c.setDefaults();
Document doc=c.getTheDocument();
doc.putIfAbsent(ProfiledConcessione.SOGGETTO,new String[]{"Research Excavation","Archaeology"});
doc.putIfAbsent(ProfiledConcessione.DSCRIZIONE_CONTENUTO,"Relazione di fine scavo e relativo abstract; selezione di immagini rappresentative;"
+ " posizionamento topografico dell'area indagata, pianta di fine scavo.");
// Super Section
c.getInfo().getAccess().setLicense(
ConstraintCheck.defaultFor(c.getInfo().getAccess().getLicense(), "CC0-1.0").evaluate());
//RELAZIONE
// TODO NB provare se object gia' presente sia usando Document che sub Object
doc.putIfAbsent(ProfiledConcessione.RELAZIONE_SCAVO,new Document());
Document rel=Serialization.convert(doc.get(ProfiledConcessione.RELAZIONE_SCAVO), Document.class);
rel.putIfAbsent(ProfiledConcessione.Sections.TITOLO,doc.getString(ProfiledConcessione.NOME)+" relazione di scavo");
rel.putIfAbsent(ProfiledConcessione.SOGGETTO,doc.get(ProfiledConcessione.SOGGETTO));
rel.putIfAbsent(RegisteredFileSet.CREATION_INFO,c.getInfo().getCreationInfo());
rel.putIfAbsent(RegisteredFileSet.ACCESS,c.getInfo().getAccess());
Access relAccess=Serialization.convert(rel.get(RegisteredFileSet.ACCESS),Access.class);
relAccess.setLicense(ConstraintCheck.defaultFor(relAccess.getLicense(),"CC-BY-4.0").evaluate());
relAccess.setPolicy(ConstraintCheck.defaultFor(relAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
//ABSTRACT Relazione
doc.putIfAbsent(ProfiledConcessione.ABSTRACT_RELAZIONE,new Document());
Document abs=Serialization.convert(doc.get(ProfiledConcessione.ABSTRACT_RELAZIONE),Document.class);
abs.putIfAbsent(ProfiledConcessione.Sections.TITOLO,doc.getString(ProfiledConcessione.NOME)+" abstract relazione di scavo");
abs.putIfAbsent(RegisteredFileSet.CREATION_INFO,c.getInfo().getCreationInfo());
abs.putIfAbsent(RegisteredFileSet.ACCESS,c.getInfo().getAccess());
Access absAccess=Serialization.convert(abs.get(RegisteredFileSet.ACCESS),Access.class);
absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate());
absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
//TODO complete setDefaults
//IMMAGINI RAPPRESENTATIVE
if(doc.containsKey(ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE)) {
for (BsonValue bsonValue : doc.toBsonDocument(null, null).
getArray(ProfiledConcessione.IMMAGINI_RAPPRESENTATIVE)) {
BsonDocument imgDocument = bsonValue.asDocument();
imgDocument.putIfAbsent(ProfiledConcessione.SOGGETTO,new BsonString(doc.getString(ProfiledConcessione.SOGGETTO)));
// imgDocument.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
// imgDocument.putIfAbsent(RegisteredFileSet.CREATION_INFO,new BsonDocument(new Document()));
// imgDocument.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
// Access absAccess=rel.get(RegisteredFileSet.ACCESS,Access.class);
// absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate());
// absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
}
}
return c;
}

View File

@ -9,7 +9,6 @@ import org.gcube.application.geoportal.common.model.document.Access;
import org.gcube.application.geoportal.common.model.document.AccessPolicy;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.document.RegisteredFileSet;
import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck;
import java.util.List;
@ -65,58 +64,5 @@ public class ProfiledConcessione extends ProfiledDocument {
}
@Override
public void setDefaults() {
Document doc=this.getTheDocument();
doc.putIfAbsent(SOGGETTO,new String[]{"Research Excavation","Archaeology"});
doc.putIfAbsent(DSCRIZIONE_CONTENUTO,"Relazione di fine scavo e relativo abstract; selezione di immagini rappresentative;"
+ " posizionamento topografico dell'area indagata, pianta di fine scavo.");
// Super Section
this.getInfo().getAccess().setLicense(
ConstraintCheck.defaultFor(getInfo().getAccess().getLicense(), "CC0-1.0").evaluate());
//RELAZIONE
// TODO NB provare se object gia' presente sia usando Document che sub Object
doc.putIfAbsent(RELAZIONE_SCAVO,new Document());
RelazioneScavo rel=doc.get(RELAZIONE_SCAVO,RelazioneScavo.class);
// rel.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" relazione di scavo");
// rel.putIfAbsent(SOGGETTO,doc.get(SOGGETTO));
// rel.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
// rel.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
// Access relAccess=rel.get(RegisteredFileSet.ACCESS,Access.class);
// relAccess.setLicense(ConstraintCheck.defaultFor(relAccess.getLicense(),"CC-BY-4.0").evaluate());
// relAccess.setPolicy(ConstraintCheck.defaultFor(relAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
//ABSTRACT Relazione
doc.putIfAbsent(ABSTRACT_RELAZIONE,new Document());
Document abs=doc.get(ABSTRACT_RELAZIONE,Document.class);
abs.putIfAbsent(Sections.TITOLO,doc.getString(NOME)+" abstract relazione di scavo");
abs.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
abs.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
Access absAccess=abs.get(RegisteredFileSet.ACCESS,Access.class);
absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate());
absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
//TODO complete setDefaults
//IMMAGINI RAPPRESENTATIVE
if(doc.containsKey(IMMAGINI_RAPPRESENTATIVE)) {
for (BsonValue bsonValue : doc.toBsonDocument(null, null).
getArray(IMMAGINI_RAPPRESENTATIVE)) {
BsonDocument imgDocument = bsonValue.asDocument();
imgDocument.putIfAbsent(SOGGETTO,new BsonString(doc.getString(SOGGETTO)));
// imgDocument.putIfAbsent(RegisteredFileSet.CREATION_INFO,this.getInfo().getCreationInfo());
// imgDocument.putIfAbsent(RegisteredFileSet.CREATION_INFO,new BsonDocument(new Document()));
// imgDocument.putIfAbsent(RegisteredFileSet.ACCESS,this.getInfo().getAccess());
// Access absAccess=rel.get(RegisteredFileSet.ACCESS,Access.class);
// absAccess.setLicense(ConstraintCheck.defaultFor(absAccess.getLicense(),"CC-BY-4.0").evaluate());
// absAccess.setPolicy(ConstraintCheck.defaultFor(absAccess.getPolicy(), AccessPolicy.OPEN).evaluate());
}
}
}
}

View File

@ -2,7 +2,7 @@ package org.gcube.application.geoportal.client.legacy;
import org.gcube.application.geoportal.common.model.legacy.*;
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.model.rest.TempFile;
public interface ConcessioniManagerI extends MongoConcessioni{

View File

@ -9,7 +9,7 @@ import org.gcube.application.geoportal.client.DefaultMongoConcessioni;
import org.gcube.application.geoportal.common.model.legacy.*;
import org.gcube.application.geoportal.common.utils.FileSets;
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.common.clients.delegates.ProxyDelegate;

View File

@ -1,19 +1,10 @@
package org.gcube.application.geoportal;
import org.apache.commons.io.IOUtils;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.utils.Files;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
public class StorageTests {

View File

@ -7,9 +7,9 @@ public class BasicVreTests {
@BeforeClass
public static void setScope(){
// TokenSetter.set("/pred4s/preprod/preVRE");
TokenSetter.set("/pred4s/preprod/preVRE");
// TokenSetter.set("/d4science.research-infrastructures.eu/D4OS/GeoNA-Prototype");
TokenSetter.set("/gcube/devsec/devVRE");
// TokenSetter.set("/gcube/devsec/devVRE");
}

View File

@ -13,8 +13,7 @@ import org.gcube.application.geoportal.client.legacy.ConcessioniManagerI;
import org.gcube.application.geoportal.client.utils.Serialization;
import org.gcube.application.geoportal.common.model.legacy.*;
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.utils.Files;
import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.junit.Test;

View File

@ -14,7 +14,7 @@ import org.bson.types.ObjectId;
@ToString
public class ProfiledDocument {
public static final String _ID="_id";
public static final String ID="_id";
public static final String VERSION="version";
public static final String INFO="info";
public static final String PROFILE_ID="profileID";
@ -47,8 +47,5 @@ public class ProfiledDocument {
private Document theDocument;
public void setDefaults(){
// TODO APPLY DEFAULTS ??
};
}

View File

@ -0,0 +1,51 @@
package org.gcube.application.geoportal.common.model.profile;
import lombok.*;
import org.bson.Document;
import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public class DataAccessPolicy {
public static final String POLICY = "policy";
public static final String ROLES = "roles";
public static final String ENFORCER = "enforcer";
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public static class Policy {
public static final String WRITE="write";
public static final String READ="read";
public static enum Type{
OWN,NONE,ANY
}
private Type write;
private Type read;
}
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public static class PolicyEnforcer {
public static final String FILTER="filter";
private Document filter;
}
private Policy policy;
private List<String> roles;
private PolicyEnforcer enforcer;
}

View File

@ -12,7 +12,11 @@ public class Field extends Document {
public static final String CHILDREN="_children";
public static final String MAX_CARDINALITY="_max";
public static final String MIN_CARDINALITY="_min";
public static final String LABEL="_label";
public String getLabel(){
return this.getString(LABEL);
}
public String getType(){
return this.getString(TYPE);
@ -22,6 +26,11 @@ public class Field extends Document {
return this.get(CHILDREN,List.class);
}
public Boolean isCollection() {
Integer maxCard=this.getMaxCardinality();
return (maxCard>1||maxCard<0); // Negative values for unbounded
}
public Integer getMaxCardinality(){
return (Integer) this.getOrDefault(MAX_CARDINALITY,1);
}

View File

@ -31,6 +31,9 @@ public class Profile{
private List<HandlerDeclaration> handlers;
private List<DataAccessPolicy> dataAccessPolicies;
/**
* Returns map Type -> Handler Declaration
* @return

View File

@ -10,12 +10,12 @@ import lombok.NoArgsConstructor;
import org.bson.Document;
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.rest.TempFile;
@XmlRootElement
@Data
@AllArgsConstructor
@NoArgsConstructor
@Deprecated
public class AddSectionToConcessioneRequest {
private String destinationPath;

View File

@ -0,0 +1,39 @@
package org.gcube.application.geoportal.common.model.rest;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.Document;
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RegisterFileSetRequest {
/** Behavior for existing JSON Object at @destinationPath
*
* REPLACE_EXISTING : removes previously defined attributes (only on single match)
* MERGE_EXISTING : merges the provided attributes with the matching ones (only on single match)
* APPEND : appends the object to the existing collection (only if field is multiple)
*/
public static enum ClashOptions {
REPLACE_EXISTING,MERGE_EXISTING, APPEND
}
private String fieldPath;
private String destinationPath;
private List<TempFile> streams;
private Document attributes;
private ClashOptions clashOption;
public void validate()throws InvalidRequestException {
if(streams==null || streams.isEmpty()) throw new InvalidRequestException("No Temp File declared");
for(TempFile t : streams) t.validate();
}
}

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportal.common.rest;
package org.gcube.application.geoportal.common.model.rest;
import lombok.AllArgsConstructor;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package org.gcube.application.geoportal.common.rest;
package org.gcube.application.geoportal.common.model.rest;
import lombok.AllArgsConstructor;
import lombok.Data;

View File

@ -1,8 +1,8 @@
package org.gcube.application.geoportal.common.utils;
import org.gcube.application.geoportal.common.model.legacy.InputStreamDescriptor;
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import java.io.File;
@ -13,7 +13,7 @@ import java.util.ArrayList;
public class FileSets {
public static class RequestBuilder {
AddSectionToConcessioneRequest theRequest=new AddSectionToConcessioneRequest();
RegisterFileSetRequest theRequest=new RegisterFileSetRequest();
public RequestBuilder add(TempFile... f){
if(theRequest.getStreams()==null)
@ -39,7 +39,7 @@ public class FileSets {
public AddSectionToConcessioneRequest getTheRequest(){return theRequest;}
public RegisterFileSetRequest getTheRequest(){return theRequest;}
}
@ -62,7 +62,7 @@ public class FileSets {
return toReturn.toArray(new TempFile[toReturn.size()]);
}
public static AddSectionToConcessioneRequest prepareRequestFromFolder(StorageUtils storage, String path, File directory) throws FileNotFoundException {
public static RegisterFileSetRequest prepareRequestFromFolder(StorageUtils storage, String path, File directory) throws FileNotFoundException {
File[] children =directory.listFiles();
System.out.println("Found "+children+ " files to push");
@ -71,7 +71,7 @@ public class FileSets {
}
public static AddSectionToConcessioneRequest prepareRequest(StorageUtils storage, String path, File... toUpload) throws FileNotFoundException {
public static RegisterFileSetRequest prepareRequest(StorageUtils storage, String path, File... toUpload) throws FileNotFoundException {
FileSets.RequestBuilder builder = FileSets.build(path);
for (File f : toUpload) {

View File

@ -1,12 +1,14 @@
package org.gcube.application.geoportal.common.utils;
import com.jayway.jsonpath.*;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingProvider;
import lombok.Getter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.*;
public class JSONPathWrapper {
@ -14,11 +16,33 @@ public class JSONPathWrapper {
public static Configuration JSON_PATH_PATHS_CONFIGURATION=null;
static {
Configuration.setDefaults(new Configuration.Defaults() {
private JsonProvider jacksonProvider = new JacksonJsonProvider();
private final MappingProvider mappingProvider = new JacksonMappingProvider();
@Override
public JsonProvider jsonProvider() {
return jacksonProvider;
}
@Override
public Set<Option> options() {
return EnumSet.noneOf(Option.class);
}
@Override
public MappingProvider mappingProvider() {
return mappingProvider;
}
});
JSON_PATH_ALWAYS_LIST_CONFIG= Configuration.builder().options(Option.ALWAYS_RETURN_LIST,Option.SUPPRESS_EXCEPTIONS,Option.DEFAULT_PATH_LEAF_TO_NULL).build();
JSON_PATH_PATHS_CONFIGURATION = Configuration.builder().options(Option.AS_PATH_LIST,Option.SUPPRESS_EXCEPTIONS,Option.DEFAULT_PATH_LEAF_TO_NULL).build();
}
@Getter
DocumentContext ctx=null;

View File

@ -7,7 +7,7 @@ import java.io.InputStream;
import java.util.UUID;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;

View File

@ -13,7 +13,7 @@ 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;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.application.geoportal.common.utils.Files;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.application.geoportal.service.engine.ImplementationProvider;
@ -98,7 +98,7 @@ public class ConcessioniMongoManager extends MongoManager{
toReturn.setMongo_id(asString(id));
toReturn = asConcessione(replace(asDocument(toReturn),collectionName));
toReturn = asConcessione(replace(asDocument(toReturn),id,collectionName));
log.debug("Registered {} ",toReturn);
return toReturn;
}
@ -106,7 +106,7 @@ public class ConcessioniMongoManager extends MongoManager{
public Concessione replace(Concessione toRegister) throws IOException {
log.trace("Replacing {} ",toRegister);
toRegister=onUpdate(toRegister);
return asConcessione(replace(asDocument(toRegister),collectionName));
return asConcessione(replace(asDocument(toRegister),new ObjectId(toRegister.getMongo_id()),collectionName));
}
/* public Concessione update(String id,String json) throws IOException {
@ -183,7 +183,7 @@ public class ConcessioniMongoManager extends MongoManager{
}catch(DeletionException e) {
//storing updated - partially deleted
concessione=onUpdate(concessione);
replace(asDocument(concessione), collectionName);
replace(asDocument(concessione),new ObjectId(concessione.getMongo_id()), collectionName);
throw e;
}
}catch(Throwable t){
@ -202,7 +202,7 @@ public class ConcessioniMongoManager extends MongoManager{
log.debug("Concessione after unpublishing is "+toReturn);
toReturn = onUpdate(toReturn);
return asConcessione(replace(asDocument(toReturn),collectionName));
return asConcessione(replace(asDocument(toReturn),new ObjectId(toReturn.getMongo_id()),collectionName));
}catch(Throwable t){
throw new DeletionException("Unable to unpublish "+id,t);
}
@ -221,7 +221,7 @@ public class ConcessioniMongoManager extends MongoManager{
toReturn=index(toReturn);
// replace(asDocument(toReturn),collectionName);
return asConcessione(replace(asDocument(toReturn),collectionName));
return asConcessione(replace(asDocument(toReturn),new ObjectId(toReturn.getMongo_id()),collectionName));
}
@ -244,7 +244,7 @@ public class ConcessioniMongoManager extends MongoManager{
toClearContent.getActualContent().clear();
c=onUpdate(c);
return asConcessione(replace(asDocument(c),collectionName));
return asConcessione(replace(asDocument(c),new ObjectId(c.getMongo_id()),collectionName));
}catch(Exception e) {
throw new Exception("Unable to unregister files.",e);
@ -274,7 +274,7 @@ public class ConcessioniMongoManager extends MongoManager{
store(section,files,ws,storage,baseFolder);
c=onUpdate(c);
return asConcessione(replace(asDocument(c),collectionName));
return asConcessione(replace(asDocument(c),new ObjectId(c.getMongo_id()),collectionName));
}catch(Exception e) {
throw new Exception("Unable to save file.",e);
}

View File

@ -127,11 +127,11 @@ public abstract class MongoManager {
return coll.find(filter,clazz);
}
public Document replace(Document toUpdate,String collectionName) {
public Document replace(Document toUpdate,ObjectId id, String collectionName) {
MongoDatabase database=getDatabase();
MongoCollection<Document> coll=database.getCollection(collectionName);
return coll.findOneAndReplace(
eq(ID,toUpdate.getObjectId(ID)), toUpdate,new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER));
eq(ID,id), toUpdate,new FindOneAndReplaceOptions().returnDocument(ReturnDocument.AFTER));
}

View File

@ -4,9 +4,9 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import org.bson.Document;
import org.gcube.application.cms.plugins.faults.StepException;
import org.gcube.application.geoportal.common.faults.StorageException;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
import org.gcube.application.geoportal.service.model.internal.faults.DeletionException;
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
@ -39,6 +39,6 @@ public interface MongoManagerI<T> {
public T performStep(String id, String step, Document options) throws IOException, StepException;
public T registerFileSet(String id, String destination, Document attributes, List<TempFile> files) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException;
public T registerFileSet(String id, RegisterFileSetRequest request) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException;
public T deleteFileSet(String id, String destination, Boolean force) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException;
}

View File

@ -16,12 +16,12 @@ import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.faults.StorageException;
import org.gcube.application.geoportal.common.model.document.*;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.legacy.WorkspaceContent;
import org.gcube.application.geoportal.common.model.profile.Field;
import org.gcube.application.geoportal.common.model.profile.HandlerDeclaration;
import org.gcube.application.geoportal.common.model.profile.Profile;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.application.geoportal.common.utils.JSONPathWrapper;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.application.geoportal.service.engine.ImplementationProvider;
@ -145,7 +145,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
log.debug("Going to register {} ",toRegister);
// Insert object
ObjectId id =insert(asDocument(toRegister),getCollectionName());
ObjectId id =insert(asDocumentWithId(toRegister),getCollectionName());
log.info("Obtained id {} ",id);
return getByID(id.toHexString());
@ -158,7 +158,9 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
toUpdate.setTheDocument(toSet);
toUpdate=onUpdate(toUpdate);
return convert(replace(asDocument(toUpdate),getCollectionName()),ProfiledDocument.class);
ProfiledDocument toReturn =convert(replace(asDocumentWithId(toUpdate),new ObjectId(id),getCollectionName()),ProfiledDocument.class);
log.debug("Updated ProfiledDocument is {}",toReturn);
return toReturn;
}
@ -191,7 +193,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}catch(DeletionException e) {
//storing updated - partially deleted
// concessione=onUpdate(concessione);
// replace(asDocument(concessione), collectionName);
// replace(asDocumentWithId(concessione), collectionName);
throw e;
}
}catch(Throwable t){
@ -234,7 +236,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
@Override
public ProfiledDocument performStep(String id, String step, Document options) throws StepException, JsonProcessingException {
ExecutionReport report = step(getByID(id), step, options);
return convert(replace(asDocument(report.getResult()),getCollectionName()),ProfiledDocument.class);
return convert(replace(asDocumentWithId(report.getResult()),new ObjectId(id),getCollectionName()),ProfiledDocument.class);
}
@ -242,54 +244,98 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
/**
* NB Put at path :
*
* Path Examples
* artifact
* images
* images[1]
* layers[?(@.name = 'myName')]
*
*
*
*/
@Override
public ProfiledDocument registerFileSet(String id, String destination, Document attributes, List<TempFile> files) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException {
log.info("Registering fileset [size : {}] for {} at {} with options {}",files.size(),id,destination,attributes);
public ProfiledDocument registerFileSet(String id,RegisterFileSetRequest request) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException {
List<TempFile> files=request.getStreams();
Document attributes =request.getAttributes();
log.info("Registering Fileset for {}, Request is {} ",id,request);
ProfiledDocument doc=getByID(id);
WorkspaceManager ws=new WorkspaceManager();
StorageUtils storage=ImplementationProvider.get().getStorageProvider().getObject();
log.debug("Checking {}  path against profile {}",destination,profile.getId());
log.debug("Checking {}  path against profile {}",request.getFieldPath(),profile.getId());
JSONPathWrapper schemaWrapper= new JSONPathWrapper(profile.getSchema().toJson());
List<Object> fieldDefinitions=schemaWrapper.getByPath(destination);
if(fieldDefinitions==null || fieldDefinitions.isEmpty()) throw new WebApplicationException("No Field found in schema "+profile.getId()+" at "+destination, Response.Status.BAD_REQUEST);
if(fieldDefinitions.size()>1) throw new WebApplicationException("Multiple field definitions ("+fieldDefinitions.size()+") found in "+profile.getId()+" for "+destination,Response.Status.BAD_REQUEST);
Field fieldDefinition=Serialization.convert(fieldDefinitions.get(0),Field.class);
List<Field> fieldDefinitions=schemaWrapper.getByPath(request.getFieldPath(),Field.class);
if(fieldDefinitions==null || fieldDefinitions.isEmpty())
throw new WebApplicationException("No Field found in schema "+profile.getId()+" at "+request.getFieldPath(), Response.Status.BAD_REQUEST);
if(fieldDefinitions.size()>1)
throw new WebApplicationException("Multiple field definitions ("+fieldDefinitions.size()+") found in "+profile.getId()+" for "+request.getFieldPath(),Response.Status.BAD_REQUEST);
Field fieldDefinition=fieldDefinitions.get(0);
log.debug("Field definition is {}",fieldDefinition);
JSONPathWrapper docWrapper=new JSONPathWrapper(doc.getTheDocument().toJson());
List<RegisteredFileSet> found=docWrapper.getByPath(destination,RegisteredFileSet.class);
List<RegisteredFileSet> found=docWrapper.getByPath(request.getDestinationPath(),RegisteredFileSet.class);
if(fieldDefinition.getMaxCardinality()==1 && (!found.isEmpty())){
throw new WebApplicationException("Cannot add registered fileset at "+destination+" : field is not collection.",Response.Status.BAD_REQUEST);
throw new WebApplicationException("Cannot add registered fileset at "+request.getFieldPath()+" : field is not collection.",Response.Status.BAD_REQUEST);
}
RegisteredFileSet registeredFileSet=prepareRegisteredFileSet(doc,profile,destination,attributes,files,storage,ws);
Object toSet=null;
log.debug("Registered fileset is {} ",registeredFileSet);
if(fieldDefinition.isCollection()){
if(fieldDefinition.getMaxCardinality()>1){
// Field is collection
found.add(registeredFileSet);
docWrapper.set(destination,found);
}
else {
docWrapper.set(destination,registeredFileSet);
}
// Manage clash options
if(!found.isEmpty())
switch (request.getClashOption()){
case REPLACE_EXISTING: {
if(found.size()>1)
throw new WebApplicationException("Cannot replace multiple items at "+request.getDestinationPath()+".",Response.Status.BAD_REQUEST);
deleteFileSet(doc.get_id(),request.getDestinationPath(),false);
toSet = prepareRegisteredFileSet(doc,profile,request.getDestinationPath(),attributes,files,storage,ws);
break;
}case MERGE_EXISTING: {
if(found.size()>1)
throw new WebApplicationException("Cannot merge multiple items at "+request.getDestinationPath()+".",Response.Status.BAD_REQUEST);
attributes.putAll(Serialization.asDocument(found.get(0)));
deleteFileSet(doc.get_id(),request.getDestinationPath(),false);
toSet = prepareRegisteredFileSet(doc,profile,request.getDestinationPath(),attributes,files,storage,ws);
break;
}case APPEND: {
if(!fieldDefinition.isCollection())
throw new WebApplicationException("Cannot append to "+request.getDestinationPath()+" : field "+request.getFieldPath()+" is not collection.",
Response.Status.BAD_REQUEST);
RegisteredFileSet registeredFileSet=prepareRegisteredFileSet(doc,profile,request.getDestinationPath(),attributes,files,storage,ws);
found.add(registeredFileSet);
toSet=found;
break;
}
}
docWrapper.set(request.getDestinationPath(),toSet);
// if(fieldDefinition.getMaxCardinality()>1){
// // Field is collection
// found.add(registeredFileSet);
// docWrapper.set(destination,found);
// }
// else {
// docWrapper.set(destination,registeredFileSet);
// }
log.debug("Setting result on profiled document");
doc.setTheDocument(Document.parse(docWrapper.getCtx().jsonString()));
doc=onUpdate(doc);
return convert(replace(asDocument(doc),getCollectionName()),ProfiledDocument.class);
return convert(replace(asDocumentWithId(doc),new ObjectId(id),getCollectionName()),ProfiledDocument.class);
}
@Override

View File

@ -3,13 +3,11 @@ package org.gcube.application.geoportal.service.rest;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
import org.gcube.application.geoportal.common.model.rest.Configuration;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.rest.StepExecutionRequest;
import org.gcube.application.geoportal.service.engine.mongo.ConcessioniMongoManager;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest;
import org.gcube.application.geoportal.service.engine.mongo.ProfiledMongoManager;
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
import org.gcube.application.cms.Serialization;
@ -100,7 +98,7 @@ public class ProfiledDocuments {
@Produces(MediaType.APPLICATION_JSON)
@Path("/"+InterfaceConstants.Methods.REGISTER_FILES_PATH+"/{"+InterfaceConstants.Parameters.PROJECT_ID+"}")
public ProfiledDocument registerFileSet(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,
AddSectionToConcessioneRequest request) {
RegisterFileSetRequest request) {
return new GuardedMethod<ProfiledDocument>() {
@Override
protected ProfiledDocument run() throws Exception, WebApplicationException {
@ -109,7 +107,7 @@ public class ProfiledDocuments {
manager.getProfile().getId(),
id,request.getDestinationPath());
request.validate();
return manager.registerFileSet(id,request.getDestinationPath(),request.getAttributes(),request.getStreams());
return manager.registerFileSet(id,request);
}
}.execute().getResult();
}

View File

@ -2,15 +2,89 @@
"id" : "profiledConcessioni",
"version" : "1.0.0",
"name" : "Concessione",
"schema" : {
"relazioneScavo" : {
"_type" : "RegisteredFileSet",
"_max" : 1,
"_min" : 1},
"imgs" : {
"_type" : "RegisteredFileSet",
"_max" : -1}
},
"description" : "Embedded profile for concessioni [mibac] management",
"creationInfo": {
"user" : {
"username": "fabio.sinibaldi"
}
},
"data_access_policy" : [
{"policy" : {"read" : "own", "write" : "own"}, "roles":[]},
{"policy" : {"read" : "any", "write" : "none"}, "roles":["Guest"],
"enforcer": {"filter" : {"lifecycleInformation.phase" : {"$eq" : "Published"}}}},
{"policy" : {"read" : "any", "write" : "none"}, "roles":["Admin"]},
{"policy" : {"read" : "any", "write" : "any"}, "roles":["Data-Manager"]}
],
"handlers" : [
{
"id" : "GNA-CONCESSIONI-LC",
"type" : "LifecycleManagement"}
"type" : "LifecycleManagement",
"configuration" : {
"step_access" : [
{"STEP" : "PUBLISH", "roles" :[ "DataManager"]}
]
}
},
{
"id" : "org.gcube....geoportal-data-entry-portlet",
"type" : "DATA_ENTRY_GUI",
"case" : "",
"configuration" : {
"gcubeProfiles" : [
{
"gcubeCategory" : "",
"gcubeName" : "",
"order" : "",
"sectionName": "",
"sectionTitle" : "",
"cardinality" : "",
"parentName" : "",
"filePaths" : [
{"field" : "field id from XML gcube Profile",
"path" : "$.abstract.associatedFiles" }
]
}
]
}
},
{
"id" : "org.gcube....geoportal-data-list",
"type" : "DATA_LIST_GUI",
"case" : "smallList",
"configuration" : {
"projection" : {"nome" : 1, "lifecycleInformation.phase" : 1},
"orderPaths":[
{"label" : "author", "path" : "info.creationInfo.user.username"}],
"searchPaths":[
{"label" : "author", "path" : "info.creationInfo.user.username"}],
"actions" :[
{ "status" : "OK",
"phase" : "VALIDATE_DRAFT",
"butoonsDefintion" : [
{"id" : "report_forward","action" : "STEP", "label" : "Sottometti"},
{"id" : "list_back_workflow", "action" : "STEP" , "label" : "Rifiuta"},
{"id" : "report_backward", "action" : "STEP" , "label" : "Rifiuta"}
]}
],
"implicit_filter":{"nome" : {"$eq" : "ciao" }}
}
}
]
}

View File

@ -40,7 +40,7 @@ public class BasicServiceTestUnit extends JerseyTest {
String resString=resp.readEntity(String.class);
if(resp.getStatus()<200||resp.getStatus()>=300)
throw new Exception("RESP STATUS IS "+resp.getStatus()+". Message : "+resString);
System.out.println("Resp String is "+resString);
log.debug("Resp String is "+resString);
if(clazz!=null)
if (clazz==String.class)
return (T) resString;

View File

@ -4,18 +4,25 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import org.bson.Document;
import org.gcube.application.cms.Serialization;
import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.rest.Configuration;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.utils.FileSets;
import org.gcube.application.geoportal.common.utils.Files;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.internal.runners.TestMethod;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.File;
import java.util.Collections;
import java.util.List;
@ -37,9 +44,9 @@ public class ProfiledDocumentsTests extends BasicServiceTestUnit{
// GET
@Test
public void testMissingProfile(){
Response resp = baseTarget()
Response resp = target(InterfaceConstants.Methods.PROJECTS)
.path("non-existent-profile").request().get();
assertEquals(resp.getStatus(),404);
assertEquals(404,resp.getStatus());
}
@ -64,7 +71,7 @@ public class ProfiledDocumentsTests extends BasicServiceTestUnit{
@Test
public void getConfiguration() {
System.out.println(baseTarget().request(MediaType.APPLICATION_JSON).get(Configuration.class));
System.out.println(baseTarget().path(InterfaceConstants.Methods.CONFIGURATION_PATH).request(MediaType.APPLICATION_JSON).get(Configuration.class));
}
// Queries
@ -82,11 +89,6 @@ public class ProfiledDocumentsTests extends BasicServiceTestUnit{
createNew();
}
private ProfiledDocument createNew() throws Exception {
Document document =new Document(Collections.singletonMap("dumbKey","dumbValue"));
return check(baseTarget().request(MediaType.APPLICATION_JSON).
post(Entity.entity(document, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
}
@Test
public void edit() throws Exception {
@ -104,10 +106,34 @@ public class ProfiledDocumentsTests extends BasicServiceTestUnit{
public void addFileSet() throws Exception {
ProfiledDocument doc = createNew();
doc = upload(
new StorageUtils(),
doc.get_id(),
"relazioneScavo",
"relazioneScavo",
Document.parse("{\"titolo\" : \"mio titolo\"}"),
"relazione.pdf");
System.out.println(Serialization.write(doc));
}
// @@@@@@@@@@@@@@@ Routines
private ProfiledDocument createNew() throws Exception {
Document document =new Document(Collections.singletonMap("dumbKey","dumbValue"));
return check(baseTarget().request(MediaType.APPLICATION_JSON).
post(Entity.entity(document, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
}
private ProfiledDocument upload(StorageUtils storage, String id, String path, String fieldPath, Document attributes, String ...files) throws Exception {
FileSets.RequestBuilder builder = FileSets.build(path);
for(String file:files)
builder.add(storage.putOntoStorage(new File(TestConcessioniModel.getBaseFolder(),file),file));
return check(baseTarget().path(InterfaceConstants.Methods.REGISTER_FILES_PATH).path(id).request(MediaType.APPLICATION_JSON).
post(Entity.entity(Serialization.write(builder.getTheRequest()),
MediaType.APPLICATION_JSON)),ProfiledDocument.class);
}
}

View File

@ -11,7 +11,7 @@
"creationUser" : {$eq : "fabio.sinibaldi"}
},
"projection" : {
"nome" : 1
"nome" : 1,
}

View File

@ -7,7 +7,7 @@ import org.gcube.application.geoportal.client.utils.Serialization;
import org.gcube.application.geoportal.common.model.legacy.*;
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.application.geoportal.common.utils.Files;
import org.gcube.application.geoportal.common.utils.StorageUtils;