Search in sources :

Example 1 with UserGroup

use of org.cerberus.crud.entity.UserGroup in project cerberus-source by cerberustesting.

the class UpdateUser method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, IndexOutOfBoundsException {
    // TODO create class Validator to validate all parameter from page
    JSONObject jsonResponse = new JSONObject();
    MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
    Answer ans = new Answer();
    Answer finalAnswer = new Answer(msg1);
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);
    String id = request.getParameter("id");
    String login = request.getParameter("login");
    String name = request.getParameter("name");
    String email = request.getParameter("email");
    String team = request.getParameter("team");
    String systems = request.getParameter("systems");
    String requests = request.getParameter("request");
    String groups = request.getParameter("groups");
    String defaultSystem = request.getParameter("defaultSystem");
    if (StringUtil.isNullOrEmpty(login) || StringUtil.isNullOrEmpty(id)) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", "User").replace("%OPERATION%", "Update").replace("%REASON%", "User login is missing."));
        ans.setResultMessage(msg);
    } else {
        LOG.info("Updating user " + login);
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        IUserService userService = appContext.getBean(UserService.class);
        IUserGroupService userGroupService = appContext.getBean(UserGroupService.class);
        IFactoryUserSystem userSystemFactory = appContext.getBean(IFactoryUserSystem.class);
        IUserSystemService userSystemService = appContext.getBean(IUserSystemService.class);
        IFactoryUserGroup factoryGroup = new FactoryUserGroup();
        User myUser;
        List<UserGroup> newGroups = null;
        List<UserSystem> newSystems = null;
        try {
            myUser = userService.findUserByKey(id);
            List<String> listGroup = new ArrayList<String>();
            JSONArray GroupArray = new JSONArray(request.getParameter("groups"));
            for (int i = 0; i < GroupArray.length(); i++) {
                listGroup.add(GroupArray.getString(i));
            }
            newGroups = new ArrayList<UserGroup>();
            for (String group : listGroup) {
                newGroups.add(factoryGroup.create(group));
            }
            myUser.setLogin(login);
            myUser.setName(name);
            myUser.setTeam(team);
            newSystems = new ArrayList<UserSystem>();
            JSONArray SystemArray = new JSONArray(request.getParameter("systems"));
            List<String> listSystem = new ArrayList<String>();
            for (int i = 0; i < SystemArray.length(); i++) {
                listSystem.add(SystemArray.getString(i));
            }
            for (String system : listSystem) {
                newSystems.add(userSystemFactory.create(login, system));
            }
            myUser.setDefaultSystem(defaultSystem);
            myUser.setRequest(requests);
            myUser.setEmail(email);
            try {
                ans = userService.update(myUser);
                AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                    /**
                     * Update was successful. Adding Log entry.
                     */
                    ILogEventService logEventService = appContext.getBean(LogEventService.class);
                    logEventService.createForPrivateCalls("/UpdateUser", "UPDATE", "Updated user : " + login, request);
                    if (!newGroups.isEmpty()) {
                        userGroupService.updateUserGroups(myUser, newGroups);
                        /**
                         * Adding Log entry.
                         */
                        logEventService = appContext.getBean(LogEventService.class);
                        logEventService.createForPrivateCalls("/UpdateUser", "UPDATE", "Updated user groups : " + login, request);
                    }
                    if (!newSystems.isEmpty()) {
                        request.getSession().setAttribute("MySystem", newSystems.get(0).getSystem());
                        userSystemService.updateUserSystems(myUser, newSystems);
                        /**
                         * Adding Log entry.
                         */
                        logEventService = appContext.getBean(LogEventService.class);
                        logEventService.createForPrivateCalls("/UpdateUser", "UPDATE", "Updated user system : " + login, request);
                    }
                }
                /**
                 * Adding Log entry.
                 */
                finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());
                jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());
                response.getWriter().print(jsonResponse);
            } catch (CerberusException ex) {
                response.getWriter().print(ex.getMessageError().getDescription());
            }
        } catch (CerberusException ex) {
            response.getWriter().print(ex.getMessageError().getDescription());
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : User(org.cerberus.crud.entity.User) UserSystem(org.cerberus.crud.entity.UserSystem) IFactoryUserSystem(org.cerberus.crud.factory.IFactoryUserSystem) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) ILogEventService(org.cerberus.crud.service.ILogEventService) LogEventService(org.cerberus.crud.service.impl.LogEventService) IUserGroupService(org.cerberus.crud.service.IUserGroupService) FactoryUserGroup(org.cerberus.crud.factory.impl.FactoryUserGroup) IFactoryUserGroup(org.cerberus.crud.factory.IFactoryUserGroup) UserGroup(org.cerberus.crud.entity.UserGroup) ApplicationContext(org.springframework.context.ApplicationContext) IFactoryUserSystem(org.cerberus.crud.factory.IFactoryUserSystem) ILogEventService(org.cerberus.crud.service.ILogEventService) IUserSystemService(org.cerberus.crud.service.IUserSystemService) CerberusException(org.cerberus.exception.CerberusException) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) FactoryUserGroup(org.cerberus.crud.factory.impl.FactoryUserGroup) IFactoryUserGroup(org.cerberus.crud.factory.IFactoryUserGroup) Answer(org.cerberus.util.answer.Answer) JSONObject(org.json.JSONObject) IUserService(org.cerberus.crud.service.IUserService) IFactoryUserGroup(org.cerberus.crud.factory.IFactoryUserGroup)

Example 2 with UserGroup

use of org.cerberus.crud.entity.UserGroup in project cerberus-source by cerberustesting.

the class ReadUser method findUserList.

// </editor-fold>
private AnswerItem findUserList(ApplicationContext appContext, HttpServletRequest request, HttpServletResponse response) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject jsonResponse = new JSONObject();
    userService = appContext.getBean(UserService.class);
    int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
    int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
    /*int sEcho  = Integer.valueOf(request.getParameter("sEcho"));*/
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "1"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "userID,login,name");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));
    Map<String, List<String>> individualSearch = new HashMap<>();
    for (int a = 0; a < columnToSort.length; a++) {
        if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {
            List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));
            if (individualLike.contains(columnToSort[a])) {
                individualSearch.put(columnToSort[a] + ":like", search);
            } else {
                individualSearch.put(columnToSort[a], search);
            }
        }
    }
    AnswerList resp = userService.readByCriteria(startPosition, length, columnName, sort, searchParameter, individualSearch);
    JSONArray jsonArray = new JSONArray();
    boolean userHasPermissions = request.isUserInRole("IntegratorRO");
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (User user : (List<User>) resp.getDataList()) {
            JSONObject res = convertUserToJSONObject(user);
            if (request.getParameter("systems") != null) {
                IUserSystemService userSystemService = appContext.getBean(IUserSystemService.class);
                AnswerList a = userSystemService.readByUser(user.getLogin());
                if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && a.getDataList() != null) {
                    JSONArray JSONsystems = new JSONArray();
                    List<UserSystem> systems = a.getDataList();
                    for (UserSystem u : systems) {
                        JSONsystems.put(convertUserSystemToJSONObject(u));
                    }
                    res.put("systems", JSONsystems);
                }
            }
            if (request.getParameter("groups") != null) {
                IUserGroupService userGroupService = appContext.getBean(UserGroupService.class);
                AnswerList a = userGroupService.readByUser(user.getLogin());
                if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && a.getDataList() != null) {
                    JSONArray JSONgroups = new JSONArray();
                    List<UserGroup> groups = a.getDataList();
                    for (UserGroup u : groups) {
                        JSONgroups.put(convertUserGroupToJSONObject(u));
                    }
                    res.put("groups", JSONgroups);
                }
            }
            jsonArray.put(res);
        }
    }
    jsonResponse.put("hasPermissions", userHasPermissions);
    jsonResponse.put("contentTable", jsonArray);
    jsonResponse.put("iTotalRecords", resp.getTotalRows());
    jsonResponse.put("iTotalDisplayRecords", resp.getTotalRows());
    item.setItem(jsonResponse);
    item.setResultMessage(resp.getResultMessage());
    return item;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) User(org.cerberus.crud.entity.User) UserSystem(org.cerberus.crud.entity.UserSystem) IUserService(org.cerberus.crud.service.IUserService) UserService(org.cerberus.crud.service.impl.UserService) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) IUserGroupService(org.cerberus.crud.service.IUserGroupService) UserGroup(org.cerberus.crud.entity.UserGroup) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) IUserSystemService(org.cerberus.crud.service.IUserSystemService)

Example 3 with UserGroup

use of org.cerberus.crud.entity.UserGroup in project cerberus-source by cerberustesting.

the class UserGroupService method updateGroupsByUser.

@Override
public Answer updateGroupsByUser(User user, List<UserGroup> newGroups) {
    Answer a = new Answer(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "UPDATE"));
    AnswerList an = this.readByUser(user.getLogin());
    if (an.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        List<UserGroup> oldGroups = an.getDataList();
        // delete if don't exist in new
        for (UserGroup old : oldGroups) {
            if (!newGroups.contains(old)) {
                Answer del = userGroupDAO.remove(old);
                if (!del.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                    a = del;
                }
            }
        }
        // insert if don't exist in old
        for (UserGroup group : newGroups) {
            if (!oldGroups.contains(group)) {
                Answer add = userGroupDAO.create(group);
                if (!add.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                    a = add;
                }
            }
        }
    }
    return a;
}
Also used : Answer(org.cerberus.util.answer.Answer) AnswerList(org.cerberus.util.answer.AnswerList) MessageEvent(org.cerberus.engine.entity.MessageEvent) UserGroup(org.cerberus.crud.entity.UserGroup)

Example 4 with UserGroup

use of org.cerberus.crud.entity.UserGroup in project cerberus-source by cerberustesting.

the class UpdateTestCaseWithDependencies method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 * @throws org.cerberus.exception.CerberusException
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException {
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    String initialTest = request.getParameter("informationInitialTest");
    String initialTestCase = request.getParameter("informationInitialTestCase");
    String test = request.getParameter("informationTest");
    String testCase = request.getParameter("informationTestCase");
    TestCase tc = getTestCaseFromParameter(request, appContext, test, testCase);
    boolean duplicate = false;
    ITestService tService = appContext.getBean(ITestService.class);
    ITestCaseService tcService = appContext.getBean(ITestCaseService.class);
    ITestCaseCountryService tccService = appContext.getBean(ITestCaseCountryService.class);
    ITestCaseCountryPropertiesService tccpService = appContext.getBean(ITestCaseCountryPropertiesService.class);
    ITestCaseStepService tcsService = appContext.getBean(ITestCaseStepService.class);
    ITestCaseStepActionService tcsaService = appContext.getBean(ITestCaseStepActionService.class);
    ITestCaseStepActionControlService tcsacService = appContext.getBean(ITestCaseStepActionControlService.class);
    IInvariantService invariantService = appContext.getBean(IInvariantService.class);
    IUserService userService = appContext.getBean(IUserService.class);
    IUserGroupService userGroupService = appContext.getBean(IUserGroupService.class);
    /**
     * Get User and Groups of this user
     */
    User user = userService.findUserByKey(request.getUserPrincipal().getName());
    // List<UserGroup> userGroupList = groupService.findGroupByUser(user);
    List<UserGroup> userGroupList = userGroupService.convert(userGroupService.readByUser(user.getLogin()));
    List<String> groupList = new ArrayList();
    for (UserGroup group : userGroupList) {
        groupList.add(group.getGroup());
    }
    /**
     * Verify the Test is the same than initialTest If it is the same > Do
     * nothing If it is not the same > Verify if test already exists If not
     * exist > create it If exist > do nothing
     */
    if (!tc.getTest().equals(initialTest)) {
        if (tService.findTestByKey(tc.getTest()) == null) {
            if (groupList.contains("TestAdmin")) {
                Test newTest = tService.findTestByKey(initialTest);
                newTest.setTest(tc.getTest());
                tService.convert(tService.create(newTest));
            } else {
                response.sendError(403, MessageGeneralEnum.GUI_TEST_CREATION_NOT_HAVE_RIGHT.getDescription());
                return;
            }
        }
    }
    if (!tc.getTest().equals(initialTest) || !tc.getTestCase().equals(initialTestCase)) {
        duplicate = true;
    }
    /**
     * If the testcase is a duplication, set the creator as the one which
     * duplicate the testcase and the status in the initial one.
     */
    if (duplicate) {
        tc.setUsrCreated(user.getLogin());
        // TODO: handle if the response does not turn ok
        AnswerList answer = invariantService.readByIdname("TCSTATUS");
        tc.setStatus(((List<Invariant>) answer.getDataList()).get(0).getValue());
    }
    /**
     * If not duplicate and test in Working status and user with no admin
     * right, raise an error
     */
    if (!duplicate && "WORKING".equals(tc.getStatus()) && !groupList.contains("TestAdmin")) {
        response.sendError(403, MessageGeneralEnum.GUI_TESTCASE_NON_ADMIN_SAVE_WORKING_TESTCASE.getDescription());
        return;
    }
    /**
     * Verify testcase is the same than initialTestCase If it is the same >
     * update If it is not the same, > verify if testcase already exist If
     * it already exist > Send Error If it do not already exists > Create it
     */
    if (!duplicate) {
        tcService.updateTestCase(tc);
    } else if (tcService.findTestCaseByKey(tc.getTest(), tc.getTestCase()) != null) {
        response.sendError(403, MessageGeneralEnum.GUI_TESTCASE_DUPLICATION_ALREADY_EXISTS.getDescription());
        return;
    } else {
        tcService.createTestCase(tc);
    }
    /**
     * For the list of testcase country verify it exists. If it does not
     * exists > create it If it exist, verify if it's the
     */
    List<TestCaseCountry> tccFromPage = getTestCaseCountryFromParameter(request, appContext, test, testCase);
    List<TestCaseCountry> tccFromDtb = tccService.findTestCaseCountryByTestTestCase(initialTest, initialTestCase);
    /**
     * Iterate on (TestCaseCountry From Page - TestCaseCountry From
     * Database) If TestCaseCountry in Database has same key : Update and
     * remove from the list. If TestCaseCountry in database does ot exist :
     * Insert it.
     */
    List<TestCaseCountry> tccToUpdateOrInsert = new ArrayList(tccFromPage);
    tccToUpdateOrInsert.removeAll(tccFromDtb);
    List<TestCaseCountry> tccToUpdateOrInsertToIterate = new ArrayList(tccToUpdateOrInsert);
    for (TestCaseCountry tccDifference : tccToUpdateOrInsertToIterate) {
        for (TestCaseCountry tccInDatabase : tccFromDtb) {
            if (tccDifference.hasSameKey(tccInDatabase)) {
                tccToUpdateOrInsert.remove(tccDifference);
            }
        }
    }
    tccService.insertListTestCaseCountry(tccToUpdateOrInsert);
    /**
     * Iterate on (TestCaseCountry From Database - TestCaseCountry From
     * Page). If TestCaseCountry in Page has same key : remove from the
     * list. Then delete the list of TestCaseCountry
     */
    if (!duplicate) {
        List<TestCaseCountry> tccToDelete = new ArrayList(tccFromDtb);
        tccToDelete.removeAll(tccFromPage);
        List<TestCaseCountry> tccToDeleteToIterate = new ArrayList(tccToDelete);
        for (TestCaseCountry tccDifference : tccToDeleteToIterate) {
            for (TestCaseCountry tccInPage : tccFromPage) {
                if (tccDifference.hasSameKey(tccInPage)) {
                    tccToDelete.remove(tccDifference);
                }
            }
        }
        tccService.deleteListTestCaseCountry(tccToDelete);
    }
    /**
     * For the list of testcase country verify it exists. If it does not
     * exists > create it If it exist, verify if it's the
     */
    List<TestCaseCountryProperties> tccpFromPage = getTestCaseCountryPropertiesFromParameter(request, appContext, test, testCase);
    List<TestCaseCountryProperties> tccpFromDtb = tccpService.findListOfPropertyPerTestTestCase(initialTest, initialTestCase);
    /**
     * Iterate on (TestCaseCountryProperties From Page -
     * TestCaseCountryProperties From Database) If TestCaseCountryProperties
     * in Database has same key : Update and remove from the list. If
     * TestCaseCountryProperties in database does ot exist : Insert it.
     */
    List<TestCaseCountryProperties> tccpToUpdateOrInsert = new ArrayList(tccpFromPage);
    tccpToUpdateOrInsert.removeAll(tccpFromDtb);
    List<TestCaseCountryProperties> tccpToUpdateOrInsertToIterate = new ArrayList(tccpToUpdateOrInsert);
    for (TestCaseCountryProperties tccpDifference : tccpToUpdateOrInsertToIterate) {
        for (TestCaseCountryProperties tccpInDatabase : tccpFromDtb) {
            if (tccpDifference.hasSameKey(tccpInDatabase)) {
                tccpService.updateTestCaseCountryProperties(tccpDifference);
                tccpToUpdateOrInsert.remove(tccpDifference);
            }
        }
    }
    tccpService.insertListTestCaseCountryProperties(tccpToUpdateOrInsert);
    /**
     * Iterate on (TestCaseCountryProperties From Database -
     * TestCaseCountryProperties From Page). If TestCaseCountryProperties in
     * Page has same key : remove from the list. Then delete the list of
     * TestCaseCountryProperties
     */
    if (!duplicate) {
        List<TestCaseCountryProperties> tccpToDelete = new ArrayList(tccpFromDtb);
        tccpToDelete.removeAll(tccpFromPage);
        List<TestCaseCountryProperties> tccpToDeleteToIterate = new ArrayList(tccpToDelete);
        for (TestCaseCountryProperties tccpDifference : tccpToDeleteToIterate) {
            for (TestCaseCountryProperties tccpInPage : tccpFromPage) {
                if (tccpDifference.hasSameKey(tccpInPage)) {
                    tccpToDelete.remove(tccpDifference);
                }
            }
        }
        tccpService.deleteListTestCaseCountryProperties(tccpToDelete);
    }
    /*
         * Get steps, actions and controls from page by:
         * - generating a new step, action or control number,
         * - setting the correct related step and action for action or control
         */
    List<TestCaseStep> tcsFromPage = getTestCaseStepFromParameter(request, appContext, test, testCase, duplicate);
    List<TestCaseStepAction> tcsaFromPage = new ArrayList();
    List<TestCaseStepActionControl> tcsacFromPage = new ArrayList();
    int nextStepNumber = getMaxStepNumber(tcsFromPage);
    for (TestCaseStep tcs : tcsFromPage) {
        if (tcs.getStep() == -1) {
            tcs.setStep(++nextStepNumber);
        }
        if (tcs.getTestCaseStepAction() != null) {
            int nextSequenceNumber = getMaxSequenceNumber(tcs.getTestCaseStepAction());
            for (TestCaseStepAction tcsa : tcs.getTestCaseStepAction()) {
                if (tcsa.getSequence() == -1) {
                    tcsa.setSequence(++nextSequenceNumber);
                }
                tcsa.setStep(tcs.getStep());
                if (tcsa.getTestCaseStepActionControl() != null) {
                    int nextControlNumber = getMaxControlNumber(tcsa.getTestCaseStepActionControl());
                    for (TestCaseStepActionControl tscac : tcsa.getTestCaseStepActionControl()) {
                        if (tscac.getControlSequence() == -1) {
                            tscac.setControlSequence(++nextControlNumber);
                        }
                        tscac.setStep(tcs.getStep());
                        tscac.setSequence(tcsa.getSequence());
                    }
                    tcsacFromPage.addAll(tcsa.getTestCaseStepActionControl());
                }
            }
            tcsaFromPage.addAll(tcs.getTestCaseStepAction());
        }
    }
    /*
         * Create, update or delete step, action and control according to the needs
         */
    List<TestCaseStep> tcsFromDtb = new ArrayList(tcsService.getListOfSteps(initialTest, initialTestCase));
    tcsService.compareListAndUpdateInsertDeleteElements(tcsFromPage, tcsFromDtb, duplicate);
    List<TestCaseStepAction> tcsaFromDtb = new ArrayList(tcsaService.findTestCaseStepActionbyTestTestCase(initialTest, initialTestCase));
    tcsaService.compareListAndUpdateInsertDeleteElements(tcsaFromPage, tcsaFromDtb, duplicate);
    List<TestCaseStepActionControl> tcsacFromDtb = new ArrayList(tcsacService.findControlByTestTestCase(initialTest, initialTestCase));
    tcsacService.compareListAndUpdateInsertDeleteElements(tcsacFromPage, tcsacFromDtb, duplicate);
    /**
     * Adding Log entry.
     */
    ILogEventService logEventService = appContext.getBean(LogEventService.class);
    logEventService.createForPrivateCalls("/UpdateTestCase", "UPDATE", "Update testcase : ['" + tc.getTest() + "'|'" + tc.getTestCase() + "']", request);
    String encodedTest = URLEncoder.encode(tc.getTest(), "UTF-8");
    String encodedTestCase = URLEncoder.encode(tc.getTestCase(), "UTF-8");
    response.sendRedirect(response.encodeRedirectURL("TestCase.jsp?Load=Load&Test=" + encodedTest + "&TestCase=" + encodedTestCase));
}
Also used : ITestCaseStepActionService(org.cerberus.crud.service.ITestCaseStepActionService) IFactoryTestCaseStepAction(org.cerberus.crud.factory.IFactoryTestCaseStepAction) TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) User(org.cerberus.crud.entity.User) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) ArrayList(java.util.ArrayList) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) TestCaseStep(org.cerberus.crud.entity.TestCaseStep) IUserGroupService(org.cerberus.crud.service.IUserGroupService) ITestCaseCountryService(org.cerberus.crud.service.ITestCaseCountryService) UserGroup(org.cerberus.crud.entity.UserGroup) ApplicationContext(org.springframework.context.ApplicationContext) ITestService(org.cerberus.crud.service.ITestService) Test(org.cerberus.crud.entity.Test) ITestCaseCountryPropertiesService(org.cerberus.crud.service.ITestCaseCountryPropertiesService) ITestCaseService(org.cerberus.crud.service.ITestCaseService) TestCaseCountry(org.cerberus.crud.entity.TestCaseCountry) IFactoryTestCaseCountry(org.cerberus.crud.factory.IFactoryTestCaseCountry) ILogEventService(org.cerberus.crud.service.ILogEventService) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl) AnswerList(org.cerberus.util.answer.AnswerList) ITestCaseStepService(org.cerberus.crud.service.ITestCaseStepService) IInvariantService(org.cerberus.crud.service.IInvariantService) ITestCaseStepActionControlService(org.cerberus.crud.service.ITestCaseStepActionControlService) TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) IUserService(org.cerberus.crud.service.IUserService)

Example 5 with UserGroup

use of org.cerberus.crud.entity.UserGroup in project cerberus-source by cerberustesting.

the class UserGroupDAO method findGroupByKey.

@Override
public List<UserGroup> findGroupByKey(String login) {
    List<UserGroup> list = null;
    final String query = "SELECT groupname FROM usergroup WHERE login = ? ORDER BY groupname";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, login);
            ResultSet resultSet = preStat.executeQuery();
            try {
                list = new ArrayList<UserGroup>();
                while (resultSet.next()) {
                    UserGroup group = factoryGroup.create(resultSet.getString("groupname"));
                    list.add(group);
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return list;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) UserGroup(org.cerberus.crud.entity.UserGroup) IFactoryUserGroup(org.cerberus.crud.factory.IFactoryUserGroup)

Aggregations

UserGroup (org.cerberus.crud.entity.UserGroup)10 User (org.cerberus.crud.entity.User)6 IUserGroupService (org.cerberus.crud.service.IUserGroupService)6 IUserService (org.cerberus.crud.service.IUserService)6 UserSystem (org.cerberus.crud.entity.UserSystem)5 IUserSystemService (org.cerberus.crud.service.IUserSystemService)5 AnswerList (org.cerberus.util.answer.AnswerList)5 JSONArray (org.json.JSONArray)5 JSONObject (org.json.JSONObject)5 IFactoryUserGroup (org.cerberus.crud.factory.IFactoryUserGroup)4 ApplicationContext (org.springframework.context.ApplicationContext)4 ArrayList (java.util.ArrayList)3 MessageEvent (org.cerberus.engine.entity.MessageEvent)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ILogEventService (org.cerberus.crud.service.ILogEventService)2 CerberusException (org.cerberus.exception.CerberusException)2 Answer (org.cerberus.util.answer.Answer)2