Skip to content

Commit

Permalink
redploy oni
Browse files Browse the repository at this point in the history
  • Loading branch information
johnf committed Nov 23, 2024
1 parent 4497015 commit 847801f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
25 changes: 4 additions & 21 deletions app/controllers/api/v1/oni_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def objects
collection_ids = ids.select { |id| id['type'] == 'collection' }.pluck('id')
item_ids = ids.select { |id| id['type'] == 'item' }.pluck('id')

collection_mimetypes = Essence.joins(item: :collection).where(item: { collection_id: collection_ids }).distinct.pluck(:mimetype)
item_mimetypes = Essence.joins(:item).where(item_id: item_ids).distinct.pluck(:mimetype)
@mime_types = collection_mimetypes.concat(item_mimetypes).uniq

collections = Collection.where(id: collection_ids)
.select('collections.*, COUNT(DISTINCT items.id) AS items_count, COUNT(essences.id) AS essences_count')
.left_joins(items: :essences)
Expand All @@ -87,27 +91,6 @@ def objects
end
end

def object
unless params[:id]
render json: { error: 'id is required' }, status: :bad_request

return
end

md = params[:id].match(repository_item_url(collection_identifier: '(.*)', item_identifier: '(.*)'))
if md
@collection = Collection.where(private: false).find_by(identifier: md[1])
@data = @collection.items.where(private: false).find_by(identifier: md[2])
else
md = params[:id].match(repository_collection_url(collection_identifier: '(.*)'))
unless md
render json: { error: 'Invalid id parameter' }, status: :bad_request
return
end
@data = Collection.find_by(identifier: md[1])
end
end

def object_meta
unless params[:id]
render json: { error: 'id is required' }, status: :bad_request
Expand Down
29 changes: 19 additions & 10 deletions app/views/api/v1/oni/objects.json.jb
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,35 @@
description: object.description.truncate(256),
conformsTo: "https://w3id.org/ldac/profile##{is_item ? 'Object' : 'Collection'}",
recordType: ['Data', 'Object', is_item ? 'RepositoryObject' : 'RepositoryCollection'],
# FIXME: Outside of current API spec and subject to change
inLanguage: (is_item ? object.content_languages : object.languages).map { |language| { name: language.name, code: language.code } }[0]
extra: {
language: (is_item ? object.content_languages : object.languages).map(&:name),
}
}

if is_item
response[:memberOf] = repository_collection_url(object.collection)
response[:parent] = repository_collection_url(object.collection)
response[:root] = repository_collection_url(object.collection)
end

if object.has_attribute?(:items_count)
response[:metadata] ||= {}
response[:metadata][:objectsCount] = object.items_count
end
extra = response[:extra]

extra[:objectsCount] = object.items_count if object.has_attribute?(:items_count)
extra[:filesCount] = object.essences_count if object.has_attribute?(:essences_count)

if object.has_attribute?(:essences_count)
response[:metadata] ||= {}
response[:metadata][:filesCount] = object.essences_count
if object.private?
extra[:accessControl] = 'AccessControlList'
elsif object.access_condition.nil?
extra[:accessControl] = 'AuthorizationByInvitation'
elsif object.access_condition.name == 'Open (subject to agreeing to PDSC access conditions)'
extra[:accessControl] = 'AgreeToTerms'
else
extra[:accessControl] = 'Public'
end

# TODO:: add communicationMode

extra[:mediaType] = @mime_types

response
end
}
2 changes: 1 addition & 1 deletion docker/oni.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM node:lts AS builder

ARG ONI_API_CLIENTID
ARG ONI_API_CLIENTSECRET
ARG BUMP=4
ARG BUMP=5

WORKDIR /tmp
RUN git clone https://github.com/paradisec-archive/oni.git && cd oni && git switch paradisec
Expand Down

0 comments on commit 847801f

Please sign in to comment.