NIHVIVO-2186 Implement one approach to hiding statements with no linked individual from non-editors, and apply it to the authorInAuthorship list view query.
This commit is contained in:
parent
b5bfd92888
commit
75e7c198f9
1 changed files with 22 additions and 10 deletions
|
@ -100,7 +100,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
|
|
||||||
// Get the config for this object property
|
// Get the config for this object property
|
||||||
try {
|
try {
|
||||||
config = new PropertyListConfig(op, vreq);
|
config = new PropertyListConfig(op, vreq, policyHelper);
|
||||||
} catch (InvalidConfigurationException e) {
|
} catch (InvalidConfigurationException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -325,6 +325,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
private static final String NODE_NAME_TEMPLATE = "template";
|
private static final String NODE_NAME_TEMPLATE = "template";
|
||||||
private static final String NODE_NAME_POSTPROCESSOR = "postprocessor";
|
private static final String NODE_NAME_POSTPROCESSOR = "postprocessor";
|
||||||
private static final String NODE_NAME_COLLATION_FRAGMENT = "collation-fragment";
|
private static final String NODE_NAME_COLLATION_FRAGMENT = "collation-fragment";
|
||||||
|
private static final String NODE_NAME_LINKED_INDIVIDUAL_OPTIONAL = "linked-individual-optional";
|
||||||
|
|
||||||
/* NB The default post-processor is not the same as the post-processor for the default view. The latter
|
/* NB The default post-processor is not the same as the post-processor for the default view. The latter
|
||||||
* actually defines its own post-processor, whereas the default post-processor is used for custom views
|
* actually defines its own post-processor, whereas the default post-processor is used for custom views
|
||||||
|
@ -339,7 +340,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
private String templateName;
|
private String templateName;
|
||||||
private ObjectPropertyDataPostProcessor postprocessor = null;
|
private ObjectPropertyDataPostProcessor postprocessor = null;
|
||||||
|
|
||||||
PropertyListConfig(ObjectProperty op, VitroRequest vreq)
|
PropertyListConfig(ObjectProperty op, VitroRequest vreq, EditingPolicyHelper policyHelper)
|
||||||
throws InvalidConfigurationException {
|
throws InvalidConfigurationException {
|
||||||
|
|
||||||
// Get the custom config filename
|
// Get the custom config filename
|
||||||
|
@ -359,7 +360,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME);
|
configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME);
|
||||||
// Should we test for the existence of the default, and throw an error if it doesn't exist?
|
// Should we test for the existence of the default, and throw an error if it doesn't exist?
|
||||||
}
|
}
|
||||||
setValuesFromConfigFile(configFilePath, op, vreq.getWebappDaoFactory());
|
setValuesFromConfigFile(configFilePath, op, vreq.getWebappDaoFactory(), policyHelper);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error processing config file " + configFilePath + " for object property " + op.getURI(), e);
|
log.error("Error processing config file " + configFilePath + " for object property " + op.getURI(), e);
|
||||||
|
@ -379,7 +380,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
" in " + configFilePath + ":\n" +
|
" in " + configFilePath + ":\n" +
|
||||||
configError + " Using default config instead.");
|
configError + " Using default config instead.");
|
||||||
configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME);
|
configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE_NAME);
|
||||||
setValuesFromConfigFile(configFilePath, op, vreq.getWebappDaoFactory());
|
setValuesFromConfigFile(configFilePath, op, vreq.getWebappDaoFactory(), policyHelper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +419,8 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setValuesFromConfigFile(String configFilePath, ObjectProperty op, WebappDaoFactory wdf) {
|
private void setValuesFromConfigFile(String configFilePath, ObjectProperty op, WebappDaoFactory wdf,
|
||||||
|
EditingPolicyHelper policyHelper) {
|
||||||
|
|
||||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder db;
|
DocumentBuilder db;
|
||||||
|
@ -429,7 +431,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
String propertyUri = op.getURI();
|
String propertyUri = op.getURI();
|
||||||
|
|
||||||
// Required values
|
// Required values
|
||||||
selectQuery = getSelectQuery(doc, propertyUri);
|
selectQuery = getSelectQuery(doc, propertyUri, policyHelper);
|
||||||
|
|
||||||
templateName = getConfigValue(doc, NODE_NAME_TEMPLATE, propertyUri);
|
templateName = getConfigValue(doc, NODE_NAME_TEMPLATE, propertyUri);
|
||||||
|
|
||||||
|
@ -457,21 +459,31 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSelectQuery(Document doc, String propertyUri) {
|
private String getSelectQuery(Document doc, String propertyUri, EditingPolicyHelper policyHelper) {
|
||||||
Node selectQueryNode = doc.getElementsByTagName(NODE_NAME_QUERY_SELECT).item(0);
|
Node selectQueryNode = doc.getElementsByTagName(NODE_NAME_QUERY_SELECT).item(0);
|
||||||
String value = null;
|
String value = null;
|
||||||
if (selectQueryNode != null) {
|
if (selectQueryNode != null) {
|
||||||
boolean removeCollationFragments = ObjectPropertyTemplateModel.this instanceof UncollatedObjectPropertyTemplateModel;
|
boolean removeCollationFragments = ObjectPropertyTemplateModel.this instanceof UncollatedObjectPropertyTemplateModel;
|
||||||
|
/* If editing the page (policyHelper != null), show statements with missing linked individual; otherwise, hide these
|
||||||
|
* statements. We might want to refine this based on whether the user can edit the statement in question, but that
|
||||||
|
* would require a completely different approach: including the statement in the query results, and then during the
|
||||||
|
* postprocessing phase, checking the editing policy, and removing the statement if it's not editable. We would not
|
||||||
|
* preprocess the query, as here.
|
||||||
|
*/
|
||||||
|
boolean linkedIndividualOptional = policyHelper != null;
|
||||||
NodeList children = selectQueryNode.getChildNodes();
|
NodeList children = selectQueryNode.getChildNodes();
|
||||||
int childCount = children.getLength();
|
int childCount = children.getLength();
|
||||||
value = "";
|
value = "";
|
||||||
for (int i = 0; i < childCount; i++) {
|
for (int i = 0; i < childCount; i++) {
|
||||||
Node node = children.item(i);
|
Node node = children.item(i);
|
||||||
if (node.getNodeName().equals(NODE_NAME_COLLATION_FRAGMENT)) {
|
if (node.getNodeName().equals(NODE_NAME_COLLATION_FRAGMENT)) {
|
||||||
if (removeCollationFragments) {
|
if (!removeCollationFragments) {
|
||||||
continue;
|
value += node.getChildNodes().item(0).getNodeValue();
|
||||||
|
}
|
||||||
|
} else if (node.getNodeName().equals(NODE_NAME_LINKED_INDIVIDUAL_OPTIONAL)) {
|
||||||
|
if (linkedIndividualOptional) {
|
||||||
|
value += node.getChildNodes().item(0).getNodeValue();
|
||||||
}
|
}
|
||||||
value += node.getChildNodes().item(0).getNodeValue();
|
|
||||||
} else {
|
} else {
|
||||||
value += node.getNodeValue();
|
value += node.getNodeValue();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue