def make_grib2_mapping(fu_p, arecord, userid, branchid, force): errs = [] agribcomp, errs = grib2_comp(arecord, errs) acfcomp = cfname(arecord.cfname, arecord.units) inv = '"True"' replaces = fu_p.find_valid_mapping(agribcomp, acfcomp, graph=branchid) if replaces: replaced = metarelate.Mapping(replaces.get('mapping')) replaced.populate_from_uri(fu_p, branchid) replaced = update_mappingmeta(replaced, userid) result = replaced else: target_differs = fu_p.find_valid_mapping(agribcomp, None, graph=branchid) if target_differs: replaced = metarelate.Mapping(target_differs.get('mapping')) replaced.populate_from_uri(fu_p, branchid) replaced = update_mappingmeta(replaced, userid) mr = _report(replaced) replaced.source = agribcomp replaced.target = acfcomp nr = _report(replaced) if not force: errs.append('forcing replacement of ' '{m} with {n}'.format(m=mr, n=nr)) result = replaced else: amap = metarelate.Mapping(None, agribcomp, acfcomp, creator=userid, invertible=inv) result = amap return result, errs
def make_stash_mapping(fu_p, stashmsi, name, units, userid, branchid, force): errs = [] astashcomp, errs = stash_comp(stashmsi, errs) acfcomp = cfname(name, units) replaces = fu_p.find_valid_mapping(astashcomp, acfcomp, graph=branchid) if replaces: replaced = metarelate.Mapping(replaces.get('mapping')) replaced.populate_from_uri(fu_p, branchid) replaced = update_mappingmeta(replaced, userid) result = replaced else: target_differs = fu_p.find_valid_mapping(astashcomp, None, graph=branchid) if target_differs: replaced = metarelate.Mapping(target_differs.get('mapping')) replaced.populate_from_uri(fu_p, branchid) mr = _report(replaced) replaced = update_mappingmeta(replaced, userid) replaced.source = astashcomp replaced.target = acfcomp nr = _report(replaced) if not force: errs.append('forcing replacement of ' '{m} with {n}'.format(m=mr, n=nr)) result = replaced else: amap = metarelate.Mapping(None, astashcomp, acfcomp, creator=userid, invertible='"False"') result = amap return result, errs
def mapping_json(request, mapping_id): branch = _get_branch(request) mapping = metarelate.Mapping(None) mapping.shaid = mapping_id try: mapping.populate_from_uri(fuseki_process, graph=branch) except Exception, e: logger.error('mapping failed to populate\n{}'.format(e)) raise Http404
def mapping_view_graph(request, mapping_id): """""" branch = _get_branch(request) mapping = metarelate.Mapping(None) mapping.shaid = mapping_id mapping.populate_from_uri(fuseki_process, graph=branch) response = HttpResponse(content_type="image/svg+xml") graph = mapping.dot() response.write(graph.create_svg()) return response
def list_mappings(request, validate): """ list mappings which reference the concept search criteria by concept by source then target """ if validate == 'False': validate = False else: validate = True requestor_path = request.GET.get('ref', '') requestor_path = urllib.unquote(requestor_path).decode('utf8') if requestor_path == '': requestor_path = '{}' requestor = json.loads(requestor_path) if validate: results = fuseki_process.validate(requestor) else: results = fuseki_process.search(requestor) mapping_links = [] validated = True for key, inv_mappings in results.iteritems(): mapping_link = {'label': key, 'mappings': []} for inv_map in inv_mappings: validated = False muri = inv_map['amap'] mapping = metarelate.Mapping(muri) url = reverse('mapping', kwargs={'mapping_id': mapping.shaid}) label = inv_map.get('signature', []) mapping_link['mappings'].append({'url': url, 'label': label}) mapping_links.append(mapping_link) context_dict = {'invalid': mapping_links} if validate and validated: context_dict['validated'] = ('This graph has successfully validated ' 'and is suitable for merging.') elif validate: context_dict['validated'] = ('This graph has not validated and should ' 'not be merged. Details below:') context = RequestContext(request, context_dict) return render_to_response('select_list.html', context)
def retrieve_mappings(self, sourcetype, targettype, service=None): sourcetype = metarelate.Item(sourcetype) targettype = metarelate.Item(targettype) templates = self.retrieve_mapping_templates(sourcetype, targettype, service=service) map_templates = json.loads(templates) mapping_list = deque() mapping_queue = Queue() mq = 0 for mt in map_templates: mapping_queue.put( metarelate.Mapping(mt.get('mapping'), invertible=mt.get('invertible'), inverted=mt.get('inverted'))) mq += 1 for i in range(MAXTHREADS): MappingPopulateWorker(mapping_queue, mapping_list, self, service).start() mapping_queue.join() if len(mapping_list) != mq: msg = '{} entries in mapping_list, expected {}' raise ValueError(msg.format(len(mapping_list), mq)) return mapping_list
def make_mappings(fu_p, arecord, userid, branchid, force): serrs = [] gerrs = [] astashcomp, serrs = stash_comp(arecord.stash, serrs) agribcomp, gerrs = grib2_comp(arecord, gerrs) acfcomp = cfname(arecord.cfname, arecord.units) replaces = fu_p.find_valid_mapping(astashcomp, acfcomp, graph=branchid) if replaces: replaced = metarelate.Mapping(replaces.get('mapping')) replaced.populate_from_uri(fu_p, branchid) replaced = update_mappingmeta(replaced, userid) smap = replaced else: target_differs = fu_p.find_valid_mapping(astashcomp, None, graph=branchid) if target_differs: replaced = metarelate.Mapping(target_differs.get('mapping')) replaced.populate_from_uri(fu_p, branchid) mr = stcf._report(replaced) replaced = update_mappingmeta(replaced, userid) replaced.source = astashcomp replaced.target = acfcomp nr = stcf._report(replaced) if not force: serrs.append('forcing replacement of ' '{m} with {n}'.format(m=mr, n=nr)) smap = replaced else: smap = metarelate.Mapping(None, astashcomp, acfcomp, creator=userid, invertible='"False"') inv = '"True"' replaces = fu_p.find_valid_mapping(agribcomp, acfcomp, graph=branchid) if replaces: replaced = metarelate.Mapping(replaces.get('mapping')) replaced.populate_from_uri(fu_p, branchid) replaced = update_mappingmeta(replaced, userid) gmap = replaced else: target_differs = fu_p.find_valid_mapping(agribcomp, None, graph=branchid) if target_differs: replaced = metarelate.Mapping(target_differs.get('mapping')) replaced.populate_from_uri(fu_p, branchid) replaced = update_mappingmeta(replaced, userid) mr = g2cf._report(replaced) replaced.source = agribcomp replaced.target = acfcomp nr = g2cf._report(replaced) if not force: gerrs.append('forcing replacement of ' '{m} with {n}'.format(m=mr, n=nr)) gmap = replaced else: gmap = metarelate.Mapping(None, agribcomp, acfcomp, creator=userid, invertible=inv) return (smap, serrs, gmap, gerrs)
def simple_mapping_um_cf(): uri = '<http://www.metarelate.net/test/mapping/test_m001>' return metarelate.Mapping(uri, source=simple_component_um(), target=simple_component_cf())
def test_eq_fail(self): mapping = metarelate.Mapping('uri', stock.simple_component_cf(), stock.simple_component_um()) self.assertNotEqual(self.mapping, mapping)