Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #40 from chrode/sprint-35/DD-1084
Browse files Browse the repository at this point in the history
[DD-1087] adapt task execution endpoint changes
  • Loading branch information
knutwalker committed Apr 2, 2015
2 parents 2e77c4c + 56b6d34 commit 8b63106
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 42 deletions.
55 changes: 32 additions & 23 deletions yo/app/scripts/directives/transformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
};

/**
Expand Down Expand Up @@ -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) {
Expand Down
44 changes: 25 additions & 19 deletions yo/test/spec/directives/transformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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' } ]. ????

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 8b63106

Please sign in to comment.