This commit is contained in:
Fabio Sinibaldi 2019-10-09 17:05:27 +00:00
parent cf19a870ee
commit c3be6b2e78
17 changed files with 551 additions and 619 deletions

View File

@ -4,7 +4,7 @@
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.0</version>
</parent>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>geonetwork</artifactId>
@ -124,7 +124,6 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
@ -177,7 +176,7 @@
</execution>
</executions>
</plugin>
</plugins>
</plugins>
<resources>
<resource>
<directory>src/xmlTemplates</directory>

View File

@ -1,34 +1,72 @@
package org.gcube.spatial.data.geonetwork.iso;
import java.net.URISyntaxException;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
import org.gcube.spatial.data.geonetwork.iso.tpl.DistributionInfo;
import org.gcube.spatial.data.geonetwork.iso.tpl.ISOMetadataByTemplate;
import org.gcube.spatial.data.geonetwork.iso.tpl.Keyword;
import org.gcube.spatial.data.geonetwork.iso.tpl.MetadataDescriptor;
import org.gcube.spatial.data.geonetwork.iso.tpl.OnlineResource;
import org.gcube.spatial.data.geonetwork.iso.tpl.ResponsibleParty;
import org.gcube.spatial.data.geonetwork.iso.tpl.DistributionInfo.DistributionInfoType;
import org.gcube.spatial.data.geonetwork.iso.tpl.ResponsibleParty.Contact;
import org.gcube.spatial.data.geonetwork.utils.StringValidator;
import org.geotoolkit.metadata.iso.extent.DefaultExtent;
import org.geotoolkit.xml.XML;
import org.opengis.metadata.Metadata;
import org.opengis.metadata.citation.PresentationForm;
import org.opengis.metadata.identification.KeywordType;
import org.opengis.metadata.identification.TopicCategory;
import org.opengis.metadata.spatial.GeometricObjectType;
import org.opengis.metadata.spatial.TopologyLevel;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@RequiredArgsConstructor
public class GcubeISOMetadata {
private EnvironmentConfiguration config;
private String user=null;
private MetadataDescriptor descriptor;
@NonNull
private String user;
@NonNull
private String lineageStatement;
//Identification
private String title=null;
private Date creationDate=null;
private PresentationForm presentationForm=null;
private String abstractField=null;
private String purpose=null;
@NonNull
private String title;
@NonNull
private Date creationDate;
@NonNull
private PresentationForm presentationForm;
@NonNull
private String abstractField;
@NonNull
private String purpose;
@NonNull
private String UUIDIdentifier;
private ArrayList<String> credits=new ArrayList<String>();
@ -38,8 +76,6 @@ public class GcubeISOMetadata {
private DefaultExtent extent=(DefaultExtent) DefaultExtent.WORLD;
//Spatial Representation
private GeometricObjectType geometricObjectType=GeometricObjectType.SURFACE;
@ -53,7 +89,7 @@ public class GcubeISOMetadata {
private ArrayList<String> graphicOverviewsURI=new ArrayList<String>();
private DistributionInfo distributionInfo;
public GcubeISOMetadata() throws Exception {
@ -82,131 +118,91 @@ public class GcubeISOMetadata {
}
public Metadata getMetadata() throws URISyntaxException, MissingInformationException{
checkConstraints();
// public File getMetadataFile() throws Exception{
// checkConstraints();
// // TODO
// MetadataDescriptor desc=new MetadataDescriptor();
// ArrayList<ResponsibleParty> respParties=new ArrayList<>();
// AuthorizationEntry authEntry = authorizationService().get(SecurityTokenProvider.instance.get());
//
// respParties.add(new ResponsibleParty(this.getUser(), "gCube Context "+authEntry.getContext(),ResponsibleParty.Roles.AUTHOR));
// respParties.add(new ResponsibleParty(config.getProjectName(), config.getProjectName(), ResponsibleParty.Roles.ORIGINATOR));
// respParties.add(new ResponsibleParty(config.getDistributorIndividualName(), config.getDistributorOrganisationName(), ResponsibleParty.Roles.DISTRIBUTOR,new Contact(config.getDistributorEMail(),config.getDistributorSite())));
// respParties.add(new ResponsibleParty(config.getProviderIndividualName(), config.getProviderOrganisationName(), ResponsibleParty.Roles.RESOURCE_PROVIDER,new Contact(config.getProviderEMail(),config.getProviderSite())));
//
// desc.setResponsibleParties(respParties);
//
// desc.setTitle(this.getTitle());
// desc.setCreationTime(this.getCreationDate());
// desc.setAbstractField(this.getAbstractField());
//
//
// //TODO Multiple Credits
// desc.setCredit(this.getCredits().get(0));
//
//
// desc.setGeometricObjectCount(new Long(this.getGeometryCount()));
//
//
// ArrayList<Keyword> keys=new ArrayList<>();
//// for(Entry<Thesaurus,HashSet<String> > entry : this.getDescriptiveKeywords().entrySet()) {
//// Thesaurus t=entry.getKey();
//// if(t.getType().equals(KeywordType.THEME))
////
//// }
// desc.setKeywords(keys);
//
//
// desc.setPublicationTime(desc.getCreationTime());
//
// desc.setPurpose(this.getPurpose());
//
// desc.setUUIDIdentifier(UUIDIdentifier!=null?UUIDIdentifier:UUID.randomUUID().toString());
// desc.setBoundingBox(BoundingBox.WORLD_EXTENT);
//
// desc.setSpatialResolution(this.getResolution());
//
//
// // TODO Multiple Categories
// desc.setTopicCategory(this.getTopicCategories().get(0).identifier());
//
//
// desc.setDistributionInfo(distributionInfo);
//
// desc.setLineageStatement(this.getLineageStatement());
//
//
// return ISOMetadataByTemplate.createXML(desc);
// }
public void setGeoServerDistributionInfo(String geoServerUrl,String layerName, String workspace, String style, String CRS) throws UriResolverMapException, IllegalArgumentException{
List<OnlineResource> resources=new ArrayList<OnlineResource>();
String bbox=BoundingBox.WORLD_EXTENT.toString();
String wmsUrl=ISOMetadataFactory.getWmsUrl(geoServerUrl, layerName, workspace, style, bbox, CRS);
String wcsUrl=ISOMetadataFactory.getWcsUrl(geoServerUrl, layerName, workspace, bbox);
String wfsUrl=ISOMetadataFactory.getWfsUrl(geoServerUrl, layerName, workspace);
String gisViewerUrl=ISOMetadataFactory.getGisLinkByUUID(UUIDIdentifier);
return ISOMetadataFactory.generateMeta(this);
resources.add(new OnlineResource(wmsUrl, "WMS Link"));
resources.add(new OnlineResource(wcsUrl, "WCS Link"));
resources.add(new OnlineResource(wfsUrl, "WFS Link"));
resources.add(new OnlineResource(gisViewerUrl, "GISViewer Link"));
distributionInfo=new DistributionInfo(DistributionInfoType.GeoServer, resources);
}
/**
* @return the user
*/
public String getUser() {
return user;
@Deprecated
public Metadata getMetadata() throws Exception{
return (Metadata) XML.unmarshal(getMetadataFile());
}
/**
* @param user the user to set
*/
public void setUser(String user) {
this.user = user;
}
/**
* @return the title
*/
public String getTitle() {
return title;
}
/**
* @param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* @return the creationDate
*/
public Date getCreationDate() {
return creationDate;
}
/**
* @param creationDate the creationDate to set
*/
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
/**
* @return the presentationForm
*/
public PresentationForm getPresentationForm() {
return presentationForm;
}
/**
* @param presentationForm the presentationForm to set
*/
public void setPresentationForm(PresentationForm presentationForm) {
this.presentationForm = presentationForm;
}
/**
* @return the abstractField
*/
public String getAbstractField() {
return abstractField;
}
/**
* @param abstractField the abstractField to set
*/
public void setAbstractField(String abstractField) {
this.abstractField = abstractField;
}
/**
* @return the extent
*/
public DefaultExtent getExtent() {
return extent;
}
/**
* @param extent the extent to set [Default is WORLD]
*/
public void setExtent(DefaultExtent extent) {
this.extent = extent;
}
/**
* @return the geometricObjectType
*/
public GeometricObjectType getGeometricObjectType() {
return geometricObjectType;
}
/**
* @param geometricObjectType the geometricObjectType to set [Default is SURFACE]
*/
public void setGeometricObjectType(GeometricObjectType geometricObjectType) {
this.geometricObjectType = geometricObjectType;
}
/**
* @return the geometryCount
*/
public int getGeometryCount() {
return geometryCount;
}
/**
* @param geometryCount the geometryCount to set [Default is 0]
*/
public void setGeometryCount(int geometryCount) {
this.geometryCount = geometryCount;
}
/**
* @return the config
*/
public EnvironmentConfiguration getConfig() {
return config;
}
// READ ONLY GETTERS AND ADDERS
/**
* @return the credits
*/
@ -275,92 +271,4 @@ public class GcubeISOMetadata {
graphicOverviewsURI.add(uri);
}
/**
* @return the purpose
*/
public String getPurpose() {
return purpose;
}
/**
* @param purpose the purpose to set
*/
public void setPurpose(String purpose) {
this.purpose = purpose;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GcubeISOMetadata [config=");
builder.append(config);
builder.append(", user=");
builder.append(user);
builder.append(", title=");
builder.append(title);
builder.append(", creationDate=");
builder.append(creationDate);
builder.append(", presentationForm=");
builder.append(presentationForm);
builder.append(", abstractField=");
builder.append(abstractField);
builder.append(", credits=");
builder.append(credits);
builder.append(", descriptiveKeywords=");
builder.append(descriptiveKeywords);
builder.append(", topicCategories=");
builder.append(topicCategories);
builder.append(", extent=");
builder.append(extent);
builder.append(", geometricObjectType=");
builder.append(geometricObjectType);
builder.append(", geometryCount=");
builder.append(geometryCount);
builder.append(", graphicOverviewsURI=");
builder.append(graphicOverviewsURI);
builder.append("]");
return builder.toString();
}
/**
*
* @return the current Topology Level
*/
public TopologyLevel getTopologyLevel() {
return topologyLevel;
}
/**
*
* @param topologyLevel the Topology level to set [Default is GEOMETRY_ONLY]
*/
public void setTopologyLevel(TopologyLevel topologyLevel) {
this.topologyLevel = topologyLevel;
}
/**
*
* @return the current layer resolution
*/
public double getResolution() {
return resolution;
}
/**
*
*
* @param resoulution The resolution to be set [Default is 0.5]
*/
public void setResolution(double resoulution) {
this.resolution = resoulution;
}
}

View File

@ -1,204 +0,0 @@
package org.gcube.spatial.data.geonetwork.iso;
import java.util.Date;
import org.opengis.metadata.identification.KeywordType;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("Thesaurus")
public class Thesaurus {
private KeywordType type;
private String title;
private Date citationDate;
private String citationDescription;
private String citationUri;
private String citationOrganization;
private boolean isAuthored=false;
public Thesaurus(KeywordType type, String title, Date citationDate) {
super();
this.type = type;
this.title = title;
this.citationDate = citationDate;
}
public Thesaurus(KeywordType type, String title, Date citationDate,
String citationDescription, String citationUri,
String citationOrganization) {
super();
this.type = type;
this.title = title;
this.citationDate = citationDate;
this.citationDescription = citationDescription;
this.citationUri = citationUri;
this.citationOrganization = citationOrganization;
this.isAuthored=true;
}
/**
* @return the type
*/
public KeywordType getType() {
return type;
}
/**
* @param type the type to set
*/
public void setType(KeywordType type) {
this.type = type;
}
/**
* @return the title
*/
public String getTitle() {
return title;
}
/**
* @param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* @return the citationDate
*/
public Date getCitationDate() {
return citationDate;
}
/**
* @param citationDate the citationDate to set
*/
public void setCitationDate(Date citationDate) {
this.citationDate = citationDate;
}
/**
* @return the citationDescription
*/
public String getCitationDescription() {
return citationDescription;
}
/**
* @param citationDescription the citationDescription to set
*/
public void setCitationDescription(String citationDescription) {
this.citationDescription = citationDescription;
}
/**
* @return the citationUri
*/
public String getCitationUri() {
return citationUri;
}
/**
* @param citationUri the citationUri to set
*/
public void setCitationUri(String citationUri) {
this.citationUri = citationUri;
}
/**
* @return the citationOrganization
*/
public String getCitationOrganization() {
return citationOrganization;
}
/**
* @param citationOrganization the citationOrganization to set
*/
public void setCitationOrganization(String citationOrganization) {
this.citationOrganization = citationOrganization;
}
/**
* @return the isAuthored
*/
public boolean isAuthored() {
return isAuthored;
}
/**
* @param isAuthored the isAuthored to set
*/
public void setAuthored(boolean isAuthored) {
this.isAuthored = isAuthored;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((title == null) ? 0 : title.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Thesaurus other = (Thesaurus) obj;
if (title == null) {
if (other.title != null)
return false;
} else if (!title.equals(other.title))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Thesaurus [type=");
builder.append(type);
builder.append(", title=");
builder.append(title);
builder.append(", citationDate=");
builder.append(citationDate);
builder.append(", citationDescription=");
builder.append(citationDescription);
builder.append(", citationUri=");
builder.append(citationUri);
builder.append(", citationOrganization=");
builder.append(citationOrganization);
builder.append(", isAuthored=");
builder.append(isAuthored);
builder.append("]");
return builder.toString();
}
}

View File

@ -61,14 +61,14 @@ public class ISOMetadataByTemplate {
public static final String createXML(MetadataDescriptor desc) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException{
public static final File createXML(MetadataDescriptor desc) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException{
Writer out=null;
try{
Template temp = cfg.getTemplate("BaseTemplate.ftlx");
File output=File.createTempFile("ISO_", ".xml");
out=new OutputStreamWriter(new FileOutputStream(output));
temp.process(desc, out);
return output.getAbsolutePath();
return output;
}finally{
if(out!=null)
IOUtils.closeQuietly(out);

View File

@ -0,0 +1,29 @@
package org.gcube.spatial.data.geonetwork.iso.tpl;
public class InvalidValueException extends Exception {
public InvalidValueException() {
// TODO Auto-generated constructor stub
}
public InvalidValueException(String arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
public InvalidValueException(Throwable arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
public InvalidValueException(String arg0, Throwable arg1) {
super(arg0, arg1);
// TODO Auto-generated constructor stub
}
public InvalidValueException(String arg0, Throwable arg1, boolean arg2, boolean arg3) {
super(arg0, arg1, arg2, arg3);
// TODO Auto-generated constructor stub
}
}

View File

@ -1,80 +0,0 @@
package org.gcube.spatial.data.geonetwork.iso.tpl;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;
@Data
@AllArgsConstructor
@ToString
public class Keyword {
public static class Types{
public static final String DISCIPLINE="discipline";
public static final String PLACE="place";
public static final String STRATUM="stratum";
public static final String TEMPORAL="temporal";
public static final String THEME="theme";
}
public static class Themes{
public static final String ADDRESSES="Addresses";
public static final String ADMINISTRATIVE_UNITS="Administrative units";
public static final String CADASTRAL_PARCELS="Cadastral parcels";
public static final String COORDINATE_REFERENCE_SYSTEM="Coordinate reference systems";
public static final String GEOGRAPHICAL_GRID_SYSTEM="Geographical grid systems";
public static final String GEOGRAPHICAL_NAMES="Geographical names";
public static final String HYDROGRAPHY="Hydrography";
public static final String PROTECTED_SITES="Protected sites";
public static final String TRANSPORT_NETWORKS="Transport networks";
// ANNEX: 2
public static final String ELEVATION="Elevation";
public static final String GEOLOGY="Geology";
public static final String LAND_COVER="Land cover";
public static final String ORTHOIMAGERY="Orthoimagery";
// ANNEX: 3
public static final String AGRICULTURAL_AND_AQUACULTURE_FACILITIES="Agricultural and aquaculture facilities";
public static final String AREA_MANAGEMENT_RESTRICTION_REGULATION_ZONES_AND_REPORT_UNITS="Area management / restriction / regulation zones & reporting units";
public static final String ATMOSPHERIC_CONDITIONS="Atmospheric conditions";
public static final String BIO_GEOGRAPHICAL_REGIONS="Bio-geographical regions";
public static final String BUILDINGS="Buildings";
public static final String ENERGY_RESOURCES="Energy Resources";
public static final String ENVINROMENTAL_MONITORING_FACILITIES="Environmental monitoring Facilities";
public static final String HABITATS_AND_BIOTOPES="Habitats and biotopes";
public static final String HUMAN_HEALTH_AND_SAFETY="Human health and safety";
public static final String LAND_USE="Land use";
public static final String METEOROLOGICAL_GEOGRAPHICAL_FEATURES="Meteorological geographical features";
public static final String MINERAL_RESOURCES="Mineral Resources";
public static final String NATURAL_RISK_ZONES="Natural risk zones";
public static final String OCEANOGRAPHIC_GEOGRAPHICAL_FEATURES="Oceanographic geographical features";
public static final String POPULATION_DISTRIBUTION_AND_DEMOGRAPHY="Population distribution and demography";
public static final String PRODUCTION_AND_INDUSTRIAL_FACILITIES="Production and industrial facilities";
public static final String SEA_REGIONS="Sea regions";
public static final String SOIL="Soil";
public static final String SPECIES_DISTRIBUTION="Species distribution";
public static final String STATISTICAL_UNITS="Statistical units";
public static final String UTILITY_AND_GOVERNMENTAL_SERVICES="Utility and governmental services";
}
public static final Date INSPIRE_THEME_PUBLICATION_TIME=new Date(2008,06,01);
public static final String INSPIRE_THEME_THESAURUS_NAME="GEMET - INSPIRE themes, version 1.0";
private Collection<String> values;
private Date creationDate;
private String type;
private String thesaurus;
public static Keyword getInspireTheme(String theme){
return new Keyword(Collections.singleton(theme), INSPIRE_THEME_PUBLICATION_TIME, Types.THEME, INSPIRE_THEME_THESAURUS_NAME);
}
}

View File

@ -10,6 +10,7 @@ import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapExcept
import org.gcube.spatial.data.geonetwork.iso.BoundingBox;
import org.gcube.spatial.data.geonetwork.iso.ISOMetadataFactory;
import org.gcube.spatial.data.geonetwork.iso.tpl.DistributionInfo.DistributionInfoType;
import org.gcube.spatial.data.geonetwork.iso.tpl.keys.KeywordSet;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -36,7 +37,7 @@ public class MetadataDescriptor {
private String purpose;
private String credit;
private Collection<Keyword> keywords;
private ArrayList<KeywordSet> keywordSets=new ArrayList<>();
private DistributionInfo distributionInfo;
@ -44,13 +45,14 @@ public class MetadataDescriptor {
private Double spatialResolution;
private String topicCategory;
private String guidelinesConformityExplanation;
private Boolean guidelinesConformityPass;
private String referenceSystem="WGS:84";
private String lineageStatement;
public void setGeoServerDistributionInfo(String geoServerUrl,String layerName, String workspace, String style, String CRS) throws UriResolverMapException, IllegalArgumentException{
List<OnlineResource> resources=new ArrayList<OnlineResource>();
String bbox=this.getBoundingBox().toString();

View File

@ -0,0 +1,39 @@
package org.gcube.spatial.data.geonetwork.iso.tpl.keys;
import java.util.HashSet;
import java.util.Set;
import org.gcube.spatial.data.geonetwork.iso.tpl.InvalidValueException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
@AllArgsConstructor
public class KeywordSet {
@NonNull
private KeywordType type;
private Set<String> values=new HashSet<>();
private Thesaurus thesaurus;
public void validate() throws InvalidValueException{
if(values.isEmpty()) throw new InvalidValueException("KeywordSet cannot be empty. Thesaurus is : "+thesaurus);
if(thesaurus!=null)
for(String v:values) {
if(!thesaurus.validate(v))
throw new InvalidValueException("Invalid value "+v+" for Thesaurus : "+thesaurus);
}
}
public KeywordSet(KeywordType type, Thesaurus thesaurus) {
super();
this.type = type;
this.thesaurus = thesaurus;
}
}

View File

@ -0,0 +1,21 @@
package org.gcube.spatial.data.geonetwork.iso.tpl.keys;
public enum KeywordType {
DISCIPLINE("discipline"),
PLACE("place"),
STRATUM("stratum"),
TEMPORAL("temporal"),
THEME("theme");
private final String id;
KeywordType(String id) {
this.id=id;
}
public String getId() {
return id;
}
}

View File

@ -0,0 +1,90 @@
package org.gcube.spatial.data.geonetwork.iso.tpl.keys;
import java.util.Date;
import java.util.HashSet;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@AllArgsConstructor
public class Thesaurus {
public static final Thesaurus INSPIRE_THEMES=new Thesaurus("GEMET - INSPIRE themes, version 1.0", new Date(2008,06,01));
static {
INSPIRE_THEMES.codelist.add("Addresses");
INSPIRE_THEMES.codelist.add("Administrative units");
INSPIRE_THEMES.codelist.add("Cadastral parcels");
INSPIRE_THEMES.codelist.add("Coordinate reference systems");
INSPIRE_THEMES.codelist.add("Geographical grid systems");
INSPIRE_THEMES.codelist.add("Geographical names");
INSPIRE_THEMES.codelist.add("Hydrography");
INSPIRE_THEMES.codelist.add("Protected sites");
INSPIRE_THEMES.codelist.add("Transport networks");
// ANNEX: 2
INSPIRE_THEMES.codelist.add("Elevation");
INSPIRE_THEMES.codelist.add("Geology");
INSPIRE_THEMES.codelist.add("Land cover");
INSPIRE_THEMES.codelist.add("Orthoimagery");
// ANNEX: 3
INSPIRE_THEMES.codelist.add("Agricultural and aquaculture facilities");
INSPIRE_THEMES.codelist.add("Area management / restriction / regulation zones & reporting units");
INSPIRE_THEMES.codelist.add("Atmospheric conditions");
INSPIRE_THEMES.codelist.add("Bio-geographical regions");
INSPIRE_THEMES.codelist.add("Buildings");
INSPIRE_THEMES.codelist.add("Energy Resources");
INSPIRE_THEMES.codelist.add("Environmental monitoring Facilities");
INSPIRE_THEMES.codelist.add("Habitats and biotopes");
INSPIRE_THEMES.codelist.add("Human health and safety");
INSPIRE_THEMES.codelist.add("Land use");
INSPIRE_THEMES.codelist.add("Meteorological geographical features");
INSPIRE_THEMES.codelist.add("Mineral Resources");
INSPIRE_THEMES.codelist.add("Natural risk zones");
INSPIRE_THEMES.codelist.add("Oceanographic geographical features");
INSPIRE_THEMES.codelist.add("Population distribution and demography");
INSPIRE_THEMES.codelist.add("Production and industrial facilities");
INSPIRE_THEMES.codelist.add("Sea regions");
INSPIRE_THEMES.codelist.add("Soil");
INSPIRE_THEMES.codelist.add("Species distribution");
INSPIRE_THEMES.codelist.add("Statistical units");
INSPIRE_THEMES.codelist.add("Utility and governmental services");
}
@NonNull
private String name;
@NonNull
private Date creationDate;
private HashSet<String> codelist=new HashSet<String>();
public HashSet<String> codelistValues(){
return (HashSet<String>) codelist.clone();
}
public boolean validate(String value) {
return codelist.contains(value);
}
public Date getCreationDate() {
return creationDate;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "Thesaurus [name=" + name + "]";
}
}

View File

@ -24,7 +24,7 @@ import it.geosolutions.geonetwork.util.GNSearchResponse.GNMetadata;
public class LoginTest {
private static final String defaultScope="/gcube/devsec/devVRE";
private static final String defaultScope="/gcube/devNext";
// private static final String defaultScope="/gcube";
// private static final String defaultScope="/d4science.research-infrastructures.eu/gCubeApps";
@ -36,28 +36,28 @@ public class LoginTest {
TokenSetter.set(defaultScope);
// System.out.println("Checking scope : "+defaultScope);
// GeoNetworkReader reader=GeoNetwork.get();
// reader.login(LoginLevel.CKAN);
// System.out.println(queryAll(reader));
GeoNetworkReader reader=GeoNetwork.get();
reader.login(LoginLevel.CKAN);
System.out.println(queryAll(reader));
//
// Filter second search
TokenSetter.set("/gcube");
GeoNetworkReader reader=GeoNetwork.get();
reader.login(LoginLevel.DEFAULT);
List<Long> firstLevelIds=getIds(queryAll(reader));
System.out.println("First Level count : "+firstLevelIds.size());
TokenSetter.set("/gcube/devsec/devVRE");
reader=GeoNetwork.get();
reader.login(LoginLevel.CKAN);
List<Long> secondLevelIds=getIds(queryAll(reader));
System.out.println("Second Level count "+secondLevelIds.size());
secondLevelIds.removeAll(firstLevelIds);
System.out.println("Second level filtered count : "+secondLevelIds.size());
System.out.println("IDS : ");
System.out.println(secondLevelIds);
// TokenSetter.set("/gcube");
// GeoNetworkReader reader=GeoNetwork.get();
// reader.login(LoginLevel.DEFAULT);
// List<Long> firstLevelIds=getIds(queryAll(reader));
//
// System.out.println("First Level count : "+firstLevelIds.size());
// TokenSetter.set("/gcube/devsec/devVRE");
// reader=GeoNetwork.get();
// reader.login(LoginLevel.CKAN);
// List<Long> secondLevelIds=getIds(queryAll(reader));
// System.out.println("Second Level count "+secondLevelIds.size());
// secondLevelIds.removeAll(firstLevelIds);
// System.out.println("Second level filtered count : "+secondLevelIds.size());
// System.out.println("IDS : ");
// System.out.println(secondLevelIds);
// String metaFile="meta.xml";
@ -69,7 +69,7 @@ public class LoginTest {
// }
// checkLevelsCount();
checkLevelsCount();
// getMetaById("5a68c6a4-916b-4789-8442-ee3a4aac14d5", LoginLevel.DEFAULT);

View File

@ -51,8 +51,7 @@ public class MyApplicationIsoMetadata extends GcubeISOMetadata {
@Override
public Metadata getMetadata() throws URISyntaxException,
MissingInformationException {
public Metadata getMetadata() throws Exception {
Metadata toReturn=super.getMetadata();
//We set our mandatory field to the metadata
return toReturn;

View File

@ -34,7 +34,7 @@ public class TestConfiguration {
toUseConfiguration=new LocalResourceConfiguration(resConfig);
// toUseConfiguration=new DefaultConfiguration();
toUseConfiguration=new DefaultConfiguration();
}
return GeoNetwork.get(toUseConfiguration);
}

View File

@ -2,6 +2,7 @@ package org.gcube.spatial.data.geonetwork.test;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.UUID;
@ -9,10 +10,12 @@ import org.gcube.spatial.data.geonetwork.GeoNetworkPublisher;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.gcube.spatial.data.geonetwork.iso.BoundingBox;
import org.gcube.spatial.data.geonetwork.iso.tpl.ISOMetadataByTemplate;
import org.gcube.spatial.data.geonetwork.iso.tpl.Keyword;
import org.gcube.spatial.data.geonetwork.iso.tpl.MetadataDescriptor;
import org.gcube.spatial.data.geonetwork.iso.tpl.ResponsibleParty;
import org.gcube.spatial.data.geonetwork.iso.tpl.ResponsibleParty.Contact;
import org.gcube.spatial.data.geonetwork.iso.tpl.keys.KeywordSet;
import org.gcube.spatial.data.geonetwork.iso.tpl.keys.KeywordType;
import org.gcube.spatial.data.geonetwork.iso.tpl.keys.Thesaurus;
import it.geosolutions.geonetwork.util.GNInsertConfiguration;
@ -23,9 +26,13 @@ public class TrueMarbleMeta {
* @throws Exception
*/
public static void main(String[] args) throws Exception {
TokenSetter.set("/gcube/devsec");
TokenSetter.set("/gcube/devNext");
// TokenSetter.set("/pred4s/preprod/preVRE");
// TokenSetter.set("/d4science.research-infrastructures.eu");
// GCUBE OBJECT
// GcubeISOMetadata gMeta=new GcubeISOMetadata();
// gMeta.setAbstractField("This layer is used as a base layer for GIS VIewer widget");
// gMeta.setCreationDate(new Date(System.currentTimeMillis()));
@ -38,9 +45,75 @@ public class TrueMarbleMeta {
// Thesaurus general=gMeta.getConfig().getThesauri().get("General");
// gMeta.addKeyword("True Marble", general);
// gMeta.addTopicCategory(TopicCategory.ENVIRONMENT);
//
// Metadata meta=gMeta.getMetadata();
//
// ((DefaultMetadata)meta).setDistributionInfo(ISOMetadataFactory.getDistributionByLayer("TrueMarble.16km.2700x1350", "http://geoserver-dev.d4science.org/geoserver", "raster", "-180.0,-90.0,180.0,90.0", gMeta.getConfig()));
// XML.marshal(meta, new File("TrueMarble.xml"));
// VASSILIS
// GcubeISOMetadata gMeta=new GcubeISOMetadata();
// gMeta.setAbstractField("Layer from geopolis");
// gMeta.setCreationDate(new Date());
// gMeta.setExtent((DefaultExtent) DefaultExtent.WORLD);
// gMeta.setGeometricObjectType(GeometricObjectType.SURFACE);
// gMeta.setPresentationForm(PresentationForm.valueOf(PresentationForm.MAP_DIGITAL.name()));
// gMeta.setResolution(1.2);
// gMeta.setPurpose("Test library");
// gMeta.setTitle("Title");
// gMeta.setTopologyLevel(TopologyLevel.GEOMETRY_ONLY);
// gMeta.setUser("Some user");
//
// gMeta.addCredits("Team of geospatialists");
// gMeta.addGraphicOverview("http://localhost:8080/wms/something");
//
// Thesaurus generalThesaurus = gMeta.getConfig().getThesauri().get("General");
// gMeta.addKeyword("key1", generalThesaurus);
// gMeta.addKeyword("key2", generalThesaurus);
// gMeta.addTopicCategory(TopicCategory.ENVIRONMENT);
// gMeta.setGeoServerDistributionInfo("http://geoserver.d4science.org/geoserver", "ws","wmpa", "speciesProb", "EPSG:4326");
//
// gMeta.setLineageStatement("I made with my own hands");
//
// Metadata meta=gMeta.getMetadata();
GeoNetworkPublisher publisher=TestConfiguration.getClient();
publisher.login(LoginLevel.SCOPE);
GNInsertConfiguration config=publisher.getCurrentUserConfiguration("dataset", "_none_");
config.setValidate(true);
//Long id=publisher.insertMetadata(config,new File("/tmp/GEO_1069334659927122420.xml"));
// try{
// Long id=publisher.insertMetadata(config,meta);
// System.out.println("Inserted meta with id : "+id);
// }catch(Throwable t) {
// try{
// System.out.println("Trying with file...");
// File f=gMeta.getMetadataFile();
//
// System.out.println("Going to publish : "+f.getAbsolutePath());
// System.out.println("Inserted meta with id : "+publisher.insertMetadata(config,f));
// }catch(Throwable t1) {
// System.err.println("Unable to push meta : ");
//
// t1.printStackTrace(System.err);
// }
// }
// TEMPLATES
MetadataDescriptor desc=new MetadataDescriptor();
desc.setResponsibleParties(Arrays.asList(
new ResponsibleParty("The scope ","the infra",ResponsibleParty.Roles.DISTRIBUTOR,new Contact("my.mail@this.place.com","www.mipiacitu.com")),
@ -57,7 +130,7 @@ public class TrueMarbleMeta {
desc.setCreationTime(new GregorianCalendar().getTime());
desc.setGeometricObjectCount(1000l);
desc.setKeywords(Arrays.asList(Keyword.getInspireTheme(Keyword.Themes.SEA_REGIONS)));
desc.getKeywordSets().add(new KeywordSet(KeywordType.THEME,Collections.singleton("Species distribution"),Thesaurus.INSPIRE_THEMES));
desc.setPublicationTime(desc.getCreationTime());
desc.setPurpose("Just for fun");
@ -69,30 +142,21 @@ public class TrueMarbleMeta {
desc.setTopicCategory("environment");
desc.setLineageStatement("I made with my own hands");
System.out.println(desc.getBoundingBox());
String metaPath=ISOMetadataByTemplate.createXML(desc);
System.out.println("Going to Publish ----->> "+metaPath);
GeoNetworkPublisher publisher=TestConfiguration.getClient();
publisher.login(LoginLevel.SCOPE);
GNInsertConfiguration config=publisher.getCurrentUserConfiguration("dataset", "_none_");
long id=publisher.insertMetadata(config, new File(metaPath));
System.out.println("PUBLISHED WITH ID : "+id);
// Metadata meta=gMeta.getMetadata();
//
// ((DefaultMetadata)meta).setDistributionInfo(ISOMetadataFactory.getDistributionByLayer("TrueMarble.16km.2700x1350", "http://geoserver-dev.d4science.org/geoserver", "raster", "-180.0,-90.0,180.0,90.0", gMeta.getConfig()));
// XML.marshal(meta, new File("TrueMarble.xml"));
File metaFile=ISOMetadataByTemplate.createXML(desc);
System.out.println("Going to Publish ----->> "+metaFile.getAbsolutePath());
// GeoNetworkPublisher publisher=TestConfiguration.getClient();
// publisher.login(LoginLevel.SCOPE);
// GNInsertConfiguration config=publisher.getCurrentUserConfiguration("dataset", "_none_");
//
// //Long id=publisher.insertMetadata(config,new File("/tmp/GEO_1069334659927122420.xml"));
// Long id=publisher.insertMetadata(config,meta);
// System.out.println("Inserted meta with id : "+id);
// config.setValidate(true);
System.out.println("Settings : "+publisher.getConfiguration().getScopeConfiguration());
System.out.println("Publishing Settings : validate = "+config.getValidate());
long id=publisher.insertMetadata(config, metaFile);
System.out.println("PUBLISHED WITH ID : "+id);
}

View File

@ -1,4 +1,4 @@
log4j.rootLogger=DEBUG, A1,stdout
#log4j.rootLogger=DEBUG, A1,stdout
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=log.txt
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
@ -8,6 +8,9 @@ log4j.appender.A1.MaxFileSize=100MB
# ***** Keep one backup file
log4j.appender.A1.MaxBackupIndex=1
#CONSOLE
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=DEBUG

View File

@ -1,10 +1,12 @@
<#setting url_escaping_charset='ISO-8859-1'>
<#include "Macros.ftlx">
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gmd:MD_Metadata xmlns:gco="http://www.isotc211.org/2005/gco"
xmlns:fra="http://www.cnig.gouv.fr/2005/fra" xmlns:gmx="http://www.isotc211.org/2005/gmx"
xmlns:gmi="http://www.isotc211.org/2005/gmi" xmlns:gmd="http://www.isotc211.org/2005/gmd"
xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xlink="http://www.w3.org/1999/xlink">
<#compress>
<gmd:fileIdentifier>
<gco:CharacterString>${UUIDIdentifier}</gco:CharacterString>
</gmd:fileIdentifier>
@ -23,12 +25,10 @@
<!-- RESPONSIBLE PARTIES : contact-->
<#list responsibleParties as responsibleParty>
<gmd:contact>
<#include "ResponsibleParty.ftlx">
</gmd:contact>
<#list responsibleParties as party>
<gmd:contact>
<@responsibleParty party.individualName party.organization party.contact.email party.contact.site party.role/>
</gmd:contact>
</#list>
@ -38,7 +38,12 @@
<gco:DateTime>${.now?iso_utc}</gco:DateTime>
</gmd:dateStamp>
<gmd:metadataStandardName>
<gco:CharacterString>ISO19115</gco:CharacterString>
</gmd:metadataStandardName>
<gmd:metadataStandardVersion>
<gco:CharacterString>2003/Cor.1:2006</gco:CharacterString>
</gmd:metadataStandardVersion>
<!-- SPATIAL REPRESENTATION INFO -->
@ -62,18 +67,22 @@
</gmd:geometricObjects>
</gmd:MD_VectorSpatialRepresentation>
</gmd:spatialRepresentationInfo>
<gmd:referenceSystemInfo>
<gmd:MD_ReferenceSystem>
<gmd:referenceSystemIdentifier>
<gmd:RS_Identifier>
<gmd:code>
<gco:CharacterString>http://www.opengis.net/def/crs/EPSG/0/4326</gco:CharacterString>
</gmd:code>
</gmd:RS_Identifier>
</gmd:referenceSystemIdentifier>
</gmd:MD_ReferenceSystem>
</gmd:referenceSystemInfo>
<!-- REFERENCE SYSTEM -->
<gmd:referenceSystemInfo>
<gmd:MD_ReferenceSystem>
<gmd:referenceSystemIdentifier>
<gmd:RS_Identifier>
<gmd:code>
<gco:CharacterString>${referenceSystem}</gco:CharacterString>
</gmd:code>
</gmd:RS_Identifier>
</gmd:referenceSystemIdentifier>
</gmd:MD_ReferenceSystem>
</gmd:referenceSystemInfo>
<!-- IDENTIFICATION INFO -->
<gmd:identificationInfo>
@ -121,14 +130,13 @@
<!-- RESPONSIBLE PARTIES -->
<#list responsibleParties as responsibleParty>
<gmd:pointOfContact>
<#include "ResponsibleParty.ftlx">
</gmd:pointOfContact>
<#list responsibleParties as party>
<#if party.role == "pointOfContact">
<@responsibleParty party.individualName party.organization party.contact.email party.contact.site party.role/>
</#if>
</#list>
</gmd:pointOfContact>
<gmd:resourceMaintenance>
<gmd:MD_MaintenanceInformation>
@ -141,40 +149,8 @@
</gmd:resourceMaintenance>
<!-- KEYWORDS -->
<#list keywords as keyword>
<gmd:descriptiveKeywords>
<gmd:MD_Keywords>
<#list keyword.values as value>
<gmd:keyword>
<gco:CharacterString>${value}</gco:CharacterString>
</gmd:keyword>
</#list>
<gmd:type>
<gmd:MD_KeywordTypeCode codeListValue="${keyword.type}"
codeList="http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#MD_KeywordTypeCode"/>
</gmd:type>
<gmd:thesaurusName>
<gmd:CI_Citation>
<gmd:title>
<gco:CharacterString>${keyword.thesaurus}</gco:CharacterString>
</gmd:title>
<gmd:date>
<gmd:CI_Date>
<gmd:date>
<gco:Date>${keyword.creationDate?string["yyyy-MM-dd"]}</gco:Date>
</gmd:date>
<gmd:dateType>
<gmd:CI_DateTypeCode codeSpace="eng"
codeListValue="publication"
codeList="http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#CI_DateTypeCode"/>
</gmd:dateType>
</gmd:CI_Date>
</gmd:date>
</gmd:CI_Citation>
</gmd:thesaurusName>
</gmd:MD_Keywords>
</gmd:descriptiveKeywords>
<#list keywordSets as keywordSet>
<@keywords keywordSet/>
</#list>
@ -374,3 +350,4 @@
</gmd:metadataConstraints>
-->
</gmd:MD_Metadata>
</#compress>

View File

@ -0,0 +1,85 @@
<#macro responsibleParty name organization mail site role>
<gmd:CI_ResponsibleParty>
<gmd:individualName>
<gco:CharacterString>${name}</gco:CharacterString>
</gmd:individualName>
<gmd:organisationName>
<gco:CharacterString>${organization}</gco:CharacterString>
</gmd:organisationName>
<gmd:contactInfo>
<gmd:CI_Contact>
<gmd:address>
<gmd:CI_Address>
<gmd:electronicMailAddress>
<gco:CharacterString>${mail}</gco:CharacterString>
</gmd:electronicMailAddress>
</gmd:CI_Address>
</gmd:address>
<gmd:onlineResource>
<gmd:CI_OnlineResource>
<gmd:linkage>
<gmd:URL>${site}</gmd:URL>
</gmd:linkage>
<gmd:protocol>
<gco:CharacterString>WWW:LINK-1.0-http--link</gco:CharacterString>
</gmd:protocol>
<gmd:name>
<gco:CharacterString>${name} site.</gco:CharacterString>
</gmd:name>
</gmd:CI_OnlineResource>
</gmd:onlineResource>
</gmd:CI_Contact>
</gmd:contactInfo>
<gmd:role>
<gmd:CI_RoleCode codeListValue="${role}"
codeList="http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#CI_RoleCode"/>
</gmd:role>
</gmd:CI_ResponsibleParty>
</#macro>
<#macro keywords set>
<gmd:descriptiveKeywords>
<gmd:MD_Keywords>
<#list set.values as value>
<gmd:keyword>
<gco:CharacterString>${value}</gco:CharacterString>
</gmd:keyword>
</#list>
<#if set.type??>
<gmd:type>
<gmd:MD_KeywordTypeCode codeListValue="${set.type}"
codeList="http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#MD_KeywordTypeCode"/>
</gmd:type>
</#if>
<#if set.thesaurus??>
<gmd:thesaurusName>
<gmd:CI_Citation>
<gmd:title>
<gco:CharacterString>${set.thesaurus.name}</gco:CharacterString>
</gmd:title>
<gmd:date>
<gmd:CI_Date>
<gmd:date>
<gco:Date>${set.thesaurus.creationDate?string["yyyy-MM-dd"]}</gco:Date>
</gmd:date>
<gmd:dateType>
<gmd:CI_DateTypeCode codeSpace="eng"
codeListValue="publication"
codeList="http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#CI_DateTypeCode"/>
</gmd:dateType>
</gmd:CI_Date>
</gmd:date>
</gmd:CI_Citation>
</gmd:thesaurusName>
</#if>
</gmd:MD_Keywords>
</gmd:descriptiveKeywords>
</#macro>