Skip to content

Commit

Permalink
gh-401 Create endpoint to return single ProfileProviderService
Browse files Browse the repository at this point in the history
- Also give profile providers index optional parameter to only return latest versions
- Add tests to verify new endpoint
  • Loading branch information
pjmonks committed Mar 13, 2023
1 parent f41d64f commit 65046bc
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ class ProfileController implements ResourcelessMdmController, DataBinder {


def profileProviders() {
respond profileProviderServices: profileService.getAllProfileProviderServices(false)
respond profileProviderServices: profileService.getAllProfileProviderServices(params.boolean('latestVersionByMetadataNamespace', false))
}

def profileProvider() {
List<ProfileProviderService> allProviders = profileService.getAllProfileProviderServices(false)
ProfileProviderService profileProviderService = profileService.findProfileProviderService(allProviders, params.profileNamespace, params.profileName, params.profileVersion)
if (!profileProviderService) {
return notFound(ProfileProviderService, getProfileProviderServiceId(params))
}

respond profileProviderService: profileProviderService
}

def dynamicProfileProviders() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ProfileInterceptor extends FacetInterceptor {

boolean before() {
// Public or secured at controller as using listAll
if (actionName in ['profileProviders', 'dynamicProfileProviders', 'listModelsInProfile', 'listValuesInProfile', 'emptyProfile']) return true
if (actionName in ['profileProviders', 'profileProvider', 'dynamicProfileProviders', 'listModelsInProfile', 'listValuesInProfile', 'emptyProfile']) return true
if (!params.containsKey('multiFacetAwareItemDomainType') && actionName == 'search') return true
facetResourceChecks()
checkActionAllowedOnFacet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class UrlMappings {
group '/profiles', {
get '/providers'(controller: 'profile', action: 'profileProviders')
get '/providers/dynamic'(controller: 'profile', action: 'dynamicProfileProviders')
get "/providers/$profileNamespace/$profileName/$profileVersion?"(controller: 'profile', action: 'profileProvider')

group "/$profileNamespace/$profileName", {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import uk.ac.ox.softeng.maurodatamapper.profile.provider.ProfileProviderService

model {
ProfileProviderService profileProviderService
}

json tmpl.'/profileProviderService/profileProviderService'(profileProviderService)
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,32 @@ class ProfileFunctionalSpec extends BaseFunctionalSpec {
}]'''
}

void '01.1 : test getting single profile provider'() {
when:
GET('profiles/providers/uk.ac.ox.softeng.maurodatamapper.profile/ProfileSpecificationProfileService', STRING_ARG)

then:
verifyJsonResponse OK, '''
{
"name": "ProfileSpecificationProfileService",
"version": "${json-unit.matches:version}",
"displayName": "Profile Specification Profile (Data Model)",
"namespace": "uk.ac.ox.softeng.maurodatamapper.profile",
"allowsExtraMetadataKeys": false,
"knownMetadataKeys": [
"metadataNamespace",
"domainsApplicable",
"editableAfterFinalisation"
],
"providerType": "Profile",
"metadataNamespace": "uk.ac.ox.softeng.maurodatamapper.profile",
"domains": [
"DataModel"
],
"editableAfterFinalisation": false
}'''
}

void '02 : test get all models in profile which doesnt exist'() {
when:
GET("profiles/${getProfilePath()}/DataModel")
Expand Down

0 comments on commit 65046bc

Please sign in to comment.