Unable to save Policy remove action

Hi,

Jmix 2.0

Screen :

ResourceRoleModelListView override to  ExtResourceRoleModelListView
ResourceRoleModelDetailView override to ExtResourceRoleModelDetailView

I had override the resource role policy screen. When i try to remove any policy added for the roles , policy deleted-by and deleted-date is updated properly in SEC_RESOURCE_POLICY table but when i click on role on the workbench removed values are still present. Then i log out and again login values are not getting removed from the role list. If i stop the project and run again and check values are now removed from the list. I had tried with below code and if i modify my code and remove Transaction and use savecontext it doesnt work as it worked for above scenario and if i directly save in datamanager instead of savecontext it still doesnt work.


try{
    TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);

    Object processFlag = transactionTemplate.execute(new TransactionCallback<Object>() {
        @Override
        public Object doInTransaction(TransactionStatus status) {
            // Perform database operations within the transaction
            try{
                StringBuilder updateQuery = new StringBuilder();

                updateQuery.append("UPDATE SEC_RESOURCE_POLICY ");
                updateQuery.append("SET ");
                updateQuery.append("UPDATE_TS = ?, ");
                updateQuery.append("UPDATED_BY = ?, ");
                updateQuery.append("DELETE_TS = ?, ");
                updateQuery.append("DELETED_BY = ? ");
                updateQuery.append("WHERE ");
                updateQuery.append("ID = ? ");

                for(ResourceRoleCheckerMakerMapping makerMapping : creation.getResRoleCheckerMakerMapgId()){
                    if(makerMapping.getTableType()!=null && makerMapping.getTableType().equalsIgnoreCase(Constants.ResourceRole.SEC_RESOURCE_POLICY)){
                        if(makerMapping.getEditType()!=null && makerMapping.getEditType().equalsIgnoreCase(Constants.ResourceRole.REMOVE)){

                            List<Object> objectList = new ArrayList<Object>();

                            objectList.add(new Timestamp(System.currentTimeMillis()));
                            objectList.add(makerMapping.getCreatedBy());
                            objectList.add(new Timestamp(System.currentTimeMillis()));
                            objectList.add(makerMapping.getCreatedBy());
                            objectList.add(makerMapping.getResourceRoleId());

                            Object[] objectArr = objectList.toArray();
                            log.info("setPolicyEntityRemove :: update query :: " + updateQuery);
                            int updateCaseMappingCount =  jdbcTemplate.update(updateQuery.toString(),objectArr);
                            log.info("setPolicyEntityRemove:: update count :: " + updateCaseMappingCount);
                        }
                    }
                }
                return true;
            }
            catch (Exception e){
                status.setRollbackOnly();
                e.printStackTrace();
                log.info("Exception :::: " + e);
                return false;
            }
        }
    });

    log.info("setPolicyEntityRemove :: processFlag :: " + processFlag);

    if(processFlag instanceof Boolean && (boolean)processFlag){
        return Constants.SUCCESSFUL;
    }
    else{
        return Constants.RESPONSE_FAIL;
    }

}catch (Exception e){
    e.printStackTrace();
    log.info("Exception ::: " + e);
    return Constants.RESPONSE_FAIL;
}

I wouldn’t recommend you to override role management views. They have complicated logic and may be changed in the future version of the framework.

Better add your functionality in separate entities and views referring to roles.

Regards,
Konstantin

1 Like