diff --git a/pom.xml b/pom.xml index c3669c8..312230a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ maven-parent org.gcube.tools - 1.1.0-SNAPSHOT + 1.1.0 org.gcube.spatial.data geonetwork @@ -124,7 +124,6 @@ junit junit 4.11 - test @@ -177,7 +176,7 @@ - + src/xmlTemplates diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/iso/GcubeISOMetadata.java b/src/main/java/org/gcube/spatial/data/geonetwork/iso/GcubeISOMetadata.java index c71770c..480bb04 100644 --- a/src/main/java/org/gcube/spatial/data/geonetwork/iso/GcubeISOMetadata.java +++ b/src/main/java/org/gcube/spatial/data/geonetwork/iso/GcubeISOMetadata.java @@ -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 credits=new ArrayList(); @@ -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 graphicOverviewsURI=new ArrayList(); - + 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 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 keys=new ArrayList<>(); +//// for(Entry > 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 resources=new ArrayList(); + 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; - } - - - - } diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/iso/Thesaurus.java b/src/main/java/org/gcube/spatial/data/geonetwork/iso/Thesaurus.java deleted file mode 100644 index 3698a1a..0000000 --- a/src/main/java/org/gcube/spatial/data/geonetwork/iso/Thesaurus.java +++ /dev/null @@ -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(); - } - -} diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/ISOMetadataByTemplate.java b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/ISOMetadataByTemplate.java index 4993f69..75a5e98 100644 --- a/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/ISOMetadataByTemplate.java +++ b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/ISOMetadataByTemplate.java @@ -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); diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/InvalidValueException.java b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/InvalidValueException.java new file mode 100644 index 0000000..abbacdc --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/InvalidValueException.java @@ -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 + } + +} diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/Keyword.java b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/Keyword.java deleted file mode 100644 index 2cd6b8a..0000000 --- a/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/Keyword.java +++ /dev/null @@ -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 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); - } -} diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/MetadataDescriptor.java b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/MetadataDescriptor.java index 73e299a..4d9e7f9 100644 --- a/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/MetadataDescriptor.java +++ b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/MetadataDescriptor.java @@ -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 keywords; + private ArrayList 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 resources=new ArrayList(); String bbox=this.getBoundingBox().toString(); diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/keys/KeywordSet.java b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/keys/KeywordSet.java new file mode 100644 index 0000000..43089f7 --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/keys/KeywordSet.java @@ -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 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; + } + +} diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/keys/KeywordType.java b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/keys/KeywordType.java new file mode 100644 index 0000000..c621818 --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/keys/KeywordType.java @@ -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; + } + +} diff --git a/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/keys/Thesaurus.java b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/keys/Thesaurus.java new file mode 100644 index 0000000..d577709 --- /dev/null +++ b/src/main/java/org/gcube/spatial/data/geonetwork/iso/tpl/keys/Thesaurus.java @@ -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 codelist=new HashSet(); + + public HashSet codelistValues(){ + return (HashSet) 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 + "]"; + } + + +} diff --git a/src/test/java/org/gcube/spatial/data/geonetwork/test/LoginTest.java b/src/test/java/org/gcube/spatial/data/geonetwork/test/LoginTest.java index 15035b4..b808cbf 100644 --- a/src/test/java/org/gcube/spatial/data/geonetwork/test/LoginTest.java +++ b/src/test/java/org/gcube/spatial/data/geonetwork/test/LoginTest.java @@ -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 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 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 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 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); diff --git a/src/test/java/org/gcube/spatial/data/geonetwork/test/MyApplicationIsoMetadata.java b/src/test/java/org/gcube/spatial/data/geonetwork/test/MyApplicationIsoMetadata.java index 361263f..4dbfff7 100644 --- a/src/test/java/org/gcube/spatial/data/geonetwork/test/MyApplicationIsoMetadata.java +++ b/src/test/java/org/gcube/spatial/data/geonetwork/test/MyApplicationIsoMetadata.java @@ -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; diff --git a/src/test/java/org/gcube/spatial/data/geonetwork/test/TestConfiguration.java b/src/test/java/org/gcube/spatial/data/geonetwork/test/TestConfiguration.java index fa9ee2c..49f8e1d 100644 --- a/src/test/java/org/gcube/spatial/data/geonetwork/test/TestConfiguration.java +++ b/src/test/java/org/gcube/spatial/data/geonetwork/test/TestConfiguration.java @@ -34,7 +34,7 @@ public class TestConfiguration { toUseConfiguration=new LocalResourceConfiguration(resConfig); -// toUseConfiguration=new DefaultConfiguration(); + toUseConfiguration=new DefaultConfiguration(); } return GeoNetwork.get(toUseConfiguration); } diff --git a/src/test/java/org/gcube/spatial/data/geonetwork/test/TrueMarbleMeta.java b/src/test/java/org/gcube/spatial/data/geonetwork/test/TrueMarbleMeta.java index 8694153..e77edde 100644 --- a/src/test/java/org/gcube/spatial/data/geonetwork/test/TrueMarbleMeta.java +++ b/src/test/java/org/gcube/spatial/data/geonetwork/test/TrueMarbleMeta.java @@ -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); + + + } diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties index 8e07125..a7ee947 100644 --- a/src/test/resources/log4j.properties +++ b/src/test/resources/log4j.properties @@ -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 diff --git a/src/xmlTemplates/BaseTemplate.ftlx b/src/xmlTemplates/BaseTemplate.ftlx index 45f75e8..30ef7a0 100644 --- a/src/xmlTemplates/BaseTemplate.ftlx +++ b/src/xmlTemplates/BaseTemplate.ftlx @@ -1,10 +1,12 @@ <#setting url_escaping_charset='ISO-8859-1'> +<#include "Macros.ftlx"> + <#compress> ${UUIDIdentifier} @@ -23,12 +25,10 @@ - <#list responsibleParties as responsibleParty> - - - <#include "ResponsibleParty.ftlx"> - - + <#list responsibleParties as party> + + <@responsibleParty party.individualName party.organization party.contact.email party.contact.site party.role/> + @@ -38,7 +38,12 @@ ${.now?iso_utc} - + + ISO19115 + + + 2003/Cor.1:2006 + @@ -62,18 +67,22 @@ - - - - - - http://www.opengis.net/def/crs/EPSG/0/4326 - - - - - + + + + + + + + ${referenceSystem} + + + + + + + @@ -121,14 +130,13 @@ - <#list responsibleParties as responsibleParty> - - <#include "ResponsibleParty.ftlx"> - - + <#list responsibleParties as party> + <#if party.role == "pointOfContact"> + <@responsibleParty party.individualName party.organization party.contact.email party.contact.site party.role/> + - + @@ -141,40 +149,8 @@ - - <#list keywords as keyword> - - - <#list keyword.values as value> - - ${value} - - - - - - - - - ${keyword.thesaurus} - - - - - ${keyword.creationDate?string["yyyy-MM-dd"]} - - - - - - - - - - + <#list keywordSets as keywordSet> + <@keywords keywordSet/> @@ -374,3 +350,4 @@ --> + diff --git a/src/xmlTemplates/Macros.ftlx b/src/xmlTemplates/Macros.ftlx new file mode 100644 index 0000000..69dade0 --- /dev/null +++ b/src/xmlTemplates/Macros.ftlx @@ -0,0 +1,85 @@ +<#macro responsibleParty name organization mail site role> + + + ${name} + + + ${organization} + + + + + + + + + ${mail} + + + + + + + ${site} + + + WWW:LINK-1.0-http--link + + + ${name} site. + + + + + + + + + + + + + + + +<#macro keywords set> + + + <#list set.values as value> + + ${value} + + + + <#if set.type??> + + + + + + <#if set.thesaurus??> + + + + ${set.thesaurus.name} + + + + + ${set.thesaurus.creationDate?string["yyyy-MM-dd"]} + + + + + + + + + + + + \ No newline at end of file