use of eu.etaxonomy.cdm.common.URI in project cdmlib by cybertaxonomy.
the class MediaInfoServiceReaderTest method setUp.
@Before
public void setUp() throws Exception {
jpegImageUri = new URI("https://pictures.bgbm.org/digilib/Scaler?fn=Cyprus/Sisymbrium_aegyptiacum_C1.jpg&mo=file");
jpegMetadataUri = new URI("https://image.bgbm.org/metadata/info?file=Cyprus/Sisymbrium_aegyptiacum_C1.jpg");
}
use of eu.etaxonomy.cdm.common.URI in project cdmlib by cybertaxonomy.
the class MobotOpenUrlServiceWrapper method doResolve.
/**
* BHL uses the response format as specified in the
* http://code.google.com/p/
* bhl-bits/source/browse/trunk/portal/OpenUrlUtilities
* /OpenUrlResponse.cs?r=17 there seems to be no xml schema available
* though.
* @param query the MobotOpenUrlQuery object
* @return
*/
public List<OpenUrlReference> doResolve(MobotOpenUrlQuery query) {
List<NameValuePair> pairs = new ArrayList<>();
// find the appropriate schemadapter using the schemaShortName
if (query.schemaShortName == null) {
query.schemaShortName = "MOBOT.OpenUrl.Utilities.OpenUrlResponse";
}
SchemaAdapterBase<OpenUrlReference> schemaAdapter = schemaAdapterMap.get(query.schemaShortName);
if (schemaAdapter == null) {
logger.error("No SchemaAdapter found for " + query.schemaShortName);
}
addNameValuePairTo(pairs, "format", "xml");
addNameValuePairTo(pairs, "url_ver", urlVersion);
/* info:ofi/fmt:kev:mtx:book or info:ofi/fmt:kev:mtx:journal */
addNameValuePairTo(pairs, "rft_val_fmt", "info:ofi/fmt:kev:mtx:" + query.refType);
/* Book title */
addNameValuePairTo(pairs, "rft.btitle", query.bookTitle);
/* Journal title */
addNameValuePairTo(pairs, "rft.jtitle", query.journalTitle);
/* Author name ("last, first" or "corporation") */
addNameValuePairTo(pairs, "rft.au", query.authorName);
/* Author last name */
addNameValuePairTo(pairs, "rft.aulast", query.authorLastName);
/* Author first name */
addNameValuePairTo(pairs, "rft.aufirst", query.authorFirstName);
/* Author name (corporation) */
addNameValuePairTo(pairs, "rft.aucorp", query.authorNameCorporation);
/* Publication details */
addNameValuePairTo(pairs, "rft.publisher", query.publicationDetails);
/* Publisher name */
addNameValuePairTo(pairs, "rft.pub", query.publisherName);
/* Publication place */
addNameValuePairTo(pairs, "rft.place", query.publicationPlace);
/* Publication date (YYYY or YYYY-MM or YYYY-MM-DD) */
addNameValuePairTo(pairs, "rft.date", query.publicationDate);
/* ISSN */
addNameValuePairTo(pairs, "rft.issn", query.ISSN);
/* ISBN */
addNameValuePairTo(pairs, "rft.isbn", query.ISBN);
/* CODEN */
addNameValuePairTo(pairs, "rft.coden", query.CODEN);
/* Abbreviation = abbreviated Title */
addNameValuePairTo(pairs, "rft.stitle", query.abbreviation);
/* Volume */
addNameValuePairTo(pairs, "rft.volume", query.volume);
/* Issue */
addNameValuePairTo(pairs, "rft.issue", query.issue);
/* Start page */
if (query.startPage != null) {
Integer page = parsePageNumber(query.startPage);
addNameValuePairTo(pairs, "rft.spage", page.toString());
}
/* BHL title ID (where XXXX is the ID value)*/
addNameValuePairTo(pairs, "rft_id", query.bhlTitleURI);
/* BHL page ID (where XXXX is the ID value)*/
addNameValuePairTo(pairs, "rft_id", query.bhlPageURI);
/* OCLC number (where XXXX is the ID value)*/
if (query.oclcNumber != null) {
pairs.add(new BasicNameValuePair("rft_id", "info:oclcnum/" + query.oclcNumber));
}
/* Lib. of Congress ID (where XXXX is the ID value)*/
if (query.libofCongressID != null) {
pairs.add(new BasicNameValuePair("rft_id", "info:lccn/" + query.libofCongressID));
}
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Accept-Charset", "UTF-8");
try {
URI requestUri = createUri(null, pairs);
InputStream stream = executeHttpGet(requestUri, requestHeaders);
// String search = "utf-16";
// String replace = "UTF-8";
// // stream = StreamUtils.streamReplace(stream, search, replace);
// fix the "org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x1) was found" problem
// stream = StreamUtils.streamReplaceAll(stream, "[\\x00-\\x10]", " ");
List<OpenUrlReference> referenceList = schemaAdapter.getCmdEntities(stream);
// TODO : we need to set ReferenceType here unless we know that the field Genre returns the reference type
for (OpenUrlReference ref : referenceList) {
ref.setReferenceType(query.refType);
}
return referenceList;
} catch (IOException e) {
// thrown by doHttpGet
logger.error(e);
} catch (URISyntaxException e) {
// thrown by createUri
logger.error(e);
}
return null;
}
use of eu.etaxonomy.cdm.common.URI in project cdmlib by cybertaxonomy.
the class SruServiceWrapper method doSearchRetrieve.
/**
* The GRIB sru service is available at "http://gso.gbv.de/sru/DB=1.83/"
* The documentation is found at http://bhleurope.gbv.de/#sru from where the following text has been retrieved:
* <p>
* General information about Search/Retrieve via URL (SRU) is available in
* the official SRU specification (http://www.loc.gov/standards/sru/). The SRU-Interface of GRIB supports some
* specific search keys. Please do not use the (dc) fields but only the
* (pica) search fields:
* <dl>
* <dt>PPN</dt>
* <dd>Internal record id without prefix 'grib:ppn:' (This may change)</dd>
* <dt>DST</dt>
* <dd>Digitization status (8300-8305: 8300=not digitized, 8301=should be digitized, 8302=will be digitized, 8305=document available)</dd>
* <dt>URL</dt>
* <dd>URL of a digitized object</dd>
* <dt>??? (not defined yet)</td>
* <dd>Stable identifier of a record (PICA+ field 006Y)</dd>
* </dl>
* </p>
* @param cqlQuery
* an <b>URL encoded</b> CQL Query string see
* {@link http://www.loc.gov/standards/sru/specs/cql.html} for documentation
* @param recordSchema
* @return
*/
public List<Reference> doSearchRetrieve(String cqlQuery, String recordSchema) {
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
SchemaAdapterBase<Reference> schemaAdapter = schemaAdapterMap.get(recordSchema);
if (schemaAdapter == null) {
logger.error("No SchemaAdapter found for " + recordSchema);
}
String sruOperation = "searchRetrieve";
pairs.add(new BasicNameValuePair("operation", sruOperation));
pairs.add(new BasicNameValuePair("version", sruVersion));
pairs.add(new BasicNameValuePair("query", cqlQuery));
pairs.add(new BasicNameValuePair("recordSchema", recordSchema));
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Accept-Charset", "UTF-8");
try {
URI requestUri = createUri(null, pairs);
InputStream stream = executeHttpGet(requestUri, requestHeaders);
return schemaAdapter.getCmdEntities(stream);
} catch (IOException e) {
// thrown by doHttpGet
logger.error(e);
} catch (URISyntaxException e) {
// thrown by createUri
logger.error(e);
}
return null;
}
use of eu.etaxonomy.cdm.common.URI in project cdmlib by cybertaxonomy.
the class EditGeoServiceTest method setUp.
@Before
public void setUp() throws Exception {
// allows EditGeoServiceUtilities to skip some line of code
System.setProperty("ONLY-A-TEST", "TRUE");
editMapServiceUri = new URI(EDIT_MAPSERVICE_URI_STING);
}
use of eu.etaxonomy.cdm.common.URI in project cdmlib by cybertaxonomy.
the class GbifJsonOccurrenceParser method parseJsonRecords.
/**
* Parses the given {@link JSONArray} for occurrences.
* @param jsonString JSON data as an {@link JSONArray}
* @return the found occurrences as a collection of {@link GbifResponse}
*/
private static Collection<GbifResponse> parseJsonRecords(JSONArray jsonArray) {
Collection<GbifResponse> results = new ArrayList<>();
String[] tripleId = new String[3];
String string;
for (Object o : jsonArray) {
// parse every record
tripleId = new String[3];
if (o instanceof JSONObject) {
String dataSetKey = null;
GbifDataSetProtocol dataSetProtocol = null;
DerivedUnitFacade derivedUnitFacade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
TaxonName name = null;
JSONObject record = (JSONObject) o;
if (record.has(DATASET_PROTOCOL)) {
dataSetProtocol = GbifDataSetProtocol.parseProtocol(record.getString(DATASET_PROTOCOL));
}
if (record.has(DATASET_KEY)) {
dataSetKey = record.getString(DATASET_KEY);
}
if (record.has(COUNTRY_CODE)) {
string = record.getString(COUNTRY_CODE);
Country country = Country.getCountryByIso3166A2(string);
if (country != null) {
derivedUnitFacade.setCountry(country);
}
}
if (record.has(LOCALITY)) {
string = record.getString(LOCALITY);
derivedUnitFacade.setLocality(string);
}
if (record.has("species")) {
Rank rank = null;
if (record.has(TAXON_RANK)) {
string = record.getString(TAXON_RANK);
try {
rank = Rank.getRankByLatinName(string);
} catch (UnknownCdmTypeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (rank != null) {
if (record.has(NOMENCLATURALCODE)) {
string = record.getString(NOMENCLATURALCODE);
if (string.equals(NomenclaturalCode.ICZN.getTitleCache())) {
name = TaxonNameFactory.NewZoologicalInstance(rank);
} else if (string.equals(NomenclaturalCode.ICNAFP.getTitleCache())) {
name = TaxonNameFactory.NewBotanicalInstance(rank);
} else if (string.equals(NomenclaturalCode.ICNP.getTitleCache())) {
name = TaxonNameFactory.NewBacterialInstance(rank);
} else if (string.equals(NomenclaturalCode.ICNCP.getTitleCache())) {
name = TaxonNameFactory.NewCultivarInstance(rank);
} else if (string.equals(NomenclaturalCode.ICVCN.getTitleCache())) {
name = TaxonNameFactory.NewViralInstance(rank);
} else if (string.equals("ICN")) {
name = TaxonNameFactory.NewBotanicalInstance(rank);
}
} else {
if (record.has(KINGDOM)) {
if (record.getString(KINGDOM).equals(PLANTAE)) {
name = TaxonNameFactory.NewBotanicalInstance(rank);
} else if (record.getString(KINGDOM).equals(ANIMALIA)) {
name = TaxonNameFactory.NewZoologicalInstance(rank);
} else if (record.getString(KINGDOM).equals(FUNGI)) {
name = TaxonNameFactory.NewBotanicalInstance(rank);
} else if (record.getString(KINGDOM).equals(BACTERIA)) {
name = TaxonNameFactory.NewBacterialInstance(rank);
} else {
name = TaxonNameFactory.NewNonViralInstance(rank);
}
} else {
name = TaxonNameFactory.NewNonViralInstance(rank);
}
}
if (name == null) {
name = TaxonNameFactory.NewNonViralInstance(rank);
}
if (record.has(GENUS)) {
name.setGenusOrUninomial(record.getString(GENUS));
}
if (record.has(SPECIFIC_EPITHET)) {
name.setSpecificEpithet(record.getString(SPECIFIC_EPITHET));
}
if (record.has(INFRASPECIFIC_EPITHET)) {
name.setInfraSpecificEpithet(record.getString(INFRASPECIFIC_EPITHET));
}
if (record.has(SCIENTIFIC_NAME)) {
name.setTitleCache(record.getString(SCIENTIFIC_NAME), true);
}
}
DeterminationEvent detEvent = DeterminationEvent.NewInstance();
if (record.has(IDENTIFIED_BY)) {
Person determiner = Person.NewTitledInstance(record.getString(IDENTIFIED_BY));
detEvent.setDeterminer(determiner);
}
detEvent.setTaxonName(name);
detEvent.setPreferredFlag(true);
derivedUnitFacade.addDetermination(detEvent);
}
// GPS location
Point location = Point.NewInstance();
derivedUnitFacade.setExactLocation(location);
try {
if (record.has(LATITUDE)) {
String lat = record.getString(LATITUDE);
location.setLatitudeByParsing(lat);
}
if (record.has(LONGITUDE)) {
String lon = record.getString(LONGITUDE);
location.setLongitudeByParsing(lon);
}
} catch (ParseException e) {
logger.error("Could not parse GPS coordinates", e);
}
if (record.has(GEOREFERENCE_PROTOCOL)) {
String geo = record.getString(GEOREFERENCE_PROTOCOL);
ReferenceSystem referenceSystem = null;
// to check which reference system is used?
if (ReferenceSystem.WGS84().getLabel().contains(geo)) {
referenceSystem = ReferenceSystem.WGS84();
} else if (ReferenceSystem.GOOGLE_EARTH().getLabel().contains(geo)) {
referenceSystem = ReferenceSystem.GOOGLE_EARTH();
} else if (ReferenceSystem.GAZETTEER().getLabel().contains(geo)) {
referenceSystem = ReferenceSystem.GAZETTEER();
}
location.setReferenceSystem(referenceSystem);
}
if (record.has(ELEVATION)) {
try {
// parse integer and strip of unit
string = record.getString(ELEVATION);
int length = string.length();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; i++) {
if (Character.isDigit(string.charAt(i))) {
builder.append(string.charAt(i));
} else {
break;
}
}
derivedUnitFacade.setAbsoluteElevation(Integer.parseInt(builder.toString()));
} catch (NumberFormatException e) {
logger.warn("Could not parse elevation", e);
}
}
// Date (Gathering Period)
TimePeriod timePeriod = TimePeriod.NewInstance();
derivedUnitFacade.setGatheringPeriod(timePeriod);
// TODO what happens with eventDate??
if (record.has(YEAR)) {
timePeriod.setStartYear(record.getInt(YEAR));
}
if (record.has(MONTH)) {
timePeriod.setStartMonth(record.getInt(MONTH));
}
if (record.has(DAY)) {
timePeriod.setStartDay(record.getInt(DAY));
}
if (record.has(RECORDED_BY)) {
Person person = Person.NewTitledInstance(record.getString(RECORDED_BY));
// FIXME check data base if collector already present
derivedUnitFacade.setCollector(person);
}
// collector number (fieldNumber OR recordNumber)
if (record.has(FIELD_NUMBER)) {
derivedUnitFacade.setFieldNumber(record.getString(FIELD_NUMBER));
}
// collector number (fieldNumber OR recordNumber)
if (record.has(RECORD_NUMBER)) {
derivedUnitFacade.setFieldNumber(record.getString(RECORD_NUMBER));
}
if (record.has(EVENT_REMARKS)) {
derivedUnitFacade.setGatheringEventDescription(record.getString(EVENT_REMARKS));
}
if (record.has(OCCURRENCE_REMARKS)) {
derivedUnitFacade.setEcology(record.getString(OCCURRENCE_REMARKS));
}
if (record.has(COLLECTION_CODE)) {
String collectionCode = record.getString(COLLECTION_CODE);
tripleId[2] = collectionCode;
// FIXME: check data base for existing collections
eu.etaxonomy.cdm.model.occurrence.Collection collection = eu.etaxonomy.cdm.model.occurrence.Collection.NewInstance();
collection.setCode(collectionCode);
if (record.has(INSTITUTION_CODE)) {
Institution institution = Institution.NewNamedInstance(record.getString(INSTITUTION_CODE));
institution.setCode(record.getString(INSTITUTION_CODE));
collection.setInstitute(institution);
}
derivedUnitFacade.setCollection(collection);
}
if (record.has(CATALOG_NUMBER)) {
derivedUnitFacade.setCatalogNumber(record.getString(CATALOG_NUMBER));
derivedUnitFacade.setAccessionNumber(record.getString(CATALOG_NUMBER));
tripleId[0] = record.getString(CATALOG_NUMBER);
}
if (record.has(INSTITUTION_CODE)) {
derivedUnitFacade.setAccessionNumber(record.getString(INSTITUTION_CODE));
tripleId[1] = record.getString(INSTITUTION_CODE);
}
if (record.has(OCCURENCE_ID)) {
IdentifiableSource source = IdentifiableSource.NewDataImportInstance((record.getString(OCCURENCE_ID)));
derivedUnitFacade.addSource(source);
}
if (record.has(MULTIMEDIA)) {
// http://ww2.bgbm.org/herbarium/images/B/-W/08/53/B_-W_08537%20-00%201__3.jpg
JSONArray multimediaArray = record.getJSONArray(MULTIMEDIA);
JSONObject mediaRecord;
SpecimenOrObservationType type = null;
for (Object object : multimediaArray) {
// parse every record
Media media = Media.NewInstance();
URI uri = null;
CdmImageInfo imageInf = null;
if (object instanceof JSONObject) {
mediaRecord = (JSONObject) object;
if (mediaRecord.has("identifier")) {
try {
uri = new URI(mediaRecord.getString("identifier"));
imageInf = MediaInfoFileReader.legacyFactoryMethod(uri).readBaseInfo().getCdmImageInfo();
} catch (URISyntaxException | IOException | HttpException e) {
e.printStackTrace();
}
// media.addIdentifier(mediaRecord.getString("identifier"), null);
}
if (mediaRecord.has("references")) {
}
if (mediaRecord.has("format")) {
}
if (mediaRecord.has("type")) {
if (mediaRecord.get("type").equals("StillImage")) {
type = SpecimenOrObservationType.StillImage;
}
}
}
ImageFile imageFile = ImageFile.NewInstance(uri, null, imageInf);
MediaRepresentation representation = MediaRepresentation.NewInstance();
representation.addRepresentationPart(imageFile);
media.addRepresentation(representation);
derivedUnitFacade.addDerivedUnitMedia(media);
}
// identifier=http://ww2.bgbm.org/herbarium/images/B/-W/08/53/B_-W_08537%20-00%201__3.jpg
// references=http://ww2.bgbm.org/herbarium/view_biocase.cfm?SpecimenPK=136628
// format=image/jpeg
// type=StillImage
}
// create dataset URL
URI uri = null;
try {
uri = UriUtils.createUri(new URL(GbifQueryServiceWrapper.BASE_URL), "/v1/dataset/" + dataSetKey + "/endpoint", null, null);
} catch (MalformedURLException e) {
logger.error("Endpoint URI could not be created!", e);
} catch (URISyntaxException e) {
logger.error("Endpoint URI could not be created!", e);
}
results.add(new GbifResponse(derivedUnitFacade, uri, dataSetProtocol, tripleId, name));
}
}
return results;
}
Aggregations