Source:
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(principalId); setSucceeded(true); }

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); }