NIHVIVO-1512 ReadOnlyBeansWrapper exposes getters and not setters, though the identification of a setter is only approximated.
This commit is contained in:
parent
ba11f54394
commit
655d92284c
3 changed files with 21 additions and 11 deletions
|
@ -60,7 +60,7 @@ import edu.cornell.mannlib.vitro.webapp.utils.jena.ExtendedLinkedDataUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individuallist.ListedIndividual;
|
||||||
import freemarker.ext.beans.BeansWrapper;
|
import freemarker.ext.beans.ReadOnlyBeansWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles requests for entity information.
|
* Handles requests for entity information.
|
||||||
|
@ -140,11 +140,14 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
* This is still safe, because we are only putting BaseTemplateModel objects
|
* This is still safe, because we are only putting BaseTemplateModel objects
|
||||||
* into the data model: no real data can be modified.
|
* into the data model: no real data can be modified.
|
||||||
*/
|
*/
|
||||||
body.put("individual", wrap(itm, BeansWrapper.EXPOSE_SAFE));
|
//body.put("individual", wrap(itm, BeansWrapper.EXPOSE_SAFE));
|
||||||
|
body.put("individual", wrap(itm, new ReadOnlyBeansWrapper()));
|
||||||
|
|
||||||
body.put("headContent", getRdfLinkTag(itm));
|
body.put("headContent", getRdfLinkTag(itm));
|
||||||
|
|
||||||
//If special values required for individuals like menu, include values in template values
|
//If special values required for individuals like menu, include values in template values
|
||||||
this.includeSpecialEditingValues(vreq, body);
|
body.putAll(getSpecialEditingValues(vreq));
|
||||||
|
|
||||||
String template = getIndividualTemplate(individual, vreq);
|
String template = getIndividualTemplate(individual, vreq);
|
||||||
|
|
||||||
return new TemplateResponseValues(template, body);
|
return new TemplateResponseValues(template, body);
|
||||||
|
@ -214,10 +217,15 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get special values for cases such as Menu Management editing
|
//Get special values for cases such as Menu Management editing
|
||||||
private void includeSpecialEditingValues(VitroRequest vreq, Map<String, Object> body) {
|
private Map<String, Object> getSpecialEditingValues(VitroRequest vreq) {
|
||||||
|
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
|
||||||
if(vreq.getAttribute(VitroRequest.SPECIAL_WRITE_MODEL) != null) {
|
if(vreq.getAttribute(VitroRequest.SPECIAL_WRITE_MODEL) != null) {
|
||||||
body.put("reorderUrl", vreq.getContextPath() + DisplayVocabulary.REORDER_MENU_URL);
|
map.put("reorderUrl", UrlBuilder.getUrl(DisplayVocabulary.REORDER_MENU_URL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> getRelatedSubject(VitroRequest vreq) {
|
private Map<String, Object> getRelatedSubject(VitroRequest vreq) {
|
||||||
|
|
|
@ -276,7 +276,7 @@ public class GroupedPropertyList extends BaseTemplateModel {
|
||||||
* there are groups or not.
|
* there are groups or not.
|
||||||
*/
|
*/
|
||||||
if (groupCount == 0) {
|
if (groupCount == 0) {
|
||||||
log.warn("groupList has no groups on entering addPropertiesToGroups(); will create a new group");
|
log.warn("groupList has no groups on entering addPropertiesToGroups(); creating a dummy group");
|
||||||
PropertyGroup dummyGroup = pgDao.createDummyPropertyGroup(null, 1);
|
PropertyGroup dummyGroup = pgDao.createDummyPropertyGroup(null, 1);
|
||||||
dummyGroup.getPropertyList().addAll(propertyList);
|
dummyGroup.getPropertyList().addAll(propertyList);
|
||||||
groupList.add(dummyGroup);
|
groupList.add(dummyGroup);
|
||||||
|
@ -312,7 +312,7 @@ public class GroupedPropertyList extends BaseTemplateModel {
|
||||||
}
|
}
|
||||||
groupCount -= removedCount;
|
groupCount -= removedCount;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("Exception on trying to prune groups list with properties: "
|
log.error("Exception on trying to prune unpopulated groups from group list: "
|
||||||
+ ex.getMessage());
|
+ ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,13 @@ public class ReadOnlyBeansWrapper extends BeansWrapper {
|
||||||
@Override
|
@Override
|
||||||
protected void finetuneMethodAppearance(Class cls, Method method, MethodAppearanceDecision decision) {
|
protected void finetuneMethodAppearance(Class cls, Method method, MethodAppearanceDecision decision) {
|
||||||
|
|
||||||
if ( method.getName().startsWith("set") ||
|
// How to define a setter? This is an approximation: a method whose name
|
||||||
method.getReturnType() == null ) {
|
// starts with "set" or returns void.
|
||||||
|
if ( method.getName().startsWith("set") ) {
|
||||||
|
decision.setExposeMethodAs(null);
|
||||||
|
} else if ( method.getReturnType().getName().equals("void") ) {
|
||||||
decision.setExposeMethodAs(null);
|
decision.setExposeMethodAs(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue