@@ -200,52 +200,48 @@ def to_rdf
200200 end
201201
202202 rdfxml_str = graph . dump ( :rdfxml , prefixes : { sdo : 'http://schema.org/' , dc : 'http://purl.org/dc/terms/' } )
203- rdfxml_str . sub ( /\A <\? xml.*?\? >\s */ , '' ) # remove XML declaration
204- end
205-
206- # Dublin Core mappings for OAI-PMH
207- # no mapping needed for contributor, description and title
208- # coverage and source not mappable
209- alias_attribute :creators , :authors
210-
211- def dates
212- [ date_published , date_created , date_modified ] . compact . map ( &:iso8601 )
213- end
203+ rdfxml_str . sub ( /\A <\? xml.*?\? >\s */ , '' ) # remove XML declaration because this is used inside OAI-PMH response
204+ end
205+
206+ def to_oai_dc
207+ xml = ::Builder ::XmlMarkup . new
208+ xml . tag! ( 'oai_dc:dc' ,
209+ 'xmlns:oai_dc' => 'http://www.openarchives.org/OAI/2.0/oai_dc/' ,
210+ 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/' ,
211+ 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' ,
212+ 'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd' ) do
213+ xml . tag! ( 'dc:title' , title )
214+ xml . tag! ( 'dc:description' , description )
215+ authors . each { |a | xml . tag! ( 'dc:creator' , a ) }
216+ contributors . each { |a | xml . tag! ( 'dc:contributor' , a ) }
217+ xml . tag! ( 'dc:publisher' , content_provider . title ) if content_provider
218+
219+ xml . tag! ( 'dc:format' , 'text/html' )
220+ xml . tag! ( 'dc:language' , 'en' )
221+ xml . tag! ( 'dc:rights' , licence ) if licence . present?
222+
223+ [ date_published , date_created , date_modified ] . compact . each do |d |
224+ xml . tag! ( 'dc:date' , d . iso8601 )
225+ end
214226
215- def format = 'text/html'
227+ if doi . present?
228+ doi_iri = doi . start_with? ( 'http://' , 'https://' ) ? doi : "https://doi.org/#{ doi } "
229+ xml . tag! ( 'dc:identifier' , doi_iri )
230+ else
231+ xml . tag! ( 'dc:identifier' , url )
232+ end
216233
217- def identifier
218- if !doi . nil? && !doi . empty?
219- doi_iri = doi . start_with? ( 'http://' , 'https://' ) ? doi : "https://doi.org/#{ doi } "
220- else
221- url
222- end
223- end
234+ ( keywords + scientific_topics . map ( &:uri ) + operations . map ( &:uri ) ) . each do |s |
235+ xml . tag! ( 'dc:subject' , s )
236+ end
224237
225- def language = 'en'
238+ xml . tag! ( 'dc:type' , 'http://purl.org/dc/dcmitype/Text' )
239+ xml . tag! ( 'dc:type' , 'https://schema.org/LearningResource' )
240+ resource_type . each { |t | xml . tag! ( 'dc:type' , t ) }
226241
227- def publishers
228- if content_provider
229- [ content_provider . title ]
230- else
231- [ ]
242+ xml . tag! ( 'dc:relation' , "#{ TeSS ::Config . base_url } #{ Rails . application . routes . url_helpers . material_path ( self ) } " )
243+ xml . tag! ( 'dc:relation' , content_provider . url ) if content_provider &.url
232244 end
233- end
234-
235- # currently only url of tess resource, content provider url
236- def relations
237- [
238- "#{ TeSS ::Config . base_url } #{ Rails . application . routes . url_helpers . material_path ( self ) } "
239- ] + ( content_provider ? [ content_provider . url ] : [ ] )
240- end
241-
242- alias_attribute :rights , :licence
243-
244- def subjects
245- keywords + scientific_topics . map ( &:uri ) + operations . map ( &:uri )
246- end
247-
248- def types
249- [ 'http://purl.org/dc/dcmitype/Text' , 'https://schema.org/LearningResource' ] + resource_type
245+ xml . target!
250246 end
251247end
0 commit comments