Merge branch 'issue-vivo-154' into develop

This commit is contained in:
Brian Caruso 2013-07-17 11:54:11 -04:00
commit 68284acd99
4 changed files with 113 additions and 77 deletions

View file

@ -1,87 +1,87 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */ /* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vedit.controller; package edu.cornell.mannlib.vedit.controller;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.io.IOException; import java.io.IOException;
/** /**
* This controller exists only so we can request different edit form controllers * This controller exists only so we can request different edit form controllers
* without having to have entries in web.xml for each. * without having to have entries in web.xml for each.
* @author bjl23 * @author bjl23
* *
*/ */
public class EditFrontController extends VitroHttpServlet { public class EditFrontController extends VitroHttpServlet {
private static final Log log = LogFactory.getLog(EditFrontController.class.getName()); private static final Log log = LogFactory.getLog(EditFrontController.class.getName());
private static final String CONTROLLER_PKG = "edu.cornell.mannlib.vitro.webapp.controller.edit"; private static final String CONTROLLER_PKG = "edu.cornell.mannlib.vitro.webapp.controller.edit";
public void doPost(HttpServletRequest request, public void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException { HttpServletResponse response) throws IOException, ServletException {
String controllerName = request.getParameter("controller")+"RetryController"; String controllerName = request.getParameter("controller")+"RetryController";
if (controllerName==null || controllerName.length()==0) { if (controllerName==null || controllerName.length()==0) {
log.error("doPost() found no controller parameter"); log.error("doPost() found no controller parameter");
} }
Class controller = null; Class controller = null;
Object controllerInstance = null; Object controllerInstance = null;
try { try {
controller = Class.forName(CONTROLLER_PKG+"."+controllerName); controller = Class.forName(CONTROLLER_PKG+"."+controllerName);
try { try {
controllerInstance = controller.getConstructor( controllerInstance = controller.getConstructor(
(Class[]) null).newInstance((Object[]) null); (Class[]) null).newInstance((Object[]) null);
((HttpServlet)controllerInstance).init(getServletConfig()); ((HttpServlet)controllerInstance).init(getServletConfig());
} catch (Exception e) { } catch (Exception e) {
String errMsg = "doPost() could not instantiate specific " + String errMsg = "doPost() could not instantiate specific " +
"controller " + controllerName; "controller " + controllerName;
log.error(errMsg, e); log.error(errMsg, e);
throw new RuntimeException(errMsg, e); throw new RuntimeException(errMsg, e);
} }
} catch (ClassNotFoundException e){ } catch (ClassNotFoundException e){
String errMsg = "doPost() could not find controller " + String errMsg = "doPost() could not find controller " +
CONTROLLER_PKG + "." + controllerName; CONTROLLER_PKG + "." + controllerName;
log.error(errMsg); log.error(errMsg);
throw new RuntimeException(errMsg); throw new RuntimeException(errMsg);
} }
Class[] args = new Class[2]; Class[] args = new Class[2];
args[0] = HttpServletRequest.class; args[0] = HttpServletRequest.class;
args[1] = HttpServletResponse.class; args[1] = HttpServletResponse.class;
try { try {
Method meth = controller.getDeclaredMethod("doGet",args); Method meth = controller.getDeclaredMethod("doGet",args);
Object[] methArgs = new Object[2]; Object[] methArgs = new Object[2];
methArgs[0] = request; methArgs[0] = request;
methArgs[1] = response; methArgs[1] = response;
try { try {
meth.invoke(controllerInstance,methArgs); meth.invoke(controllerInstance,methArgs);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
String errMsg = "doPost() encountered IllegalAccessException " + String errMsg = "doPost() encountered IllegalAccessException " +
"while invoking " + controllerName; "while invoking " + controllerName;
log.error(errMsg, e); log.error(errMsg, e);
throw new RuntimeException(errMsg, e); throw new RuntimeException(errMsg, e);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
String errMsg = "doPost() encountered InvocationTargetException " + String errMsg = "doPost() encountered InvocationTargetException " +
"while invoking " + controllerName; "while invoking " + controllerName;
log.error(errMsg, e); log.error(errMsg, e);
throw new RuntimeException(errMsg, e); throw new RuntimeException(errMsg, e);
} }
} catch (NoSuchMethodException e){ } catch (NoSuchMethodException e){
log.error("could not find doPost() method in " + controllerName); log.error("could not find doPost() method in " + controllerName);
throw new RuntimeException("could not find doPost() method in " + throw new RuntimeException("could not find doPost() method in " +
controllerName); controllerName);
} }
} }
public void doGet(HttpServletRequest request, public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException { HttpServletResponse response) throws IOException, ServletException {
doPost(request,response); doPost(request,response);
} }
} }

View file

@ -148,8 +148,9 @@ public class BaseResourceBean implements ResourceBean {
} }
public String getLocalNameWithPrefix() { public String getLocalNameWithPrefix() {
return localNameWithPrefix==null ? getLocalName()==null ? return localNameWithPrefix != null ? localNameWithPrefix :
(URI==null ? "(no name)" : URI ): getLocalName() : localNameWithPrefix; getLocalName() != null ? getLocalName() :
URI != null ? URI : "(no name)" ;
} }
public void setLocalNameWithPrefix(String prefixedLocalName) { public void setLocalNameWithPrefix(String prefixedLocalName) {
this.localNameWithPrefix = prefixedLocalName; this.localNameWithPrefix = prefixedLocalName;

View file

@ -123,12 +123,24 @@ public class IndividualTypeRetryController extends BaseEditController {
public void doPost (HttpServletRequest request, HttpServletResponse response) { public void doPost (HttpServletRequest request, HttpServletResponse response) {
// shouldn't be posting to this controller // shouldn't be posting to this controller
} }
private class OptionCollator implements Comparator { static class OptionCollator implements Comparator<Option> {
public int compare (Object o1, Object o2) { public int compare (Option o1, Option o2) {
Collator collator = Collator.getInstance(); // Collator collator = Collator.getInstance();
return collator.compare( ((Option)o1).getBody().toString().substring(((Option)o1).getBody().toString().indexOf(":")) , ((Option)o2).getBody().toString().substring(((Option)o2).getBody().toString().indexOf(":")) ); return getLocalName ( o1.getBody().toString() )
.compareTo(
getLocalName ( o2.getBody().toString() ) );
}
private String getLocalName( String in ){
if( in == null )
return "";
int i = in.indexOf(':');
if( i >= 0 )
return in.substring( i );
else
return in;
} }
} }

View file

@ -0,0 +1,23 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.edit;
import junit.framework.Assert;
import org.junit.Test;
import edu.cornell.mannlib.vedit.beans.Option;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
public class IndividualTypeRetryControllerTest extends AbstractTestClass {
@Test
public void optionCollator(){
IndividualTypeRetryController.OptionCollator oc = new IndividualTypeRetryController.OptionCollator();
int comp = oc.compare(
new Option("foo", "foo"),
new Option("Person", "foaf:Person") );
//we just want compare() to not throw an exception
}
}