From 56b6d34410b45df26021d74e3f4672b6c38dc23b Mon Sep 17 00:00:00 2001 From: Christof Rodejohann Date: Thu, 2 Apr 2015 11:39:13 +0200 Subject: [PATCH] [IMPROVEMENT] [DD-1087] adapt task execution endpoint changes --- yo/app/scripts/directives/transformation.js | 55 ++++++++++++--------- yo/test/spec/directives/transformation.js | 44 ++++++++++------- 2 files changed, 57 insertions(+), 42 deletions(-) diff --git a/yo/app/scripts/directives/transformation.js b/yo/app/scripts/directives/transformation.js index 42588cb1..4e9e4b72 100644 --- a/yo/app/scripts/directives/transformation.js +++ b/yo/app/scripts/directives/transformation.js @@ -1096,19 +1096,20 @@ angular.module('dmpApp') * @param task - Transformations to send * @param persist - if true, the transformation result should be persisted by the backend */ - function sendTransformations(task, persist) { + function transmitTransformations(payload) { - var runTask = angular.copy(task); - Util.ensureUniqueParameterMappingVars(runTask.job.mappings); - var finalTask = Util.toJson(runTask); + var runPayload = angular.copy(payload); + Util.ensureUniqueParameterMappingVars(runPayload.task.job.mappings); - var finishMessage = createTransformationStatusMessage(task, persist); + var finishMessage = createTransformationStatusMessage(runPayload.task, runPayload.persist); + + var finalPayload = Util.toJson(runPayload); ngProgress.start(); - // TODO: At some point the atMost parameter should be configurable from frontend. Right now hardcoded. - var taskEndpointParameters = {persist: !!persist, atMost: 3}; - if(persist) { delete taskEndpointParameters['atMost']; } - TaskResource.execute(taskEndpointParameters, finalTask).$promise.then(function(result) { + + if(finalPayload.persist) { delete finalPayload['at_most']; } + + TaskResource.execute({}, finalPayload).$promise.then(function(result) { ngProgress.complete(); showAlert.show($scope, 'info', finishMessage('successfully finished.')); PubSub.broadcast('transformationFinished', result); @@ -1126,16 +1127,20 @@ angular.module('dmpApp') $scope.sendTransformation = function() { var payload = { - name: $scope.activeMapping.name, - description: 'A Transformation', - job: { - mappings: [$scope.activeMapping] + 'task' : { + name: $scope.activeMapping.name, + description: 'A Transformation', + job: { + mappings: [$scope.activeMapping] + }, + input_data_model: $scope.project.input_data_model, + output_data_model: $scope.project.output_data_model }, - input_data_model: $scope.project.input_data_model, - output_data_model: $scope.project.output_data_model + 'at_most' : 3, + 'persist' : false }; - sendTransformations(payload, false); + transmitTransformations(payload); }; /** @@ -1164,16 +1169,20 @@ angular.module('dmpApp') $scope.sendTransformations = function(persist) { var payload = { - name: 'Project: ' + $scope.project.name + ' (' + $scope.project.uuid + ')', - description: 'With mappings: ' + $scope.returnMappingNames(', '), - job: { - mappings: $scope.project.mappings + 'task' : { + name: 'Project: ' + $scope.project.name + ' (' + $scope.project.uuid + ')', + description: 'With mappings: ' + $scope.returnMappingNames(', '), + job: { + mappings: $scope.project.mappings + }, + input_data_model: $scope.project.input_data_model, + output_data_model: $scope.project.output_data_model }, - input_data_model: $scope.project.input_data_model, - output_data_model: $scope.project.output_data_model + 'at_most' : 3, + 'persist' : persist }; - sendTransformations(payload, persist); + transmitTransformations(payload); }; PubSub.subscribe($scope, 'sendTransformations', function(persist) { diff --git a/yo/test/spec/directives/transformation.js b/yo/test/spec/directives/transformation.js index 93dabace..c5e4817b 100644 --- a/yo/test/spec/directives/transformation.js +++ b/yo/test/spec/directives/transformation.js @@ -633,7 +633,7 @@ describe('Directive: Transformation', function() { var taskResult = [ {'foo': 'bar'} ]; - $httpBackend.expectPOST('foo/tasks?atMost=3&persist=false').respond(taskResult); + $httpBackend.expectPOST('foo/tasks').respond(taskResult); scope.$digest(); var elScope = element.scope(); @@ -652,16 +652,21 @@ describe('Directive: Transformation', function() { output_data_model: project.output_data_model }; - var payloadExpect = angular.copy(payload); - Util.ensureUniqueParameterMappingVars(payloadExpect.job.mappings); + var payloadExpect = { + 'task' : angular.copy(payload), + 'at_most' : 3, + 'persist' : false + }; + + Util.ensureUniqueParameterMappingVars(payloadExpect.task.job.mappings); spyOn(TaskResource, 'execute').and.callThrough(); spyOn(PubSub, 'broadcast'); - elScope.sendTransformation(elScope.tabs[dataIdx]); + elScope.sendTransformation(); $httpBackend.flush(); - expect(TaskResource.execute).toHaveBeenCalledWith({ atMost: 3, persist: false }, Util.toJson(payloadExpect)); + expect(TaskResource.execute).toHaveBeenCalledWith({ }, Util.toJson(payloadExpect)); // JS, Y U NO WORK? // Error: Expected [ { foo : 'bar' } ] to equal [ { foo : 'bar' } ]. ???? @@ -673,7 +678,7 @@ describe('Directive: Transformation', function() { })); it('should alert an error on wrong transformations', inject(function(TaskResource, $window) { - $httpBackend.expectPOST('foo/tasks?atMost=3&persist=false').respond(500, {error: 'foo bar'}); + $httpBackend.expectPOST('foo/tasks').respond(500, {error: 'foo bar'}); scope.$digest(); var elScope = element.scope(); @@ -708,7 +713,7 @@ describe('Directive: Transformation', function() { var taskResult = [ {'foo': 'bar'} ]; - $httpBackend.expectPOST('foo/tasks?atMost=3&persist=false').respond(taskResult); + $httpBackend.expectPOST('foo/tasks').respond(taskResult); scope.$digest(); var elScope = element.scope(); @@ -717,29 +722,30 @@ describe('Directive: Transformation', function() { $rootScope.$broadcast('connectionSelected', connectionDatas[1]); var payload = { - name: 'Transformations', - description: 'Transformations', - job: { - mappings: project.mappings + 'task' : { + name: 'Project: ' + project.name + ' (' + project.uuid + ')', + description: 'With mappings: ' + elScope.returnMappingNames(', '), + job: { + mappings: project.mappings + }, + input_data_model: project.input_data_model, + output_data_model: project.output_data_model }, - input_data_model: project.input_data_model, - output_data_model: project.output_data_model + 'at_most' : 3, + 'persist' : false }; var payloadExpect = angular.copy(payload); - payloadExpect.name = 'Project: ' + project.name + ' (' + project.uuid + ')'; - payloadExpect.description = 'With mappings: ' + elScope.returnMappingNames(', '); - - Util.ensureUniqueParameterMappingVars(payloadExpect.job.mappings); + Util.ensureUniqueParameterMappingVars(payloadExpect.task.job.mappings); spyOn(TaskResource, 'execute').and.callThrough(); spyOn(PubSub, 'broadcast'); - elScope.sendTransformations(); + elScope.sendTransformations(false); $httpBackend.flush(); - expect(TaskResource.execute).toHaveBeenCalledWith({ atMost : 3, persist: false }, Util.toJson(payloadExpect)); + expect(TaskResource.execute).toHaveBeenCalledWith({ }, Util.toJson(payloadExpect)); // JS, Y U NO WORK? // Error: Expected [ { foo : 'bar' } ] to equal [ { foo : 'bar' } ]. ???? expect(PubSub.broadcast.calls.count()).toBe(1);