Class: DigitalObjectIdentifier

Inherits:
Object
  • Object
show all
Defined in:
app/models/digital_object_identifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#accepted_dateObject

Returns the value of attribute accepted_date.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def accepted_date
  @accepted_date
end

#contributorObject

Returns the value of attribute contributor.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def contributor
  @contributor
end

#created_dateObject

Returns the value of attribute created_date.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def created_date
  @created_date
end

#creatorObject

Returns the value of attribute creator.



3
4
5
# File 'app/models/digital_object_identifier.rb', line 3

def creator
  @creator
end

#data_sizeObject

Returns the value of attribute data_size.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def data_size
  @data_size
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def description
  @description
end

#formatObject

Returns the value of attribute format.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def format
  @format
end

#langObject

Returns the value of attribute lang.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def lang
  @lang
end

#name_idObject

Returns the value of attribute name_id.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def name_id
  @name_id
end

#publicationyearObject

Returns the value of attribute publicationyear.



3
4
5
# File 'app/models/digital_object_identifier.rb', line 3

def publicationyear
  @publicationyear
end

#publisherObject

Returns the value of attribute publisher.



3
4
5
# File 'app/models/digital_object_identifier.rb', line 3

def publisher
  @publisher
end

#resource_typeObject

Returns the value of attribute resource_type.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def resource_type
  @resource_type
end

#rightsObject

Returns the value of attribute rights.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def rights
  @rights
end

#subjectObject

Returns the value of attribute subject.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def subject
  @subject
end

#subtitleObject

Returns the value of attribute subtitle.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def subtitle
  @subtitle
end

#targetObject

Returns the value of attribute target.



3
4
5
# File 'app/models/digital_object_identifier.rb', line 3

def target
  @target
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'app/models/digital_object_identifier.rb', line 3

def title
  @title
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'app/models/digital_object_identifier.rb', line 4

def version
  @version
end

Instance Method Details

#create_doiObject

Step - 1: Create DOI by passing 5 metadata - target, creator, title, publisher, publicationyear



12
13
14
15
# File 'app/models/digital_object_identifier.rb', line 12

def create_doi
  response = RestClient.post DoiConfig.url_for_creating_doi, data, :content_type => 'text/plain'
  return response
end

#create_xmlObject

This method creates XML data which is used for extra metadata other than the 5 metadata which was used in Step - 1.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/digital_object_identifier.rb', line 38

def create_xml
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.resource("xmlns" => "http://datacite.org/schema/kernel-2.2", "xmlns:xsi" =>"http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => "http://datacite.org/schema/kernel-2.2 http://schema.datacite.org/meta/kernel-2.2/metadata.xsd") {
      xml.identifier(:identifierType => "DOI"){ xml.text doi.sub("doi:", "") }
      xml.creators{
        xml.creator{
          xml.creatorName creator
          xml.nameIdentifier(:nameIdentifierScheme => "ISNI") { xml.text name_id }
        }
      }
      xml.titles{
        xml.title title
        xml.title(:titleType => "Subtitle") { xml.text subtitle}
      }
      xml.publisher publisher
      xml.publicationYear publicationyear
      xml.subjects{
        xml.subject subject
      }
      xml.contributors{
        xml.contributor(:contributorType => "DataManager"){
          xml.contributorName contributor
        }
      }
      xml.dates{
        xml.date(:dateType => "Valid"){ xml.text created_date }
        xml.date(:dateType => "Accepted"){ xml.text accepted_date }
      }
      xml.language lang
      xml.resourceType(:resourceTypeGeneral => "Image"){ xml.text resource_type }
      xml.sizes{
        xml.size data_size
      }
      xml.formats{
        xml.format format
      }
      xml.version version
      xml.rights rights
      xml.descriptions{
        xml.description(:descriptionType => "Other") { xml.text description }
      }
    }
  end
end

#dataObject

Mandatory fields for creating DOI.



7
8
9
# File 'app/models/digital_object_identifier.rb', line 7

def data
  "_target: #{target}\ndatacite.creator: #{creator}\ndatacite.title: #{title}\ndatacite.publisher: #{publisher}\ndatacite.publicationyear: #{publicationyear}\n"
end

#doiObject

Create DOI or return if already created.



18
19
20
21
22
23
24
# File 'app/models/digital_object_identifier.rb', line 18

def doi
  @doi ||= create_doi
  if @doi.include?("success")
    @doi = @doi.split("|")[0].sub("success:", "").strip
  end
  @doi
end

#sanitize_dataObject

This method replaces special characters like %, :, n and r in the XML data and appends to the basic metadata which was used while creating DOI in Step - 1.



33
34
35
# File 'app/models/digital_object_identifier.rb', line 33

def sanitize_data
  data + "datacite: #{create_xml.to_xml.gsub("%", "%25").gsub(":", "%3A").gsub("\n", "%0D%0A").gsub("\r", "")}\n"
end

#update_doiObject

Step - 2: Update the DOI metadata with more attributes. The extra metadata will need to be in the xml format.



27
28
29
30
# File 'app/models/digital_object_identifier.rb', line 27

def update_doi
  response = RestClient.post "#{DoiConfig.url_for_updating_doi}#{doi}", sanitize_data, :content_type => 'text/plain; charset=UTF-8', :content_length => sanitize_data.size, :accept => 'text/plain'
  return response
end