Commit 8b7c3383 authored by R.W.Majeed's avatar R.W.Majeed
Browse files

fixed using description for tooltip. Use readable path if no description is available.

parent 893dfbe6
Loading
Loading
Loading
Loading
+47 −2
Original line number Diff line number Diff line
@@ -311,6 +311,49 @@ public class Import implements AutoCloseable{
		}
		return xmlbuf.toString();
	}
	/**
	 * Build a readable representation of a concept path.
	 * E.g. remove base path and namespace prefixes from path names
	 * @param path ontology path
	 * @return readable path
	 */
	public String readableConceptPath(String path){
		if( path.startsWith(metaBase) ){
			path = path.substring(metaBase.length());
		}
		StringBuilder b = new StringBuilder();
		int pos = 0;
		boolean done = false;
		char prefix_char;
		do{
			int sep = path.indexOf('\\', pos);
			if( sep == -1 ){
				done = true;
				sep = path.length();
			}else if( sep == path.length()-1 ){
				// empty backslash at end of path
				done = true;
			}
			// skip the http:// part of url prefixes
			if( path.substring(pos,pos+7).equals("http://") ){
				// prefixes will end in #
				prefix_char = '#';
				pos += 7;
			}else{
				// prefix will end in :
				prefix_char = ':';
			}
			// is there a prefix in the path segment?
			int pfx = path.indexOf(prefix_char, pos);
			if( pfx != -1 && pfx < sep ){
				// prefix found, ignore the prefix
				pos = pfx+1;
			}
			b.append('\\').append(path.substring(pos, sep));
			pos = sep+1;
		}while( !done );
		return b.toString();
	}
	private void insertMeta(int level, String path_prefix, Concept concept, boolean accessRoot) throws SQLException, OntologyException{
		insertMeta.setInt(1, level);
		String label = concept.getPrefLabel(locale);
@@ -399,8 +442,10 @@ public class Import implements AutoCloseable{
		// c_tooltip
		// try to use concept description
		String descr = concept.getDescription(locale);
		if( descr == null )descr = path; // use path if no description available
		insertMeta.setString(9, path);
		if( descr == null ){
			descr = readableConceptPath(path); // use path if no description available
		}
		insertMeta.setString(9, descr);
		
		// m_applied_path
		insertMeta.setString(10, "@");
+55 −0
Original line number Diff line number Diff line
package de.sekmi.histream.i2b2.ont;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import de.sekmi.histream.i2b2.sql.VirtualConnection;

public class TestOntologyImport {
	VirtualConnection dbcData;
	VirtualConnection dbcMeta;
	Import imp;
	
	@Before
	public void prepareVirtualConnections() throws SQLException{
		dbcData = new VirtualConnection( a -> {} );
		dbcMeta = new VirtualConnection( a -> {} );
		Map<String, String> props = new HashMap<>();
		// set preferences
		props.put("meta.basepath", "\\i2b2\\");
		props.put("meta.sourcesystem_cd", "test");
		props.put("meta.table", "i2b2metadata.i2b2");
		props.put("meta.access", "i2b2metadata.table_access");
		props.put("data.concept.table", "i2b2crcdata.concepts");
		props.put("ont.language", "en");
		imp = new Import(dbcMeta, dbcData, props);
	}

	@After
	public void closeVirtualConnections() throws SQLException{
		imp.close();
//		dbcData.close();
//		dbcMeta.close();
	}
	@Test
	public void verifyReadablePath(){
		String path = "\\i2b2\\asdf:First\\k23kskd:Second\\";
		String readable = imp.readableConceptPath(path);
		// there should be no prefixes
		Assert.assertEquals(-1, readable.indexOf(':'));
		// print for debugging
		System.out.println(readable);

		// second test with url prefixes
		path = "\\i2b2\\http://lala/xyz#First\\asdf:Second";
		String readable2 = imp.readableConceptPath(path);
		System.out.println(readable);
		Assert.assertEquals(readable, readable2);
	}
}