@Test public void testSaveFailsWhenKeyChanged() { TestUtil.login("admin", ApplicationAccessControlConfig.PERMISSION_FIND_KEY_LIST, ApplicationAccessControlConfig.PERMISSION_SAVE_KEY_LIST); KeyListEto keyList = this.keymanagement.findKeyListByKey(KeyListCountryTestAspect.KEY_COUNTRY); KeyListCountryTestAspect.verifyCountry(keyList); keyList.setKey("modifiedKey"); try { this.keymanagement.saveKeyList(keyList); failBecauseExceptionWasNotThrown(KeyModificationException.class); } catch (KeyModificationException e) { assertThat(e.getMessage()).contains( "You can not change the business key of entity KeyListEntity[id=1,key=country] to modifiedKey! If you really need to change the business key, create a new entity and delete the old one."); } }
@Override @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_SAVE_KEY_LIST) public KeyListEto saveKeyList(KeyListEto keyList) { Objects.requireNonNull(keyList, "keyList"); KeyListEntity keyListEntity = getBeanMapper().map(keyList, KeyListEntity.class); KeyList entity = keyList; Long id = keyList.getId(); if (id != null) { KeyListEntity keyListFromDb = getKeyListRepository().find(id); verifyKeyNotModified(keyList, keyListFromDb); entity = keyListFromDb; } String permission = entity.getPermission(); if ((permission != null) && !permission.isEmpty()) { requireAnyPermission(permission, ApplicationAccessControlConfig.GROUP_ADMIN); } KeyListEntity resultEntity = getKeyListRepository().save(keyListEntity); LOG.debug("KeyList with id '{}' has been created.", resultEntity.getId()); return getBeanMapper().map(resultEntity, KeyListEto.class); }
UcManageKeyListImpl extends AbstractKeyListUc implements UcManageKeyList { @Override @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_SAVE_KEY_LIST) public KeyListEto saveKeyList(KeyListEto keyList) { Objects.requireNonNull(keyList, "keyList"); KeyListEntity keyListEntity = getBeanMapper().map(keyList, KeyListEntity.class); KeyList entity = keyList; Long id = keyList.getId(); if (id != null) { KeyListEntity keyListFromDb = getKeyListRepository().find(id); verifyKeyNotModified(keyList, keyListFromDb); entity = keyListFromDb; } String permission = entity.getPermission(); if ((permission != null) && !permission.isEmpty()) { requireAnyPermission(permission, ApplicationAccessControlConfig.GROUP_ADMIN); } KeyListEntity resultEntity = getKeyListRepository().save(keyListEntity); LOG.debug("KeyList with id '{}' has been created.", resultEntity.getId()); return getBeanMapper().map(resultEntity, KeyListEto.class); } }
UcManageKeyListImpl extends AbstractKeyListUc implements UcManageKeyList { @Override @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_SAVE_KEY_LIST) public KeyListEto saveKeyList(KeyListEto keyList) { Objects.requireNonNull(keyList, "keyList"); KeyListEntity keyListEntity = getBeanMapper().map(keyList, KeyListEntity.class); KeyList entity = keyList; Long id = keyList.getId(); if (id != null) { KeyListEntity keyListFromDb = getKeyListRepository().find(id); verifyKeyNotModified(keyList, keyListFromDb); entity = keyListFromDb; } String permission = entity.getPermission(); if ((permission != null) && !permission.isEmpty()) { requireAnyPermission(permission, ApplicationAccessControlConfig.GROUP_ADMIN); } KeyListEntity resultEntity = getKeyListRepository().save(keyListEntity); LOG.debug("KeyList with id '{}' has been created.", resultEntity.getId()); return getBeanMapper().map(resultEntity, KeyListEto.class); }  }
UcManageKeyListImpl extends AbstractKeyListUc implements UcManageKeyList { @Override @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_SAVE_KEY_LIST) public KeyListEto saveKeyList(KeyListEto keyList) { Objects.requireNonNull(keyList, "keyList"); KeyListEntity keyListEntity = getBeanMapper().map(keyList, KeyListEntity.class); KeyList entity = keyList; Long id = keyList.getId(); if (id != null) { KeyListEntity keyListFromDb = getKeyListRepository().find(id); verifyKeyNotModified(keyList, keyListFromDb); entity = keyListFromDb; } String permission = entity.getPermission(); if ((permission != null) && !permission.isEmpty()) { requireAnyPermission(permission, ApplicationAccessControlConfig.GROUP_ADMIN); } KeyListEntity resultEntity = getKeyListRepository().save(keyListEntity); LOG.debug("KeyList with id '{}' has been created.", resultEntity.getId()); return getBeanMapper().map(resultEntity, KeyListEto.class); }  @Override @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_DELETE_KEY_LIST) boolean deleteKeyList(IdRef<KeyList> id); @Override @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_SAVE_KEY_LIST) KeyListEto saveKeyList(KeyListEto keyList); }
UcManageKeyListImpl extends AbstractKeyListUc implements UcManageKeyList { @Override @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_SAVE_KEY_LIST) public KeyListEto saveKeyList(KeyListEto keyList) { Objects.requireNonNull(keyList, "keyList"); KeyListEntity keyListEntity = getBeanMapper().map(keyList, KeyListEntity.class); KeyList entity = keyList; Long id = keyList.getId(); if (id != null) { KeyListEntity keyListFromDb = getKeyListRepository().find(id); verifyKeyNotModified(keyList, keyListFromDb); entity = keyListFromDb; } String permission = entity.getPermission(); if ((permission != null) && !permission.isEmpty()) { requireAnyPermission(permission, ApplicationAccessControlConfig.GROUP_ADMIN); } KeyListEntity resultEntity = getKeyListRepository().save(keyListEntity); LOG.debug("KeyList with id '{}' has been created.", resultEntity.getId()); return getBeanMapper().map(resultEntity, KeyListEto.class); }  @Override @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_DELETE_KEY_LIST) boolean deleteKeyList(IdRef<KeyList> id); @Override @RolesAllowed(ApplicationAccessControlConfig.PERMISSION_SAVE_KEY_LIST) KeyListEto saveKeyList(KeyListEto keyList);  }