Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- normalize list primitive response
- list query
- def build_list_name(list_uri:, list_name:, element_name:, customer_uri:, comment:)
- %(
- PREFIX rdfs: <#{PrefixesService::PREFIXES[:rdfs]}>
- PREFIX owl: <#{PrefixesService::PREFIXES[:owl]}>
- PREFIX rdf: <#{PrefixesService::PREFIXES[:rdf]}>
- PREFIX wco: <#{PrefixesService::PREFIXES[:wco]}>
- INSERT DATA {
- <#{list_uri}> a wco:List ;
- rdfs:subClassOf wco:CustomMetadatum ;
- rdfs:subClassOf wco:List ;
- rdfs:label "#{list_name}" ;
- #{comment_part(comment)} ;
- rdf:first <#{PrefixesService::PREFIXES[:wci]}#{element_name}> .
- <#{customer_uri}> wco:hasCustomMetadatum <#{list_uri}> .
- }
- )
- end
- def find_by_list_name(customer_uri:, list_name:)
- %(
- PREFIX rdfs: <#{PrefixesService::PREFIXES[:rdfs]}>
- PREFIX wco: <#{PrefixesService::PREFIXES[:wco]}>
- SELECT ?listLabel ?element ?comment
- WHERE {
- <#{customer_uri}> wco:hasCustomMetadatum wco:#{list_name} .
- ?list a wco:List ;
- rdfs:label ?listLabel ;
- rdf:rest*/rdf:first ?element .
- OPTIONAL { ?list rdfs:comment ?comment } .
- FILTER (STRSTARTS(STR(?list), "#{PrefixesService::PREFIXES[:wco]}#{list_name}"))
- }
- )
- end
- def comment_part(comment)
- comment.nil? ? "" : "rdfs:comment \"#{comment}\" ;"
- end
- end
- private_class_method :comment_part
- list service
- def create_list(list_name, elements, customer, comment)
- list_metadatum = "Metadatum-#{SecureRandom.uuid}"
- list_uri = "#{PrefixesService::PREFIXES[:wco]}#{list_metadatum}"
- element_name = build_name(element: elements.first)
- sparql_query = ListQuery.build_list_name(list_uri: list_uri,
- list_name: list_name,
- element_name: element_name,
- customer_uri: customer.uri, comment: comment)
- result = GraphDBConnector.instance.sparql_api_statement(sparql_query)
- if result[:success]
- elements[1..-1].each do |element_name|
- element_name = build_name(element: element_name)
- sparql_query = ListQuery.build_elements(list_uri: list_uri, element_name: element_name)
- GraphDBConnector.instance.sparql_api_statement(sparql_query)
- end
- { data: list_uri }
- else
- { error: result[:error] }
- end
- end
- def find_by_list_name(customer, list_name)
- return nil unless customer
- sparql_query = ListQuery.find_by_list_name(customer_uri: customer.uri, list_name: list_name)
- result = GraphDBConnector.instance.query(sparql_query)
- return nil unless result[:success] && result[:data].present?
- result[:data]
- end
- metadatum query
- def select_custom_metadata_for_customer(customer_uri:)
- %(
- PREFIX rdfs: <#{PrefixesService::PREFIXES[:rdfs]}>
- PREFIX wco: <#{PrefixesService::PREFIXES[:wco]}>
- PREFIX wci: <#{PrefixesService::PREFIXES[:wci]}>
- SELECT ?metadatum ?metadatumLabel ?subClassOf ?comment WHERE {
- <#{customer_uri}> wco:hasCustomMetadatum ?metadatum .
- ?metadatum rdfs:subClassOf wco:CustomMetadatum ;
- rdfs:subClassOf wco:PrimitiveType ;
- rdfs:subClassOf ?subClassOf ;
- rdfs:label ?metadatumLabel ;
- OPTIONAL { ?metadatum rdfs:comment ?comment } .
- FILTER (?subClassOf NOT IN (
- wco:PrimitiveType, owl:Thing, wco:CustomMetadatum, wco:Metadatum)
- )
- FILTER(?subClassOf IN (wco:Date, wco:Number, wco:Text, wco:Time, wco:List, wco:Amount))
- }
- )
- end
- ontology serializer
- comment = datum.comment.value rescue nil
- {
- uri: datum.metadatum.value,
- class_name: datum.metadatum.value.split("#").last,
- label: datum.metadatumLabel.value,
- comment: comment,
- sub_class_of: {
- uri: datum.subClassOf.value,
- type: datum.subClassOf.value.split("#").last
- }
- }
- metadatum serializer
- def serializable_hash
- return nil unless @records
- type = @records.find{|el| el if el[:subclassOf].value.split("#").last != @params[:name] }
- object = @records.find{|el| el if el[:subclassOf].value.split("#").last == @params[:name] }
- uri, type = if type.present?
- [type[:subclassOf].value, type[:subclassOf].value.split("#").last]
- else
- ["#{PrefixesService::WEBDOX_URI}/ontology#List", "List"]
- end
- comment = object[:comment].value rescue nil
- {
- uri: object[:class].value,
- class_name: object[:class].value.split("#").last,
- label: object[:label].value,
- comment: comment,
- sub_class_of: {
- uri: uri,
- type: type
- }
- }
- metadatum query
- def find_by_metadatum_name(name:, customer_uri:)
- sparql_query = %(
- PREFIX rdfs: <#{PrefixesService::PREFIXES[:rdfs]}>
- PREFIX owl: <#{PrefixesService::PREFIXES[:owl]}>
- PREFIX wco: <#{PrefixesService::PREFIXES[:wco]}>
- SELECT ?class ?label ?subclassOf ?comment
- WHERE {
- <#{customer_uri}> wco:hasCustomMetadatum wco:#{name} .
- ?class a owl:Class ;
- rdfs:label ?label .
- OPTIONAL { ?class rdfs:subClassOf ?subclassOf }
- OPTIONAL { ?class rdfs:comment ?comment }
- FILTER (?subclassOf NOT IN (
- wco:PrimitiveType,owl:Thing, wco:CustomMetadatum, wco:Metadatum)
- )
- FILTER (?class = wco:#{name})
- }
- )
- result = GraphDBConnector.instance.query(sparql_query)
- return nil unless result[:success] && result[:data].any?
- result[:data]
- end
- contract request template serializer
- comment = el.comment.value rescue nil
- base_options = {
- contract_request_template_uri: contract_request_template.uri,
- metadatum_uri: el.ontology.value,
- metadatum_short_uri: el.ontology.value.split("#").last,
- metadatum_label: el.label.value,
- comment: comment
- }
- contract request template query
- def metadata(contract_request_template_uri:)
- %(
- PREFIX wco: <#{PrefixesService::PREFIXES[:wco]}>
- PREFIX rdfs: <#{PrefixesService::PREFIXES[:rdfs]}>
- SELECT DISTINCT ?ontology ?label ?type ?subClassOf ?comment
- WHERE {
- {
- <#{contract_request_template_uri}> wco:hasCustomMetadatumWRT ?ontology .
- ?ontology rdfs:label ?label .
- ?ontology rdf:type ?type .
- OPTIONAL { ?ontology rdfs:comment ?comment }
- OPTIONAL { ?ontology rdfs:subClassOf ?subClassOf . }
- FILTER (
- (?type = wco:List && ?subClassOf = wco:CustomMetadatum) ||
- (?subClassOf IN (wco:Number, wco:Text, wco:Date, wco:Time, wco:Amount) && ?type = wco:CustomMetadatum)
- )
- }
- UNION
- {
- SELECT ?ontology ?label ?type ?subClassOf ?comment
- WHERE {
- <#{contract_request_template_uri}> wco:hasAssignedMetadatum ?ontology .
- ?ontology rdfs:label ?label .
- ?ontology rdf:type ?type .
- ?ontology rdfs:subClassOf ?subClassOf .
- OPTIONAL { ?ontology rdfs:comment ?comment }
- FILTER (
- ?type IN (wco:Metadatum) && ?subClassOf IN (wco:Amount, wco:Metadatum-Party, wco:Metadatum-Counterparty
- ))
- }
- }
- }
- ORDER BY LCASE(?label)
- )
- end
- add comments to ontology, parties, counterparties?
Advertisement
Add Comment
Please, Sign In to add comment