• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 5db21940-59bd-4742-a25d-02e5e58d6646

pending completion
5db21940-59bd-4742-a25d-02e5e58d6646

Pull #1014

circleci

Carolyn Cole
Creating a folder in Amazon so the curators do not need to do it by hand fixes #1001
Pull Request #1014: Creating a folder in Amazon so the curators do not need to do it by hand

3 of 3 new or added lines in 2 files covered. (100.0%)

1703 of 1872 relevant lines covered (90.97%)

80.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/app/services/form_to_resource_service.rb
1
# frozen_string_literal: true
2
class FormToResourceService
1✔
3
  class << self
1✔
4
    # Convert params into a resource
5
    #
6
    #  @param [Hash] params controller params to be converted
7
    #  @param [Work] work params will be applied to. Utilizes the work for old values if needed.
8
    #
9
    # @return [PDCMetadata::Resource] Fully formed resource containing updates from the user
10
    def convert(params, work)
1✔
11
      resource = reset_resource_to_work(work)
16✔
12

13
      resource.description = params["description"]
16✔
14
      resource.publisher = params["publisher"] if params["publisher"].present?
16✔
15
      resource.publication_year = params["publication_year"] if params["publication_year"].present?
16✔
16
      resource.rights = PDCMetadata::Rights.find(params["rights_identifier"])
16✔
17
      resource.keywords = (params["keywords"] || "").split(",").map(&:strip)
16✔
18
      resource.domains = params["domains"] || []
16✔
19

20
      add_curator_controlled(params, resource)
16✔
21
      add_titles(params, resource)
16✔
22
      add_related_objects(params, resource)
16✔
23
      add_creators(params, resource)
16✔
24
      add_individual_contributors(params, resource)
16✔
25
      add_organizational_contributors(params, resource)
16✔
26
      add_funders(params, resource)
16✔
27

28
      resource
16✔
29
    end
30

31
    private
1✔
32

33
      def reset_resource_to_work(work)
1✔
34
        resource = PDCMetadata::Resource.new
16✔
35

36
        resource.doi = work.doi
16✔
37
        resource.ark = work.ark
16✔
38
        resource.collection_tags = work.resource.collection_tags || []
16✔
39
        resource
16✔
40
      end
41

42
      def add_curator_controlled(params, resource)
1✔
43
        resource.doi = params["doi"] if params["doi"].present?
16✔
44
        resource.ark = params["ark"] if params["ark"].present?
16✔
45
        resource.version_number = params["version_number"] if params["version_number"].present?
16✔
46
        resource.collection_tags = params["collection_tags"].split(",").map(&:strip) if params["collection_tags"]
16✔
47
        resource.resource_type = params["resource_type"] if params["resource_type"]
16✔
48
        resource.resource_type_general = params["resource_type_general"] if params["resource_type_general"]
16✔
49
      end
50

51
      # Titles:
52

53
      def add_titles(params, resource)
1✔
54
        resource.titles << PDCMetadata::Title.new(title: params["title_main"])
16✔
55
        resource.titles.concat((1..params["existing_title_count"].to_i).filter_map do |i|
16✔
56
          title = params["title_#{i}"]
3✔
57
          title_type = params["title_type_#{i}"]
3✔
58
          new_title(title, title_type)
3✔
59
        end)
60
        resource.titles.concat((1..params["new_title_count"].to_i).filter_map do |i|
16✔
61
          title = params["new_title_#{i}"]
3✔
62
          title_type = params["new_title_type_#{i}"]
3✔
63
          new_title(title, title_type)
3✔
64
        end)
65
      end
66

67
      def new_title(title, title_type)
1✔
68
        return if title.blank?
6✔
69
        PDCMetadata::Title.new(title: title, title_type: title_type)
3✔
70
      end
71

72
      # Related Objects:
73

74
      def add_related_objects(params, resource)
1✔
75
        resource.related_objects = (1..params["related_object_count"].to_i).filter_map do |i|
16✔
76
          related_identifier = params["related_identifier_#{i}"]
3✔
77
          related_identifier_type = params["related_identifier_type_#{i}"]
3✔
78
          relation_type = params["relation_type_#{i}"]
3✔
79
          new_related_object(related_identifier, related_identifier_type, relation_type)
3✔
80
        end
81
      end
82

83
      def new_related_object(related_identifier, related_identifier_type, relation_type)
1✔
84
        return if related_identifier.blank? && related_identifier_type.blank? && relation_type.blank?
3✔
85
        PDCMetadata::RelatedObject.new(related_identifier: related_identifier, related_identifier_type: related_identifier_type, relation_type: relation_type)
×
86
      end
87

88
      # Creators:
89

90
      def add_creators(params, resource)
1✔
91
        resource.creators = (1..params["creator_count"].to_i).filter_map do |i|
16✔
92
          given_name = params["given_name_#{i}"]
22✔
93
          family_name = params["family_name_#{i}"]
22✔
94
          orcid = params["orcid_#{i}"]
22✔
95
          sequence = params["sequence_#{i}"]
22✔
96
          new_creator(given_name, family_name, orcid, sequence)
22✔
97
        end
98
      end
99

100
      def new_creator(given_name, family_name, orcid, sequence)
1✔
101
        return if family_name.blank? && given_name.blank? && orcid.blank?
22✔
102
        PDCMetadata::Creator.new_person(given_name, family_name, orcid, sequence)
22✔
103
      end
104

105
      # Individual Contributors:
106

107
      def add_individual_contributors(params, resource)
1✔
108
        resource.individual_contributors = (1..params["contributor_count"].to_i).filter_map do |i|
16✔
109
          given_name = params["contributor_given_name_#{i}"]
×
110
          family_name = params["contributor_family_name_#{i}"]
×
111
          orcid = params["contributor_orcid_#{i}"]
×
112
          type = params["contributor_role_#{i}"]
×
113
          sequence = params["contributor_sequence_#{i}"]
×
114
          new_individual_contributor(given_name, family_name, orcid, type, sequence)
×
115
        end
116
      end
117

118
      def new_individual_contributor(given_name, family_name, orcid, type, sequence)
1✔
119
        return if family_name.blank? && given_name.blank? && orcid.blank?
×
120
        PDCMetadata::Creator.new_individual_contributor(given_name, family_name, orcid, type, sequence)
×
121
      end
122

123
      # Organizational Contributors:
124

125
      def add_organizational_contributors(params, resource)
1✔
126
        # (New pattern: Use rails param name conventions rather than numbering fields.)
127
        resource.organizational_contributors = (params[:organizational_contributors] || []).filter_map do |contributor|
16✔
128
          value = contributor["value"]
×
129
          ror = contributor["ror"]
×
130
          type = contributor["type"]
×
131
          new_organizational_contributor(value, ror, type)
×
132
        end
133
      end
134

135
      def new_organizational_contributor(value, ror, type)
1✔
136
        return if value.blank? && ror.blank?
×
137
        PDCMetadata::Creator.new_organizational_contributor(value, ror, type)
×
138
      end
139

140
      # Funders:
141

142
      def add_funders(params, resource)
1✔
143
        resource.funders = (params[:funders] || []).filter_map do |funder|
16✔
144
          new_funder(funder[:ror], funder[:funder_name], funder[:award_number], funder[:award_uri])
×
145
        end
146
      end
147

148
      def new_funder(ror, funder_name, award_number, award_uri)
1✔
149
        return if funder_name.blank? && award_number.blank? && award_uri.blank?
×
150
        PDCMetadata::Funder.new(ror, funder_name, award_number, award_uri)
×
151
      end
152
  end
153
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc