1.0.5 #3

Merged
fabio.sinibaldi merged 19 commits from 1.0.5 into master 2021-01-14 16:49:22 +01:00
24 changed files with 578 additions and 37 deletions

View File

@ -2,6 +2,25 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for org.gcube.application.geoportal-common
# [v1.0.5] - 2020-12-9
Mongo Id in record
Mongo Concessioni interface
Added Files.fixFileNAme
ValidationReport as field
Updated Model (#20357)
# [v1.0.4-SNAPSHOT] - 2020-12-9
Projects Rest Interface
TempFile support
# [v1.0.3] - 2020-12-4
Project model update
# [v1.0.2-SNAPSHOT] - 2020-12-4
Model update
## [v1.0.1] - 2020-11-11
Model update

33
pom.xml
View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.application</groupId>
<artifactId>geoportal-common</artifactId>
<version>1.0.1</version>
<version>1.0.5</version>
<name>Geoportal Common</name>
@ -51,9 +51,12 @@
<version>1.14.8</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
</dependency>
<!-- TEST -->
<dependency>
@ -62,22 +65,34 @@
<scope>test</scope>
<version>4.11</version>
</dependency>
<!-- read JSON -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<!-- jackson java time -->
<!-- jackson java time -->
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.8</version>
</dependency>
<!-- STORAGE -->
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
<version>[2.0.0, 3.0.0)</version>
</dependency>
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<version>[2.0.0, 3.0.0)</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>

View File

@ -19,7 +19,7 @@ import lombok.Setter;
public abstract class AssociatedContent {
private String mongo_id;
private long id;
private AccessPolicy policy;

View File

@ -87,6 +87,107 @@ public class Concessione extends Record{
}
public static class Paths{
public final static String RELAZIONE="relazione";
public final static String POSIZIONAMENTO="posizionamentoScavo";
public final static String PIANTE="piante";
public final static String IMMAGINI="immagini";
public static final String MONGO_ID="mongo_id";
public final static String piantaByIndex(int index) {return makeByIndex(PIANTE,index);};
public final static String imgByIndex(int index) {return makeByIndex(IMMAGINI,index);};
public final static String piantaById(String id) {return makeByStringField(PIANTE, MONGO_ID, id);};
public final static String imgById(String id) {return makeByStringField(IMMAGINI, MONGO_ID, id);};
private static String makeByIndex(String base,int value) {return String.format("%1$s[%2$d]",base,value);}
private static String makeByStringField(String base,String field,String value)
{return String.format("%1$s.%2$s:\"%3$s\"",base,field,value);}
}
@Override
public AssociatedContent getContentByPath(String path) {
switch(path) {
case Paths.RELAZIONE : return getRelazioneScavo();
case Paths.POSIZIONAMENTO : return getPosizionamentoScavo();
}
if(path.matches("\\w+\\[\\d+\\]")) {
// Array section
String field=path.substring(0,path.lastIndexOf("["));
Integer index=Integer.parseInt(path.substring(path.lastIndexOf("[")+1,path.lastIndexOf("]")));
List<? extends AssociatedContent> list=null;
switch (field) {
case Paths.IMMAGINI : list = immaginiRappresentative; break;
case Paths.PIANTE : list = pianteFineScavo; break;
}
return getByIndex(list,index);
}
if(path.matches("\\w+\\.\\w+\\s*\\:\\s*\\\"\\w+\\\"")) {
// Map section
String field=path.substring(0,path.lastIndexOf("."));
String subField=path.substring(path.indexOf(".")+1,path.lastIndexOf(":")).trim();
String value=path.substring(path.indexOf("\"")+1,path.lastIndexOf("\""));
List<? extends AssociatedContent> list=null;
switch (field) {
case Paths.IMMAGINI : list = immaginiRappresentative; break;
case Paths.PIANTE : list = pianteFineScavo; break;
}
return getByFieldValue(list, subField, value);
}
return null;
}
private static AssociatedContent getByIndex(List<? extends AssociatedContent> list, int index) {
if(list == null )return null;
return list.get(index);
}
// NB only mongo_id is supported in this impl.
private static AssociatedContent getByFieldValue(List<? extends AssociatedContent> list, String field, Object value) {
for(AssociatedContent c: list) {
switch(field) {
case Paths.MONGO_ID : {
if(c.getMongo_id()!=null&&c.getMongo_id().equals(value))
return c;
}
}
}
return null;
}
@Override
public void setAtPath(AssociatedContent toSet, String path) {
switch(path) {
case Paths.RELAZIONE : {
setRelazioneScavo((RelazioneScavo) toSet);
break;
}
case Paths.POSIZIONAMENTO : {
setRelazioneScavo((RelazioneScavo) toSet);
break;
}
case Paths.PIANTE : {
if(pianteFineScavo==null)pianteFineScavo=new ArrayList<LayerConcessione>();
pianteFineScavo.add((LayerConcessione) toSet);
break;
}
case Paths.IMMAGINI: {
if(immaginiRappresentative==null)immaginiRappresentative=new ArrayList<UploadedImage>();
pianteFineScavo.add((LayerConcessione) toSet);
break;
}
//TODO MATCH if()case Paths.PIANTa : return
//TODO MATCH if()case Paths.Img : return
}
}
@Override
public ValidationReport validate() {
ValidationReport validator= super.validate();
@ -448,5 +549,4 @@ public class Concessione extends Record{
}
}

View File

@ -22,7 +22,7 @@ public class LayerConcessione extends SDILayerDescriptor{
//layer
private String layerName;
private String wmsLink;
private String workspace;
//1.Identificazione

View File

@ -17,6 +17,7 @@ import lombok.ToString;
public abstract class Record {
private String mongo_id;
//Generic Info
private long id;
@ -41,7 +42,7 @@ public abstract class Record {
private ValidationReport report;
public ValidationReport validate() {
@ -50,8 +51,9 @@ public abstract class Record {
validator.checkMandatory(getRecordType(), "Record Type");
validator.checkMandatory(getNome(), "Nome");
return validator;
setReport(validator);
return getReport();
}
public void setDefaults() {
@ -65,6 +67,8 @@ public abstract class Record {
setLicenzaID(ConstraintCheck.defaultFor(getLicenzaID(),"CC-BY").evaluate());
}
public abstract AssociatedContent getContentByPath(String path);
public abstract void setAtPath(AssociatedContent toSet,String path);
}

View File

@ -16,7 +16,9 @@ public class RelazioneScavo extends AssociatedContent {
private String abstractSection;
// private String abstractSection;
private String abstractIta;
private String abstractEng;
private List<String> responsabili;
private List<String> soggetto;
@ -36,7 +38,7 @@ public class RelazioneScavo extends AssociatedContent {
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((abstractSection == null) ? 0 : abstractSection.hashCode());
// result = prime * result + ((abstractSection == null) ? 0 : abstractSection.hashCode());
// result = prime * result + ((responsabili == null) ? 0 : responsabili.hashCode());
result = prime * result + CollectionsUtils.hashCode(responsabili);
// result = prime * result + ((soggetto == null) ? 0 : soggetto.hashCode());
@ -53,11 +55,11 @@ public class RelazioneScavo extends AssociatedContent {
if (getClass() != obj.getClass())
return false;
RelazioneScavo other = (RelazioneScavo) obj;
if (abstractSection == null) {
if (other.abstractSection != null)
return false;
} else if (!abstractSection.equals(other.abstractSection))
return false;
// if (abstractSection == null) {
// if (other.abstractSection != null)
// return false;
// } else if (!abstractSection.equals(other.abstractSection))
// return false;
// if (responsabili == null) {
// if (other.responsabili != null)
// return false;

View File

@ -18,5 +18,8 @@ public abstract class SDILayerDescriptor extends AssociatedContent{
public abstract String getWmsLink();
public abstract void setWmsLink(String wmsLink);
public abstract void setWorkspace(String workspace);
public abstract String getWorkspace();
public abstract BBOX getBbox();
public abstract void setBbox(BBOX toSet);
}

View File

@ -5,11 +5,19 @@ import java.util.ArrayList;
import java.util.List;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class ValidationReport implements Serializable{
/**
*
*/
private static final long serialVersionUID = -3629142756787381094L;
public static enum ValidationStatus{
PASSED, ERROR, WARNING
}

View File

@ -31,17 +31,13 @@ public class Project {
*
*/
public static enum Status{
VALID,INVALID,PUBLISHED
}
private String _id;
private String profile_id;
private PublicationDetails publication;
private Status status;
private BasicJSONObject document;
private Object document;
private Centroid centroid;
private PublicationDetails publication;
private String json;
}

View File

@ -0,0 +1,11 @@
package org.gcube.application.geoportal.common.model.project;
import java.util.List;
public class Status {
private StatusPhase phase;
private List<String> messages;
}

View File

@ -0,0 +1,13 @@
package org.gcube.application.geoportal.common.model.project;
public enum StatusPhase {
DRAFT,
UNDER_VALIDATION,
INVALID,
VALID,
UNDER_PUBLICATION,
PUBLICATION_ERROR,
PUBLISHED
}

View File

@ -0,0 +1,4 @@
package org.gcube.application.geoportal.common.model.project;

View File

@ -4,16 +4,17 @@ import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.application.geoportal.common.model.legacy.AssociatedContent;
import org.gcube.application.geoportal.common.model.legacy.InputStreamDescriptor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@XmlRootElement
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AddSectionToConcessioneRequest {
private AssociatedContent toRegister;
private List<InputStreamDescriptor> streams;
private String destinationPath;
private List<TempFile> streams;
}

View File

@ -15,6 +15,12 @@ public class InterfaceConstants {
public static final String PROJECTS="projects";
public static final String CONCESSIONI="concessioni";
public static final String MONGO_CONCESSIONI="mongo-concessioni";
public static final String PUBLISH_PATH="publish";
public static final String REGISTER_FILES_PATH="registerFiles";
}
public static final class Parameters{

View File

@ -0,0 +1,17 @@
package org.gcube.application.geoportal.common.rest;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
public interface MongoConcessioni {
public Concessione createNew(Concessione c) throws Exception;
public void deleteById(String id) throws Exception;
public Concessione getById(String id) throws Exception;
public Iterable<Concessione> getList()throws Exception;
public Concessione publish(String id) throws Exception;
public Concessione registerFile(String id, AddSectionToConcessioneRequest request) throws Exception;
public Concessione update(String id, String jsonUpdate) throws Exception;
public Concessione replace(Concessione replacement) throws Exception;
}

View File

@ -0,0 +1,16 @@
package org.gcube.application.geoportal.common.rest;
import org.gcube.application.geoportal.common.model.project.Project;
public interface ProjectsI {
public Iterable<Project> getAll() throws Exception;
public Iterable<Project> getByProfile(String profileId) throws Exception;
public Project getById(String profileId,String id) throws Exception;
public Iterable<Project> getByFilter(String filter)throws Exception;
public Iterable<Project> getByFilter(String filter, String profileId)throws Exception;
public Project registrNew(String profileId, String jsonDocument)throws Exception;
public Project update(String profileId, String projectId,String jsonDocument) throws Exception;
public void deleteById(String profileId, String projectId)throws Exception;
}

View File

@ -0,0 +1,15 @@
package org.gcube.application.geoportal.common.rest;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TempFile {
private String id;
private String filename;
}

View File

@ -0,0 +1,41 @@
package org.gcube.application.geoportal.common.utils;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import lombok.extern.slf4j.Slf4j;
@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";
}
}
}

View File

@ -37,5 +37,12 @@ public class Files {
}
public static String fixFilename(String toFix) {
if(toFix.contains(".")) {
String prefix=toFix.substring(toFix.lastIndexOf("."));
toFix=toFix.substring(0,toFix.lastIndexOf("."));
return toFix.toLowerCase().replaceAll("[\\*\\+\\/\\\\ \\[\\]\\(\\)\\.\\\"\\:\\;\\|]","_")+prefix;
}
return toFix.toLowerCase().replaceAll("[\\*\\+\\/\\\\ \\[\\]\\(\\)\\.\\\"\\:\\;\\|]","_");
}
}

View File

@ -0,0 +1,55 @@
package org.gcube.application.geoportal.common.utils;
import java.io.FileNotFoundException;
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.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class StorageUtils {
public static final IClient getClient(){
return new StorageClient(InterfaceConstants.SERVICE_CLASS, InterfaceConstants.SERVICE_NAME, ContextUtils.getCurrentCaller(), AccessType.SHARED, MemoryType.VOLATILE).getClient();
}
private IClient client;
public StorageUtils() {
client=getClient();
}
//return Id
public TempFile putOntoStorage(InputStream source,String filename) throws RemoteBackendException, FileNotFoundException{
log.debug("Uploading source "+filename);
String id=client.put(true).LFile(source).RFile(getUniqueString());
return new TempFile(id,filename);
}
public static final boolean checkStorageId(String id){
return getClient().getHttpUrl().RFile(id)!=null;
}
public static final String getUrlById(String id){
IClient client=getClient();
log.debug("Id is "+id);
return client.getHttpUrl().RFile(id);
}
public static final void removeById(String id){
IClient client=getClient();
client.remove().RFile(id);
}
public static final String getUniqueString(){
return UUID.randomUUID().toString();
}
}

View File

@ -0,0 +1,67 @@
package org.gcube.application.geoportal.common.model;
import static org.junit.Assert.assertEquals;
import java.util.UUID;
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;
import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
import org.junit.Test;
public class PathsTest {
@Test
public void embeddedPaths() {
Concessione c=TestModel.prepareConcessione();
c=TestModel.setIds(c);
LayerConcessione p=(LayerConcessione) c.getContentByPath(Paths.POSIZIONAMENTO);
assertEquals(c.getPosizionamentoScavo(), p);
RelazioneScavo rel=(RelazioneScavo) c.getContentByPath(Paths.RELAZIONE);
assertEquals(c.getRelazioneScavo(), rel);
for(int i=0;i<c.getPianteFineScavo().size();i++) {
LayerConcessione l=(LayerConcessione) c.getContentByPath(Paths.piantaByIndex(i));
assertEquals(c.getPianteFineScavo().get(i),l);
}
for(int i=0;i<c.getImmaginiRappresentative().size();i++) {
UploadedImage l=(UploadedImage) c.getContentByPath(Paths.imgByIndex(i));
assertEquals(c.getImmaginiRappresentative().get(i),l);
}
for(int i=0;i<c.getPianteFineScavo().size();i++) {
LayerConcessione layer=c.getPianteFineScavo().get(i);
LayerConcessione l=(LayerConcessione) c.getContentByPath(Paths.piantaById(layer.getMongo_id()));
assertEquals(layer,l);
}
for(int i=0;i<c.getImmaginiRappresentative().size();i++) {
UploadedImage layer=c.getImmaginiRappresentative().get(i);
UploadedImage l=(UploadedImage) c.getContentByPath(Paths.imgById(layer.getMongo_id()));
assertEquals(layer,l);
}
System.out.println();
System.out.println();
}
}

View File

@ -48,4 +48,18 @@ public class SerializationTest {
System.out.println("Concessione is "+concessione.toString());
}
@Test
public void generic() throws JsonProcessingException, IOException {
Concessione conc=TestModel.prepareConcessione();
conc.validate();
full(conc);
}
public void full(Object obj) throws JsonProcessingException, IOException {
String asString=mapper.writeValueAsString(obj);
Object other=mapper.readerFor(obj.getClass()).readValue(asString);
}
}

View File

@ -0,0 +1,127 @@
package org.gcube.application.geoportal.common.model;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
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.legacy.LayerConcessione;
import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
public class TestModel {
private static final String rnd() {
return UUID.randomUUID().toString().replace("-", "_");
}
public static final Concessione setIds(Concessione c) {
c.setMongo_id(rnd());
c.getRelazioneScavo().setMongo_id(rnd());
c.getPosizionamentoScavo().setMongo_id(rnd());
c.getPianteFineScavo().forEach((LayerConcessione l)->{l.setMongo_id(rnd());});
c.getImmaginiRappresentative().forEach((UploadedImage i)->{i.setMongo_id(rnd());});
return c;
}
public static Concessione prepareEmptyConcessione() {
Concessione concessione=new Concessione();
// Generic fields
// Concessione fields
concessione.setNome("MONGO Italia, forse, ma su ");
concessione.setIntroduzione("This is my MONGO project");
concessione.setDescrizioneContenuto("It contains this and that");
concessione.setAuthors(Arrays.asList(new String[] {"Some one","Some, oneelse"}));
concessione.setContributore("Contrib 1");
concessione.setTitolari(Arrays.asList(new String[] {"Some one","Some, oneelse"}));
concessione.setResponsabile("Someone");
concessione.setEditore("Editore");
concessione.setFontiFinanziamento(Arrays.asList(new String[] {"Big pharma","Pentagon"}));
concessione.setSoggetto(Arrays.asList(new String[] {"Research Excavation","Archeology"}));
concessione.setDataInizioProgetto(LocalDateTime.now());
concessione.setDataFineProgetto(LocalDateTime.now());
concessione.setLicenzaID("CC-BY");
concessione.setTitolareLicenza(Arrays.asList(new String[] {"Qualcun altro"}));
concessione.setTitolareCopyright(Arrays.asList(new String[] {"Chiedilo in giro"}));
concessione.setParoleChiaveLibere(Arrays.asList(new String[] {"Robba","Stuff"}));
concessione.setParoleChiaveICCD(Arrays.asList(new String[] {"vattelapesca","somthing something"}));
concessione.setCentroidLat(43.0); //N-S
concessione.setCentroidLong(9.0); //E-W
return concessione;
}
public static Concessione prepareConcessione() {
Concessione concessione=prepareEmptyConcessione();
// Attachments
// Relazione scavo
RelazioneScavo relScavo=new RelazioneScavo();
relScavo.setAbstractEng("simple abstract section");
relScavo.setResponsabili(concessione.getAuthors());
concessione.setRelazioneScavo(relScavo);
//Immagini rappresentative
ArrayList<UploadedImage> imgs=new ArrayList<>();
for(int i=0;i<5;i++) {
UploadedImage img=new UploadedImage();
img.setTitolo("My image number "+i);
img.setDidascalia("You can see my image number "+i);
img.setFormat("TIFF");
img.setCreationTime(LocalDateTime.now());
img.setResponsabili(concessione.getAuthors());
imgs.add(img);
}
concessione.setImmaginiRappresentative(imgs);
//Posizionamento
LayerConcessione posizionamento=new LayerConcessione();
posizionamento.setValutazioneQualita("Secondo me si");
posizionamento.setMetodoRaccoltaDati("Fattobbene");
posizionamento.setScalaAcquisizione("1:10000");
posizionamento.setAuthors(concessione.getAuthors());
concessione.setPosizionamentoScavo(posizionamento);
// Piante fine scavo
ArrayList<LayerConcessione> piante=new ArrayList<LayerConcessione>();
for(int i=0;i<4;i++) {
LayerConcessione pianta=new LayerConcessione();
pianta.setValutazioneQualita("Secondo me si");
pianta.setMetodoRaccoltaDati("Fattobbene");
pianta.setScalaAcquisizione("1:10000");
pianta.setAuthors(concessione.getAuthors());
pianta.setPolicy(AccessPolicy.RESTRICTED);
piante.add(pianta);
}
concessione.setPianteFineScavo(piante);
return concessione;
}
}