Gianpaolo Coro 2014-03-06 11:57:09 +00:00
parent 9b76e5e8a6
commit 386ad5dfcf
1 changed files with 178 additions and 0 deletions

View File

@ -648,4 +648,182 @@ public class GenericLayerMetadata {
}
return categories;
}
public Metadata createBasicMeta(String[] urls,String[] protocols) throws Exception {
// layer uri: wms, wfs wcs
List<String> layerUris = new ArrayList<String>();
for (int i=0;i<urls.length;i++)
layerUris.add(urls[i].trim());
// layer keywords
HashMap<KeywordType, HashSet<String>> descriptiveKeyWords = new HashMap<KeywordType, HashSet<String>>();
HashSet<String> keySet = new HashSet<String>();
if (customTopics!=null)
keySet.addAll(customTopics);
descriptiveKeyWords.put(KeywordType.THEME, keySet);
if (startDate!=null){
HashSet<String> temporalkeySet = new HashSet<String>();
temporalkeySet.add(startDate.toString());
if (!endDate.equals(startDate))
temporalkeySet.add(endDate.toString());
descriptiveKeyWords.put(KeywordType.TEMPORAL, temporalkeySet);
}
// author:
DefaultResponsibleParty party = new DefaultResponsibleParty();
party.setIndividualName(author);
DefaultContact contact = new DefaultContact();
contact.setContactInstructions(new DefaultInternationalString(contactInfo));
party.setContactInfo(contact);
party.setRole(Role.ORIGINATOR);
// citation:
DefaultCitation citation = new DefaultCitation();
citation.setTitle(new DefaultInternationalString(title));
ArrayList<DefaultCitationDate> citDates = new ArrayList<DefaultCitationDate>();
citDates.add(new DefaultCitationDate(sourceGenerationDate, DateType.CREATION));
citDates.add(new DefaultCitationDate(sourceGenerationDate, DateType.PUBLICATION));
citDates.add(new DefaultCitationDate(sourceGenerationDate, DateType.REVISION));
citation.setDates(citDates);
ArrayList<InternationalString> citAltTitle = new ArrayList<InternationalString>();
citAltTitle.add(new DefaultInternationalString(title));
citation.setAlternateTitles(citAltTitle);
citation.setEditionDate(sourceGenerationDate);
citation.getPresentationForms().add(PresentationForm.MAP_DIGITAL);
ArrayList<DefaultKeywords> keywordslist = new ArrayList<DefaultKeywords>();
for (Entry<KeywordType, HashSet<String>> entry : descriptiveKeyWords.entrySet()) {
DefaultKeywords keywords = new DefaultKeywords();
for (String key : entry.getValue())
keywords.getKeywords().add(new DefaultInternationalString(key));
keywords.setType(entry.getKey());
DefaultCitation thesaurus = new DefaultCitation();
thesaurus.setTitle(new DefaultInternationalString("General"));
thesaurus.setDates(citDates);
keywords.setThesaurusName(thesaurus);
keywordslist.add(keywords);
}
// usage:
DefaultUsage usage = new DefaultUsage();
usage.setSpecificUsage(new DefaultInternationalString(usageField));
usage.setUsageDate(sourceGenerationDate);
usage.setUserDeterminedLimitations(new DefaultInternationalString(usageLimitations));
usage.setUserContactInfo(new ArrayList<ResponsibleParty>(Arrays.asList(party)));
ArrayList<DefaultUsage> usages = new ArrayList<DefaultUsage>(Arrays.asList(usage));
//build categories by guessing on the filename
List<TopicCategory> categories = guessTopicCategory(categoryTypes);
AnalysisLogger.getLogger().debug("Guessed Topics: "+categories);
// Spatial Rapresentation Info
DefaultGeometricObjects geoObjs = new DefaultGeometricObjects();
geoObjs.setGeometricObjectType(GeometricObjectType.COMPLEX);
DefaultVectorSpatialRepresentation spatial = new DefaultVectorSpatialRepresentation();
spatial.setTopologyLevel(TopologyLevel.GEOMETRY_ONLY);
spatial.getGeometricObjects().add(geoObjs);
// Extent:
DefaultExtent extent = new DefaultExtent();
extent.setGeographicElements(Collections.singleton(new DefaultGeographicBoundingBox(xLL, xRU, yLL, yRU)));
extent.setDescription(new DefaultInternationalString("Bounding box"));
/*Only with Geotoolkit 4.x
DefaultTemporalExtent stext = new DefaultTemporalExtent(startDate,endDate);
stext.setStartTime(startDate);
stext.setEndTime(endDate);
extent.setTemporalElements(Arrays.asList(stext));
*/
extent.freeze();
//resolution
DefaultNominalResolution resolution = new DefaultNominalResolution();
resolution.setGroundResolution(res);
resolution.setScanningResolution(res);
DefaultResolution dres = new DefaultResolution();
dres.setDistance(res);
// layers access:
DefaultDistribution distribution = new DefaultDistribution();
DefaultDigitalTransferOptions transferOptions = new DefaultDigitalTransferOptions();
for (String uri : layerUris)
transferOptions.getOnLines().add(new DefaultOnlineResource(new URI(uri)));
distribution.getTransferOptions().add(transferOptions);
DefaultFormat [] formats = new DefaultFormat[protocols.length];
for (int i=0;i<protocols.length;i++){
DefaultFormat format = new DefaultFormat();
format.setName(new DefaultInternationalString(protocols[i]));
format.setVersion(new DefaultInternationalString("1.0.0"));
formats[i]=format;
}
distribution.setDistributionFormats(new ArrayList<DefaultFormat>(Arrays.asList(formats)));
// legal constraints
DefaultLegalConstraints constraints = new DefaultLegalConstraints();
constraints.getUseLimitations().add(new DefaultInternationalString("Licensed"));
constraints.getAccessConstraints().add(Restriction.LICENSE);
constraints.getUseConstraints().add(Restriction.LICENSE);
// quality declaration:
DefaultDataQuality processQuality = new DefaultDataQuality();
//citation
DefaultCitation sourceCitation = new DefaultCitation();
sourceCitation.setTitle(new DefaultInternationalString(title));
sourceCitation.getDates().add(new DefaultCitationDate(sourceGenerationDate, DateType.CREATION));
sourceCitation.getIdentifiers().add(new DefaultIdentifier(categoryTypes));
//source
DefaultSource source = new DefaultSource();
source.setResolution(resolution);
source.setDescription(new DefaultInternationalString(title));
source.setSourceCitation(sourceCitation);
// provenance
DefaultProcessStep preprocessStep = new DefaultProcessStep();
DefaultProcessStep processStep = new DefaultProcessStep(preprocessStep);
DefaultProcessing processing = new DefaultProcessing();
processing.setSoftwareReferences(new ArrayList<DefaultCitation>(Arrays.asList(sourceCitation)));
processStep.setDescription(new DefaultInternationalString(processdescription));
DefaultLineage processLineage = new DefaultLineage();
processLineage.setProcessSteps(new ArrayList<ProcessStep>(Arrays.asList(processStep)));
processQuality.setLineage(processLineage);
processQuality.setScope(new DefaultScope(ScopeCode.DATASET));
// fulfill identification
DefaultDataIdentification ident = new DefaultDataIdentification();
ident.setCitation(citation);
ident.setAbstract(new DefaultInternationalString(abstractField));
ident.setPurpose(new DefaultInternationalString(purpose));
ident.getResourceMaintenances().add(new DefaultMaintenanceInformation(MaintenanceFrequency.AS_NEEDED));
ident.setDescriptiveKeywords(keywordslist);
ident.setTopicCategories(categories);
ident.setResourceSpecificUsages(usages);
ident.setExtents(new ArrayList<DefaultExtent>(Arrays.asList(extent)));
ident.setSpatialRepresentationTypes(new ArrayList<SpatialRepresentationType>(Arrays.asList(SpatialRepresentationType.GRID)));
ident.setSpatialResolutions(new ArrayList<DefaultResolution>(Arrays.asList(dres)));
ident.setLanguages(new ArrayList<Locale>(Arrays.asList(Locale.ENGLISH)));
// Metadata Obj:
DefaultMetadata meta = new DefaultMetadata(party, sourceGenerationDate, ident);
meta.getSpatialRepresentationInfo().add(spatial);
meta.setDistributionInfo(distribution);
meta.getMetadataConstraints().add(constraints);
meta.getDataQualityInfo().add(processQuality);
meta.setLanguage(Locale.ENGLISH);
return meta;
}
}