+ 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)");
+ }
+ val uncompleteInstIdWithData = identifier.toInstanceIdentifier
+ val schemaNode = uncompleteInstIdWithData.mountPoint.findModule(payload)?.getSchemaChildNode(payload)
+ val value = normalizeNode(payload, schemaNode, uncompleteInstIdWithData.mountPoint)
+ val completeInstIdWithData = uncompleteInstIdWithData.addLastIdentifierFromData(value, schemaNode)
+ var RpcResult<TransactionStatus> status = null
+ if (completeInstIdWithData.mountPoint !== null) {
+ status = broker.commitConfigurationDataPostBehindMountPoint(completeInstIdWithData.mountPoint,
+ completeInstIdWithData.instanceIdentifier, value)?.get();
+ } else {
+ status = broker.commitConfigurationDataPost(completeInstIdWithData.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 schemaNode = findModule(null, payload)?.getSchemaChildNode(payload)
+ 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 Module findModule(MountInstance mountPoint, CompositeNode data) {
+ if (mountPoint !== null) {
+ return mountPoint.findModuleByNamespace(data.nodeType.namespace)
+ } else {
+ return findModuleByNamespace(data.nodeType.namespace)