summaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsDataService.java13
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java8
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java13
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java40
4 files changed, 65 insertions, 9 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
index 012d7f8259..6332f09109 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
@@ -123,6 +123,19 @@ public interface CpsDataService {
FetchDescendantsOption fetchDescendantsOption);
/**
+ * Retrieves datanodes by XPath for given dataspace and anchor.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param xpaths collection of xpath
+ * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
+ * (recursively) as well
+ * @return data node object
+ */
+ Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, Collection<String> xpaths,
+ FetchDescendantsOption fetchDescendantsOption);
+
+ /**
* Updates data node for given dataspace and anchor using xpath to parent node.
*
* @param dataspaceName dataspace name
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
index 65dfa7f5c6..38fa92a09d 100755
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
@@ -130,6 +130,14 @@ public class CpsDataServiceImpl implements CpsDataService {
}
@Override
+ public Collection<DataNode> getDataNodes(final String dataspaceName, final String anchorName,
+ final Collection<String> xpaths,
+ final FetchDescendantsOption fetchDescendantsOption) {
+ cpsValidator.validateNameCharacters(dataspaceName, anchorName);
+ return cpsDataPersistenceService.getDataNodes(dataspaceName, anchorName, xpaths, fetchDescendantsOption);
+ }
+
+ @Override
public void updateNodeLeaves(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final String jsonData, final OffsetDateTime observedTimestamp) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
index b9da4af025..0989ccae2d 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
@@ -112,6 +112,19 @@ public interface CpsDataPersistenceService {
FetchDescendantsOption fetchDescendantsOption);
/**
+ * Retrieves datanode by XPath for given dataspace and anchor.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param xpaths collection of xpaths
+ * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
+ * (recursively) as well
+ * @return data node object
+ */
+ Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, Collection<String> xpaths,
+ FetchDescendantsOption fetchDescendantsOption);
+
+ /**
* Updates leaves for existing data node.
*
* @param dataspaceName dataspace name
diff --git a/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java b/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java
index 3654042078..09f2e16c6a 100644
--- a/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/XmlFileUtils.java
@@ -49,7 +49,10 @@ import org.xml.sax.SAXException;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class XmlFileUtils {
- private static DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ private static final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ private static boolean isNewDocumentBuilderFactoryInstance = true;
+ private static final TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ private static boolean isNewTransformerFactoryInstance = true;
private static final Pattern XPATH_PROPERTY_REGEX =
Pattern.compile("\\[@(\\S{1,100})=['\\\"](\\S{1,100})['\\\"]\\]");
@@ -72,7 +75,7 @@ public class XmlFileUtils {
*
* @param xmlContent XML content sent to store
* @param parentSchemaNode Parent schema node
- * @Param xpath Parent xpath
+ * @param xpath Parent xpath
*
* @return XML content wrapped by root node (if needed)
*/
@@ -98,7 +101,7 @@ public class XmlFileUtils {
final String namespace,
final Map<String, String> rootNodeProperty)
throws IOException, SAXException, ParserConfigurationException, TransformerException {
- final DocumentBuilder documentBuilder = dbFactory.newDocumentBuilder();
+ final DocumentBuilder documentBuilder = getDocumentBuilderFactory().newDocumentBuilder();
final StringBuilder xmlStringBuilder = new StringBuilder();
xmlStringBuilder.append(xmlContent);
final Document document = documentBuilder.parse(
@@ -108,10 +111,7 @@ public class XmlFileUtils {
&& !root.getTagName().equals(YangUtils.DATA_ROOT_NODE_TAG_NAME)) {
final Document documentWithRootNode = addDataRootNode(root, rootNodeTagName, namespace, rootNodeProperty);
documentWithRootNode.setXmlStandalone(true);
- final TransformerFactory transformerFactory = TransformerFactory.newInstance();
- transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
- transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
- final Transformer transformer = transformerFactory.newTransformer();
+ final Transformer transformer = getTransformerFactory().newTransformer();
final StringWriter stringWriter = new StringWriter();
transformer.transform(new DOMSource(documentWithRootNode), new StreamResult(stringWriter));
return stringWriter.toString();
@@ -145,8 +145,8 @@ public class XmlFileUtils {
final String namespace,
final Map<String, String> rootNodeProperty) {
try {
- final DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
- final Document document = docBuilder.newDocument();
+ final DocumentBuilder documentBuilder = getDocumentBuilderFactory().newDocumentBuilder();
+ final Document document = documentBuilder.newDocument();
final Element rootElement = document.createElementNS(namespace, tagName);
for (final Map.Entry<String, String> entry : rootNodeProperty.entrySet()) {
final Element propertyElement = document.createElement(entry.getKey());
@@ -160,4 +160,26 @@ public class XmlFileUtils {
throw new DataValidationException("Can't parse XML", "XML can't be parsed", exception);
}
}
+
+ private static DocumentBuilderFactory getDocumentBuilderFactory() {
+
+ if (isNewDocumentBuilderFactoryInstance) {
+ documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+ documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+ isNewDocumentBuilderFactoryInstance = false;
+ }
+
+ return documentBuilderFactory;
+ }
+
+ private static TransformerFactory getTransformerFactory() {
+
+ if (isNewTransformerFactoryInstance) {
+ transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+ transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
+ isNewTransformerFactoryInstance = false;
+ }
+
+ return transformerFactory;
+ }
}