Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix installation instructions #432

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ This application provides the means to map (crosswalk) data specifications (stan

## Local installation 2

> Precondition -> The following technilogies are needed before starting the installation:
> - ruby 2.7.1
> - postgreSQL 13
> - npm
> - node
> - yarn
### Dependencies

1. Ruby (see [.ruby-version](.ruby-version) or [Gemfile](Gemfile) to find out the required version)
2. PostgreSQL 13
3. Node 14 and Yarn
4. libpq-dev

### Steps

1. Clone this project locally.
2. Create an ".env" file by copying the ".env.example" file.
3. Make sure the version of ruby on your system is the same as declared in the Gemfile.
4. Run `bundle install` (backend dependencies).
5. Run `yarn install` (frontend dependencies).
6. Create a user in postgres to manage the db creation/migration. Or use postgres credentials.
7. Make sure the ennvironment variables for the database are set into the .env file (the user and password should be the same as on the step 6.)
8. Run `rake db:create db:migrate db:seed` (Database structure creation and population).
9. Run `rails s`
10. Go to http://localhost:3000
2. Create a database user and enable a password-based authentication method for the user (e.g. `md5`).
3. Create a `.env` file by copying the [.env.example](.env.example) file. Modify the `.env` file to use the database user's credentials.
4. Run `gem install bundler:<VERSION>` to install Bundler (see the very bottom of [Gemfile.lock](Gemfile.lock) to find out the required version).
5. Run `bin/bundle` to install the backend dependencies.
6. Run `yarn install` to install the frontend dependencies.
7. Run `bin/rails db:create db:migrate` to create the database.
8. (Optional) Run `bin/rails db:seed` to populate the database with sample data.
9. Run `bin/rails s` to start the server.
10. Visit the app URL specified in the `.env` file.

## Collaborate

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/mappings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def permitted_params
def with_instance
return Mapping.new if params[:id].blank?

@instance ||= current_organization.mappings.find(params[:id])
@instance ||= current_configuration_profile.mappings.find(params[:id])
rescue ActiveRecord::RecordNotFound
raise "Couldn't find mapping"
end
Expand Down
186 changes: 127 additions & 59 deletions app/services/exporters/mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,76 @@ class Mapping
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"sdo": "http://schema.org/",
"xsd": "http://www.w3.org/2001/XMLSchema#"
"xsd": "http://www.w3.org/2001/XMLSchema#",
"dct:title": {
"@container": "@language"
},
"dct:description": {
"@container": "@language"
},
"dct:created": {
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
},
"dct:dateModified": {
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
},
"desm:abstractClassType": {
"@type": "@id"
},
"desm:hasClassMapping": {
"@type": "@id"
},
"desm:hasDSO": {
"@type": "@id"
},
"desm:abstractClassModeled": {
"@type": "@id"
},
"dct:hasPart": {
"@type": "@id"
},
"desm:spineTerm": {
"@type": "@id"
},
"desm:mappedTerm": {
"@type": "@id"
},
"desm:mappingPredicate": {
"@type": "@id"
},
"rdfs:label": {
"@container": "@language"
},
"rdfs:comment": {
"@container": "@language"
},
"rdfs:domain": {
"@type": "@id"
},
"rdfs:subPropertyOf": {
"@type": "@id"
},
"desm:inSchema": {
"@type": "@id"
}
}.freeze

attr_reader :alignments, :mapping

delegate :created_at, :slug, :spine, :title, :updated_at,
to: :mapping
delegate :domain, to: :spine

###
# @description: Initializes this class with the instance to export.
###
def initialize instance
@instance = instance
def initialize mapping
@alignments = mapping
.alignments
.where.not(predicate_id: nil)
.includes(:mapped_terms, :predicate, :spine_term)

@mapping = mapping
end

###
Expand All @@ -38,76 +100,82 @@ def initialize instance
def export
{
"@context": CONTEXT,
"@graph": @instance.alignments.map {|alignment|
term_nodes(alignment)
}.flatten.unshift(main_node)
"@graph": [config_node, class_node, *alignment_nodes]
}
end

