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

pulibrary / pdc_describe / 4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

07 Apr 2025 06:36PM UTC coverage: 1.283% (-94.6%) from 95.862%
4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

Pull #1994

circleci

hectorcorrea
Switched to use the autocomplete that we aleady use for ROR. Integrated it with the existing logic for creators
Pull Request #1994: Started adding auto complete to contributors

0 of 46 new or added lines in 2 files covered. (0.0%)

4806 existing lines in 74 files now uncovered.

65 of 5065 relevant lines covered (1.28%)

0.01 hits per line

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

0.0
/app/services/form_to_resource_service.rb
1
# frozen_string_literal: true
UNCOV
2
class FormToResourceService
×
UNCOV
3
  class << self
×
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
    #
UNCOV
11
    def convert(params, work)
×
UNCOV
12
      resource = reset_resource_to_work(work)
×
13

UNCOV
14
      resource.description = params["description"]
×
UNCOV
15
      resource.publisher = params["publisher"] if params["publisher"].present?
×
UNCOV
16
      resource.publication_year = params["publication_year"] if params["publication_year"].present?
×
UNCOV
17
      resource.keywords = (params["keywords"] || "").split(",").map(&:strip)
×
18

UNCOV
19
      add_rights(params, resource)
×
UNCOV
20
      add_additional_metadata(params, resource)
×
UNCOV
21
      add_curator_controlled(params, resource)
×
UNCOV
22
      add_titles(params, resource)
×
UNCOV
23
      add_related_objects(params, resource)
×
UNCOV
24
      add_creators(params, resource)
×
UNCOV
25
      add_individual_contributors(params, resource)
×
UNCOV
26
      add_organizational_contributors(params, resource)
×
UNCOV
27
      add_funders(params, resource)
×
28

UNCOV
29
      resource
×
UNCOV
30
    end
×
31

UNCOV
32
    private
×
33

UNCOV
34
      def reset_resource_to_work(work)
×
UNCOV
35
        resource = PDCMetadata::Resource.new
×
36

UNCOV
37
        resource.doi = work.doi
×
UNCOV
38
        resource.ark = work.ark
×
UNCOV
39
        resource.migrated = work.resource.migrated
×
UNCOV
40
        resource.collection_tags = work.resource.collection_tags || []
×
UNCOV
41
        resource.publisher = work.group.publisher
×
UNCOV
42
        resource
×
UNCOV
43
      end
×
44

UNCOV
45
      def add_rights(params, resource)
×
UNCOV
46
        resource.rights_many = (params["rights_identifiers"] || []).map do |rights_id|
×
UNCOV
47
          PDCMetadata::Rights.find(rights_id)
×
UNCOV
48
        end.compact
×
UNCOV
49
      end
×
50

UNCOV
51
      def add_additional_metadata(params, resource)
×
UNCOV
52
        resource.domains = params["domains"] || []
×
UNCOV
53
        resource.communities = params["communities"] || []
×
UNCOV
54
        resource.subcommunities = params["subcommunities"] || []
×
UNCOV
55
      end
×
56

UNCOV
57
      def add_curator_controlled(params, resource)
×
UNCOV
58
        resource.doi = params["doi"] if params["doi"].present?
×
UNCOV
59
        resource.ark = params["ark"] if params["ark"].present?
×
UNCOV
60
        resource.version_number = params["version_number"] if params["version_number"].present?
×
UNCOV
61
        resource.collection_tags = params["collection_tags"].split(",").map(&:strip) if params["collection_tags"]
×
UNCOV
62
        resource.resource_type = params["resource_type"] if params["resource_type"]
×
UNCOV
63
        resource.resource_type_general = params["resource_type_general"] if params["resource_type_general"]
×
UNCOV
64
      end
×
65

66
      # Titles:
67

UNCOV
68
      def add_titles(params, resource)
×
UNCOV
69
        resource.titles << PDCMetadata::Title.new(title: params["title_main"])
×
UNCOV
70
        resource.titles.concat((1..params["existing_title_count"].to_i).filter_map do |i|
×
UNCOV
71
          title = params["title_#{i}"]
×
UNCOV
72
          title_type = params["title_type_#{i}"]
×
UNCOV
73
          new_title(title, title_type)
×
UNCOV
74
        end)
×
UNCOV
75
        resource.titles.concat((1..params["new_title_count"].to_i).filter_map do |i|
×
UNCOV
76
          title = params["new_title_#{i}"]
×
UNCOV
77
          title_type = params["new_title_type_#{i}"]
×
UNCOV
78
          new_title(title, title_type)
×
UNCOV
79
        end)
