app/services/external_apis/re3data_service.rb
def process_repository(id:, node:)
        return nil unless id.present? && node.present?

        scheme = IdentifierScheme.find_by(name: "rethreedata")
        repo_id = Identifier.where(identifier_scheme: scheme)
                            .where("value LIKE ?", "%#{id}").first
        repo = repo_id.identifiable if repo_id.present?

        # If the Repo couldn't be found by it's re3data ID then attempt to find by name
        # or initialize a new one
        unless repo.present?
          repo = Repository.find_or_initialize_by(name: node.xpath("//r3d:repositoryName")&.text)
        end
        repo_id = repo.identifier_for_scheme(scheme: scheme) unless repo_id.present?

        repo = parse_repository(repo: repo, node: node)
        return repo if repo_id.present?

        # Attach the re3data identifier
        Identifier.create(identifier_scheme: scheme, identifiable: repo,
                          value: id, attrs: { name: repo.name, url: repo.url })
        repo.reload
      end
# Updates or Creates a repository based on the XML input
Updates or Creates a repository based on the XML input
Updates or Creates a repository based on the XML input
def process_repository(id:, node:)
        return nil unless id.present? && node.present?
        scheme = IdentifierScheme.find_by(name: "rethreedata")
        repo_id = Identifier.where(identifier_scheme: scheme)
                            .where("value LIKE ?", "%#{id}").first
        repo = repo_id.identifiable if repo_id.present?
        unless repo.present?
          repo = Repository.find_or_initialize_by(name: node.xpath("//r3d:repositoryName")&.text)
        end
        repo_id = repo.identifier_for_scheme(scheme: scheme) unless repo_id.present?
        repo = parse_repository(repo: repo, node: node)
        return repo if repo_id.present?
        Identifier.create(identifier_scheme: scheme, identifiable: repo,
                          value: id, attrs: { name: repo.name, url: repo.url })
        repo.reload
      end
def process_repository ( id : , node : ) return nil unless id . present? && node . present? scheme = IdentifierScheme . find_by ( name : "rethreedata" ) repo_id = Identifier . where ( identifier_scheme : scheme ) . where ( "value LIKE ?" , "%#{id}" ) . first repo = repo_id . identifiable if repo_id . present? unless repo . present? repo = Repository . find_or_initialize_by ( name : node . xpath ( "//r3d:repositoryName" ) &. text ) end repo_id = repo . identifier_for_scheme ( scheme : scheme ) unless repo_id . present? repo = parse_repository ( repo : repo , node : node ) return repo if repo_id . present? Identifier . create ( identifier_scheme : scheme , identifiable : repo , value : id , attrs : { name : repo . name , url : repo . url } ) repo . reload end
Updates or Creates a repository based on the XML input
Updates or Creates a repository based on the XML input
# If the Repo couldn't be found by it's re3data ID then attempt to find by name # or initialize a new one # Attach the re3data identifier
id
node