3333using System . Text ;
3434using System . Web . Http ;
3535using System . Linq ;
36- using Sif . Framework . Model . Settings ;
3736
3837namespace Sif . Framework . Providers
3938{
@@ -102,12 +101,12 @@ public virtual HttpResponseMessage Post([FromUri] string serviceName, [FromUri]
102101 {
103102 return Request . CreateErrorResponse ( HttpStatusCode . BadRequest , "Request requires use of advisory id, but none has been supplied." ) ;
104103 }
105-
104+
106105 Guid id = service . Create ( item , zone : ( zone == null ? null : zone [ 0 ] ) , context : ( context == null ? null : context [ 0 ] ) ) ;
107106
108- if ( SettingsManager . ProviderSettings . JobBinding )
107+ if ( SettingsManager . ProviderSettings . JobBinding )
109108 {
110- service . Bind ( sessionToken , id ) ;
109+ service . Bind ( getOwnerId ( sessionToken ) , id ) ;
111110 }
112111
113112 jobType job = service . Retrieve ( id , zone : ( zone == null ? null : zone [ 0 ] ) , context : ( context == null ? null : context [ 0 ] ) ) ;
@@ -161,7 +160,8 @@ public virtual HttpResponseMessage Post([FromUri] string serviceName, [FromBody]
161160 List < createType > creates = new List < createType > ( ) ;
162161 foreach ( jobType job in items . job )
163162 {
164- try {
163+ try
164+ {
165165 if ( ! service . AcceptJob ( serviceName , job . name ) )
166166 {
167167 throw new ArgumentException ( "Service " + serviceName + " does not handle jobs named " + job . name ) ;
@@ -170,16 +170,17 @@ public virtual HttpResponseMessage Post([FromUri] string serviceName, [FromBody]
170170
171171 if ( SettingsManager . ProviderSettings . JobBinding )
172172 {
173- service . Bind ( sessionToken , id ) ;
173+ service . Bind ( getOwnerId ( sessionToken ) , id ) ;
174174 }
175175
176176 creates . Add ( ProviderUtils . CreateCreate ( HttpStatusCode . Created , id . ToString ( ) , job . id ) ) ;
177- } catch ( CreateException e )
177+ }
178+ catch ( CreateException e )
178179 {
179180 ProviderUtils . CreateCreate ( HttpStatusCode . Conflict , job . id , error : ProviderUtils . CreateError ( HttpStatusCode . Conflict , HttpStatusCode . Conflict . ToString ( ) , e . Message ) ) ;
180181 }
181182 }
182-
183+
183184 createResponseType createResponse = ProviderUtils . CreateCreateResponse ( creates . ToArray ( ) ) ;
184185
185186 result = Request . CreateResponse < createResponseType > ( HttpStatusCode . Created , createResponse ) ;
@@ -244,7 +245,7 @@ public virtual ICollection<jobType> Get([FromUri] string serviceName, [MatrixPar
244245 foreach ( jobType job in jobs )
245246 {
246247 if ( ! SettingsManager . ProviderSettings . JobBinding
247- || service . IsBound ( sessionToken , Guid . Parse ( job . id ) ) )
248+ || service . IsBound ( getOwnerId ( sessionToken ) , Guid . Parse ( job . id ) ) )
248249 {
249250 items . Add ( job ) ;
250251 }
@@ -283,7 +284,7 @@ public virtual HttpResponseMessage Get([FromUri] string serviceName, [FromUri] G
283284 item = service . Retrieve ( id , zone : ( zone == null ? null : zone [ 0 ] ) , context : ( context == null ? null : context [ 0 ] ) ) ;
284285
285286 if ( SettingsManager . ProviderSettings . JobBinding
286- && ! service . IsBound ( sessionToken , Guid . Parse ( item . id ) ) )
287+ && ! service . IsBound ( getOwnerId ( sessionToken ) , Guid . Parse ( item . id ) ) )
287288 {
288289 throw new InvalidSessionException ( "Request failed as one or more jobs referred to in this request do not belong to this consumer." ) ;
289290 }
@@ -343,7 +344,7 @@ public virtual HttpResponseMessage Delete([FromUri] string serviceName, [FromUri
343344 IFunctionalService service = getService ( serviceName ) ;
344345
345346 if ( SettingsManager . ProviderSettings . JobBinding
346- && ! service . IsBound ( sessionToken , id ) )
347+ && ! service . IsBound ( getOwnerId ( sessionToken ) , id ) )
347348 {
348349 throw new InvalidSessionException ( "Request failed as one or more jobs referred to in this request do not belong to this consumer." ) ;
349350 }
@@ -383,7 +384,7 @@ public virtual HttpResponseMessage Delete([FromUri] string serviceName, [FromBod
383384 try
384385 {
385386 if ( SettingsManager . ProviderSettings . JobBinding
386- && ! service . IsBound ( sessionToken , Guid . Parse ( deleteId . id ) ) )
387+ && ! service . IsBound ( getOwnerId ( sessionToken ) , Guid . Parse ( deleteId . id ) ) )
387388 {
388389 throw new InvalidSessionException ( "Request failed as one or more jobs referred to in this request do not belong to this consumer." ) ;
389390 }
@@ -443,7 +444,7 @@ public virtual HttpResponseMessage Post([FromUri] string serviceName, [FromUri]
443444 {
444445 IFunctionalService service = getService ( serviceName ) ;
445446 if ( SettingsManager . ProviderSettings . JobBinding
446- && ! service . IsBound ( sessionToken , id ) )
447+ && ! service . IsBound ( getOwnerId ( sessionToken ) , id ) )
447448 {
448449 throw new InvalidSessionException ( "Request failed as the job referred to in this request does not belong to this consumer." ) ;
449450 }
@@ -484,7 +485,7 @@ public virtual HttpResponseMessage Get([FromUri] string serviceName, [FromUri] G
484485 {
485486 IFunctionalService service = getService ( serviceName ) ;
486487 if ( SettingsManager . ProviderSettings . JobBinding
487- && ! service . IsBound ( sessionToken , id ) )
488+ && ! service . IsBound ( getOwnerId ( sessionToken ) , id ) )
488489 {
489490 throw new InvalidSessionException ( "Request failed as the job referred to in this request does not belong to this consumer." ) ;
490491 }
@@ -523,7 +524,7 @@ public virtual HttpResponseMessage Put([FromUri] string serviceName, [FromUri] G
523524 {
524525 IFunctionalService service = getService ( serviceName ) ;
525526 if ( SettingsManager . ProviderSettings . JobBinding
526- && ! service . IsBound ( sessionToken , id ) )
527+ && ! service . IsBound ( getOwnerId ( sessionToken ) , id ) )
527528 {
528529 throw new InvalidSessionException ( "Request failed as the job referred to in this request does not belong to this consumer." ) ;
529530 }
@@ -564,7 +565,7 @@ public virtual HttpResponseMessage Delete([FromUri] string serviceName, [FromUri
564565 {
565566 IFunctionalService service = getService ( serviceName ) ;
566567 if ( SettingsManager . ProviderSettings . JobBinding
567- && ! service . IsBound ( sessionToken , id ) )
568+ && ! service . IsBound ( getOwnerId ( sessionToken ) , id ) )
568569 {
569570 throw new InvalidSessionException ( "Request failed as the job referred to in this request does not belong to this consumer." ) ;
570571 }
@@ -608,7 +609,7 @@ public virtual HttpResponseMessage Post([FromUri] string serviceName, [FromUri]
608609 {
609610 IFunctionalService service = getService ( serviceName ) ;
610611 if ( SettingsManager . ProviderSettings . JobBinding
611- && ! service . IsBound ( sessionToken , id ) )
612+ && ! service . IsBound ( getOwnerId ( sessionToken ) , id ) )
612613 {
613614 throw new InvalidSessionException ( "Request failed as the job referred to in this request does not belong to this consumer." ) ;
614615 }
@@ -634,7 +635,7 @@ public virtual HttpResponseMessage Post([FromUri] string serviceName, [FromUri]
634635 {
635636 throw new HttpResponseException ( Request . CreateErrorResponse ( HttpStatusCode . InternalServerError , "Request failed for creating state for phase " + phaseName + " in job " + id + ".\n " + e . Message ) ) ;
636637 }
637-
638+
638639 return result ;
639640 }
640641
@@ -684,7 +685,7 @@ protected virtual string CheckAuthorisation(string[] zone, string[] context)
684685 {
685686 throw new HttpResponseException ( Request . CreateErrorResponse ( HttpStatusCode . BadRequest , "Request failed as Zone and/or Context are invalid." ) ) ;
686687 }
687-
688+
688689 return sessionToken ;
689690 }
690691
@@ -751,7 +752,7 @@ where s.Type.Equals(ServiceType.FUNCTIONAL.ToString())
751752 /// <param name="right">The right to search for (the needle)</param>
752753 private void CheckRights ( string serviceName , IDictionary < string , Right > rights , Right right )
753754 {
754-
755+
755756 }
756757
757758 /// <summary>
@@ -772,16 +773,22 @@ protected virtual void preventPagingHeaders()
772773 /// <returns>A response message</returns>
773774 protected HttpResponseMessage OKResult ( string payload = null )
774775 {
775- if ( StringUtils . IsEmpty ( payload ) )
776+ if ( StringUtils . IsEmpty ( payload ) )
776777 {
777778 return new HttpResponseMessage ( HttpStatusCode . NoContent ) ;
778779 }
779780
780781 string accept = HttpUtils . GetAccept ( Request ) ;
781- return new HttpResponseMessage ( HttpStatusCode . OK ) {
782+ return new HttpResponseMessage ( HttpStatusCode . OK )
783+ {
782784 Content = new StringContent ( payload , Encoding . UTF8 , accept )
783785 } ;
784786 }
787+
788+ private String getOwnerId ( String sessionToken )
789+ {
790+ return sessionToken ;
791+ }
785792 }
786793
787794}
0 commit comments