×
UNCOV
80
      end
×
81

UNCOV
82
      def new_title(title, title_type)
×
UNCOV
83
        return if title.blank?
×
UNCOV
84
        PDCMetadata::Title.new(title:, title_type:)
×
UNCOV
85
      end
×
86

87
      # Related Objects:
88

UNCOV
89
      def add_related_objects(params, resource)
×
UNCOV
90
        return if params[:related_objects].blank?
×
UNCOV
91
        resource.related_objects = params[:related_objects].each.filter_map do |related_object|
×
UNCOV
92
          new_related_object(related_object[:related_identifier], related_object[:related_identifier_type], related_object[:relation_type])
×
UNCOV
93
        end
×
UNCOV
94
      end
×
95

UNCOV
96
      def new_related_object(related_identifier, related_identifier_type, relation_type)
×
UNCOV
97
        return if related_identifier.blank? && related_identifier_type.blank? && relation_type.blank?
×
UNCOV
98
        PDCMetadata::RelatedObject.new(related_identifier:, related_identifier_type:, relation_type:)
×
UNCOV
99
      end
×
100

101
      # Creators:
102

UNCOV
103
      def add_creators(params, resource)
×
UNCOV
104
        resource.creators = params[:creators].each_with_index.filter_map do |creator, idx|
×
UNCOV
105
          new_creator(creator[:given_name], creator[:family_name], creator[:orcid], idx, creator[:affiliation], creator[:ror])
×
UNCOV
106
        end
×
UNCOV
107
      end
×
108

UNCOV
109
      def new_creator(given_name, family_name, orcid, sequence, affiliation, ror)
×
UNCOV
110
        return if family_name.blank? && given_name.blank? && orcid.blank?
×
UNCOV
111
        PDCMetadata::Creator.new_person(given_name, family_name, orcid, sequence, affiliation:, ror:)
×
UNCOV
112
      end
×
113

114
      # Individual Contributors:
115

UNCOV
116
      def add_individual_contributors(params, resource)
×
UNCOV
117
        return if params[:contributors].blank?
×
UNCOV
118
        resource.individual_contributors = params[:contributors].each_with_index.filter_map do |contributor, idx|
×
UNCOV
119
          new_individual_contributor(contributor[:given_name], contributor[:family_name], contributor[:orcid], contributor[:role], idx)
×
UNCOV
120
        end
×
UNCOV
121
      end
×
122

UNCOV
123
      def new_individual_contributor(given_name, family_name, orcid, type, sequence)
×
UNCOV
124
        return if family_name.blank? && given_name.blank? && orcid.blank?
×
UNCOV
125
        PDCMetadata::Creator.new_individual_contributor(given_name, family_name, orcid, type, sequence)
×
UNCOV
126
      end
×
127

128
      # Organizational Contributors:
129

UNCOV
130
      def add_organizational_contributors(params, resource)
×
131
        # (New pattern: Use rails param name conventions rather than numbering fields.)
UNCOV
132
        resource.organizational_contributors = (params[:organizational_contributors] || []).filter_map do |contributor|
×
UNCOV
133
          value = contributor["value"]
×
UNCOV
134
          ror = contributor["ror"]
×
UNCOV
135
          type = contributor["type"]
×
UNCOV
136
          new_organizational_contributor(value, ror, type)
×
UNCOV
137
        end
×
UNCOV
138
      end
×
139

UNCOV
140
      def new_organizational_contributor(value, ror, type)
×
UNCOV
141
        return if value.blank? && ror.blank?
×
142
        PDCMetadata::Creator.new_organizational_contributor(value, ror, type)
×
UNCOV
143
      end
×
144

145
      # Funders:
146

UNCOV
147
      def add_funders(params, resource)
×
UNCOV
148
        resource.funders = (params[:funders] || []).filter_map do |funder|
×
UNCOV
149
          new_funder(funder[:ror], funder[:funder_name], funder[:award_number], funder[:award_uri])
×
UNCOV
150
        end
×
UNCOV
151
      end
×
152

UNCOV
153
      def new_funder(ror, funder_name, award_number, award_uri)
×
UNCOV
154
        return if funder_name.blank? && award_number.blank? && award_uri.blank?
×
UNCOV
155
        PDCMetadata::Funder.new(ror, funder_name, award_number, award_uri)
×
UNCOV
156
      end
×
UNCOV
157
  end
×
UNCOV
158
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