diff --git a/rowan/projects/Hyperspace.ston b/rowan/projects/Hyperspace.ston index 6d08130..2a213c0 100644 --- a/rowan/projects/Hyperspace.ston +++ b/rowan/projects/Hyperspace.ston @@ -2,7 +2,7 @@ RwLoadSpecificationV2 { #specName: 'Hyperspace', #projectName : 'Hyperspace', #gitUrl : 'https://github.com/ba-st/Hyperspace.git', - #revision : 'v5', + #revision : 'v6', #projectSpecFile : 'rowan/project.ston', #componentNames : [ 'Deployment', diff --git a/rowan/projects/JRPC.ston b/rowan/projects/JRPC.ston index 195e287..9e29e9a 100644 --- a/rowan/projects/JRPC.ston +++ b/rowan/projects/JRPC.ston @@ -2,7 +2,7 @@ RwLoadSpecificationV2 { #specName: 'JRPC', #projectName : 'JRPC', #gitUrl : 'https://github.com/ba-st-dependencies/JRPC.git', - #revision : 'v4', + #revision : 'v5', #projectSpecFile : 'rowan/project.ston', #componentNames : [ 'Deployment' diff --git a/rowan/projects/JSONWebToken.ston b/rowan/projects/JSONWebToken.ston index 836ee5d..111a2c9 100644 --- a/rowan/projects/JSONWebToken.ston +++ b/rowan/projects/JSONWebToken.ston @@ -2,7 +2,7 @@ RwLoadSpecificationV2 { #specName: 'JSONWebToken', #projectName : 'JSONWebToken', #gitUrl : 'https://github.com/ba-st-dependencies/JSONWebToken.git', - #revision : 'v1', + #revision : 'v2', #projectSpecFile : 'rowan/project.ston', #componentNames : [ 'Deployment' diff --git a/rowan/projects/Launchpad.ston b/rowan/projects/Launchpad.ston index a49052b..147fee4 100644 --- a/rowan/projects/Launchpad.ston +++ b/rowan/projects/Launchpad.ston @@ -2,7 +2,7 @@ RwLoadSpecificationV2 { #specName: 'Launchpad', #projectName : 'Launchpad', #gitUrl : 'https://github.com/ba-st/Launchpad.git', - #revision : 'v5', + #revision : 'v6', #projectSpecFile : 'rowan/project.ston', #componentNames : [ 'Deployment', diff --git a/rowan/projects/SortFunctions.ston b/rowan/projects/SortFunctions.ston index c008dc2..7783b17 100644 --- a/rowan/projects/SortFunctions.ston +++ b/rowan/projects/SortFunctions.ston @@ -2,7 +2,7 @@ RwLoadSpecificationV2 { #specName: 'SortFunctions', #projectName : 'SortFunctions', #gitUrl : 'https://github.com/ba-st-dependencies/SortFunctions.git', - #revision : 'v1', + #revision : 'v2', #projectSpecFile : 'rowan/project.ston', #componentNames : [ 'Deployment' diff --git a/rowan/projects/Teapot.ston b/rowan/projects/Teapot.ston index c7e86b5..8a290b4 100644 --- a/rowan/projects/Teapot.ston +++ b/rowan/projects/Teapot.ston @@ -2,7 +2,7 @@ RwLoadSpecificationV2 { #specName: 'Teapot', #projectName : 'Teapot', #gitUrl : 'https://github.com/ba-st-dependencies/Teapot.git', - #revision : 'v2', + #revision : 'v3', #projectSpecFile : 'rowan/project.ston', #componentNames : [ 'Deployment' diff --git a/source/BaselineOfStargate/BaselineOfStargate.class.st b/source/BaselineOfStargate/BaselineOfStargate.class.st index eb1ff30..21745f4 100644 --- a/source/BaselineOfStargate/BaselineOfStargate.class.st +++ b/source/BaselineOfStargate/BaselineOfStargate.class.st @@ -76,12 +76,12 @@ BaselineOfStargate >> setUpCorePackages: spec [ BaselineOfStargate >> setUpDependencies: spec [ spec - baseline: 'Buoy' with: [ spec repository: 'github://ba-st/Buoy:v7' ]; + baseline: 'Buoy' with: [ spec repository: 'github://ba-st/Buoy:v8' ]; project: 'Buoy-Deployment' copyFrom: 'Buoy' with: [ spec loads: 'Deployment' ]; project: 'Buoy-SUnit' copyFrom: 'Buoy' with: [ spec loads: 'Dependent-SUnit-Extensions' ]. spec - baseline: 'Hyperspace' with: [ spec repository: 'github://ba-st/Hyperspace:v5' ]; + baseline: 'Hyperspace' with: [ spec repository: 'github://ba-st/Hyperspace:v6' ]; project: 'Hyperspace-Deployment' copyFrom: 'Hyperspace' with: [ spec loads: 'Deployment' ]; project: 'Hyperspace-Tools' copyFrom: 'Hyperspace' with: [ spec loads: 'Tools' ]; project: 'Hyperspace-SUnit' @@ -89,19 +89,19 @@ BaselineOfStargate >> setUpDependencies: spec [ with: [ spec loads: 'Dependent-SUnit-Extensions' ]. spec - baseline: 'Teapot' with: [ spec repository: 'github://ba-st-dependencies/Teapot:v2' ]; + baseline: 'Teapot' with: [ spec repository: 'github://ba-st-dependencies/Teapot:v3' ]; project: 'Teapot-Deployment' copyFrom: 'Teapot' with: [ spec loads: 'Deployment' ]. spec - baseline: 'JSONWebToken' with: [ spec repository: 'github://ba-st-dependencies/JSONWebToken:v1' ]; + baseline: 'JSONWebToken' with: [ spec repository: 'github://ba-st-dependencies/JSONWebToken:v2' ]; project: 'JSONWebToken-Deployment' copyFrom: 'JSONWebToken' with: [ spec loads: 'SSL' ]. spec - baseline: 'JRPC' with: [ spec repository: 'github://ba-st-dependencies/JRPC:v4' ]; + baseline: 'JRPC' with: [ spec repository: 'github://ba-st-dependencies/JRPC:v5' ]; project: 'JRPC-Deployment' copyFrom: 'JRPC' with: [ spec loads: 'Server-Deployment' ]. spec - baseline: 'Launchpad' with: [ spec repository: 'github://ba-st/Launchpad:v5' ]; + baseline: 'Launchpad' with: [ spec repository: 'github://ba-st/Launchpad:v6' ]; project: 'Launchpad-Deployment' copyFrom: 'Launchpad' with: [ spec loads: 'Deployment' ]; project: 'Launchpad-SUnit' copyFrom: 'Launchpad' with: [ spec loads: 'Dependent-SUnit-Extensions' ] ] diff --git a/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st b/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st index ced337f..5f6a546 100644 --- a/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st +++ b/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st @@ -39,6 +39,30 @@ SouthAmericanCurrenciesRESTfulControllerTest >> languageRange [ ^ 'de,en;q=0.5,es;q=0.6' ] +{ #category : 'private' } +SouthAmericanCurrenciesRESTfulControllerTest >> performTest [ + + self + use: [ :translator | + translator + translationFor: 'Argentine peso' in: 'es-AR' is: 'Peso'; + translationFor: 'Bolivian boliviano' in: 'es-AR' is: 'Boliviano'; + translationFor: 'Brazilian real' in: 'es-AR' is: 'Real brasileño'; + translationFor: 'Chilean peso' in: 'es-AR' is: 'Peso chileno'; + translationFor: 'Colombian peso' in: 'es-AR' is: 'Peso colombiano'; + translationFor: 'Guyanese dollar' in: 'es-AR' is: 'Dólar guyanés'; + translationFor: 'Paraguayan guaraní' in: 'es-AR' is: 'Guaraní'; + translationFor: 'Peruvian sol' in: 'es-AR' is: 'Sol'; + translationFor: 'Surinamese dollar' in: 'es-AR' is: 'Dólar surinamés'; + translationFor: 'Uruguayan peso' in: 'es-AR' is: 'Peso uruguayo'; + translationFor: 'Venezuelan bolívar soberano' in: 'es-AR' is: 'Bolívar'; + translationFor: '{1} was not found in the system' + in: 'es-AR' + is: 'No se encontró {1} en el sistema' + ] + asNaturalLanguageTranslatorDuring: [ super performTest ] +] + { #category : 'running' } SouthAmericanCurrenciesRESTfulControllerTest >> setUpResourceController [ @@ -54,7 +78,7 @@ SouthAmericanCurrenciesRESTfulControllerTest >> spanish [ { #category : 'private - language ranges' } SouthAmericanCurrenciesRESTfulControllerTest >> supportedLanguages [ - ^ Array with: self argentineSpanish with: self unitedStatesEnglish + ^ { self argentineSpanish . self unitedStatesEnglish } ] { #category : 'tests' } @@ -447,14 +471,36 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetCurrenciesInSpanish [ { #category : 'tests' } SouthAmericanCurrenciesRESTfulControllerTest >> testGetCurrencyNotFoundShouldFail [ - self - should: [ - resourceController - currencyBasedOn: ( self requestToGETResourceIdentifiedBy: 'ZZZ' accepting: '*/*' ) - within: self newHttpRequestContext - ] - raise: HTTPClientError - withExceptionDo: [ :error | self assert: error code equals: 404 ] + self + should: [ + resourceController + currencyBasedOn: ( self requestToGETResourceIdentifiedBy: 'ZZZ' accepting: '*/*' ) + within: self newHttpRequestContext + ] + raise: HTTPClientError + withExceptionDo: [ :error | + self + assert: error code equals: 404; + assert: error messageText equals: 'ZZZ was not found in the system' + ] +] + +{ #category : 'tests' } +SouthAmericanCurrenciesRESTfulControllerTest >> testGetCurrencyNotFoundShouldFailInSpanish [ + + self + should: [ + | request | + request := self requestToGETResourceIdentifiedBy: 'ZZZ' accepting: '*/*'. + request setAcceptLanguage: self spanish. + resourceController currencyBasedOn: request within: self newHttpRequestContext + ] + raise: HTTPClientError + withExceptionDo: [ :error | + self + assert: error code equals: 404; + assert: error messageText equals: 'No se encontró ZZZ en el sistema' + ] ] { #category : 'tests' } diff --git a/source/Stargate-Examples/SouthAmericanCurrenciesRESTfulController.class.st b/source/Stargate-Examples/SouthAmericanCurrenciesRESTfulController.class.st index 017885e..62c015c 100644 --- a/source/Stargate-Examples/SouthAmericanCurrenciesRESTfulController.class.st +++ b/source/Stargate-Examples/SouthAmericanCurrenciesRESTfulController.class.st @@ -11,7 +11,7 @@ Class { 'banknotesByCurrency', 'banknotesRequestHandler', 'currenciesRequestHandler', - 'currenciesByLanguage' + 'currencies' ], #category : 'Stargate-Examples-Currencies', #package : 'Stargate-Examples', @@ -27,21 +27,7 @@ SouthAmericanCurrenciesRESTfulController >> banknotesTemplate [ { #category : 'API' } SouthAmericanCurrenciesRESTfulController >> currenciesBasedOn: httpRequest within: requestContext [ - ^ currenciesRequestHandler - from: httpRequest - within: requestContext - getCollection: [ self currenciesInLanguageAt: requestContext ] -] - -{ #category : 'private' } -SouthAmericanCurrenciesRESTfulController >> currenciesInLanguageAt: requestContext [ - - | targetLanguage | - - targetLanguage := [ requestContext targetLanguageTag ] - on: NotFound - do: [ :error | error return: 'en-US' asLanguageTag ]. - ^ currenciesByLanguage at: targetLanguage + ^ currenciesRequestHandler from: httpRequest within: requestContext getCollection: [ currencies ] ] { #category : 'API' } @@ -56,14 +42,12 @@ SouthAmericanCurrenciesRESTfulController >> currencyBanknotesBasedOn: httpReques { #category : 'API' } SouthAmericanCurrenciesRESTfulController >> currencyBasedOn: httpRequest within: requestContext [ - ^ currenciesRequestHandler - from: httpRequest - within: requestContext - get: [ :isoCode | - ( self currenciesInLanguageAt: requestContext ) - detect: [ :currency | currency isoCode = isoCode ] - ifNone: [ NotFound signal ] - ] + ^ currenciesRequestHandler from: httpRequest within: requestContext get: [ :isoCode | + currencies + detect: [ :currency | currency isoCode = isoCode ] + ifNone: [ + NotFound signal: ( '{1} was not found in the system' localizedWithAll: { isoCode } ) ] + ] ] { #category : 'private' } @@ -158,66 +142,58 @@ SouthAmericanCurrenciesRESTfulController >> initializeBanknotesRequestHandler [ { #category : 'initialization' } SouthAmericanCurrenciesRESTfulController >> initializeCurrencies [ - currenciesByLanguage := Dictionary new - at: 'en-US' asLanguageTag - put: - ( OrderedCollection new - add: ( self currencyNamed: 'Argentine peso' symbol: '$' isoCode: 'ARS' ); - add: ( self currencyNamed: 'Bolivian boliviano' symbol: 'Bs.' isoCode: 'BOB' ); - add: ( self currencyNamed: 'Brazilian real' symbol: 'R$' isoCode: 'BRL' ); - add: ( self currencyNamed: 'Chilean peso' symbol: '$' isoCode: 'CLP' ); - add: ( self currencyNamed: 'Colombian peso' symbol: '$' isoCode: 'COP' ); - add: ( self currencyNamed: 'Guyanese dollar' symbol: '$' isoCode: 'GYD' ); - add: ( self currencyNamed: 'Paraguayan guaraní' symbol: '₲' isoCode: 'PYG' ); - add: ( self currencyNamed: 'Peruvian sol' symbol: 'S/.' isoCode: 'PEN' ); - add: ( self currencyNamed: 'Surinamese dollar' symbol: '$' isoCode: 'SRD' ); - add: ( self currencyNamed: 'Uruguayan peso' symbol: '$' isoCode: 'UYU' ); - add: ( self currencyNamed: 'Venezuelan bolívar soberano' symbol: 'Bs.S' isoCode: 'VES' ); - asArray ); - at: 'es-AR' asLanguageTag - put: - ( OrderedCollection new - add: ( self currencyNamed: 'Peso' symbol: '$' isoCode: 'ARS' ); - add: ( self currencyNamed: 'Boliviano' symbol: 'Bs.' isoCode: 'BOB' ); - add: ( self currencyNamed: 'Real brasileño' symbol: 'R$' isoCode: 'BRL' ); - add: ( self currencyNamed: 'Peso chileno' symbol: '$' isoCode: 'CLP' ); - add: ( self currencyNamed: 'Peso colombiano' symbol: '$' isoCode: 'COP' ); - add: ( self currencyNamed: 'Dólar guyanés' symbol: '$' isoCode: 'GYD' ); - add: ( self currencyNamed: 'Guaraní' symbol: '₲' isoCode: 'PYG' ); - add: ( self currencyNamed: 'Sol' symbol: 'S/.' isoCode: 'PEN' ); - add: ( self currencyNamed: 'Dólar surinamés' symbol: '$' isoCode: 'SRD' ); - add: ( self currencyNamed: 'Peso uruguayo' symbol: '$' isoCode: 'UYU' ); - add: ( self currencyNamed: 'Bolívar' symbol: 'Bs.S' isoCode: 'VES' ); - asArray ); - yourself + currencies := OrderedCollection new + add: ( self currencyNamed: 'Argentine peso' symbol: '$' isoCode: 'ARS' ); + add: ( self currencyNamed: 'Bolivian boliviano' symbol: 'Bs.' isoCode: 'BOB' ); + add: ( self currencyNamed: 'Brazilian real' symbol: 'R$' isoCode: 'BRL' ); + add: ( self currencyNamed: 'Chilean peso' symbol: '$' isoCode: 'CLP' ); + add: ( self currencyNamed: 'Colombian peso' symbol: '$' isoCode: 'COP' ); + add: ( self currencyNamed: 'Guyanese dollar' symbol: '$' isoCode: 'GYD' ); + add: ( self currencyNamed: 'Paraguayan guaraní' symbol: '₲' isoCode: 'PYG' ); + add: ( self currencyNamed: 'Peruvian sol' symbol: 'S/.' isoCode: 'PEN' ); + add: ( self currencyNamed: 'Surinamese dollar' symbol: '$' isoCode: 'SRD' ); + add: ( self currencyNamed: 'Uruguayan peso' symbol: '$' isoCode: 'UYU' ); + add: + ( self + currencyNamed: 'Venezuelan bolívar soberano' + symbol: 'Bs.S' + isoCode: 'VES' ); + asArray ] { #category : 'initialization' } SouthAmericanCurrenciesRESTfulController >> initializeCurrenciesRequestHandler [ - currenciesRequestHandler := RESTfulRequestHandlerBuilder new - handling: 'currencies' - extractingIdentifierWith: [ :httpRequest | self identifierIn: httpRequest ]; - whenResponding: self currencyVersion1dot0dot0MediaType - encodeToJsonApplying: - [ :resource :requestContext :writer | writer for: StargateCurrency do: [ :mapping | mapping mapInstVars ] ]; - createEntityTagHashing: [ :hasher :currency :requestContext | - hasher - include: currency name; - include: currency symbol; - include: currency isoCode - ]; - handleExceptionsApplying: [ :handler | handler addAsNotFoundError: NotFound ]; - directCachingWith: [ :caching | - caching - beImmutable; - when: [ :response :resource | resource isCollection ] apply: [ caching beStaleAfter: 1 day ]; - when: [ :response :resource | resource isCollection not and: [ resource symbol = '$' ] ] - apply: [ caching bePublic ] - ]; - addAsSupportedLanguage: 'en-US'; - addAsSupportedLanguage: 'es-AR'; - build + currenciesRequestHandler := RESTfulRequestHandlerBuilder new + handling: 'currencies' + extractingIdentifierWith: [ :httpRequest | + self identifierIn: httpRequest ]; + whenResponding: self currencyVersion1dot0dot0MediaType + encodeToJsonApplying: [ :resource :requestContext :writer | + writer + for: StargateCurrency + do: [ :mapping | + mapping mapAccessors: #( #symbol #isoCode #name ) ] ]; + createEntityTagHashing: [ :hasher :currency :requestContext | + hasher + include: currency name; + include: currency symbol; + include: currency isoCode + ]; + handleExceptionsApplying: [ :handler | + handler addAsNotFoundError: NotFound ]; + directCachingWith: [ :caching | + caching + beImmutable; + when: [ :response :resource | resource isCollection ] + apply: [ caching beStaleAfter: 1 day ]; + when: [ :response :resource | + resource isCollection not and: [ resource symbol = '$' ] ] + apply: [ caching bePublic ] + ]; + addAsSupportedLanguage: 'en-US'; + addAsSupportedLanguage: 'es-AR'; + build ] { #category : 'private' } diff --git a/source/Stargate-Examples/StargateCurrency.class.st b/source/Stargate-Examples/StargateCurrency.class.st index 68aebc9..3b2ef77 100644 --- a/source/Stargate-Examples/StargateCurrency.class.st +++ b/source/Stargate-Examples/StargateCurrency.class.st @@ -37,7 +37,7 @@ StargateCurrency >> isoCode [ { #category : 'accessing' } StargateCurrency >> name [ - ^ name + ^ name localized ] { #category : 'accessing' } diff --git a/source/Stargate-Model/HttpRequestContext.class.st b/source/Stargate-Model/HttpRequestContext.class.st index 17a50c3..f05aa7f 100644 --- a/source/Stargate-Model/HttpRequestContext.class.st +++ b/source/Stargate-Model/HttpRequestContext.class.st @@ -139,3 +139,9 @@ HttpRequestContext >> withTargetLanguageTagDo: aBlock [ knownObjects at: #targetLanguageTag ifPresent: aBlock ] + +{ #category : 'accessing' } +HttpRequestContext >> withTargetLanguageTagDo: aBlock ifNone: noneBlock [ + + ^ knownObjects at: #targetLanguageTag ifPresent: aBlock ifAbsent: noneBlock +] diff --git a/source/Stargate-Model/RESTfulRequestHandlerBehavior.class.st b/source/Stargate-Model/RESTfulRequestHandlerBehavior.class.st index 93bf63f..1f32d22 100644 --- a/source/Stargate-Model/RESTfulRequestHandlerBehavior.class.st +++ b/source/Stargate-Model/RESTfulRequestHandlerBehavior.class.st @@ -138,45 +138,51 @@ RESTfulRequestHandlerBehavior >> exceptionHandler [ { #category : 'API' } RESTfulRequestHandlerBehavior >> from: httpRequest within: requestContext get: aQueryEvaluationBlock [ - | resource response | - - self holdTargetMediaTypeAndLanguageFrom: httpRequest within: requestContext. - resource := resourceLocator - lookupResourceIdentifiedBy: httpRequest - evaluating: aQueryEvaluationBlock. - self - ifNoneMatchHeaderPresentIn: httpRequest - do: [ :etag | - etag - = ( self entityTagOf: resource encodedAs: requestContext targetMediaType within: requestContext ) - ifTrue: [ response := ZnResponse notModified. - response - setEntityTag: etag; - addToVary: 'Accept'. - self - applyCachingDirectivesFor: resource to: response within: requestContext; - putLanguageContentTagIn: response within: requestContext. - ^ response - ] - ]. - response := ZnResponse ok: ( self encodeResource: resource within: requestContext ). - self putEntityTagOf: resource in: response within: requestContext. - self - applyCachingDirectivesFor: resource to: response within: requestContext; - putLanguageContentTagIn: response within: requestContext. - ^ response + self holdTargetMediaTypeAndLanguageFrom: httpRequest within: requestContext. + ^ self useTargetLanguageTagIn: requestContext asCurrentLocaleDuring: [ + | resource response | + resource := resourceLocator + lookupResourceIdentifiedBy: httpRequest + evaluating: aQueryEvaluationBlock. + self ifNoneMatchHeaderPresentIn: httpRequest do: [ :etag | + | calculatedEtag | + calculatedEtag := self + entityTagOf: resource + encodedAs: requestContext targetMediaType + within: requestContext. + etag = calculatedEtag ifTrue: [ + response := ZnResponse notModified. + response + setEntityTag: etag; + addToVary: 'Accept'. + self + applyCachingDirectivesFor: resource to: response within: requestContext; + putLanguageContentTagIn: response within: requestContext. + ^ response + ] + ]. + response := ZnResponse ok: ( self encodeResource: resource within: requestContext ). + self putEntityTagOf: resource in: response within: requestContext. + self + applyCachingDirectivesFor: resource to: response within: requestContext; + putLanguageContentTagIn: response within: requestContext. + response + ] ] { #category : 'API' } RESTfulRequestHandlerBehavior >> from: httpRequest within: requestContext get: aQueryEvaluationBlock thenDo: actionBlock [ - | resource | + self holdTargetLanguageFrom: httpRequest within: requestContext. - resource := resourceLocator - lookupResourceIdentifiedBy: httpRequest - evaluating: aQueryEvaluationBlock. - self exceptionHandler handleConflictsDuring: [ actionBlock value: resource ]. - ^ ZnResponse noContent + ^ self useTargetLanguageTagIn: requestContext asCurrentLocaleDuring: [ + | resource | + resource := resourceLocator + lookupResourceIdentifiedBy: httpRequest + evaluating: aQueryEvaluationBlock. + self exceptionHandler handleConflictsDuring: [ actionBlock value: resource ]. + ZnResponse noContent + ] ] { #category : 'API' } @@ -210,30 +216,39 @@ RESTfulRequestHandlerBehavior >> from: httpRequest within: requestContext get: f { #category : 'API' } RESTfulRequestHandlerBehavior >> from: httpRequest within: requestContext getCollection: aQueryEvaluationBlock [ - | resourceCollection encodedResourceCollection response | + self holdTargetMediaTypeAndLanguageFrom: httpRequest within: requestContext. + ^ self useTargetLanguageTagIn: requestContext asCurrentLocaleDuring: [ + | resourceCollection encodedResourceCollection response | + resourceCollection := paginationPolicy + evaluateQuery: aQueryEvaluationBlock + basedOn: httpRequest. + encodedResourceCollection := self + encodeResourceCollection: resourceCollection + basedOn: httpRequest + within: requestContext. + response := ZnResponse ok: encodedResourceCollection. + response addToVary: 'Accept'. + self paginationPolicy affect: response within: requestContext. + self + applyCachingDirectivesFor: resourceCollection to: response within: requestContext; + putLanguageContentTagIn: response within: requestContext. + response + ] +] + +{ #category : 'private' } +RESTfulRequestHandlerBehavior >> holdTargetLanguageFrom: httpRequest within: requestContext [ - self holdTargetMediaTypeAndLanguageFrom: httpRequest within: requestContext. - resourceCollection := paginationPolicy evaluateQuery: aQueryEvaluationBlock basedOn: httpRequest. - encodedResourceCollection := self - encodeResourceCollection: resourceCollection - basedOn: httpRequest - within: requestContext. - response := ZnResponse ok: encodedResourceCollection. - response addToVary: 'Accept'. - self paginationPolicy affect: response within: requestContext. - self - applyCachingDirectivesFor: resourceCollection to: response within: requestContext; - putLanguageContentTagIn: response within: requestContext. - ^ response + httpRequest hasLanguageProrityList then: [ + requestContext targetLanguageTag: ( acceptNegotiator bestLanguageFor: httpRequest ) ] ] { #category : 'private' } RESTfulRequestHandlerBehavior >> holdTargetMediaTypeAndLanguageFrom: httpRequest within: requestContext [ - httpRequest hasLanguageProrityList - then: [ requestContext targetLanguageTag: ( acceptNegotiator bestLanguageFor: httpRequest ) ]. + self holdTargetLanguageFrom: httpRequest within: requestContext. - ^ requestContext targetMediaType: ( acceptNegotiator bestRepresentationFor: httpRequest ) + ^ requestContext targetMediaType: ( acceptNegotiator bestRepresentationFor: httpRequest ) ] { #category : 'private' } @@ -319,6 +334,14 @@ RESTfulRequestHandlerBehavior >> serverUrl: aServerUrl [ resourceLocator baseUrl: aServerUrl ] +{ #category : 'private' } +RESTfulRequestHandlerBehavior >> useTargetLanguageTagIn: httpRequestContext asCurrentLocaleDuring: aBlock [ + + ^ httpRequestContext + withTargetLanguageTagDo: [ :language | CurrentLocale use: language during: aBlock ] + ifNone: aBlock +] + { #category : 'API' } RESTfulRequestHandlerBehavior >> withRepresentationIn: httpRequest within: requestContext createResourceWith: aCreationBlock thenDo: aBlock [ @@ -334,10 +357,13 @@ RESTfulRequestHandlerBehavior >> withRepresentationIn: httpRequest within: reque { #category : 'API' } RESTfulRequestHandlerBehavior >> withResourceCreatedFrom: httpRequest within: requestContext do: aBlock [ - | creationPolicy decodedRepresentation newResource | - - creationPolicy := self resourceCreationPolicyBasedOn: httpRequest within: requestContext. - decodedRepresentation := self decode: httpRequest within: requestContext. - newResource := self exceptionHandler handleConflictsDuring: [ aBlock value: decodedRepresentation ]. - ^ creationPolicy responseFor: newResource basedOn: httpRequest within: requestContext + | creationPolicy | + creationPolicy := self resourceCreationPolicyBasedOn: httpRequest within: requestContext. + ^ self useTargetLanguageTagIn: requestContext asCurrentLocaleDuring: [ + | decodedRepresentation newResource | + decodedRepresentation := self decode: httpRequest within: requestContext. + newResource := self exceptionHandler handleConflictsDuring: [ + aBlock value: decodedRepresentation ]. + creationPolicy responseFor: newResource basedOn: httpRequest within: requestContext + ] ]