forked from Smithsonian/caas_aspace_refid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Smithsonian#20 Next refid is actually the next refid (Smithsonian#24)
- Loading branch information
1 parent
f9682c7
commit 6964f4f
Showing
7 changed files
with
230 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Code Scan | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
|
||
jobs: | ||
backend_plugins: | ||
runs-on: ubuntu-latest | ||
env: | ||
PROD_ARCHIVESSPACE_VERSION: v3.3.1 | ||
|
||
steps: | ||
- name: Checkout ArchivesSpace | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ env.PROD_ARCHIVESSPACE_VERSION }} | ||
repository: Smithsonian/archivesspace | ||
|
||
- name: Checkout plugin | ||
uses: actions/checkout@v4 | ||
with: | ||
path: ${{ github.event.repository.name }} | ||
|
||
- name: Copy plugin to ArchivesSpace | ||
run: | | ||
cp -r ${{ github.workspace }}/${{ github.event.repository.name }} ${{ github.workspace }}/plugins | ||
- name: Run Rubocop | ||
run: | | ||
./build/run rubocop -Ddir="plugins/${{ github.event.repository.name }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
inherit_from: ../../.rubocop.yml | ||
|
||
inherit_mode: | ||
merge: | ||
- Include | ||
|
||
AllCops: | ||
Include: | ||
- . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,35 @@ | ||
require 'net/http' | ||
require 'date' | ||
|
||
def generate_ref_id(resource_id) | ||
def generate_ref_id(resource) | ||
next_refid = get_next_refid(resource) | ||
|
||
begin | ||
url = URI.parse(AppConfig[:backend_url] + "/plugins/caas_next_refid?resource_id=#{resource_id}") | ||
url = URI.parse(AppConfig[:backend_url] + "/plugins/caas_next_refid?resource_id=#{resource.id}") | ||
request = Net::HTTP::Post.new(url.to_s) | ||
response = Net::HTTP.start(url.host, url.port) do |http| | ||
Net::HTTP.start(url.host, url.port) do |http| | ||
http.request(request) | ||
end | ||
refid = JSON(response.body)['next_refid'] | ||
next_refid | ||
rescue | ||
refid = DateTime.now.strftime('%Q') | ||
return DateTime.now.strftime('%Q') | ||
end | ||
refid | ||
end | ||
|
||
def get_next_refid(resource) | ||
resource['caas_next_refid'] ? resource['caas_next_refid']['next_refid'] : 1 | ||
end | ||
|
||
ArchivalObject.auto_generate(property: :ref_id, | ||
generator: proc do |json| | ||
resource = Resource.to_jsonmodel(JSONModel::JSONModel(:resource).id_for(json['resource']['ref'])) | ||
"#{resource['ead_id']}_ref#{generate_ref_id(resource['id'])}" | ||
"#{resource['ead_id']}_ref#{generate_ref_id(resource)}" | ||
end, | ||
only_on_create: true) | ||
|
||
ArchivalObject.auto_generate(property: :ref_id, | ||
generator: proc do |json| | ||
resource = Resource.to_jsonmodel(JSONModel::JSONModel(:resource).id_for(json['resource']['ref'])) | ||
"#{resource['ead_id']}_ref#{generate_ref_id(resource['id'])}" | ||
"#{resource['ead_id']}_ref#{generate_ref_id(resource)}" | ||
end, | ||
only_if: proc { |json| json['caas_regenerate_ref_id'] }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters