VIVO-216 made the controllers threadsafe (thanks for the example, Jim)

This commit is contained in:
tworrall 2013-07-22 13:25:34 -04:00
parent ea2ab8cd3b
commit a2ce7abf73
2 changed files with 20 additions and 20 deletions

View file

@ -28,9 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
public class ManageGrantsForIndividualController extends FreemarkerHttpServlet { public class ManageGrantsForIndividualController extends FreemarkerHttpServlet {
private static final Log log = LogFactory.getLog(ManageGrantsForIndividualController.class.getName()); private static final Log log = LogFactory.getLog(ManageGrantsForIndividualController.class.getName());
private VClassDao vcDao = null;
private static final String TEMPLATE_NAME = "manageGrantsForIndividual.ftl"; private static final String TEMPLATE_NAME = "manageGrantsForIndividual.ftl";
private List<String> allSubclasses;
@Override @Override
protected Actions requiredActions(VitroRequest vreq) { protected Actions requiredActions(VitroRequest vreq) {
@ -43,14 +41,13 @@ public class ManageGrantsForIndividualController extends FreemarkerHttpServlet {
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
String subjectUri = vreq.getParameter("subjectUri"); String subjectUri = vreq.getParameter("subjectUri");
body.put("subjectUri", subjectUri); body.put("subjectUri", subjectUri);
vcDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getVClassDao();
HashMap<String, List<Map<String,String>>> grants = getGrants(subjectUri, vreq); HashMap<String, List<Map<String,String>>> grants = getGrants(subjectUri, vreq);
log.debug("grants = " + grants); log.debug("grants = " + grants);
body.put("grants", grants); body.put("grants", grants);
List<String> allSubclasses = getAllSubclasses(grants);
body.put("allSubclasses", allSubclasses); body.put("allSubclasses", allSubclasses);
Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri); Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri);
@ -81,8 +78,8 @@ public class ManageGrantsForIndividualController extends FreemarkerHttpServlet {
+ " OPTIONAL { ?role core:hideFromDisplay ?hideThis } \n" + " OPTIONAL { ?role core:hideFromDisplay ?hideThis } \n"
+ "} ORDER BY ?subclass ?label2"; + "} ORDER BY ?subclass ?label2";
HashMap<String, List<Map<String,String>>> getGrants(String subjectUri, VitroRequest vreq) { HashMap<String, List<Map<String,String>>> getGrants(String subjectUri, VitroRequest vreq) {
VClassDao vcDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getVClassDao();
String queryStr = QueryUtils.subUriForQueryVar(GRANT_QUERY, "subject", subjectUri); String queryStr = QueryUtils.subUriForQueryVar(GRANT_QUERY, "subject", subjectUri);
log.debug("queryStr = " + queryStr); log.debug("queryStr = " + queryStr);
@ -107,10 +104,14 @@ public class ManageGrantsForIndividualController extends FreemarkerHttpServlet {
log.error(e, e); log.error(e, e);
} }
allSubclasses = new ArrayList<String>(subclassToGrants.keySet());
Collections.sort(allSubclasses);
return subclassToGrants; return subclassToGrants;
} }
private List<String> getAllSubclasses(HashMap<String, List<Map<String, String>>> grants) {
List<String> allSubclasses = new ArrayList<String>(grants.keySet());
Collections.sort(allSubclasses);
return allSubclasses;
}
} }

View file

@ -28,9 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
public class ManagePublicationsForIndividualController extends FreemarkerHttpServlet { public class ManagePublicationsForIndividualController extends FreemarkerHttpServlet {
private static final Log log = LogFactory.getLog(ManagePublicationsForIndividualController.class.getName()); private static final Log log = LogFactory.getLog(ManagePublicationsForIndividualController.class.getName());
private VClassDao vcDao = null;
private static final String TEMPLATE_NAME = "managePublicationsForIndividual.ftl"; private static final String TEMPLATE_NAME = "managePublicationsForIndividual.ftl";
private List<String> allSubclasses;
@Override @Override
protected Actions requiredActions(VitroRequest vreq) { protected Actions requiredActions(VitroRequest vreq) {
@ -43,14 +41,13 @@ public class ManagePublicationsForIndividualController extends FreemarkerHttpSer
Map<String, Object> body = new HashMap<String, Object>(); Map<String, Object> body = new HashMap<String, Object>();
String subjectUri = vreq.getParameter("subjectUri"); String subjectUri = vreq.getParameter("subjectUri");
body.put("subjectUri", subjectUri); body.put("subjectUri", subjectUri);
vcDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getVClassDao();
HashMap<String, List<Map<String,String>>> publications = getPublications(subjectUri, vreq); HashMap<String, List<Map<String,String>>> publications = getPublications(subjectUri, vreq);
log.debug("publications = " + publications); log.debug("publications = " + publications);
body.put("publications", publications); body.put("publications", publications);
List<String> allSubclasses = getAllSubclasses(publications);
body.put("allSubclasses", allSubclasses); body.put("allSubclasses", allSubclasses);
Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri); Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri);
@ -63,7 +60,6 @@ public class ManagePublicationsForIndividualController extends FreemarkerHttpSer
return new TemplateResponseValues(TEMPLATE_NAME, body); return new TemplateResponseValues(TEMPLATE_NAME, body);
} }
private static String PUBLICATION_QUERY = "" private static String PUBLICATION_QUERY = ""
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n" + "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
@ -79,9 +75,10 @@ public class ManagePublicationsForIndividualController extends FreemarkerHttpSer
+ " OPTIONAL { ?authorship core:hideFromDisplay ?hideThis } \n" + " OPTIONAL { ?authorship core:hideFromDisplay ?hideThis } \n"
+ "} ORDER BY ?subclass ?title"; + "} ORDER BY ?subclass ?title";
HashMap<String, List<Map<String,String>>> getPublications(String subjectUri, VitroRequest vreq) { HashMap<String, List<Map<String,String>>> getPublications(String subjectUri, VitroRequest vreq) {
VClassDao vcDao = vreq.getUnfilteredAssertionsWebappDaoFactory().getVClassDao();
String queryStr = QueryUtils.subUriForQueryVar(PUBLICATION_QUERY, "subject", subjectUri); String queryStr = QueryUtils.subUriForQueryVar(PUBLICATION_QUERY, "subject", subjectUri);
String subclass = ""; String subclass = "";
log.debug("queryStr = " + queryStr); log.debug("queryStr = " + queryStr);
@ -109,10 +106,12 @@ public class ManagePublicationsForIndividualController extends FreemarkerHttpSer
log.error(e, e); log.error(e, e);
} }
allSubclasses = new ArrayList<String>(subclassToPublications.keySet());
Collections.sort(allSubclasses);
return subclassToPublications; return subclassToPublications;
} }
}
private List<String> getAllSubclasses(HashMap<String, List<Map<String, String>>> publications) {
List<String> allSubclasses = new ArrayList<String>(publications.keySet());
Collections.sort(allSubclasses);
return allSubclasses;
}
}