@Test public void saveConfig() { List<Iterable<BConfiguration>> list = deleteAllServerConfig(); Map<String, Object> configs = new HashMap<>(); configs.put(keyUserRegistrationAllowed, false); configs.put(keyMultiEntityApp, true); try { configurationService.saveConfig(configs); BConfiguration cR = configurationRepository.findFirstByKey(keyUserRegistrationAllowed); assertNotNull(cR); assertEquals(Boolean.toString(false), cR.getValue()); cR = configurationRepository.findFirstByKey(keyMultiEntityApp); assertNotNull(cR); assertEquals(Boolean.toString(true), cR.getValue()); } catch (NotFoundEntityException e) { LOGGER.error(e.getLocalizedMessage()); fail("At least one of the keys was not found."); } catch (GmsGeneralException e) { LOGGER.error(e.getLocalizedMessage()); fail("The provided user key was not valid"); } assertTrue(hasRestoredAllServerConfig(list)); }
public void saveConfig(final Map<String, Object> configs) throws NotFoundEntityException, GmsGeneralException { if (configs.get("user") != null) { try { long id = Long.parseLong(configs.remove("user").toString()); saveConfig(configs, id); } catch (NumberFormatException e) { throw GmsGeneralException.builder() .messageI18N(CONFIG_USER_PARAM_NUMBER) .cause(e) .finishedOK(false) .httpStatus(HttpStatus.UNPROCESSABLE_ENTITY) .build(); } } String uppercaseKey; for (Map.Entry<String, Object> entry : configs.entrySet()) { uppercaseKey = entry.getKey().toUpperCase(Locale.ENGLISH); if (isValidKey(uppercaseKey) && uppercaseKey.endsWith(IN_SERVER)) { switch (ConfigKey.valueOf(uppercaseKey)) { case IS_MULTI_ENTITY_APP_IN_SERVER: setIsMultiEntity(Boolean.parseBoolean(entry.getValue().toString())); break; case IS_USER_REGISTRATION_ALLOWED_IN_SERVER: setUserRegistrationAllowed(Boolean.parseBoolean(entry.getValue().toString())); break; default: throw new NotFoundEntityException(CONFIG_NOT_FOUND); } } } }
ConfigurationService { public void saveConfig(final Map<String, Object> configs) throws NotFoundEntityException, GmsGeneralException { if (configs.get("user") != null) { try { long id = Long.parseLong(configs.remove("user").toString()); saveConfig(configs, id); } catch (NumberFormatException e) { throw GmsGeneralException.builder() .messageI18N(CONFIG_USER_PARAM_NUMBER) .cause(e) .finishedOK(false) .httpStatus(HttpStatus.UNPROCESSABLE_ENTITY) .build(); } } String uppercaseKey; for (Map.Entry<String, Object> entry : configs.entrySet()) { uppercaseKey = entry.getKey().toUpperCase(Locale.ENGLISH); if (isValidKey(uppercaseKey) && uppercaseKey.endsWith(IN_SERVER)) { switch (ConfigKey.valueOf(uppercaseKey)) { case IS_MULTI_ENTITY_APP_IN_SERVER: setIsMultiEntity(Boolean.parseBoolean(entry.getValue().toString())); break; case IS_USER_REGISTRATION_ALLOWED_IN_SERVER: setUserRegistrationAllowed(Boolean.parseBoolean(entry.getValue().toString())); break; default: throw new NotFoundEntityException(CONFIG_NOT_FOUND); } } } } }
ConfigurationService { public void saveConfig(final Map<String, Object> configs) throws NotFoundEntityException, GmsGeneralException { if (configs.get("user") != null) { try { long id = Long.parseLong(configs.remove("user").toString()); saveConfig(configs, id); } catch (NumberFormatException e) { throw GmsGeneralException.builder() .messageI18N(CONFIG_USER_PARAM_NUMBER) .cause(e) .finishedOK(false) .httpStatus(HttpStatus.UNPROCESSABLE_ENTITY) .build(); } } String uppercaseKey; for (Map.Entry<String, Object> entry : configs.entrySet()) { uppercaseKey = entry.getKey().toUpperCase(Locale.ENGLISH); if (isValidKey(uppercaseKey) && uppercaseKey.endsWith(IN_SERVER)) { switch (ConfigKey.valueOf(uppercaseKey)) { case IS_MULTI_ENTITY_APP_IN_SERVER: setIsMultiEntity(Boolean.parseBoolean(entry.getValue().toString())); break; case IS_USER_REGISTRATION_ALLOWED_IN_SERVER: setUserRegistrationAllowed(Boolean.parseBoolean(entry.getValue().toString())); break; default: throw new NotFoundEntityException(CONFIG_NOT_FOUND); } } } } @Autowired  ConfigurationService(final BConfigurationRepository configurationRepository,
                                final EUserRepository userRepository, final EOwnedEntityRepository entityRepository,
                                final BRoleRepository roleRepository, final BAuthorizationRepository authRepository,
                                final DefaultConst defaultConst); }
