Skip to content

Commit

Permalink
refactor: improve load of all enums to app config
Browse files Browse the repository at this point in the history
  • Loading branch information
jgribonvald committed Sep 21, 2021
1 parent 88bd502 commit 02958d7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 234 deletions.
177 changes: 28 additions & 149 deletions src/main/java/org/esupportail/publisher/web/rest/EnumsResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package org.esupportail.publisher.web.rest;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;
import org.esupportail.publisher.domain.enums.AccessType;
Expand Down Expand Up @@ -52,156 +54,33 @@ public class EnumsResource {

private final Logger log = LoggerFactory.getLogger(EnumsResource.class);

/**
* GET /access -> get all the AccessType.
*/
@RequestMapping(value = "/accesstype",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<AccessType>> getAllAccessType() {
return new ResponseEntity<List<AccessType>>(Arrays.asList(AccessType.values()), HttpStatus.OK);
protected enum enumList {
AccessType, ContextType, ClassificationDecorType, DisplayOrderType, FilterType, ItemStatus, ItemType, OperatorType, PermissionClass, PermissionType,
StringEvaluationMode, SubjectType, SubscribeType, WritingMode, WritingFormat
}

/**
* GET /access -> get all the AccessType.
*/
@RequestMapping(value = "/contexttype",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ContextType>> getAllContextType() {
return new ResponseEntity<List<ContextType>>(Arrays.asList(ContextType.values()), HttpStatus.OK);
@RequestMapping(value = "/all",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<enumList, List<? extends Enum<?>>>> getAllEnums() {
Map<enumList, List<? extends Enum<?>>> enums = new HashMap<>(15);
enums.put(enumList.AccessType, Arrays.asList(AccessType.values()));
enums.put(enumList.ContextType, Arrays.asList(DisplayOrderType.values()));
enums.put(enumList.ClassificationDecorType, Arrays.asList(ClassificationDecorType.values()));
enums.put(enumList.DisplayOrderType, Arrays.asList(DisplayOrderType.values()));
enums.put(enumList.FilterType, Arrays.asList(FilterType.values()));
enums.put(enumList.ItemStatus, Arrays.asList(ItemStatus.values()));
enums.put(enumList.ItemType, Arrays.asList(ItemType.values()));
enums.put(enumList.OperatorType, Arrays.asList(OperatorType.values()));
enums.put(enumList.PermissionClass, Lists.newArrayList(PermissionClass.CONTEXT, PermissionClass.CONTEXT_WITH_SUBJECTS));
enums.put(enumList.PermissionType, Arrays.asList(PermissionType.values()));
enums.put(enumList.StringEvaluationMode, Arrays.asList(StringEvaluationMode.values()));
enums.put(enumList.SubjectType, Arrays.asList(SubjectType.values()));
enums.put(enumList.SubscribeType, Arrays.asList(SubscribeType.values()));
enums.put(enumList.WritingMode, Arrays.asList(WritingMode.values()));
enums.put(enumList.WritingFormat, Arrays.asList(WritingFormat.values()));

return new ResponseEntity<Map<enumList, List<? extends Enum<?>>>>(enums, HttpStatus.OK);
}

/**
* GET /classifdecorationtype -> get all the DecorationType.
*/
@RequestMapping(value = "/classifdecorationtype",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ClassificationDecorType>> getAllClassifDecorType() {
return new ResponseEntity<List<ClassificationDecorType>>(Arrays.asList(ClassificationDecorType.values()), HttpStatus.OK);
}

/**
* GET /displayorder -> get all the DisplayOrderType.
*/
@RequestMapping(value = "/displayordertype",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<DisplayOrderType>> getAllDisplayOrder() {
return new ResponseEntity<List<DisplayOrderType>>(Arrays.asList(DisplayOrderType.values()), HttpStatus.OK);
}


/**
* GET /filter -> get all the FilterType.
*/
@RequestMapping(value = "/filtertype",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<FilterType>> getAllFilterType() {
return new ResponseEntity<List<FilterType>>(Arrays.asList(FilterType.values()), HttpStatus.OK);
}

/**
* GET /itemstatus -> get all the ItemStatus.
*/
@RequestMapping(value = "/itemstatus",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ItemStatus>> getAllItemStatus() {
return new ResponseEntity<List<ItemStatus>>(Arrays.asList(ItemStatus.values()), HttpStatus.OK);
}

/**
* GET /itemtype -> get all the ItemStatus.
*/
@RequestMapping(value = "/itemtype",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ItemType>> getAllItemType() {
return new ResponseEntity<List<ItemType>>(Arrays.asList(ItemType.values()), HttpStatus.OK);
}

/**
* GET /operator -> get all the OperatorType.
*/
@RequestMapping(value = "/operatortype",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<OperatorType>> getAllOperatorType() {
return new ResponseEntity<List<OperatorType>>(Arrays.asList(OperatorType.values()), HttpStatus.OK);
}

/**
* GET /permissionclass -> get all the PermissionClass.
*/
@RequestMapping(value = "/permissionclass",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<PermissionClass>> getAllPermissionClass() {
// to limit to managed way
// return new ResponseEntity<List<PermissionClass>>(Arrays.asList(PermissionClass.values()), HttpStatus.OK);
return new ResponseEntity<List<PermissionClass>>(Lists.newArrayList(PermissionClass.CONTEXT, PermissionClass.CONTEXT_WITH_SUBJECTS), HttpStatus.OK);
}

/**
* GET /permission -> get all the PermissionType.
*/
@RequestMapping(value = "/permissiontype",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<PermissionType>> getAllPermissionType() {
return new ResponseEntity<List<PermissionType>>(Arrays.asList(PermissionType.values()), HttpStatus.OK);
}

/**
* GET /stringevaluationmode -> get all the StringEvaluationMode.
*/
@RequestMapping(value = "/stringevaluationmode",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<StringEvaluationMode>> getAllStringEvaluationMode() {
return new ResponseEntity<List<StringEvaluationMode>>(Arrays.asList(StringEvaluationMode.values()), HttpStatus.OK);
}

/**
* GET /subject -> get all the SubjectType.
*/
@RequestMapping(value = "/subjecttype",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<SubjectType>> getAllSubjectType() {
return new ResponseEntity<List<SubjectType>>(Arrays.asList(SubjectType.values()), HttpStatus.OK);
}

/**
* GET /subscribe -> get all the SubscribeType.
*/
@RequestMapping(value = "/subscribetype",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<SubscribeType>> getAllSubscribeType() {
return new ResponseEntity<List<SubscribeType>>(Arrays.asList(SubscribeType.values()), HttpStatus.OK);
}

/**
* GET /writingmode -> get all the WritingMode.
*/
@RequestMapping(value = "/writingmode",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<WritingMode>> getAllWritingMode() {
return new ResponseEntity<List<WritingMode>>(Arrays.asList(WritingMode.values()), HttpStatus.OK);
}
/**
* GET /writingformat -> get all the WritingFormat.
*/
@RequestMapping(value = "/writingformat",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<WritingFormat>> getAllWritingFormat() {
return new ResponseEntity<List<WritingFormat>>(Arrays.asList(WritingFormat.values()), HttpStatus.OK);
}

}
}
111 changes: 26 additions & 85 deletions src/main/webapp/scripts/components/entities/enum/enum.service.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,37 @@
'use strict';

angular.module('publisherApp')
.factory('AccessType', function ($resource) {
return $resource('api/enums/accesstype/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('ClassificationDecorType', function ($resource) {
return $resource('api/enums/classifdecorationtype/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('ContextType', function ($resource) {
return $resource('api/enums/contexttype/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('DisplayOrderType', function ($resource) {
return $resource('api/enums/displayordertype/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('FilterType', function ($resource) {
return $resource('api/enums/filtertype/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('ItemStatus', function ($resource) {
return $resource('api/enums/itemstatus/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('ItemType', function ($resource) {
return $resource('api/enums/itemtype/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('OperatorType', function ($resource) {
return $resource('api/enums/operatortype/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('PermissionClass', function ($resource) {
return $resource('api/enums/permissionclass/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('PermissionType', function ($resource) {
return $resource('api/enums/permissiontype/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('StringEvaluationMode', function ($resource) {
return $resource('api/enums/stringevaluationmode/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('SubjectType', function ($resource) {
return $resource('api/enums/subjecttype/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('SubscribeType', function ($resource) {
return $resource('api/enums/subscribetype/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('WritingMode', function ($resource) {
return $resource('api/enums/writingmode/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('WritingFormat', function ($resource) {
return $resource('api/enums/writingformat/', {}, {
'query': { method: 'GET', isArray: true}
});
}).factory('EnumDatas', function($q, $state, AccessType, ClassificationDecorType, ContextType, DisplayOrderType, FilterType,
ItemStatus, ItemType, OperatorType, PermissionClass, PermissionType, StringEvaluationMode, SubjectType,
SubscribeType, WritingMode, WritingFormat) {
.factory('AllEnums', function ($resource) {
return $resource('api/enums/all/', {}, {
'query': { method: 'GET', isArray: false}
});
}).factory('EnumDatas', function($q, $state, AllEnums) {
var AccessTypeList,ClassificationDecorTypeList,ContextTypeList,DisplayOrderTypeList,FilterTypeList,ItemStatusList,ItemTypeList,OperatorTypeList,PermissionClassList,
PermissionTypeList, StringEvaluationModeList, SubjectTypeList, SubscribeTypeList, WritingModeList, WritingFormatList;
return {
init : function () {
return $q.all([AccessType.query().$promise, ContextType.query().$promise, DisplayOrderType.query().$promise,
FilterType.query().$promise, ItemStatus.query().$promise, ItemType.query().$promise, OperatorType.query().$promise,
PermissionClass.query().$promise, PermissionType.query().$promise, StringEvaluationMode.query().$promise,
SubjectType.query().$promise, SubscribeType.query().$promise, WritingMode.query().$promise, WritingFormat.query().$promise,
ClassificationDecorType.query().$promise])
return $q.all([AllEnums.query().$promise])
.then(function (results) {
AccessTypeList = results[0];
ContextTypeList = results[1];
DisplayOrderTypeList = results[2];
FilterTypeList = results[3];
ItemStatusList = results[4];
ItemTypeList = results[5];
OperatorTypeList = results[6];
PermissionClassList = results[7];
PermissionTypeList = results[8];
StringEvaluationModeList = results[9];
SubjectTypeList = results[10];
SubscribeTypeList = results[11];
WritingModeList = results[12];
WritingFormatList = results[13];
ClassificationDecorTypeList = results[14];
if (results) {
results = angular.fromJson(results[0]);
AccessTypeList = results.AccessType;
ContextTypeList = results.ContextType;
DisplayOrderTypeList = results.DisplayOrderType;
FilterTypeList = results.FilterType;
ItemStatusList = results.ItemStatus;
ItemTypeList = results.ItemType;
OperatorTypeList = results.OperatorType;
PermissionClassList = results.PermissionClass;
PermissionTypeList = results.PermissionType;
StringEvaluationModeList = results.StringEvaluationMode;
SubjectTypeList = results.SubjectType;
SubscribeTypeList = results.SubscribeType;
WritingModeList = results.WritingMode;
WritingFormatList = results.WritingFormat;
ClassificationDecorTypeList = results.ClassificationDecorType;
}
}).catch(function (error) {
//console.log(JSON.stringify(error));
console.log(JSON.stringify(error));
$state.go("error");
});
},
Expand Down Expand Up @@ -155,4 +96,4 @@ angular.module('publisherApp')
return WritingFormatList;
}
}
});
});

0 comments on commit 02958d7

Please sign in to comment.