Fix issue when validating dataset for finalization (needs rework)
This commit is contained in:
parent
1512d0c424
commit
4b3468d513
|
@ -66,6 +66,7 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
@ -691,6 +692,9 @@ public class DatasetManager {
|
||||||
datasetProfileValidators.add(node.getNodeValue());
|
datasetProfileValidators.add(node.getNodeValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expression = "//validation/@type[.=1]/ancestor::fieldSet";
|
||||||
|
nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
|
||||||
|
|
||||||
|
|
||||||
JSONObject obj = new JSONObject(dataset.getProperties());
|
JSONObject obj = new JSONObject(dataset.getProperties());
|
||||||
VisibilityRuleService visibilityRuleService = this.apiContext.getUtilitiesService().getVisibilityRuleService();
|
VisibilityRuleService visibilityRuleService = this.apiContext.getUtilitiesService().getVisibilityRuleService();
|
||||||
|
@ -702,12 +706,35 @@ public class DatasetManager {
|
||||||
|
|
||||||
|
|
||||||
for (String validator : datasetProfileValidators) {
|
for (String validator : datasetProfileValidators) {
|
||||||
if ((obj.getString(validator) == null || obj.getString(validator).trim().isEmpty()) && visibilityRuleService.isElementVisible(validator)) {
|
if ((obj.has(validator) && (obj.getString(validator) == null || obj.getString(validator).trim().isEmpty())) && isElementVisible(nodeList, validator, visibilityRuleService)) {
|
||||||
throw new Exception("Field value of " + validator + " must be filled.");
|
throw new Exception("Field value of " + validator + " must be filled.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isElementVisible(NodeList nodeList, String id, VisibilityRuleService visibilityRuleService) {
|
||||||
|
Element fieldSet = null;
|
||||||
|
for (int i = 0; i < nodeList.getLength(); i++) {
|
||||||
|
Node node = nodeList.item(i);
|
||||||
|
for (int j = 0; j < node.getChildNodes().getLength(); j++) {
|
||||||
|
Node fcnode = node.getChildNodes().item(j);
|
||||||
|
if (fcnode.getNodeName().equals("fields")) {
|
||||||
|
for(int k = 0; k < fcnode.getChildNodes().getLength(); k++) {
|
||||||
|
Node scnode = fcnode.getChildNodes().item(k);
|
||||||
|
if (scnode.getNodeName().equals("field") && scnode.getAttributes().getNamedItem("id").getNodeValue().equals(id)) {
|
||||||
|
fieldSet = (Element) node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fieldSet != null) {
|
||||||
|
return visibilityRuleService.isElementVisible(id) && visibilityRuleService.isElementVisible(fieldSet.getAttribute("id"));
|
||||||
|
} else {
|
||||||
|
return visibilityRuleService.isElementVisible(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String propertiesModelToString(PagedDatasetProfile pagedDatasetProfile) {
|
private String propertiesModelToString(PagedDatasetProfile pagedDatasetProfile) {
|
||||||
Map<String, Object> values = new HashMap();
|
Map<String, Object> values = new HashMap();
|
||||||
pagedDatasetProfile.toMap(values);
|
pagedDatasetProfile.toMap(values);
|
||||||
|
|
Loading…
Reference in New Issue