###
# @description: Specifies the format the main node (the node that represents the mapping itself)
# should have.
###
def main_node
{
"@id": "http://desmsolutions.org/TermMapping/#{@instance.id}",
"@type": "desm:AbstractClassMapping",
"dcterms:created": @instance.created_at.strftime("%F"),
"dcterms:dateModified": @instance.updated_at.strftime("%F"),
"dcterms:title": @instance.title,
# @todo: Where to take this from
"dcterms:description": "",
"desm:abstractClassMapped": {"@id": @instance.specification.domain.uri},
"dcterms:hasPart": @instance.alignments.map {|alignment|
{"@id": alignment.uri}
}
private

def alignment_nodes
@alignment_nodes ||= alignments.map {|alignment|
build_alignment_node(alignment)
}
end

###
# @description: For each alignment to a spine term, we build basically 3 nodes, one ofr the
# alignment, one for the mapped property (more than one if there are many), and the last one
# for the spine property.
###
def term_nodes alignment
[
alignment_node(alignment),
alignment.mapped_terms.map {|term| property_node(term) },
property_node(alignment.spine_term)
].flatten
# rubocop:disable Metrics/AbcSize
def build_alignment_node(alignment)
mapped_term = alignment.mapped_terms.first
spine_term = alignment.spine_term

node = {
"@id": build_uri("termMapping#{alignment.id}"),
"@type": "desm:TermMapping",
"dct:dateModified": alignment.updated_at.to_date,
"dct:created": alignment.created_at.to_date
}

if alignment.comment?
node["dct:description"] = {
"en": alignment.comment
}
end

node.merge(
"desm:spineTerm": build_uri("terms/#{spine_term.id}"),
"desm:mappedTerm": (build_uri("terms/#{mapped_term.id}") if mapped_term),
"desm:mappingPredicate": build_uri("predicates/#{alignment.predicate.slug}")
)
end
# rubocop:enable Metrics/AbcSize

###
# @description: Specifies the format the alignment node should have.
###
def alignment_node alignment
def build_uri(value)
URI(Desm::APP_DOMAIN) + "#{slug}-#{mapping.id}/#{value}"
end

def class_node
{
"@id": "http://desmsolutions.org/TermMapping/#{alignment.id}",
"@type": "desm:TermMapping",
"dcterms:isPartOf": {"@id": "http://desmsolutions.org/TermMapping/#{@instance.id}"},
"desm:comment": alignment.comment,
"desm:mappedterm": alignment.mapped_terms.map {|mapped_term|
{"@id": mapped_term.uri}
"@id": build_uri("classMapping"),
"@type": "desm:AbstractClassMapping",
"dct:title": {
"en": "`#{title}` class mapping"
},
"desm:mappingPredicate": {"@id": alignment.predicate&.uri},
"desm:spineTerm": {"@id": alignment.spine_term.uri}
"dct:description": {
"en": "A partial class mapping."
},
"dct:created": created_at.to_date,
"dct:dateModified": updated_at.to_date,
"desm:isClassMappingOf": build_uri("mappingConfig"),
"desm:abstractClassModeled": build_uri("AbstractClasses/#{domain.slug}"),
"dct:hasPart": alignment_nodes.map {|node| node.fetch(:"@id") }
}
end

###
# @description: Defines the structure of a generic property term.
###
def property_node term
def config_node
{
"@id": term.source_uri,
"@type": "rdf:Property",
"desm:sourceURI": {"@id": term.property.source_uri},
"rdfs:subPropertyOf": {"@id": term.property.subproperty_of},
"desm:valueSpace": {"@id": term.property.value_space},
"rdfs:label": term.property.label,
"rdfs:comment": term.property.comment,
"rdfs:domain": {"@id": term.property.selected_domain},
"rdfs:range": {"@id": term.property.selected_range}
"@id": build_uri("mappingConfig"),
"@type": "desm:MappingConfiguration",
"dct:title": {
"en": "Configuration for `#{title}` mapping"
},
"dct:description": {
"en": "A partial mapping config."
},
"dct:created": created_at.to_date,
"dct:dateModified": updated_at.to_date,
"desm:hasClassMapping": "http://desmsolutions.org/#{slug}/classMapping",
"desm:abstractClassType": build_uri("AbstractClasses"),
"desm:mappingPredicateType": build_uri("MappingPredicates"),
"desm:hasDSO": build_uri("mappingConfig")
}
end
end
Expand Down