Skip to content

Commit

Permalink
variable changes
Browse files Browse the repository at this point in the history
  • Loading branch information
orubel committed Aug 15, 2017
1 parent 247b3a4 commit 8be6a3a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ abstract class ApiCommLayer extends ApiCommProcess{
String authority = getUserRole() as String
response.setHeader('Authorization', roles.join(', '))
ArrayList responseList = []
ArrayList<HashMap> temp = new ArrayList()
ArrayList<LinkedHashMap> temp = new ArrayList()
if(requestDefinitions["${authority}".toString()]) {
ArrayList<HashMap> temp1 = requestDefinitions["${authority}".toString()] as ArrayList<HashMap>
ArrayList<LinkedHashMap> temp1 = requestDefinitions["${authority}".toString()] as ArrayList<LinkedHashMap>
temp.addAll(temp1)
}else{
ArrayList<HashMap> temp2 = requestDefinitions['permitAll'] as ArrayList<HashMap>
ArrayList<LinkedHashMap> temp2 = requestDefinitions['permitAll'] as ArrayList<LinkedHashMap>
temp.addAll(temp2)
}

Expand Down Expand Up @@ -145,7 +145,7 @@ abstract class ApiCommLayer extends ApiCommProcess{
String authority = getUserRole() as String
response.setHeader('Authorization', roles.join(', '))

ArrayList<HashMap> temp = (requestDefinitions["${authority}"])?requestDefinitions["${authority}"] as ArrayList<HashMap>:requestDefinitions['permitAll'] as ArrayList<HashMap>
ArrayList<LinkedHashMap> temp = (requestDefinitions["${authority}"])?requestDefinitions["${authority}"] as ArrayList<LinkedHashMap>:requestDefinitions['permitAll'] as ArrayList<LinkedHashMap>
ArrayList responseList = (ArrayList)temp.collect(){ it.name }

LinkedHashMap result = parseURIDefinitions(model,responseList)
Expand All @@ -172,7 +172,7 @@ abstract class ApiCommLayer extends ApiCommProcess{
String authority = getUserRole() as String
response.setHeader('Authorization', roles.join(', '))

ArrayList<HashMap> temp = (requestDefinitions["${authority}"])?requestDefinitions["${authority}"] as ArrayList<HashMap>:requestDefinitions['permitAll'] as ArrayList<HashMap>
ArrayList<LinkedHashMap> temp = (requestDefinitions["${authority}"])?requestDefinitions["${authority}"] as ArrayList<LinkedHashMap>:requestDefinitions['permitAll'] as ArrayList<LinkedHashMap>

ArrayList responseList = (ArrayList)temp.collect(){ it.name }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ abstract class ApiCommProcess{
boolean hasAuth = false
if (springSecurityService.loggedIn) {
def principal = springSecurityService.principal
HashSet userRoles = principal.authorities*.authority as HashSet
ArrayList userRoles = principal.authorities*.authority as ArrayList
roles.each {
if (userRoles.contains(it) || it=='permitAll') {
hasAuth = true
Expand Down Expand Up @@ -143,14 +143,14 @@ abstract class ApiCommProcess{

// TODO: put in OPTIONAL toggle in application.yml to allow for this check
boolean checkURIDefinitions(GrailsParameterMap params,LinkedHashMap requestDefinitions){
HashSet reservedNames = ['batchLength','batchInc','chainInc','apiChain','_','max','offset']
ArrayList reservedNames = ['batchLength','batchInc','chainInc','apiChain','_','max','offset']
try{
String authority = getUserRole() as String
HashSet temp = (requestDefinitions["${authority}"])?requestDefinitions["${authority}"] as HashSet:(requestDefinitions['permitAll'][0]!=null)? requestDefinitions['permitAll'] as HashSet:[]
HashSet requestList = (temp!=null)?temp.collect(){ it.name }:[]
ArrayList temp = (requestDefinitions["${authority}"])?requestDefinitions["${authority}"] as ArrayList:(requestDefinitions['permitAll'][0]!=null)? requestDefinitions['permitAll'] as ArrayList:[]
ArrayList requestList = (temp!=null)?temp.collect(){ it.name }:[]

Map methodParams = getMethodParams(params)
HashSet paramsList = methodParams.keySet() as HashSet
LinkedHashMap methodParams = getMethodParams(params)
ArrayList paramsList = methodParams.keySet() as ArrayList

// remove reservedNames from List
reservedNames.each(){ paramsList.remove(it) }
Expand Down Expand Up @@ -231,7 +231,7 @@ abstract class ApiCommProcess{
//List paramsList
//Integer msize = model.size()
//List paramsList = (model.size()==0)?[:]:model.keySet() as List
HashSet paramsList = (model.size()==0)?[:]:model.keySet() as HashSet
ArrayList paramsList = (model.size()==0)?[:]:model.keySet() as ArrayList
paramsList?.removeAll(optionalParams)

if (!responseList.containsAll(paramsList)) {
Expand Down Expand Up @@ -278,9 +278,9 @@ abstract class ApiCommProcess{
*/

// used locally
Map getMethodParams(GrailsParameterMap params){
LinkedHashMap getMethodParams(GrailsParameterMap params){
try{
Map paramsRequest = [:]
LinkedHashMap paramsRequest = [:]
paramsRequest = params.findAll { it2 -> !optionalParams.contains(it2.key) }
return paramsRequest
}catch(Exception e){
Expand All @@ -290,7 +290,7 @@ abstract class ApiCommProcess{
}

// used locally
Boolean hasRoles(HashSet set) {
Boolean hasRoles(ArrayList set) {
if(springSecurityService.principal.authorities*.authority.any { set.contains(it) }){
return true
}
Expand Down Expand Up @@ -576,7 +576,7 @@ abstract class ApiCommProcess{
LinkedHashMap throttle = Holders.grailsApplication.config.apitoolkit.throttle as LinkedHashMap
LinkedHashMap rateLimit = throttle.rateLimit as LinkedHashMap
LinkedHashMap dataLimit = throttle.dataLimit as LinkedHashMap
HashSet roles = rateLimit.keySet() as HashSet
ArrayList roles = rateLimit.keySet() as ArrayList
String auth = getUserRole()

if(roles.contains(auth)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ApiFrameworkInterceptor extends ApiCommLayer{
RequestMethod mthd
LinkedHashMap cache = [:]


ApiFrameworkInterceptor(){
match(uri:"/${entryPoint}/**")
}
Expand Down Expand Up @@ -101,7 +102,6 @@ class ApiFrameworkInterceptor extends ApiCommLayer{
def session = request.getSession()
cache = session['cache'] as LinkedHashMap


// IS APIDOC??
if(params.controller=='apidoc'){
if(cache){
Expand Down Expand Up @@ -249,12 +249,13 @@ class ApiFrameworkInterceptor extends ApiCommLayer{
ApiDescriptor cachedEndpoint = cache[params.apiObject][(String) params.action] as ApiDescriptor

// TEST FOR NESTED MAP; WE DON'T CACHE NESTED MAPS
boolean isNested = false
//boolean isNested = false
if (newModel != [:]) {
Object key = newModel?.keySet()?.iterator()?.next()
if (newModel[key].getClass().getName() == 'java.util.LinkedHashMap') {
isNested = true
}

//Object key = newModel?.keySet()?.iterator()?.next()
//if (newModel[key].getClass().getName() == 'java.util.LinkedHashMap') {
// isNested = true
//}

String content = handleApiResponse(cachedEndpoint['returns'] as LinkedHashMap, cachedEndpoint['roles'] as List, mthd, format, response, newModel, params)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ class ApiCacheService{
}
}

Map generateApiDoc(String controllername, String actionname, String apiversion){
LinkedHashMap generateApiDoc(String controllername, String actionname, String apiversion){
try{
Map doc = [:]
LinkedHashMap doc = [:]
def cache = getApiCache(controllername)

String apiPrefix = "v${Metadata.current.getApplicationVersion()}"
Expand Down

0 comments on commit 8be6a3a

Please sign in to comment.