Commit 317c1990 authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette
Browse files

modify SchemaRegistry model names

parent d9eabcd7
......@@ -29,11 +29,11 @@ module Dspace
colls
end
def self.build_schemaregistry(schemas=[])
def self.build_schemas(schemas=[])
return schemas unless schemas.is_a? Array
colls = []
schemas.each do |c|
colls << Dspace::SchemaRegistry.new(c)
colls << Dspace::Schema.new(c)
end
colls
end
......@@ -42,7 +42,7 @@ module Dspace
return fields unless fields.is_a? Array
colls = []
fields.each do |c|
colls << Dspace::Field.new(c)
colls << Dspace::MetadataField.new(c)
end
colls
end
......
module Dspace
class Field
include Dspace::Builders::HashBuilder
attr_accessor :name, :element, :description, :qualifier
attr_reader :id, :parentSchema, :expand
def initialize(args={})
@id = args['fieldId']
@name = args['name']
@element = args['element']
@description = args['description']
@qualifier = args['qualifier']
@parentSchema = args['parentSchema']
@expand = args['expand']
end
def to_h
{
fieldId: @id,
name: @name,
element: @element,
description: @description,
qualifier: @qualifier,
parentSchema: @parentSchema,
expand: @expand
}
end
end
end
......@@ -17,7 +17,7 @@ module Dspace
'GET /rest/registries/schema' do
query_keys :expand
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_schemaregistry(JSON.parse(response.body))
Dspace::Builders::ModelBuilder.build_schemas(JSON.parse(response.body))
end
end
......@@ -37,7 +37,7 @@ module Dspace
'POST /rest/registries/schema' do
body { |object| JSON.generate(object.to_h) }
handler(200) do |response|
Dspace::SchemaRegistry.new(JSON.parse(response.body))
Dspace::Schema.new(JSON.parse(response.body))
end
end
......@@ -54,7 +54,7 @@ module Dspace
'GET /rest/registries/metadata-fields/:field_id' do
query_keys :expand
handler(200) do |response|
Dspace::Field.new(JSON.parse(response.body))
Dspace::MetadataField.new(JSON.parse(response.body))
end
end
......@@ -64,7 +64,7 @@ module Dspace
'POST /rest/registries/schema/:schema_prefix/metadata-fields' do
body { |object| JSON.generate(object.to_h) }
handler(200) do |response|
Dspace::Field.new(JSON.parse(response.body))
Dspace::MetadataField.new(JSON.parse(response.body))
end
end
......@@ -89,7 +89,7 @@ module Dspace
'GET /rest/registries/schema/:schema_prefix/metadata-fields/:element' do
query_keys :expand
handler(200) do |response|
Dspace::SchemaRegistry.new(JSON.parse(response.body))
Dspace::Schema.new(JSON.parse(response.body))
end
end
......@@ -98,7 +98,7 @@ module Dspace
action :find_qualified_element,
'GET /rest/registries/schema/:schema_prefix/metadata-fields/:element/:qualifier' do
handler(200) do |response|
Dspace::Field.new(JSON.parse(response.body))
Dspace::MetadataField.new(JSON.parse(response.body))
end
end
......
module Dspace
class SchemaRegistry
include Dspace::Builders::HashBuilder
attr_accessor :namespace, :prefix, :expand
attr_reader :id, :fields
def initialize(args={})
@id = args['schemaID']
@namespace = args['namespace']
@prefix = args['prefix']
@expand = args['expand']
@fields = Dspace::Builders::ModelBuilder.build_fields(args['fields'])
end
def to_h
{
schemaID: @id,
namespace: @namespace,
prefix: @prefix,
expand: @expand,
fields: @fields
}
end
def add_field(name, element, description)
f = {}
f['name'] = name
f['element'] = element
f['description'] = description
@fields << Dspace::Field.new(f)
@fields
end
def reset_fields
@fields = []
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment