Source:
<code>protected void executeCommand() { T parameters = getParameters(); DbUser user = parameters.getUser(); if (user != null) { Guid id = user.getId(); String directory = user.getDomain(); String externalId = user.getExternalId(); DbUser existing = dbUserDao.getByIdOrExternalId(id, directory, externalId); if (existing != null) { user = existing; } else { user = addUser(user); if (user == null) { setSucceeded(false); return; } } } DbGroup group = parameters.getGroup(); if (group != null) { Guid id = group.getId(); String directory = group.getDomain(); String externalId = group.getExternalId(); DbGroup existing = dbGroupDao.getByIdOrExternalId(id, directory, externalId); if (existing != null) { group = existing; } else { group = addGroup(group); if (group == null) { setSucceeded(false); return; } } } Guid principalId; if (user != null) { principalId = user.getId(); } else if (group != null) { principalId = group.getId(); } else { principalId = parameters.getPermission().getAdElementId(); } final Permission paramPermission = parameters.getPermission(); Permission permission = permissionDao.getForRoleAndAdElementAndObject(paramPermission.getRoleId(), principalId, paramPermission.getObjectId()); if (permission == null) { paramPermission.setAdElementId(principalId); TransactionSupport.executeInNewTransaction(() -> { permissionDao.save(paramPermission); getCompensationContext().snapshotNewEntity(paramPermission); getCompensationContext().stateChanged(); return null; }); permission = paramPermission; } getReturnValue().setActionReturnValue(permission.getId()); if (user != null) { updateAdminStatus(permission); } <START> vmStaticDao.incrementDbGeneration(principalId); <END> setSucceeded(true); }</code><technical_language>principal ID is user ID object, increment for object ID if is of type VM</technical_language>

Target:
protected void executeCommand() { T parameters = getParameters(); DbUser user = parameters.getUser(); if (user != null) { Guid id = user.getId(); String directory = user.getDomain(); String externalId = user.getExternalId(); DbUser existing = dbUserDao.getByIdOrExternalId(id, directory, externalId); if (existing != null) { user = existing; } else { user = addUser(user); if (user == null) { setSucceeded(false); return; } } } DbGroup group = parameters.getGroup(); if (group != null) { Guid id = group.getId(); String directory = group.getDomain(); String externalId = group.getExternalId(); DbGroup existing = dbGroupDao.getByIdOrExternalId(id, directory, externalId); if (existing != null) { group = existing; } else { group = addGroup(group); if (group == null) { setSucceeded(false); return; } } } Guid principalId; if (user != null) { principalId = user.getId(); } else if (group != null) { principalId = group.getId(); } else { principalId = parameters.getPermission().getAdElementId(); } final Permission paramPermission = parameters.getPermission(); Permission permission = permissionDao.getForRoleAndAdElementAndObject(paramPermission.getRoleId(), principalId, paramPermission.getObjectId()); if (permission == null) { paramPermission.setAdElementId(principalId); TransactionSupport.executeInNewTransaction(() -> { permissionDao.save(paramPermission); getCompensationContext().snapshotNewEntity(paramPermission); getCompensationContext().stateChanged(); return null; }); permission = paramPermission; } getReturnValue().setActionReturnValue(permission.getId()); if (user != null) { updateAdminStatus(permission); } vmStaticDao.incrementDbGeneration(paramPermission.getObjectId()); setSucceeded(true); }