ConfigurationService { public void saveConfig(final Map<String, Object> configs) throws NotFoundEntityException, GmsGeneralException { if (configs.get("user") != null) { try { long id = Long.parseLong(configs.remove("user").toString()); saveConfig(configs, id); } catch (NumberFormatException e) { throw GmsGeneralException.builder() .messageI18N(CONFIG_USER_PARAM_NUMBER) .cause(e) .finishedOK(false) .httpStatus(HttpStatus.UNPROCESSABLE_ENTITY) .build(); } } String uppercaseKey; for (Map.Entry<String, Object> entry : configs.entrySet()) { uppercaseKey = entry.getKey().toUpperCase(Locale.ENGLISH); if (isValidKey(uppercaseKey) && uppercaseKey.endsWith(IN_SERVER)) { switch (ConfigKey.valueOf(uppercaseKey)) { case IS_MULTI_ENTITY_APP_IN_SERVER: setIsMultiEntity(Boolean.parseBoolean(entry.getValue().toString())); break; case IS_USER_REGISTRATION_ALLOWED_IN_SERVER: setUserRegistrationAllowed(Boolean.parseBoolean(entry.getValue().toString())); break; default: throw new NotFoundEntityException(CONFIG_NOT_FOUND); } } } } @Autowired  ConfigurationService(final BConfigurationRepository configurationRepository,
                                final EUserRepository userRepository, final EOwnedEntityRepository entityRepository,
                                final BRoleRepository roleRepository, final BAuthorizationRepository authRepository,
                                final DefaultConst defaultConst); boolean isApplicationConfigured(); boolean isDefaultConfigurationCreated(); boolean isDefaultUserAssignedToEntityWithRole(); Map<String, String> getConfig(); Object getConfig(final String key); String getConfig(final String key, final long userId); Map<String, Object> getConfigByUser(final long userId); void saveConfig(final Map<String, Object> configs); void saveConfig(final Map<String, Object> configs, final long userId); void setUserRegistrationAllowed(final boolean userRegistrationAllowed); void setIsMultiEntity(final boolean isMultiEntity); Long getLastAccessedEntityIdByUser(final long userId); void setLastAccessedEntityIdByUser(final long userId, final long entityId); }
ConfigurationService { public void saveConfig(final Map<String, Object> configs) throws NotFoundEntityException, GmsGeneralException { if (configs.get("user") != null) { try { long id = Long.parseLong(configs.remove("user").toString()); saveConfig(configs, id); } catch (NumberFormatException e) { throw GmsGeneralException.builder() .messageI18N(CONFIG_USER_PARAM_NUMBER) .cause(e) .finishedOK(false) .httpStatus(HttpStatus.UNPROCESSABLE_ENTITY) .build(); } } String uppercaseKey; for (Map.Entry<String, Object> entry : configs.entrySet()) { uppercaseKey = entry.getKey().toUpperCase(Locale.ENGLISH); if (isValidKey(uppercaseKey) && uppercaseKey.endsWith(IN_SERVER)) { switch (ConfigKey.valueOf(uppercaseKey)) { case IS_MULTI_ENTITY_APP_IN_SERVER: setIsMultiEntity(Boolean.parseBoolean(entry.getValue().toString())); break; case IS_USER_REGISTRATION_ALLOWED_IN_SERVER: setUserRegistrationAllowed(Boolean.parseBoolean(entry.getValue().toString())); break; default: throw new NotFoundEntityException(CONFIG_NOT_FOUND); } } } } @Autowired  ConfigurationService(final BConfigurationRepository configurationRepository,
                                final EUserRepository userRepository, final EOwnedEntityRepository entityRepository,
                                final BRoleRepository roleRepository, final BAuthorizationRepository authRepository,
                                final DefaultConst defaultConst); boolean isApplicationConfigured(); boolean isDefaultConfigurationCreated(); boolean isDefaultUserAssignedToEntityWithRole(); Map<String, String> getConfig(); Object getConfig(final String key); String getConfig(final String key, final long userId); Map<String, Object> getConfigByUser(final long userId); void saveConfig(final Map<String, Object> configs); void saveConfig(final Map<String, Object> configs, final long userId); void setUserRegistrationAllowed(final boolean userRegistrationAllowed); void setIsMultiEntity(final boolean isMultiEntity); Long getLastAccessedEntityIdByUser(final long userId); void setLastAccessedEntityIdByUser(final long userId, final long entityId); static final String IN_SERVER; static final String CONFIG_NOT_FOUND; }