+ val iiWithData = identifier.toInstanceIdentifier
+ var CompositeNode data = null;
+ if (iiWithData.mountPoint !== null) {
+ data = broker.readOperationalDataBehindMountPoint(iiWithData.mountPoint, iiWithData.getInstanceIdentifier)
+ } else {
+ data = broker.readOperationalData(iiWithData.getInstanceIdentifier);
+ }
+ return new StructuredData(data, iiWithData.schemaNode, iiWithData.mountPoint)
+ }
+
+ override updateConfigurationData(String identifier, CompositeNode payload) {
+ val iiWithData = identifier.toInstanceIdentifier
+ val value = normalizeNode(payload, iiWithData.schemaNode, iiWithData.mountPoint)
+ var RpcResult<TransactionStatus> status = null
+ if (iiWithData.mountPoint !== null) {
+ status = broker.commitConfigurationDataPutBehindMountPoint(iiWithData.mountPoint,
+ iiWithData.instanceIdentifier, value).get()
+ } else {
+ status = broker.commitConfigurationDataPut(iiWithData.instanceIdentifier, value).get();
+ }
+ switch status.result {
+ case TransactionStatus.COMMITED: Response.status(OK).build
+ default: Response.status(INTERNAL_SERVER_ERROR).build
+ }
+ }
+
+ 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
+ }
+ }
+
+ override subscribeToStream(String identifier, UriInfo uriInfo) {
+ val streamName = Notificator.createStreamNameFromUri(identifier)
+ if (streamName.nullOrEmpty) {
+ throw new ResponseException(BAD_REQUEST, "Stream name is empty.")
+ }
+ val listener = Notificator.getListenerFor(streamName);
+ if (listener === null) {
+ throw new ResponseException(BAD_REQUEST, "Stream was not found.")
+ }
+ broker.registerToListenDataChanges(listener)
+ val uriBuilder = uriInfo.getAbsolutePathBuilder()
+ val uriToWebsocketServer = uriBuilder.port(WebSocketServer.PORT).replacePath(streamName).build()
+ return Response.status(OK).location(uriToWebsocketServer).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