Fixes GEOJson management

This commit is contained in:
Fabio Sinibaldi 2022-05-06 12:45:18 +02:00
parent 2f94fdef97
commit 21cc19c713
3 changed files with 58 additions and 9 deletions

View File

@ -27,14 +27,19 @@ public class UserUtils {
log.debug("Context is {}, checking tokens..",context); log.debug("Context is {}, checking tokens..",context);
ClientInfo client = null; ClientInfo client = null;
Set<String> roles=new HashSet<>();
try{ try{
client = AuthorizationProvider.instance.get().getClient(); client = AuthorizationProvider.instance.get().getClient();
roles= new HashSet<>(client.getRoles());
}catch(Throwable e) { }catch(Throwable e) {
log.warn("Unable to get client info ",e); log.warn("Unable to get client info ",e);
roles = new HashSet<>();
} }
AuthenticatedUser toReturn = AuthenticatedUser toReturn =
new AuthenticatedUser(client,new HashSet<>(client.getRoles()), AccessTokenProvider.instance.get(),SecurityTokenProvider.instance.get(),context); new AuthenticatedUser(client,roles, AccessTokenProvider.instance.get(),SecurityTokenProvider.instance.get(),context);
log.info("Current User is {} ",toReturn); log.info("Current User is {} ",toReturn);
return toReturn; return toReturn;

View File

@ -31,6 +31,7 @@ import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer; import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException; import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.geojson.Crs;
import org.geojson.GeoJsonObject; import org.geojson.GeoJsonObject;
import org.geojson.LngLatAlt; import org.geojson.LngLatAlt;
import org.geojson.Point; import org.geojson.Point;
@ -157,7 +158,6 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
centroidDoc.put("geom", wkt); centroidDoc.put("geom", wkt);
throw new Exception("Not yet implemented");
} else{ } else{
// unable to use current Spatial reference, try evaluating it // unable to use current Spatial reference, try evaluating it
log.debug("UseCaseDescriptor {} : Getting evaluation paths from useCaseDescriptor.. ", useCaseDescriptor.getId()); log.debug("UseCaseDescriptor {} : Getting evaluation paths from useCaseDescriptor.. ", useCaseDescriptor.getId());
@ -188,18 +188,20 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
log.info("Evaluated BBOX {} ",toSet); log.info("Evaluated BBOX {} ",toSet);
String wkt = String .format("POINT (%1$f %2$f) ", String wkt = String .format("POINT (%1$f %2$f) ",
pointX, pointY); pointX, pointY);
//TODO support altitude
Double pointZ= 0d;
centroidDoc.put("geom",wkt); centroidDoc.put("geom",wkt);
Point toSetgeoJSON = new Point(); Point point = new Point();
LngLatAlt pointCoordinates = new LngLatAlt(); point.setCoordinates(new LngLatAlt(pointX,pointY,pointZ));
pointCoordinates.setLongitude(pointX); point.setBbox(toSet.asGeoJSONArray());
pointCoordinates.setLatitude(pointY);
toSetgeoJSON.setCoordinates(pointCoordinates);
toSetgeoJSON.setBbox(toSet.asGeoJSONArray());
reference = new SpatialReference(toSetgeoJSON);
//TODO Manage CRS
point.setCrs(new Crs());
reference = new SpatialReference(Serialization.asDocument(point));
log.info("UCD {} project {}, Setting Spatial Reference {} ",useCaseDescriptor.getId(),project.getId(),Serialization.write(reference));
report.addIdentificationReference(reference); report.addIdentificationReference(reference);
} }

View File

@ -0,0 +1,42 @@
package org.gcube.application.cms.sdi.plugins;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer;
import org.gcube.application.geoportal.common.model.document.identification.SpatialReference;
import org.geojson.Crs;
import org.geojson.GeoJsonObject;
import org.geojson.LngLatAlt;
import org.geojson.Point;
import org.geotoolkit.referencing.CRS;
import org.junit.Test;
import java.io.IOException;
public class GeoJSONTests {
@Test
public void checkFullCircle() throws IOException {
Point point = new Point();
point.setCoordinates(new LngLatAlt(13,12,0));
point.setCrs(new Crs());
point.setBbox(GCubeSDILayer.BBOX.WORLD.asGeoJSONArray());
String value = Serialization.write(point);
System.out.println("String is "+value);
GeoJsonObject obj = Serialization.read(value, GeoJsonObject.class);
System.out.println("OBJ is "+obj);
obj = Serialization.convert(point,GeoJsonObject.class);
System.out.println("Converted obj is "+obj);
SpatialReference reference =new SpatialReference(Serialization.asDocument(point));
String referenceString= Serialization.write(reference);
System.out.println("Serialized reference is "+referenceString);
reference=Serialization.read(referenceString,SpatialReference.class);
System.out.println("Deserialized reference is "+reference);
obj = Serialization.convert(reference.getGeoJson(),GeoJsonObject.class);
System.out.println("Converted from spatial reference is "+obj);
}
}