ProfiledDocument definition

This commit is contained in:
Fabio Sinibaldi 2021-12-01 11:13:34 +01:00
parent 1a45e44c7f
commit 70289ec603
25 changed files with 228 additions and 51 deletions

View File

@ -1,5 +1,8 @@
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# Changelog for org.gcube.application.cms.cms-test-commons
## [v1.0.1-SNAPSHOT] - 2021-09-11
- Introduced profiled documents
## [v1.0.0] - 2021-09-11
- First release

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>cms-test-commons</artifactId>
<version>1.0.0</version>
<version>1.0.1-SNAPSHOT</version>
<name>CMS Test Commons</name>

View File

@ -1,33 +1,20 @@
package org.gcube.application.cms.tests.model;
package org.gcube.application.cms.tests.model.concessioni;
import org.gcube.application.geoportal.common.utils.Files;
import sun.misc.IOUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.stream.Stream;
public class TestFilters {
public class TestConcessioniFilters {
public static final HashMap<String,String> filters=new HashMap<>();
static{
for(File f:new File(TestModel.getBaseFolder(),"filters").listFiles()){
for(File f:new File(TestConcessioniModel.getBaseFolder(),"filters").listFiles()){
try {
filters.put(f.getName(), Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()));
} catch (IOException e) {

View File

@ -1,4 +1,4 @@
package org.gcube.application.cms.tests.model;
package org.gcube.application.cms.tests.model.concessioni;
import java.io.File;
import java.time.LocalDateTime;
@ -8,7 +8,7 @@ import java.util.Arrays;
import org.bson.types.ObjectId;
import org.gcube.application.geoportal.common.model.legacy.*;
public class TestModel {
public class TestConcessioniModel {
public static File getBaseFolder(){
File toReturn =new File("../test-data/concessioni");

View File

@ -1,21 +1,19 @@
package org.gcube.application.cms.tests.model;
package org.gcube.application.cms.tests.model.concessioni;
import org.gcube.application.geoportal.common.utils.Files;
import sun.misc.IOUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.HashMap;
public class TestQueries {
public class TestConcessioniQueries {
public static final HashMap<String,String> queries =new HashMap<>();
static{
for(File f:new File(TestModel.getBaseFolder(),"queries").listFiles()){
for(File f:new File(TestConcessioniModel.getBaseFolder(),"queries").listFiles()){
try {
queries.put(f.getName(), Files.readFileAsString(f.getAbsolutePath(), Charset.defaultCharset()));
} catch (IOException e) {

View File

@ -0,0 +1,6 @@
package org.gcube.application.cms.commons.model;
public class Serialization {
}

View File

@ -1,7 +1,7 @@
package org.gcube.application.cms.commons.model.concessioni;
import org.gcube.application.cms.tests.model.TestFilters;
import org.gcube.application.cms.tests.model.TestModel;
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniFilters;
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.junit.Test;
@ -11,14 +11,14 @@ public class Models {
@Test
public void checkFilters(){
assertTrue(TestFilters.filters.size()>0);
TestFilters.filters.keySet().forEach(f -> {
assertTrue(TestConcessioniFilters.filters.size()>0);
TestConcessioniFilters.filters.keySet().forEach(f -> {
System.out.println(f);});
}
@Test
public void checkConcessione(){
Concessione c= TestModel.prepareConcessione(3,5);
Concessione c= TestConcessioniModel.prepareConcessione(3,5);
assertTrue(c.getPianteFineScavo().size()==3);
assertTrue(c.getImmaginiRappresentative().size()==5);
}

View File

@ -2,7 +2,7 @@ package org.gcube.application.cms.commons.model.concessioni;
import static org.junit.Assert.assertEquals;
import org.gcube.application.cms.tests.model.TestModel;
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
import org.gcube.application.geoportal.common.model.legacy.LayerConcessione;
@ -17,8 +17,8 @@ public class PathsTest {
@Test
public void embeddedPaths() {
Concessione c= TestModel.prepareConcessione();
c=TestModel.setIds(c);
Concessione c= TestConcessioniModel.prepareConcessione();
c= TestConcessioniModel.setIds(c);

View File

@ -3,11 +3,10 @@ package org.gcube.application.cms.commons.model.concessioni;
import java.io.File;
import java.io.IOException;
import org.gcube.application.cms.tests.model.TestModel;
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
import org.gcube.application.geoportal.common.model.legacy.AccessPolicy;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.profile.Profile;
import org.gcube.application.geoportal.common.utils.Files;
import org.junit.Assert;
import org.junit.Test;
@ -38,7 +37,7 @@ public class SerializationTest {
@Test
public void readProfile() throws JsonProcessingException, IOException {
Profile concessione=mapper.readerFor(Profile.class).readValue(new File(TestModel.getBaseFolder(),"ProfileConcessioni.json"));
Profile concessione=mapper.readerFor(Profile.class).readValue(new File(TestConcessioniModel.getBaseFolder(),"ProfileConcessioni.json"));
System.out.println("Profile is "+mapper.writeValueAsString(concessione));
@ -48,7 +47,7 @@ public class SerializationTest {
@Test
public void readConcessione() throws JsonProcessingException, IOException {
Concessione concessione=mapper.readerFor(Concessione.class).readValue(new File(TestModel.getBaseFolder(),"Concessione.json"));
Concessione concessione=mapper.readerFor(Concessione.class).readValue(new File(TestConcessioniModel.getBaseFolder(),"Concessione.json"));
System.out.println("Concessione is "+concessione.toString());
concessione.getRelazioneScavo().setPolicy(AccessPolicy.EMBARGOED);
@ -61,7 +60,7 @@ public class SerializationTest {
@Test
public void generic() throws JsonProcessingException, IOException {
Concessione conc= TestModel.prepareConcessione();
Concessione conc= TestConcessioniModel.prepareConcessione();
conc.validate();
full(conc);
}

View File

@ -11,6 +11,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicLong;
import org.bson.Document;
import org.gcube.application.cms.tests.model.TestFilters;
import org.gcube.application.cms.tests.model.TestModel;
import org.gcube.application.cms.tests.model.TestQueries;
@ -20,6 +21,7 @@ import org.gcube.application.geoportal.common.model.legacy.*;
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport.ValidationStatus;
import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportal.common.utils.FileSets;
import org.gcube.application.geoportal.common.utils.Files;
@ -45,11 +47,18 @@ public class StatelessClientTests extends BasicVreTests{
throw new RuntimeException(e);
}
});
}
@Test
public void query() throws Exception {
QueryRequest req=new QueryRequest();
req.setFilter(Document.parse("{ \"nome\" : { \"$eq\" : \"mock\" } }"));
System.out.println("FRA "+ count(client.query(req)));
// No Transformation
System.out.print("First Registered \t");
Iterator<Concessione> queriedDocuments=client.query(

View File

@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# [v1.0.8-SNAPSHOT] - 2021-11-10
- Fixes [#22369](https://support.d4science.org/issues/22369)
- Fixes [#22338](https://support.d4science.org/issues/22338)
- Profiled Documents
# [v1.0.7] - 2021-09-20
- Refactored repositories

View File

@ -4,7 +4,6 @@ import lombok.*;
@NoArgsConstructor
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
@ToString

View File

@ -6,7 +6,6 @@ import java.time.LocalDateTime;
@NoArgsConstructor
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
@ToString

View File

@ -19,6 +19,8 @@ package org.gcube.application.geoportal.common.model.document;
* under the License.
*/
import lombok.*;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
@ -60,6 +62,12 @@ import java.util.Properties;
* @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
* @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a>
*/
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public class ComparableVersion
implements Comparable<ComparableVersion>
{

View File

@ -4,7 +4,6 @@ import lombok.*;
@NoArgsConstructor
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
@ToString

View File

@ -2,11 +2,24 @@ package org.gcube.application.geoportal.common.model.document;
import lombok.*;
import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
@ToString
public class LifecycleInformation {
public enum Status{
PASSED,ERROR,WARNING
}
private String phase;
private Status lastOperationStatus;
private List<String> errorMessages;
private List<String> warningMessages;
private List<LifecycleInformation> children;
}

View File

@ -7,7 +7,6 @@ import org.bson.Document;
@NoArgsConstructor
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
@ToString

View File

@ -5,7 +5,6 @@ import org.gcube.application.geoportal.common.model.legacy.AccessPolicy;
@NoArgsConstructor
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
@ToString

View File

@ -4,9 +4,12 @@ import lombok.*;
@NoArgsConstructor
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
@ToString
public class Relationship {
private String relationshipName;
private String targetID;
}

View File

@ -4,9 +4,10 @@ import lombok.*;
@NoArgsConstructor
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
@ToString
public class TemporalReference {
private String field;
}

View File

@ -4,7 +4,6 @@ import lombok.*;
@NoArgsConstructor
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
@ToString

View File

@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Fixes [#22193](https://support.d4science.org/issues/22193)
- Fixes [#22280](https://support.d4science.org/issues/22280)
- Fixes [#20755](https://support.d4science.org/issues/20755)
- Profiled Documents
## [v1.0.6] 2021-09-20
- Refactored repositories

View File

@ -1,24 +1,29 @@
package org.gcube.application.geoportal.service.engine.mongo;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.service.model.internal.faults.DeletionException;
import java.io.IOException;
public interface MongoManagerI<T> {
// create
public T registerNew(T toRegister);
public T registerNew(T toRegister) throws IOException;
// update
public T update(String id,T toSet);
public T update(String id,T toSet) throws IOException;
// delete
public void delete(String id);
public void delete(String id,boolean force) throws DeletionException;
// get By ID
public T getByID(String id);
public T getByID(String id) throws IOException;
// query
@ -37,4 +42,6 @@ public interface MongoManagerI<T> {
// deIndex
public T deIndex(String id);
public T performStep(String id, String step, Document options);
}

View File

@ -1,5 +1,145 @@
package org.gcube.application.geoportal.service.engine.mongo;
public class ProfiledMongoManager {
import com.fasterxml.jackson.core.JsonProcessingException;
import com.mongodb.client.MongoDatabase;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.bson.types.ObjectId;
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.legacy.report.ValidationReport;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException;
import org.gcube.application.geoportal.service.model.internal.faults.DeletionException;
import org.gcube.application.geoportal.service.utils.Serialization;
import java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.Consumer;
import static org.gcube.application.geoportal.service.engine.mongo.ConcessioniMongoManager.asConcessione;
@Slf4j
public class ProfiledMongoManager extends MongoManager implements MongoManagerI<ProfiledDocument>{
public ProfiledMongoManager() throws ConfigurationException {
}
private ProfiledDocument onUpdate(ProfiledDocument updatedDocument){
throw new RuntimeException("Implement Me");
}
private Document asDocument(ProfiledDocument d) throws JsonProcessingException {
return Document.parse(Serialization.write(d));
}
private ProfiledDocument asProfiledDocument(Document d) throws IOException {
return Serialization.read(d.toJson(),ProfiledDocument.class);
}
private String getCollectionName(){
return null;
}
@Override
protected MongoDatabase getDatabase() {
return null;
}
@Override
public ProfiledDocument registerNew(ProfiledDocument toRegister) throws IOException {
super.insert(asDocument(toRegister),getCollectionName());
log.trace("Going to register {} ",toRegister);
toRegister=onUpdate(toRegister);
log.trace("Concessione with defaults is {}",toRegister);
ObjectId id=insert(asDocument(toRegister), getCollectionName());
log.trace("Obtained id {}",id);
ProfiledDocument toReturn=asProfiledDocument(getById(id,getCollectionName()));
toReturn.setId(asString(id));
toReturn = asProfiledDocument(replace(asDocument(toReturn),getCollectionName()));
log.debug("Registered {} ",toReturn);
return toReturn;
}
@Override
public ProfiledDocument update(String id, ProfiledDocument toSet) throws IOException {
log.trace("Replacing {} ",toSet);
toSet=onUpdate(toSet);
return asProfiledDocument(replace(asDocument(toSet),getCollectionName()));
}
@Override
public void delete(String id,boolean force) throws DeletionException {
log.debug("Deleting by ID {}, force {}",id,force);
try{
ProfiledDocument doc =getByID(id);
//if(!force&&isPublished(id)) throw new Exception("Cannot delete published documents. Unpublish it or use force = true");
try{
// TODO CHECK PHASE AND STATUS
// DEINDEX
// DEMATERIALIZE
// DELETE CONTENT
// DELETE ENTRY
throw new DeletionException("IMPLEMENT THIS");
// delete(asId(id), getCollectionName());
}catch(DeletionException e) {
//storing updated - partially deleted
// concessione=onUpdate(concessione);
// replace(asDocument(concessione), collectionName);
throw e;
}
}catch(Throwable t){
throw new DeletionException("Unable to delete "+id,t);
}
}
@Override
public ProfiledDocument getByID(String id) throws IOException {
return asProfiledDocument(super.getById(asId(id),getCollectionName()));
}
@Override
public Iterable<ProfiledDocument> query(QueryRequest queryRequest) {
log.info("Searching concessione for filter {} ",queryRequest);
LinkedBlockingQueue queue=new LinkedBlockingQueue<Concessione>();
query(queryRequest,getCollectionName()).forEach(
(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;
}
@Override
public ProfiledDocument materialize(String id) {
throw new RuntimeException("TO IMPLEMENT");
}
@Override
public ProfiledDocument dematerialize(String id) {
throw new RuntimeException("TO IMPLEMENT");
}
@Override
public ProfiledDocument index(String id) {
throw new RuntimeException("TO IMPLEMENT");
}
@Override
public ProfiledDocument deIndex(String id) {
throw new RuntimeException("TO IMPLEMENT");
}
@Override
public ProfiledDocument performStep(String id, String step, Document options) {
throw new RuntimeException("TO IMPLEMENT");
}
}

View File

@ -0,0 +1,4 @@
{
"filter" : { "nome" : { "$eq" : "stupid_mock_impossible_to_find_one" } }
}