From 02958d756e2684ef4daee0846a879d8232438b1c Mon Sep 17 00:00:00 2001 From: GIP RECIA - Julien Gribonvald Date: Tue, 21 Sep 2021 17:42:17 +0200 Subject: [PATCH] refactor: improve load of all enums to app config --- .../publisher/web/rest/EnumsResource.java | 177 +++--------------- .../components/entities/enum/enum.service.js | 111 +++-------- 2 files changed, 54 insertions(+), 234 deletions(-) diff --git a/src/main/java/org/esupportail/publisher/web/rest/EnumsResource.java b/src/main/java/org/esupportail/publisher/web/rest/EnumsResource.java index b6ca0a3e0..a95922e40 100644 --- a/src/main/java/org/esupportail/publisher/web/rest/EnumsResource.java +++ b/src/main/java/org/esupportail/publisher/web/rest/EnumsResource.java @@ -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; @@ -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> getAllAccessType() { - return new ResponseEntity>(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> getAllContextType() { - return new ResponseEntity>(Arrays.asList(ContextType.values()), HttpStatus.OK); + @RequestMapping(value = "/all", + method = RequestMethod.GET, + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity>>> getAllEnums() { + Map>> 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>>>(enums, HttpStatus.OK); } - /** - * GET /classifdecorationtype -> get all the DecorationType. - */ - @RequestMapping(value = "/classifdecorationtype", - method = RequestMethod.GET, - produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity> getAllClassifDecorType() { - return new ResponseEntity>(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> getAllDisplayOrder() { - return new ResponseEntity>(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> getAllFilterType() { - return new ResponseEntity>(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> getAllItemStatus() { - return new ResponseEntity>(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> getAllItemType() { - return new ResponseEntity>(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> getAllOperatorType() { - return new ResponseEntity>(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> getAllPermissionClass() { - // to limit to managed way - // return new ResponseEntity>(Arrays.asList(PermissionClass.values()), HttpStatus.OK); - return new ResponseEntity>(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> getAllPermissionType() { - return new ResponseEntity>(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> getAllStringEvaluationMode() { - return new ResponseEntity>(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> getAllSubjectType() { - return new ResponseEntity>(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> getAllSubscribeType() { - return new ResponseEntity>(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> getAllWritingMode() { - return new ResponseEntity>(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> getAllWritingFormat() { - return new ResponseEntity>(Arrays.asList(WritingFormat.values()), HttpStatus.OK); - } - -} +} \ No newline at end of file diff --git a/src/main/webapp/scripts/components/entities/enum/enum.service.js b/src/main/webapp/scripts/components/entities/enum/enum.service.js index a5c441c0c..ef887aa6d 100644 --- a/src/main/webapp/scripts/components/entities/enum/enum.service.js +++ b/src/main/webapp/scripts/components/entities/enum/enum.service.js @@ -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"); }); }, @@ -155,4 +96,4 @@ angular.module('publisherApp') return WritingFormatList; } } - }); + }); \ No newline at end of file