Updates for freemarker conversion and also updates for umls term service integration
This commit is contained in:
parent
01a90eb20d
commit
57ab4e92f3
11 changed files with 420 additions and 128 deletions
|
@ -952,6 +952,15 @@
|
||||||
<url-pattern>/UMLSTermsRetrieval</url-pattern>
|
<url-pattern>/UMLSTermsRetrieval</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>ConceptSearchService</servlet-name>
|
||||||
|
<servlet-class>edu.cornell.mannlib.vitro.webapp.servlet.ConceptSearchServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>ConceptSearchService</servlet-name>
|
||||||
|
<url-pattern>/conceptSearchService</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>ProcessTerminologyAnnotation</servlet-name>
|
<servlet-name>ProcessTerminologyAnnotation</servlet-name>
|
||||||
<servlet-class>edu.cornell.mannlib.vitro.webapp.servlet.ProcessTerminologyController</servlet-class>
|
<servlet-class>edu.cornell.mannlib.vitro.webapp.servlet.ProcessTerminologyController</servlet-class>
|
||||||
|
|
|
@ -10,20 +10,31 @@
|
||||||
<#assign sparqlForAcFilter = editConfiguration.pageData.sparqlForAcFilter />
|
<#assign sparqlForAcFilter = editConfiguration.pageData.sparqlForAcFilter />
|
||||||
<#assign disabledVal = ""/>
|
<#assign disabledVal = ""/>
|
||||||
<#if editMode = "edit">
|
<#if editMode = "edit">
|
||||||
<#assign disabledVal = "" />
|
<#assign disabledVal = "disabled=\"disabled\"" />
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
<#--the heading and submit button label depend on the predicate uri-->
|
<#--the heading and submit button label depend on the predicate uri-->
|
||||||
|
|
||||||
<#assign formHeading = "investigator entry for "/>
|
<#assign formHeading = "investigator entry for "/>
|
||||||
<#assign submitButtonLabel = "Edit Investigator" />
|
<#assign submitButtonLabel = "Investigator" />
|
||||||
<#if editConfiguration.predicateUri?ends_with("hasPrincipalInvestigatorRole") >
|
<#if editConfiguration.predicateUri?ends_with("hasPrincipalInvestigatorRole") >
|
||||||
<#assign formHeading = "principal investigator entry for "/>
|
<#assign formHeading = "principal investigator entry for "/>
|
||||||
<#assign submitButtonLabel = "Edit Principal Investigator" />
|
<#assign submitButtonLabel = "Principal Investigator" />
|
||||||
<#elseif editConfiguration.predicateUri?ends_with("hasCo-PrincipalInvestigatorRole") >
|
<#elseif editConfiguration.predicateUri?ends_with("hasCo-PrincipalInvestigatorRole") >
|
||||||
<#assign formHeading = "co-principal investigator entry for "/>
|
<#assign formHeading = "co-principal investigator entry for "/>
|
||||||
<#assign submitButtonLabel = "Edit Co-Principal Investigator" />
|
<#assign submitButtonLabel = "Co-Principal Investigator" />
|
||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
|
<#if editMode = "add">
|
||||||
|
<#assign formHeading> Create ${formHeading} </#assign>
|
||||||
|
<#else>
|
||||||
|
<#assign formHeading> Edit ${formHeading} </#assign>
|
||||||
|
<#assign submitButtonLabel> Edit ${submitButtonLabel} </#assign>
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<#--Get existing value for specific data literals and uris-->
|
<#--Get existing value for specific data literals and uris-->
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
|
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.generators.AddRoleUtils;
|
||||||
/**
|
/**
|
||||||
* Custom form for adding a grant to an person for the predicates hasCo-PrincipalInvestigatorRole
|
* Custom form for adding a grant to an person for the predicates hasCo-PrincipalInvestigatorRole
|
||||||
and hasPrincipalInvestigatorRole.
|
and hasPrincipalInvestigatorRole.
|
||||||
|
@ -648,6 +649,25 @@ public class AddGrantRoleToPersonGenerator implements EditConfigurationGenerator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**Methods for checking edit mode **
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public EditMode getEditMode(VitroRequest vreq) {
|
||||||
|
List<String> roleToGrantPredicates = getPossibleRoleToGrantPredicates();
|
||||||
|
return AddRoleUtils.getEditMode(vreq, roleToGrantPredicates);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isAddMode(VitroRequest vreq) {
|
||||||
|
return AddRoleUtils.isAddMode(getEditMode(vreq));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEditMode(VitroRequest vreq) {
|
||||||
|
return AddRoleUtils.isEditMode(getEditMode(vreq));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isRepairMode(VitroRequest vreq) {
|
||||||
|
return AddRoleUtils.isRepairMode(getEditMode(vreq));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -728,80 +748,14 @@ public class AddGrantRoleToPersonGenerator implements EditConfigurationGenerator
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getPossibleroleToGrantPredicates() {
|
public List<String> getPossibleRoleToGrantPredicates() {
|
||||||
return ModelUtils.getPossiblePropertiesForRole();
|
return ModelUtils.getPossiblePropertiesForRole();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getPossiblegrantToRolePredicates() {
|
public List<String> getPossibleGrantToRolePredicates() {
|
||||||
return ModelUtils.getPossibleInversePropertiesForRole();
|
return ModelUtils.getPossibleInversePropertiesForRole();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Methods that check edit mode
|
|
||||||
*/
|
|
||||||
|
|
||||||
//Get edit mode
|
|
||||||
private EditMode getEditMode(VitroRequest vreq) {
|
|
||||||
List<String> roleToGrantPredicates = getPossibleroleToGrantPredicates();
|
|
||||||
//We're making some assumptions here: That there is only one role objec tot one activity object
|
|
||||||
//pairing, i.e. the same role object can't be related to a different activity object
|
|
||||||
//That said, there should only be one role to Activity predicate linking a role to an activity
|
|
||||||
//So if
|
|
||||||
Individual object = EditConfigurationUtils.getObjectIndividual(vreq);
|
|
||||||
boolean foundErrorMode = false;
|
|
||||||
int numberEditModes = 0;
|
|
||||||
int numberRepairModes = 0;
|
|
||||||
int numberPredicates = roleToGrantPredicates.size();
|
|
||||||
for(String predicate:roleToGrantPredicates) {
|
|
||||||
EditMode mode = FrontEndEditingUtils.getEditMode(vreq, object, predicate);
|
|
||||||
//Any error mode should result in error
|
|
||||||
if(mode == EditMode.ERROR) {
|
|
||||||
foundErrorMode = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(mode == EditMode.EDIT) {
|
|
||||||
numberEditModes++;
|
|
||||||
}
|
|
||||||
else if(mode == EditMode.REPAIR) {
|
|
||||||
numberEditModes++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//if found an error or if more than one edit mode returned, incorrect
|
|
||||||
|
|
||||||
if(foundErrorMode || numberEditModes > 1)
|
|
||||||
{
|
|
||||||
return EditMode.ERROR;
|
|
||||||
}
|
|
||||||
EditMode mode = EditMode.ADD;
|
|
||||||
//if exactly one edit mode found, then edit mode
|
|
||||||
if(numberEditModes == 1) {
|
|
||||||
mode = EditMode.EDIT;
|
|
||||||
}
|
|
||||||
//if all modes are repair, this means that all of them have zero statements returning
|
|
||||||
//which is incorrect
|
|
||||||
if(numberRepairModes == numberPredicates) {
|
|
||||||
mode = EditMode.REPAIR;
|
|
||||||
}
|
|
||||||
//otherwise all the modes are Add and Add will be returned
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
private boolean isAddMode(VitroRequest vreq) {
|
|
||||||
EditMode mode = getEditMode(vreq);
|
|
||||||
return (mode == EditMode.ADD);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isEditMode(VitroRequest vreq) {
|
|
||||||
EditMode mode = getEditMode(vreq);
|
|
||||||
return (mode == EditMode.EDIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isRepairMode(VitroRequest vreq) {
|
|
||||||
EditMode mode = getEditMode(vreq);
|
|
||||||
return (mode == EditMode.REPAIR);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methods to return URIS for various predicates
|
* Methods to return URIS for various predicates
|
||||||
|
|
|
@ -49,6 +49,7 @@ import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
|
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.generators.AddRoleUtils;
|
||||||
/**
|
/**
|
||||||
* Generates the edit configuration for adding a Role to a Person.
|
* Generates the edit configuration for adding a Role to a Person.
|
||||||
|
|
||||||
|
@ -1092,68 +1093,26 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
|
||||||
* Methods that check edit mode
|
* Methods that check edit mode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//Get edit mode
|
|
||||||
private EditMode getEditMode(VitroRequest vreq) {
|
/**Methods for checking edit mode **
|
||||||
List<String> roleToActivityPredicates = getPossibleRoleToActivityPredicates();
|
*
|
||||||
//We're making some assumptions here: That there is only one role objec tot one activity object
|
*/
|
||||||
//pairing, i.e. the same role object can't be related to a different activity object
|
public EditMode getEditMode(VitroRequest vreq) {
|
||||||
//That said, there should only be one role to Activity predicate linking a role to an activity
|
List<String> roleToGrantPredicates = getPossibleRoleToActivityPredicates();
|
||||||
//So if
|
return AddRoleUtils.getEditMode(vreq, roleToGrantPredicates);
|
||||||
Individual object = EditConfigurationUtils.getObjectIndividual(vreq);
|
}
|
||||||
boolean foundErrorMode = false;
|
|
||||||
int numberEditModes = 0;
|
|
||||||
int numberRepairModes = 0;
|
|
||||||
int numberPredicates = roleToActivityPredicates.size();
|
|
||||||
for(String predicate:roleToActivityPredicates) {
|
|
||||||
EditMode mode = FrontEndEditingUtils.getEditMode(vreq, object, predicate);
|
|
||||||
//Any error mode should result in error
|
|
||||||
if(mode == EditMode.ERROR) {
|
|
||||||
foundErrorMode = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(mode == EditMode.EDIT) {
|
|
||||||
numberEditModes++;
|
|
||||||
}
|
|
||||||
else if(mode == EditMode.REPAIR) {
|
|
||||||
numberEditModes++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//if found an error or if more than one edit mode returned, incorrect
|
|
||||||
|
|
||||||
if(foundErrorMode || numberEditModes > 1)
|
private boolean isAddMode(VitroRequest vreq) {
|
||||||
{
|
return AddRoleUtils.isAddMode(getEditMode(vreq));
|
||||||
return EditMode.ERROR;
|
|
||||||
}
|
|
||||||
EditMode mode = EditMode.ADD;
|
|
||||||
//if exactly one edit mode found, then edit mode
|
|
||||||
if(numberEditModes == 1) {
|
|
||||||
mode = EditMode.EDIT;
|
|
||||||
}
|
|
||||||
//if all modes are repair, this means that all of them have zero statements returning
|
|
||||||
//which is incorrect
|
|
||||||
if(numberRepairModes == numberPredicates) {
|
|
||||||
mode = EditMode.REPAIR;
|
|
||||||
}
|
|
||||||
//otherwise all the modes are Add and Add will be returned
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
private boolean isAddMode(VitroRequest vreq) {
|
|
||||||
EditMode mode = getEditMode(vreq);
|
|
||||||
return (mode == EditMode.ADD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEditMode(VitroRequest vreq) {
|
private boolean isEditMode(VitroRequest vreq) {
|
||||||
EditMode mode = getEditMode(vreq);
|
return AddRoleUtils.isEditMode(getEditMode(vreq));
|
||||||
return (mode == EditMode.EDIT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isRepairMode(VitroRequest vreq) {
|
private boolean isRepairMode(VitroRequest vreq) {
|
||||||
EditMode mode = getEditMode(vreq);
|
return AddRoleUtils.isRepairMode(getEditMode(vreq));
|
||||||
return (mode == EditMode.REPAIR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methods to return URIS for various predicates
|
* Methods to return URIS for various predicates
|
||||||
|
|
|
@ -163,7 +163,9 @@ public class NewIndividualFormGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
editConfiguration.setVarNameForSubject("subjectNotUsed");
|
editConfiguration.setVarNameForSubject("subjectNotUsed");
|
||||||
editConfiguration.setSubjectUri(subjectUri);
|
editConfiguration.setSubjectUri(subjectUri);
|
||||||
editConfiguration.setEntityToReturnTo("?newInd");
|
//Note, the spaces are important - they were added by ProcessRdfFormController earlier
|
||||||
|
//as a means of ensuring the substitution worked correctly - as the regex expects spaces
|
||||||
|
editConfiguration.setEntityToReturnTo(" ?newInd ");
|
||||||
editConfiguration.setVarNameForPredicate("predicateNotUsed");
|
editConfiguration.setVarNameForPredicate("predicateNotUsed");
|
||||||
editConfiguration.setPredicateUri(predicateUri);
|
editConfiguration.setPredicateUri(predicateUri);
|
||||||
|
|
||||||
|
@ -213,7 +215,7 @@ public class NewIndividualFormGenerator implements EditConfigurationGenerator {
|
||||||
List<String> n3Optional = new ArrayList<String>();
|
List<String> n3Optional = new ArrayList<String>();
|
||||||
String editString = "@prefix foaf:<http://xmlns.com/foaf/0.1/> ." +
|
String editString = "@prefix foaf:<http://xmlns.com/foaf/0.1/> ." +
|
||||||
" ?newInd foaf:firstName ?firstName ; " +
|
" ?newInd foaf:firstName ?firstName ; " +
|
||||||
" ?newInd foaf:lastName ?lastName .";
|
" foaf:lastName ?lastName .";
|
||||||
n3Optional.add(editString);
|
n3Optional.add(editString);
|
||||||
n3Optional.add("?newInd <" + RDFS.label.getURI() + "> ?label .");
|
n3Optional.add("?newInd <" + RDFS.label.getURI() + "> ?label .");
|
||||||
return n3Optional;
|
return n3Optional;
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.servlet;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.IndividualController;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService.ConceptSearchServiceUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||||
|
import freemarker.ext.beans.BeansWrapper;
|
||||||
|
import freemarker.template.DefaultObjectWrapper;
|
||||||
|
|
||||||
|
public class ConceptSearchServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static final Log log = LogFactory.getLog(UMLSTerminologyAnnotation.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
super.doPost(req, resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
super.doGet(req, resp);
|
||||||
|
VitroRequest vreq = new VitroRequest(req);
|
||||||
|
|
||||||
|
try{
|
||||||
|
ServletContext ctx = vreq.getSession().getServletContext();
|
||||||
|
String results = ConceptSearchServiceUtils.getSearchResults(ctx, vreq);
|
||||||
|
|
||||||
|
try{
|
||||||
|
ServletOutputStream sos = resp.getOutputStream();
|
||||||
|
|
||||||
|
resp.setCharacterEncoding("UTF-8");
|
||||||
|
resp.setContentType("application/json;charset=UTF-8");
|
||||||
|
|
||||||
|
sos.print(results);
|
||||||
|
|
||||||
|
} catch(Exception ex) {
|
||||||
|
log.error("error occurred in servlet", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(Exception ex){
|
||||||
|
log.warn(ex,ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddRoleToPersonTwoStageGenerator;
|
||||||
|
|
||||||
|
abstract public class AbstractConceptSearch implements ConceptSearchInterface{
|
||||||
|
private Log log = LogFactory.getLog(AbstractConceptSearch.class);
|
||||||
|
|
||||||
|
public String doSearch(ServletContext context, VitroRequest vreq ) {
|
||||||
|
String searchEntry = vreq.getParameter("searchTerm");
|
||||||
|
String results = processResults(searchEntry);
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public String processResults(String searchEntry);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
public interface ConceptSearchInterface{
|
||||||
|
String doSearch(ServletContext context, VitroRequest vreq );
|
||||||
|
|
||||||
|
String processResults(String searchEntry);
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService;
|
||||||
|
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
|
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.PageDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupTemplateModel;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.EditConfigurationGenerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will pass these variables to the template:
|
||||||
|
* classGroupUri: uri of the classgroup associated with this page.
|
||||||
|
* vClassGroup: a data structure that is the classgroup associated with this page.
|
||||||
|
*/
|
||||||
|
public class ConceptSearchServiceUtils {
|
||||||
|
private static final Log log = LogFactory.getLog(ConceptSearchServiceUtils.class);
|
||||||
|
//Get the appropriate search service class
|
||||||
|
|
||||||
|
//Get the class that corresponds to the appropriate search
|
||||||
|
public static String getConceptSearchServiceClassName(String searchServiceName) {
|
||||||
|
HashMap<String, String> map = getMapping();
|
||||||
|
if(map.containsKey(searchServiceName)) {
|
||||||
|
return map.get(searchServiceName);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Get the hashmap mapping service name to Service class
|
||||||
|
private static HashMap<String, String> getMapping() {
|
||||||
|
HashMap<String, String> map = new HashMap<String, String>();
|
||||||
|
map.put("UMLS", "edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService.UMLSConceptSearch");
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSearchResults(ServletContext context, VitroRequest vreq) {
|
||||||
|
String searchServiceName = getSearchServiceName(vreq);
|
||||||
|
|
||||||
|
String searchServiceClassName = getConceptSearchServiceClassName(searchServiceName);
|
||||||
|
|
||||||
|
ConceptSearchInterface conceptSearchClass = null;
|
||||||
|
|
||||||
|
Object object = null;
|
||||||
|
try {
|
||||||
|
Class classDefinition = Class.forName(searchServiceClassName);
|
||||||
|
object = classDefinition.newInstance();
|
||||||
|
conceptSearchClass = (ConceptSearchInterface) object;
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
System.out.println(e);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
System.out.println(e);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(conceptSearchClass == null){
|
||||||
|
log.error("could not find Concept Search Class for " + searchServiceName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return conceptSearchClass.doSearch(context, vreq);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static String getSearchServiceName(VitroRequest vreq) {
|
||||||
|
return vreq.getParameter("searchServiceName");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.servlet.UMLSTerminologyAnnotation;
|
||||||
|
|
||||||
|
public class UMLSConceptSearch extends AbstractConceptSearch{
|
||||||
|
private static final String submissionUrl = "http://link.informatics.stonybrook.edu/MeaningLookup/MlServiceServlet?";
|
||||||
|
private static final Log log = LogFactory.getLog(UMLSConceptSearch.class);
|
||||||
|
|
||||||
|
public String processResults(String searchEntry) {
|
||||||
|
|
||||||
|
String dataUrl = submissionUrl + "textToProcess=" + URLEncoder.encode(searchEntry) + "&format=json";
|
||||||
|
String results = null;
|
||||||
|
try{
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
URL rss = new URL(dataUrl);
|
||||||
|
|
||||||
|
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(rss.openStream()));
|
||||||
|
String inputLine;
|
||||||
|
while((inputLine = in.readLine()) != null) {
|
||||||
|
sw.write(inputLine);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
results = sw.toString();
|
||||||
|
|
||||||
|
} catch(Exception ex) {
|
||||||
|
log.error("error occurred in servlet", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
results = processOutput(results);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returning string with
|
||||||
|
private String processOutput(String results) {
|
||||||
|
String newResults = null;
|
||||||
|
try {
|
||||||
|
JSONObject json = new JSONObject(results);
|
||||||
|
//Return label and CUID of object
|
||||||
|
if(json.has("All")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(json.has("BestMatch")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch(Exception ex) {
|
||||||
|
log.error("Error making json object out of output");
|
||||||
|
}
|
||||||
|
return newResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.generators;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
|
||||||
|
|
||||||
|
public class AddRoleUtils {
|
||||||
|
private static Log log = LogFactory.getLog(AddRoleUtils.class);
|
||||||
|
|
||||||
|
|
||||||
|
/* *************** Static utility methods used in role-based generators *********** */
|
||||||
|
public static EditMode getEditMode(VitroRequest vreq, List<String> possiblePredicates) {
|
||||||
|
//We're making some assumptions here: That there is only one role objec tot one activity object
|
||||||
|
//pairing, i.e. the same role object can't be related to a different activity object
|
||||||
|
//That said, there should only be one role to Activity predicate linking a role to an activity
|
||||||
|
//So if
|
||||||
|
Individual object = EditConfigurationUtils.getObjectIndividual(vreq);
|
||||||
|
boolean foundErrorMode = false;
|
||||||
|
int numberEditModes = 0;
|
||||||
|
int numberRepairModes = 0;
|
||||||
|
int numberPredicates = possiblePredicates.size();
|
||||||
|
for(String predicate:possiblePredicates) {
|
||||||
|
EditMode mode = FrontEndEditingUtils.getEditMode(vreq, object, predicate);
|
||||||
|
//Any error mode should result in error
|
||||||
|
if(mode == EditMode.ERROR) {
|
||||||
|
foundErrorMode = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(mode == EditMode.EDIT) {
|
||||||
|
numberEditModes++;
|
||||||
|
}
|
||||||
|
else if(mode == EditMode.REPAIR) {
|
||||||
|
numberRepairModes++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//if found an error or if more than one edit mode returned, incorrect
|
||||||
|
|
||||||
|
if(foundErrorMode || numberEditModes > 1)
|
||||||
|
{
|
||||||
|
return EditMode.ERROR;
|
||||||
|
}
|
||||||
|
EditMode mode = EditMode.ADD;
|
||||||
|
//if exactly one edit mode found, then edit mode
|
||||||
|
if(numberEditModes == 1) {
|
||||||
|
mode = EditMode.EDIT;
|
||||||
|
}
|
||||||
|
//if all modes are repair, this means that all of them have zero statements returning
|
||||||
|
//which is incorrect
|
||||||
|
if(numberRepairModes == numberPredicates) {
|
||||||
|
mode = EditMode.REPAIR;
|
||||||
|
}
|
||||||
|
//otherwise all the modes are Add and Add will be returned
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isAddMode(EditMode mode) {
|
||||||
|
return (mode == EditMode.ADD);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEditMode(EditMode mode) {
|
||||||
|
return (mode == EditMode.EDIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isRepairMode(EditMode mode) {
|
||||||
|
return (mode == EditMode.REPAIR);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue