Search in sources :

Example 16 with ActivityEntity

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

the class RoleTempleteBuilder method makeTable.

/**
     * This function is recursive function helps in making the tree table
     *
     * @param l
     *            List of all activities in the system
     * @param aid
     *            current activity id
     * @param buff
     *            StringBuffer which would hold the table
     * @param level
     *            level of recursion
     * @param name
     *            name to be given to control
     */
private void makeTable(List<ActivityEntity> l, Short aid, StringBuilder buff, int level, String name) {
    List<ActivityEntity> lst = childMap.get(aid);
    if (lst.size() > 0) {
        for (int i = 0; i < lst.size(); i++) {
            buff.append("<tr >");
            String name1 = name + "_" + Integer.toString(i);
            for (int j = 0; j < level; j++) {
                buff.append("<td bgcolor=\"#FFFFFF\" class=\"paddingleft05BottomBorder\">&nbsp; </td> ");
            }
            buff.append("<td width=\"3%\" bgcolor=\"#FFFFFF\" class=\"paddingleft05BottomBorder\"><input name=\"" + "activity(" + nameHelper++ + ")\"" + "  id=\"" + name1 + "\" type=\"checkbox\" ");
            // check whether it is leaf
            List<ActivityEntity> li = childMap.get(lst.get(i).getId());
            Short index = getIndex(lst.get(i).getId());
            if (li.size() == 0) {
                buff.append("value=\"" + lst.get(i).getId().shortValue() + "\"");
            } else {
                buff.append(" value=\"checkbox\"");
            }
            // check whether checked or not
            if (currentActivites.contains(lst.get(i).getId())) {
                buff.append("  checked=true ");
            } else if (checkedLinks.contains(lst.get(i).getId())) {
                buff.append("  checked=true ");
            }
            buff.append(" onclick=\"doCheck(this)\" ></td>");
            buff.append("<td colspan=\"");
            // adding colspan for proper formatting
            buff.append(maxDepth - level + "\"  ");
            buff.append("bgcolor=\"#FFFFFF\" class=\"paddingleft05BottomBorder\"  ><span class=\"fontnormal\">");
            ActivityEntity entity = l.get(index);
            String activityName = ApplicationContextProvider.getBean(MessageLookup.class).lookup(entity.getActivityNameLookupValues());
            entity.setActivityName(activityName);
            buff.append(l.get(index).getActivityName());
            buff.append("</span></td>");
            buff.append("<td width=\"50%\" bgcolor=\"#FFFFFF\" class=\"paddingleft05BottomLeftBorder\"  >" + "<span class=\"fontnormal\">");
            String description = ApplicationContextProvider.getBean(MessageLookup.class).lookup(entity.getActivityNameLookupValues());
            entity.setDescription(description);
            if (StringUtils.isBlank(entity.getDescription())) {
                buff.append(" &nbsp; ");
            } else {
                buff.append(entity.getDescription());
            }
            buff.append("</span></td></tr>");
            if (li.size() == 0) {
                makeActivityRestrictionRow(entity.getActivityRestrictionTypes(), buff);
            }
            makeTable(l, lst.get(i).getId(), buff, level + 1, name1);
        }
    }
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) MessageLookup(org.mifos.application.master.MessageLookup)

Example 17 with ActivityEntity

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

the class BirtReportsUploadActionStrutsTest method testShouldCreateFailureWhenActivityIdOutOfRange.

@Test
public void testShouldCreateFailureWhenActivityIdOutOfRange() throws Exception {
    ActivityEntity activityEntity = insertActivityForTest(Short.MIN_VALUE);
    FormFile file = new MockFormFile("testFilename");
    BirtReportsUploadActionForm actionForm = new BirtReportsUploadActionForm();
    setRequestPathInfo("/birtReportsUploadAction.do");
    addRequestParameter("method", "upload");
    actionForm.setFile(file);
    actionForm.setReportTitle("existingTitle");
    actionForm.setReportCategoryId("1");
    actionForm.setIsActive("1");
    setActionForm(actionForm);
    actionPerform();
    verifyForward("preview_failure");
    String[] errors = { ReportsConstants.ERROR_NOMOREDYNAMICACTIVITYID };
    verifyActionErrors(errors);
    deleteActivityForTest(activityEntity);
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) MockFormFile(org.mifos.reports.business.MockFormFile) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) FormFile(org.apache.struts.upload.FormFile) MockFormFile(org.mifos.reports.business.MockFormFile) Test(org.junit.Test)

Example 18 with ActivityEntity

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

the class BirtReportsUploadActionStrutsTest method testUpgradePathNotRuined.

@Test
public void testUpgradePathNotRuined() throws Exception {
    // TODO Temporary solution to avoid unsuccessful test on some machines
    // Retrieve initial activities information
    List<ActivityEntity> activities = new RolesPermissionsBusinessService().getActivities();
    int newActivityId = activities.get(activities.size() - 1).getId() + 1;
    // Upload a report creating an activity for the report
    FormFile file = new MockFormFile("testFilename.rptdesign");
    BirtReportsUploadActionForm actionForm = new BirtReportsUploadActionForm();
    setRequestPathInfo("/birtReportsUploadAction.do");
    addRequestParameter("method", "upload");
    actionForm.setFile(file);
    actionForm.setReportTitle("exsitTitle");
    actionForm.setReportCategoryId("1");
    actionForm.setIsActive("1");
    setActionForm(actionForm);
    actionPerform();
    Assert.assertEquals(0, getErrorSize());
    Assert.assertNotNull(request.getAttribute("report"));
    // Simulate an future activities upgrade
    AddActivity activity = null;
    try {
        activity = new AddActivity((short) newActivityId, SecurityConstants.ORGANIZATION_MANAGEMENT, "no name");
        activity.upgrade(StaticHibernateUtil.getSessionTL().connection());
    } catch (Exception e) {
        legacyRolesPermissionsDao.delete(request.getAttribute("report"));
        StaticHibernateUtil.flushSession();
        throw e;
    }
    // Undo
    ReportsBO report = (ReportsBO) request.getAttribute("report");
    removeReport(report.getReportId());
}
Also used : RolesPermissionsBusinessService(org.mifos.security.rolesandpermission.business.service.RolesPermissionsBusinessService) ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) MockFormFile(org.mifos.reports.business.MockFormFile) AddActivity(org.mifos.security.AddActivity) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) MifosRuntimeException(org.mifos.core.MifosRuntimeException) IOException(java.io.IOException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) FormFile(org.apache.struts.upload.FormFile) MockFormFile(org.mifos.reports.business.MockFormFile) ReportsBO(org.mifos.reports.business.ReportsBO) Test(org.junit.Test)

Example 19 with ActivityEntity

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

the class BirtReportsUploadActionStrutsTest method insertActivityForTest.

private ActivityEntity insertActivityForTest(short activityId) throws PersistenceException {
    LookUpValueEntity anLookUp = new LookUpValueEntity();
    LookUpEntity lookUpEntity = legacyMasterDao.getPersistentObject(LookUpEntity.class, Short.valueOf((short) LookUpEntity.ACTIVITY));
    anLookUp.setLookUpEntity(lookUpEntity);
    ActivityEntity parent = legacyMasterDao.getPersistentObject(ActivityEntity.class, (short) 13);
    ActivityEntity activityEntity = new ActivityEntity(activityId, parent, anLookUp);
    legacyRolesPermissionsDao.createOrUpdate(anLookUp);
    legacyRolesPermissionsDao.createOrUpdate(activityEntity);
    return activityEntity;
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) LookUpEntity(org.mifos.application.master.business.LookUpEntity) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity)

Example 20 with ActivityEntity

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

the class BirtReportsUploadActionStrutsTest method removeReport.

private void removeReport(Short reportId) throws PersistenceException {
    ReportsPersistence reportPersistence = new ReportsPersistence();
    reportPersistence.getSession().clear();
    ReportsBO report = reportPersistence.getPersistentObject(ReportsBO.class, reportId);
    ActivityEntity activityEntity = legacyRolesPermissionsDao.getPersistentObject(ActivityEntity.class, report.getActivityId());
    reportPersistence.delete(report);
    LookUpValueEntity anLookUp = activityEntity.getActivityNameLookupValues();
    legacyRolesPermissionsDao.delete(activityEntity);
    legacyRolesPermissionsDao.delete(anLookUp);
    StaticHibernateUtil.flushSession();
}
Also used : ActivityEntity(org.mifos.security.rolesandpermission.business.ActivityEntity) ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) ReportsBO(org.mifos.reports.business.ReportsBO) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity)

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