+ override createConfigurationData(String identifier, CompositeNode payload) {
+ if (payload.namespace === null) {
+ throw new ResponseException(BAD_REQUEST,
+ "Data has bad format. Root element node must have namespace (XML format) or module name(JSON format)");
+ }
+ var InstanceIdWithSchemaNode iiWithData;
+ var CompositeNode value;
+ if (payload.representsMountPointRootData) { // payload represents mount point data and URI represents path to the mount point
+ if (identifier.endsWithMountPoint) {
+ throw new ResponseException(BAD_REQUEST,
+ "URI has bad format. URI should be without \"" + ControllerContext.MOUNT + "\" for POST operation.");
+ }
+ val completIdentifier = identifier.addMountPointIdentifier
+ iiWithData = completIdentifier.toInstanceIdentifier
+ value = normalizeNode(payload, iiWithData.schemaNode, iiWithData.mountPoint)
+ } else {
+ val uncompleteInstIdWithData = identifier.toInstanceIdentifier
+ val parentSchema = uncompleteInstIdWithData.schemaNode as DataNodeContainer
+ val module = uncompleteInstIdWithData.mountPoint.findModule(payload)
+ if (module === null) {
+ throw new ResponseException(BAD_REQUEST, "Module was not found for \"" + payload.namespace + "\"")
+ }
+ val schemaNode = parentSchema.findInstanceDataChildByNameAndNamespace(payload.name, module.namespace)
+ value = normalizeNode(payload, schemaNode, uncompleteInstIdWithData.mountPoint)
+ iiWithData = uncompleteInstIdWithData.addLastIdentifierFromData(value, schemaNode)
+ }
+ var RpcResult<TransactionStatus> status = null
+ if (iiWithData.mountPoint !== null) {
+ status = broker.commitConfigurationDataPostBehindMountPoint(iiWithData.mountPoint,
+ iiWithData.instanceIdentifier, value)?.get();
+ } else {
+ status = broker.commitConfigurationDataPost(iiWithData.instanceIdentifier, value)?.get();
+ }
+ if (status === null) {
+ return Response.status(ACCEPTED).build
+ }
+ switch status.result {
+ case TransactionStatus.COMMITED: Response.status(NO_CONTENT).build
+ default: Response.status(INTERNAL_SERVER_ERROR).build
+ }
+ }
+
+ override createConfigurationData(CompositeNode payload) {
+ if (payload.namespace === null) {
+ throw new ResponseException(BAD_REQUEST,
+ "Data has bad format. Root element node must have namespace (XML format) or module name(JSON format)");
+ }
+ val module = findModule(null, payload)
+ if (module === null) {
+ throw new ResponseException(BAD_REQUEST,
+ "Data has bad format. Root element node has incorrect namespace (XML format) or module name(JSON format)");
+ }
+ val schemaNode = module.findInstanceDataChildByNameAndNamespace(payload.name, module.namespace)
+ val value = normalizeNode(payload, schemaNode, null)
+ val iiWithData = addLastIdentifierFromData(null, value, schemaNode)
+ var RpcResult<TransactionStatus> status = null
+ if (iiWithData.mountPoint !== null) {
+ status = broker.commitConfigurationDataPostBehindMountPoint(iiWithData.mountPoint,
+ iiWithData.instanceIdentifier, value)?.get();
+ } else {
+ status = broker.commitConfigurationDataPost(iiWithData.instanceIdentifier, value)?.get();
+ }
+ if (status === null) {
+ return Response.status(ACCEPTED).build
+ }
+ switch status.result {
+ case TransactionStatus.COMMITED: Response.status(NO_CONTENT).build
+ default: Response.status(INTERNAL_SERVER_ERROR).build
+ }
+ }
+
+ override deleteConfigurationData(String identifier) {
+ val iiWithData = identifier.toInstanceIdentifier
+ var RpcResult<TransactionStatus> status = null
+ if (iiWithData.mountPoint !== null) {
+ status = broker.commitConfigurationDataDeleteBehindMountPoint(iiWithData.mountPoint,
+ iiWithData.getInstanceIdentifier).get;
+ } else {
+ status = broker.commitConfigurationDataDelete(iiWithData.getInstanceIdentifier).get;
+ }
+ switch status.result {
+ case TransactionStatus.COMMITED: Response.status(OK).build
+ default: Response.status(INTERNAL_SERVER_ERROR).build
+ }
+ }
+
+ private def dispatch URI namespace(CompositeNode data) {
+ return data.nodeType.namespace
+ }
+
+ private def dispatch URI namespace(CompositeNodeWrapper data) {
+ return data.namespace
+ }
+
+ private def dispatch String localName(CompositeNode data) {
+ return data.nodeType.localName
+ }
+
+ private def dispatch String localName(CompositeNodeWrapper data) {
+ return data.localName
+ }
+
+ private def dispatch Module findModule(MountInstance mountPoint, CompositeNode data) {
+ if (mountPoint !== null) {
+ return mountPoint.findModuleByNamespace(data.nodeType.namespace)
+ } else {
+ return findModuleByNamespace(data.nodeType.namespace)