Search in sources :

Example 36 with ActivityEntity

use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.

the class LegacyRolesPermissionsDao method isActivityAllowed.

public boolean isActivityAllowed(UserContext userContext, ActivityContext activityContext) {
    try {
        ActivityEntity activity = getActivityById(activityContext.getActivityId());
        if (activity == null) {
            return false;
        }
        Set<Short> activityAllowedRoles = activity.getRoleIds();
        if (activityAllowedRoles == null) {
            return false;
        }
        Set<Short> userRoles = userContext.getRoles();
        activityAllowedRoles.retainAll(userRoles);
        if (activityAllowedRoles.isEmpty()) {
            return false;
        }
        HierarchyManager.BranchLocation where = HierarchyManager.getInstance().compareOfficeInHierarchy(userContext, activityContext.getRecordOfficeId());
        return checkAccessByHierarchy(activityContext.getRecordLoanOfficer(), where, userContext.getLevel(), userContext.getId());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : HierarchyManager(org.mifos.security.authorization.HierarchyManager) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException) SystemException(org.mifos.framework.exceptions.SystemException) ActivityGeneratorException(org.mifos.security.activity.ActivityGeneratorException) ServiceException(org.mifos.framework.exceptions.ServiceException) SecurityException(org.mifos.framework.exceptions.SecurityException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) HibernateException(org.hibernate.HibernateException) ApplicationException(org.mifos.framework.exceptions.ApplicationException)

Example 37 with ActivityEntity

use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.

the class LegacyRolesPermissionsDao method getActivitieIds.

public List<Short> getActivitieIds() throws PersistenceException {
    try {
        Query query = getSession().getNamedQuery(NamedQueryConstants.GET_ALL_ACTIVITIES);
        List<ActivityEntity> activities = query.list();
        List<Short> activityIds = new ArrayList();
        for (ActivityEntity activity : activities) {
            activityIds.add(activity.getId());
        }
        return activityIds;
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) Query(org.hibernate.Query) ArrayList(java.util.ArrayList) PersistenceException(org.mifos.framework.exceptions.PersistenceException) SystemException(org.mifos.framework.exceptions.SystemException) ActivityGeneratorException(org.mifos.security.activity.ActivityGeneratorException) ServiceException(org.mifos.framework.exceptions.ServiceException) SecurityException(org.mifos.framework.exceptions.SecurityException) MifosRuntimeException(org.mifos.core.MifosRuntimeException) HibernateProcessException(org.mifos.framework.exceptions.HibernateProcessException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) HibernateException(org.hibernate.HibernateException) ApplicationException(org.mifos.framework.exceptions.ApplicationException)

Example 38 with ActivityEntity

use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.

the class LegacyRolesPermissionsDao method changeActivityMessage.

public void changeActivityMessage(short activityId, short localeId, String newMessage) throws PersistenceException {
    ActivityEntity activityEntity = getPersistentObject(ActivityEntity.class, Short.valueOf(activityId));
    Integer lookUpId = activityEntity.getActivityNameLookupValues().getLookUpId();
    LookUpValueLocaleEntity lookUpValueLocaleEntity = legacyMasterDao.retrieveOneLookUpValueLocaleEntity(localeId, lookUpId);
    lookUpValueLocaleEntity.setLookUpValue(newMessage);
    createOrUpdate(lookUpValueLocaleEntity);
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) LookUpValueLocaleEntity(org.mifos.application.master.business.LookUpValueLocaleEntity)

Example 39 with ActivityEntity

use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.

the class LegacyRolesPermissionsDao method createActivityForQuestionGroup.

public int createActivityForQuestionGroup(short parentActivity, String lookUpDescription) throws HibernateException, PersistenceException, ServiceException, ActivityGeneratorException {
    StaticHibernateUtil.startTransaction();
    int lookUpId = createLookUpValue(DynamicLookUpValueCreationTypes.QuestionGroup, lookUpDescription);
    insertLookUpValueLocale(lookUpId, lookUpDescription);
    ActivityEntity activityEntity = createActivityEntity(parentActivity, lookUpId);
    RoleBO role = getPersistentObject(RoleBO.class, RolesAndPermissionConstants.ADMIN_ROLE);
    role.getActivities().add(activityEntity);
    StaticHibernateUtil.commitTransaction();
    return lookUpId;
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) RoleBO(org.mifos.security.rolesandpermission.business.RoleBO)

Example 40 with ActivityEntity

use of org.mifos.security.rolesandpermission.business.ActivityEntity in project head by mifos.

the class LegacyRolesPermissionsDao method reparentActivityUsingHibernate.

public void reparentActivityUsingHibernate(short activityId, Short newParent) throws PersistenceException {
    ActivityEntity parent = getPersistentObject(ActivityEntity.class, newParent);
    ActivityEntity activity = getPersistentObject(ActivityEntity.class, activityId);
    activity.setParent(parent);
    createOrUpdate(activity);
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity)

Aggregations

ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)42 PersistenceException (org.mifos.framework.exceptions.PersistenceException)13 MifosRuntimeException (org.mifos.core.MifosRuntimeException)12 Test (org.junit.Test)10 LookUpValueEntity (org.mifos.application.master.business.LookUpValueEntity)9 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)9 ArrayList (java.util.ArrayList)8 UserContext (org.mifos.security.util.UserContext)8 HibernateException (org.hibernate.HibernateException)7 ActivityGeneratorException (org.mifos.security.activity.ActivityGeneratorException)7 ApplicationException (org.mifos.framework.exceptions.ApplicationException)6 ServiceException (org.mifos.framework.exceptions.ServiceException)6 RolesPermissionsBusinessService (org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService)6 HibernateProcessException (org.mifos.framework.exceptions.HibernateProcessException)5 SystemException (org.mifos.framework.exceptions.SystemException)5 IOException (java.io.IOException)4 MessageLookup (org.mifos.application.master.MessageLookup)4 SecurityException (org.mifos.framework.exceptions.SecurityException)4 List (java.util.List)3 UserContextFactory (org.mifos.accounts.servicefacade.UserContextFactory)3