Example usage for org.apache.commons.beanutils PropertyUtils getSimpleProperty

List of usage examples for org.apache.commons.beanutils PropertyUtils getSimpleProperty

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils getSimpleProperty.

Prototype

public static Object getSimpleProperty(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Return the value of the specified simple property of the specified bean, with no type conversions.

For more details see PropertyUtilsBean.

Usage

From source file:org.itracker.web.actions.admin.language.ExportLanguageAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    ActionMessages errors = new ActionMessages();

    if (!LoginUtilities.hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) {
        return mapping.findForward("unauthorized");
    }/*from ww  w  .  ja va  2s.  co m*/

    try {
        ConfigurationService configurationService = ServletContextUtils.getItrackerServices()
                .getConfigurationService();

        String locale = (String) PropertyUtils.getSimpleProperty(form, "locale");
        if (locale != null && !locale.equals("")) {
            StringBuffer output = new StringBuffer(
                    "# ITracker language properties file for locale " + locale + "\n\n");

            List<NameValuePair> items = configurationService.getDefinedKeysAsArray(locale);
            for (int i = 0; i < items.size(); i++) {
                if (items.get(i).getName() != null && items.get(i).getValue() != null) {
                    output.append(
                            ITrackerResources.escapeUnicodeString(items.get(i).getName(), false) + "="
                                    + ITrackerResources.escapeUnicodeString(
                                            HTMLUtilities.escapeNewlines(items.get(i).getValue()), false)
                                    + "\n");
                }
            }
            response.setHeader("Content-Disposition", "attachment; filename=\"ITracker"
                    + (locale.equals(ITrackerResources.BASE_LOCALE) ? "" : "_" + locale) + ".properties\"");
            response.setHeader("Content-Type", "application/x-itracker-language-export; charset=UTF-8");
            ServletOutputStream out = response.getOutputStream();
            out.print(output.toString());
            out.flush();
            return null;
        }
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidlocale"));
    } catch (RuntimeException e) {
        log.error("Exception while exporting language.", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (IllegalAccessException e) {
        log.error("Exception while exporting language.", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (InvocationTargetException e) {
        log.error("Exception while exporting language.", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (NoSuchMethodException e) {
        log.error("Exception while exporting language.", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    }

    if (!errors.isEmpty()) {
        saveErrors(request, errors);
    }

    return mapping.findForward("error");
}

From source file:org.itracker.web.actions.admin.project.EditComponentFormAction.java

@SuppressWarnings("unchecked")
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    ActionMessages errors = new ActionMessages();

    String pageTitleKey = "";
    String pageTitleArg = "";

    try {//from   w w  w  . j a  v a  2s.  co m
        ProjectService projectService = ServletContextUtils.getItrackerServices().getProjectService();

        HttpSession session = request.getSession(true);
        String action = request.getParameter("action");
        Map<Integer, Set<PermissionType>> userPermissions = (Map<Integer, Set<PermissionType>>) session
                .getAttribute(Constants.PERMISSIONS_KEY);
        Component component = (Component) session.getAttribute(Constants.COMPONENT_KEY);
        Project project;
        ComponentForm componentForm = (ComponentForm) form;

        if (componentForm == null) {
            componentForm = new ComponentForm();
        }

        if ("create".equals(action)) {
            Integer projectId = (Integer) PropertyUtils.getSimpleProperty(form, "projectId");

            if (action != null && action.equals("create")) {
                pageTitleKey = "itracker.web.admin.editcomponent.title.create";
            }

            if (projectId == null) {
                errors.add(ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage("itracker.web.error.invalidproject"));
            } else {
                project = projectService.getProject(projectId);

                if (project == null) {
                    errors.add(ActionMessages.GLOBAL_MESSAGE,
                            new ActionMessage("itracker.web.error.invalidproject"));
                } else if (!UserUtilities.hasPermission(userPermissions, project.getId(),
                        UserUtilities.PERMISSION_PRODUCT_ADMIN)) {
                    return mapping.findForward("unauthorized");
                } else {
                    component = new Component();
                    component.setProject(project);
                    componentForm.setAction("create");
                    componentForm.setId(component.getId());
                    componentForm.setProjectId(component.getProject().getId());
                }
            }
        } else if ("update".equals(action)) {
            Integer componentId = (Integer) PropertyUtils.getSimpleProperty(form, "id");
            component = projectService.getProjectComponent(componentId);
            if (action != null && action.equals("update")) {
                pageTitleKey = "itracker.web.admin.editcomponent.title.update";
                pageTitleArg = component.getName();
            }
            if (component == null) {
                errors.add(ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage("itracker.web.error.invalidcomponent"));
            } else {
                project = component.getProject();
                if (component == null) {
                    errors.add(ActionMessages.GLOBAL_MESSAGE,
                            new ActionMessage("itracker.web.error.invalidproject"));
                } else if (!UserUtilities.hasPermission(userPermissions, component.getProject().getId(),
                        UserUtilities.PERMISSION_PRODUCT_ADMIN)) {
                    return mapping.findForward("unauthorized");
                } else {
                    componentForm.setAction("update");
                    componentForm.setId(component.getId());

                    componentForm.setProjectId(project.getId());
                    componentForm.setName(component.getName());
                    componentForm.setDescription(component.getDescription());
                }
            }
        } else {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidaction"));
        }

        if (errors.isEmpty()) {
            request.setAttribute("componentForm", componentForm);
            session.setAttribute(Constants.COMPONENT_KEY, component);
            saveToken(request);
            request.setAttribute("pageTitleKey", pageTitleKey);
            request.setAttribute("pageTitleArg", pageTitleArg);
            ActionForward af = EditComponentFormActionUtil.init(mapping, request);
            if (af != null)
                return af;
            return mapping.getInputForward();
        }
    } catch (Exception e) {
        pageTitleKey = "itracker.web.error.title";

        request.setAttribute("pageTitleKey", pageTitleKey);
        request.setAttribute("pageTitleArg", pageTitleArg);

        log.error("Exception while creating edit component form.", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    }

    if (!errors.isEmpty()) {
        saveErrors(request, errors);

        return mapping.findForward("error");
    }
    return mapping.getInputForward();
}

From source file:org.itracker.web.actions.admin.project.EditProjectAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    ActionMessages errors = new ActionMessages();

    if (!isTokenValid(request)) {
        log.debug("Invalid request token while editing project.");
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.transaction"));
        saveErrors(request, errors);// www . j  a v a  2 s.c  o  m
        saveToken(request);
        return mapping.getInputForward();

    }
    resetToken(request);

    try {
        ProjectService projectService = ServletContextUtils.getItrackerServices().getProjectService();
        UserService userService = ServletContextUtils.getItrackerServices().getUserService();

        HttpSession session = request.getSession(true);
        User user = LoginUtilities.getCurrentUser(request);

        String action = request.getParameter("action");

        if ("update".equals(action)) {

            Map<Integer, Set<PermissionType>> userPermissions = RequestHelper.getUserPermissions(session);

            Project project = projectService.getProject((Integer) PropertyUtils.getSimpleProperty(form, "id"));
            if (!UserUtilities.hasPermission(userPermissions, project.getId(), PermissionType.PRODUCT_ADMIN)) {
                return mapping.findForward("unauthorized");
            }
            AdminProjectUtilities.setFormProperties(project, projectService, form, errors);
            if (!errors.isEmpty()) {
                saveErrors(request, errors);
                return mapping.getInputForward();
            } else {
                Integer[] ownersArray = (Integer[]) PropertyUtils.getSimpleProperty(form, "owners");
                Set<Integer> ownerIds = null == ownersArray ? new HashSet<Integer>()
                        : new HashSet<Integer>(Arrays.asList(ownersArray));
                AdminProjectUtilities.updateProjectOwners(project, ownerIds, projectService, userService);

                if (log.isDebugEnabled()) {
                    log.debug("execute: updating existing project: " + project);
                }
                projectService.updateProject(project, user.getId());
            }
        } else if ("create".equals(action)) {
            if (!user.isSuperUser()) {
                return mapping.findForward("unauthorized");
            }

            Project project = new Project();
            AdminProjectUtilities.setFormProperties(project, projectService, form, errors);
            if (!errors.isEmpty()) {
                saveErrors(request, errors);
                return mapping.getInputForward();
            }
            project = projectService.createProject(project, user.getId());

            if (log.isDebugEnabled()) {
                log.debug("execute: created new project: " + project);
            }

            Integer[] users = (Integer[]) PropertyUtils.getSimpleProperty(form, "users");
            if (users != null) {
                // get the initial project members from create-form
                Set<Integer> userIds = new HashSet<Integer>(Arrays.asList(users));
                // get the permissions-set for initial project members
                Integer[] permissionArray = (Integer[]) PropertyUtils.getSimpleProperty(form, "permissions");
                Set<Integer> permissions = null == permissionArray ? new HashSet<Integer>(0)
                        : new HashSet<Integer>(Arrays.asList(permissionArray));

                Integer[] ownersArray = (Integer[]) PropertyUtils.getSimpleProperty(form, "owners");
                Set<Integer> ownerIds = null == ownersArray ? new HashSet<Integer>()
                        : new HashSet<Integer>(Arrays.asList(ownersArray));

                // if admin-permission is selected, all permissions will be
                // granted and users added as project owners
                if (permissions.contains(UserUtilities.PERMISSION_PRODUCT_ADMIN)) {
                    ownerIds.addAll(userIds);
                } else {
                    // handle special initial user-/permissions-set
                    AdminProjectUtilities.handleInitialProjectMembers(project, userIds, permissions,
                            projectService, userService);
                }

                // set project owners with all permissions
                AdminProjectUtilities.updateProjectOwners(project, ownerIds, projectService, userService);
            }

            if (log.isDebugEnabled()) {
                log.debug("execute: updating new project: " + project);
            }
            session.removeAttribute(Constants.PROJECT_KEY);
        }
    } catch (RuntimeException e) {
        log.error("execute: Exception processing form data", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (IllegalAccessException e) {
        log.error("execute: Exception processing form data", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (InvocationTargetException e) {
        log.error("execute: Exception processing form data", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (NoSuchMethodException e) {
        log.error("execute: Exception processing form data", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    }

    if (!errors.isEmpty()) {
        saveErrors(request, errors);
        if (log.isDebugEnabled()) {
            log.debug("execute: got errors in action-messages: " + errors);
        }
        return mapping.findForward("error");
    }

    return mapping.findForward("listprojectsadmin");
}

From source file:org.itracker.web.actions.admin.project.EditProjectScriptFormAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    ActionMessages errors = new ActionMessages();

    if (!LoginUtilities.hasPermission(UserUtilities.PERMISSION_USER_ADMIN, request, response)) {
        return mapping.findForward("unauthorized");
    }/*from  w  w w  .  j ava2s  . co m*/
    boolean isUpdate = false;
    String pageTitleKey = "";
    String pageTitleArg = "";
    String action = "";
    Project project;

    try {

        ProjectScriptForm projectScriptForm = (ProjectScriptForm) form;
        final ProjectService projectService = ServletContextUtils.getItrackerServices().getProjectService();
        final ConfigurationService configurationService = ServletContextUtils.getItrackerServices()
                .getConfigurationService();

        if (projectScriptForm == null) {
            projectScriptForm = new ProjectScriptForm();
        }
        final List<WorkflowScript> workflowScripts = configurationService.getWorkflowScripts();

        Integer projectId = (Integer) PropertyUtils.getSimpleProperty(projectScriptForm, "projectId");
        projectScriptForm.setProjectId(projectId);
        project = projectService.getProject(projectId);

        final List<ProjectScript> projectScripts = project.getScripts();
        pageTitleKey = "itracker.web.admin.editprojectscript.title.create";

        if (errors.isEmpty()) {
            request.setAttribute("workflowScripts", workflowScripts);
            request.setAttribute("projectScripts", projectScripts);

            final Locale locale = LoginUtilities.getCurrentLocale(request);
            Map<String, String> customFieldsMapped = new HashMap<String, String>(
                    project.getCustomFields().size());
            for (CustomField field : project.getCustomFields()) {
                String name = CustomFieldUtilities.getCustomFieldName(field.getId(), locale);
                name += " ";
                name += CustomFieldUtilities.getTypeString(field.getFieldType(), locale);
                customFieldsMapped.put(String.valueOf(field.getId()), name);
            }

            request.setAttribute("customFields", customFieldsMapped);
            request.setAttribute("projectScriptForm", projectScriptForm);
            EditProjectFormActionUtil.setUpPrioritiesInEnv(request);
            request.setAttribute("project", project);

            saveToken(request);
            request.setAttribute("pageTitleKey", pageTitleKey);
            request.setAttribute("pageTitleArg", pageTitleArg);
            return mapping.getInputForward();
        }
    } catch (RuntimeException e) {
        log.error("Exception while the " + action + " of ProjectScript form.", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (IllegalAccessException e) {
        log.error("Exception while the " + action + " of ProjectScript form.", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (InvocationTargetException e) {
        log.error("Exception while the " + action + " of ProjectScript form.", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (NoSuchMethodException e) {
        log.error("Exception while the " + action + " of ProjectScript form.", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    }

    if (!errors.isEmpty()) {
        saveErrors(request, errors);
    }
    request.setAttribute("pageTitleKey", pageTitleKey);
    request.setAttribute("pageTitleArg", pageTitleArg);
    request.setAttribute("isUpdate", isUpdate);
    return mapping.findForward("error");
}

From source file:org.itracker.web.actions.admin.project.EditVersionFormAction.java

@SuppressWarnings("unchecked")
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    ActionMessages errors = new ActionMessages();

    String pageTitleKey = "";
    String pageTitleArg = "";

    try {// ww w . jav a 2s  .c o m
        ProjectService projectService = ServletContextUtils.getItrackerServices().getProjectService();

        HttpSession session = request.getSession(true);
        String action = request.getParameter("action");
        Map<Integer, Set<PermissionType>> userPermissions = (Map<Integer, Set<PermissionType>>) session
                .getAttribute(Constants.PERMISSIONS_KEY);

        Version version;
        version = (Version) session.getAttribute(Constants.VERSION_KEY);

        Project project;

        VersionForm versionForm = (VersionForm) form;
        if (versionForm == null) {
            versionForm = new VersionForm();
        }

        Integer projectId = (Integer) PropertyUtils.getSimpleProperty(form, "projectId");

        if ("create".equals(action)) {

            if (action != null && action.equals("create")) {
                pageTitleKey = "itracker.web.admin.editversion.title.create";
            }

            if (projectId == null) {
                errors.add(ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage("itracker.web.error.invalidproject"));
            } else {
                project = projectService.getProject(projectId);

                if (project == null) {
                    errors.add(ActionMessages.GLOBAL_MESSAGE,
                            new ActionMessage("itracker.web.error.invalidproject"));
                } else if (!UserUtilities.hasPermission(userPermissions, project.getId(),
                        PermissionType.PRODUCT_ADMIN)) {
                    return mapping.findForward("unauthorized");
                } else {
                    version = new Version();
                    version.setProject(project);
                    versionForm.setAction("create");
                    versionForm.setDescription(versionForm.getDescription());
                    versionForm.setId(-1);
                    versionForm.setProjectId(version.getProject().getId());
                }
            }
        } else if ("update".equals(action)) {
            Integer versionId = (Integer) PropertyUtils.getSimpleProperty(form, "id");
            version = projectService.getProjectVersion(versionId);
            if (action != null && action.equals("update")) {
                pageTitleKey = "itracker.web.admin.editversion.title.update";
                pageTitleArg = version.getNumber();
            }
            if (version == null) {
                errors.add(ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage("itracker.web.error.invalidversion"));
            } else {
                if (!UserUtilities.hasPermission(userPermissions, version.getProject().getId(),
                        PermissionType.PRODUCT_ADMIN)) {
                    return mapping.findForward("unauthorized");
                } else {
                    versionForm.setAction("update");
                    versionForm.setId(version.getId());
                    versionForm.setProjectId(version.getProject().getId());
                    versionForm.setNumber(version.getNumber());
                    versionForm.setDescription(version.getDescription());
                }
            }
        } else {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidaction"));
        }

        if (errors.isEmpty()) {
            request.setAttribute("versionForm", versionForm);
            session.setAttribute(Constants.VERSION_KEY, version);
            saveToken(request);
            request.setAttribute("pageTitleKey", pageTitleKey);
            request.setAttribute("pageTitleArg", pageTitleArg);
            ActionForward af = EditVersionFormActionUtil.init(mapping, request);
            if (af != null)
                return af;
            return mapping.getInputForward();
        }
    } catch (Exception ex) {
        pageTitleKey = "itracker.web.error.title";

        request.setAttribute("pageTitleKey", pageTitleKey);
        request.setAttribute("pageTitleArg", pageTitleArg);

        log.error("Exception while creating edit version form.", ex);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    }

    if (!errors.isEmpty()) {
        saveErrors(request, errors);

        return mapping.findForward("error");
    }
    return mapping.getInputForward();
}

From source file:org.itracker.web.actions.admin.workflow.EditWorkflowScriptFormAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    ActionMessages errors = new ActionMessages();

    boolean isUpdate = false;

    try {/*from  www.j av a2 s .c  om*/
        WorkflowScriptForm workflowScriptForm = (WorkflowScriptForm) form;

        if (workflowScriptForm == null) {
            workflowScriptForm = new WorkflowScriptForm();
        }
        String action = workflowScriptForm.getAction();

        WorkflowScript workflowScript = new WorkflowScript();
        if ("update".equals(action)) {
            ConfigurationService configurationService = ServletContextUtils.getItrackerServices()
                    .getConfigurationService();

            Integer id = (Integer) PropertyUtils.getSimpleProperty(workflowScriptForm, "id");
            workflowScript = configurationService.getWorkflowScript(id);

            if (workflowScript == null) {
                throw new SystemConfigurationException("Invalid workflow script id " + id);
            }

            workflowScriptForm.setAction("update");
            workflowScriptForm.setId(workflowScript.getId());
            workflowScriptForm.setName(workflowScript.getName());
            workflowScriptForm.setEvent(workflowScript.getEvent());
            workflowScriptForm.setScript(workflowScript.getScript());
            workflowScriptForm.setLanguage(workflowScript.getLanguage().name());

        } else {
            workflowScriptForm.setLanguage(WorkflowScript.ScriptLanguage.BeanShell.name());
        }

        if (errors.isEmpty()) {
            HttpSession session = request.getSession(true);
            request.setAttribute("workflowScriptForm", workflowScriptForm);
            session.setAttribute(Constants.WORKFLOW_SCRIPT_KEY, workflowScript);
            request.setAttribute("action", action);
            saveToken(request);

            setupFormEventTypes(workflowScriptForm, getLocale(request));

            return mapping.getInputForward();
        }
    } catch (SystemConfigurationException sce) {
        errors.add(ActionMessages.GLOBAL_MESSAGE,
                new ActionMessage("itracker.web.error.invalidworkflowscript"));
    } catch (Exception e) {
        log.error("Exception while creating edit workflowScript form.", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    }

    if (!errors.isEmpty()) {
        saveErrors(request, errors);
    }
    return mapping.findForward("error");
}

From source file:org.itracker.web.actions.issuesearch.SearchIssuesAction.java

private IssueSearchQuery processQueryParameters(IssueSearchQuery isqm, ValidatorForm form,
        ActionMessages errors) {//from www.  ja va2 s  .c  o m
    if (isqm == null) {
        isqm = new IssueSearchQuery();
    }

    try {
        Integer creatorValue = (Integer) PropertyUtils.getSimpleProperty(form, "creator");
        if (creatorValue != null && creatorValue.intValue() != -1) {
            isqm.setCreator(ServletContextUtils.getItrackerServices().getUserService().getUser(creatorValue));
        } else {
            isqm.setCreator(null);
        }

        Integer ownerValue = (Integer) PropertyUtils.getSimpleProperty(form, "owner");
        if (ownerValue != null && ownerValue.intValue() != -1) {
            isqm.setOwner(ServletContextUtils.getItrackerServices().getUserService().getUser(ownerValue));
        } else {
            isqm.setOwner(null);
        }

        String textValue = (String) PropertyUtils.getSimpleProperty(form, "textphrase");
        if (textValue != null && textValue.trim().length() > 0) {
            isqm.setText(textValue.trim());
        } else {
            isqm.setText(null);
        }

        String resolutionValue = (String) PropertyUtils.getSimpleProperty(form, "resolution");
        if (resolutionValue != null && !resolutionValue.equals("")) {
            isqm.setResolution(resolutionValue);
        } else {
            isqm.setResolution(null);
        }

        Integer[] projectsArray = (Integer[]) PropertyUtils.getSimpleProperty(form, "projects");
        List<Integer> projects = Arrays.asList(projectsArray);
        if (projects == null || projects.size() == 0) {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.projectrequired"));
        } else {
            isqm.setProjects(projects);
        }

        Integer[] severitiesArray = (Integer[]) PropertyUtils.getSimpleProperty(form, "severities");
        if (severitiesArray != null && severitiesArray.length > 0) {
            List<Integer> severities = Arrays.asList(severitiesArray);
            isqm.setSeverities(severities);
        } else {
            isqm.setSeverities(null);
        }

        Integer[] statusesArray = (Integer[]) PropertyUtils.getSimpleProperty(form, "statuses");
        if (statusesArray != null && statusesArray.length > 0) {
            List<Integer> statuses = Arrays.asList(statusesArray);
            isqm.setStatuses(statuses);
        } else {
            isqm.setStatuses(null);
        }

        Integer[] componentsArray = (Integer[]) PropertyUtils.getSimpleProperty(form, "components");
        if (componentsArray != null && componentsArray.length > 0) {
            List<Integer> components = Arrays.asList(componentsArray);
            isqm.setComponents(components);
        } else {
            isqm.setComponents(null);
        }

        Integer[] versionsArray = (Integer[]) PropertyUtils.getSimpleProperty(form, "versions");
        if (versionsArray != null && versionsArray.length > 0) {
            List<Integer> versions = Arrays.asList(versionsArray);
            isqm.setVersions(versions);
        } else {
            isqm.setVersions(null);
        }

        Integer targetVersion = (Integer) PropertyUtils.getSimpleProperty(form, "targetVersion");
        if (targetVersion != null && targetVersion > 0) {
            isqm.setTargetVersion(targetVersion);
        } else {
            isqm.setTargetVersion(null);
        }

        String orderBy = (String) PropertyUtils.getSimpleProperty(form, "orderBy");
        if (orderBy != null && !orderBy.equals("")) {
            if (log.isDebugEnabled()) {
                log.debug("processQueryParameters: set orderBy: " + orderBy);
            }
            isqm.setOrderBy(orderBy);
        }

        Integer type = (Integer) PropertyUtils.getSimpleProperty(form, "type");
        if (type != null) {
            if (log.isDebugEnabled()) {
                log.debug("processQueryParameters: set type: " + type);
            }
            isqm.setType(type);
        }
    } catch (RuntimeException e) {
        log.error("processQueryParameters: Unable to parse search query parameters: " + e.getMessage(), e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidsearchquery"));
    } catch (IllegalAccessException e) {
        log.error("processQueryParameters: Unable to parse search query parameters: " + e.getMessage(), e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidsearchquery"));
    } catch (InvocationTargetException e) {
        log.error("processQueryParameters: Unable to parse search query parameters: " + e.getMessage(), e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidsearchquery"));
    } catch (NoSuchMethodException e) {
        log.error("processQueryParameters: Unable to parse search query parameters: " + e.getMessage(), e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.invalidsearchquery"));
    }

    return isqm;
}

From source file:org.itracker.web.actions.issuesearch.SearchIssuesFormAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    ActionMessages errors = new ActionMessages();

    HttpSession session = request.getSession();

    try {//from   w  ww  . j  a  va 2s .  c  o m
        ProjectService projectService = ServletContextUtils.getItrackerServices().getProjectService();

        ReportService reportService = ServletContextUtils.getItrackerServices().getReportService();
        UserService userService = ServletContextUtils.getItrackerServices().getUserService();
        request.setAttribute("rh", reportService);
        request.setAttribute("uh", userService);

        String projectId = request.getParameter("projectId");

        UserPreferences userPrefs = (UserPreferences) session.getAttribute(Constants.PREFERENCES_KEY);
        Map<Integer, Set<PermissionType>> userPermissions = RequestHelper.getUserPermissions(session);

        String action = (String) PropertyUtils.getSimpleProperty(form, "action");

        SearchForm searchForm = (SearchForm) form;
        if (searchForm == null) {
            searchForm = new SearchForm();
        }

        boolean newQuery = false;
        IssueSearchQuery query = (IssueSearchQuery) session.getAttribute(Constants.SEARCH_QUERY_KEY);

        log.debug("projectid = " + projectId);
        log.debug("query type = " + (query == null ? "NULL" : query.getType().toString()));
        log.debug("query projectid = " + (query == null ? "NULL" : query.getProjectId().toString()));

        if (query == null || query.getType() == null || "reset".equalsIgnoreCase(action)
                || (userPrefs != null && !userPrefs.getRememberLastSearch())) {
            log.debug("New search query.  No existing query, reset forced, or saved querys not allowed.");
            query = new IssueSearchQuery();
            query.setType(IssueSearchQuery.TYPE_FULL);
            newQuery = true;
        } else if (query.getType().intValue() == IssueSearchQuery.TYPE_FULL.intValue() && projectId != null) {
            log.debug("New search query.  Previous query FULL, new query PROJECT.");
            query = new IssueSearchQuery();
            query.setType(IssueSearchQuery.TYPE_PROJECT);
            newQuery = true;
        } else if (query.getType().intValue() == IssueSearchQuery.TYPE_PROJECT.intValue()) {
            if (projectId == null || projectId.equals("")) {
                log.debug("New search query.  Previous query PROJECT, new query FULL.");
                query = new IssueSearchQuery();
                query.setType(IssueSearchQuery.TYPE_FULL);
                newQuery = true;
            } else if (!projectId.equals(query.getProjectId().toString())) {
                log.debug("New search query.  Requested project (" + projectId
                        + ") different from previous query (" + query.getProjectId().toString() + ")");
                query = new IssueSearchQuery();
                query.setType(IssueSearchQuery.TYPE_PROJECT);
                newQuery = true;
            }
        }

        query.setAvailableProjects(null);

        List<Project> projects = projectService.getAllAvailableProjects();

        List<Project> availableProjectsList = new ArrayList<Project>();
        List<Integer> selectedProjectsList = new ArrayList<Integer>();

        for (Project project : projects) {
            if (!UserUtilities.hasPermission(userPermissions, project.getId(), PermissionType.ISSUE_VIEW_ALL)
                    && !UserUtilities.hasPermission(userPermissions, project.getId(),
                            PermissionType.ISSUE_VIEW_USERS)) {
                continue;
            }

            log.debug("Adding project " + project.getId() + " to list of available projects.");
            availableProjectsList.add(project);

            if (projectId != null && StringUtils.equals(String.valueOf(project.getId()), projectId)) {
                query.setType(IssueSearchQuery.TYPE_PROJECT);
                query.setProject(project);
                String pageTitleKey = "itracker.web.search.project.title";
                String pageTitleArg = project.getName();
                request.setAttribute("pageTitleKey", pageTitleKey);
                request.setAttribute("pageTitleArg", pageTitleArg);
                break;
            } else {
                if (query.getProjects().contains(project.getId())) {
                    selectedProjectsList.add(project.getId());
                }

            }
        }

        if (!availableProjectsList.isEmpty()) {
            log.debug("Issue Search has " + availableProjectsList.size() + " available projects.");

            Collections.sort(availableProjectsList, new Project.ProjectComparator());
            query.setAvailableProjects(availableProjectsList);
            if (query.getType().equals(IssueSearchQuery.TYPE_PROJECT)) {
                searchForm.setProject(query.getProjectId());
            }

            if (newQuery) {
                log.debug("New search query.  Clearing results and setting defaults.");
                query.setResults(null);
                List<Integer> selectedStatusesIntegerList = new ArrayList<Integer>();
                for (int i = 0; i < IssueUtilities.getStatuses().size(); i++) {
                    try {
                        int statusNumber = Integer.parseInt(IssueUtilities.getStatuses().get(i).getValue());
                        if (statusNumber < IssueUtilities.STATUS_CLOSED) {
                            selectedStatusesIntegerList.add(statusNumber);
                        }
                    } catch (Exception e) {
                        log.debug("Invalid status entry: " + IssueUtilities.getStatuses().get(i));
                    }
                }

                Integer[] statusesArray = new Integer[selectedStatusesIntegerList.size()];
                selectedStatusesIntegerList.toArray(statusesArray);
                searchForm.setStatuses(statusesArray);

                List<Integer> selectedSeverities = new ArrayList<Integer>();
                for (int i = 1; i <= IssueUtilities.getNumberSeverities(); i++) {
                    selectedSeverities.add(i);
                }

                Integer[] severitiesArray = new Integer[selectedSeverities.size()];
                selectedSeverities.toArray(severitiesArray);
                searchForm.setSeverities(severitiesArray);
            } else {
                List<Integer> selectedProjects;
                selectedProjects = selectedProjectsList;
                query.setProjects(selectedProjects);

                searchForm.setComponents(null);
                if (null != query.getComponents() && query.getComponents().size() > 0) {
                    Integer[] componentsArray = new Integer[query.getComponents().size()];
                    query.getComponents().toArray(componentsArray);
                    searchForm.setComponents(componentsArray);
                }

                searchForm.setCreator(null);
                if (null != query.getCreator()) {
                    searchForm.setCreator(query.getCreator().getId());
                }
                searchForm.setOwner(null);
                if (null != query.getOwner()) {
                    searchForm.setOwner(query.getOwner().getId());
                }
                searchForm.setOrderBy(query.getOrderBy());
                searchForm.setProject(query.getProjectId());

                searchForm.setProjects(null);
                if (null != query.getProjects() && query.getProjects().size() > 0) {
                    Integer[] projectsArray = new Integer[query.getProjects().size()];
                    query.getProjects().toArray(projectsArray);
                    searchForm.setProjects(projectsArray);
                }

                searchForm.setResolution(query.getResolution());

                searchForm.setSeverities(null);
                if (null != query.getSeverities() && query.getSeverities().size() > 0) {
                    Integer[] severitiesArray = new Integer[query.getSeverities().size()];
                    query.getSeverities().toArray(severitiesArray);
                    searchForm.setSeverities(severitiesArray);
                }

                searchForm.setStatuses(null);
                if (null != query.getStatuses() && query.getStatuses().size() > 0) {
                    Integer[] statusesArray = new Integer[query.getStatuses().size()];
                    query.getStatuses().toArray(statusesArray);
                    searchForm.setStatuses(statusesArray);
                }

                searchForm.setTargetVersion(query.getTargetVersion());
                searchForm.setTextphrase(query.getText());

                searchForm.setVersions(null);
                if (query.getVersions() != null && query.getVersions().size() > 0) {
                    Integer[] versionsArray = new Integer[query.getVersions().size()];
                    query.getVersions().toArray(versionsArray);
                    searchForm.setVersions(versionsArray);
                }

            }

            request.setAttribute("searchForm", searchForm);

            session.setAttribute(Constants.SEARCH_QUERY_KEY, query);

        } else {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.noprojects"));
        }

        if (errors.isEmpty()) {
            return mapping.getInputForward();
        }
    } catch (Exception e) {
        log.error("Exception while creating search issues form.", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    }

    if (!errors.isEmpty()) {
        saveErrors(request, errors);
    }

    return mapping.findForward("error");
}

From source file:org.itracker.web.actions.project.AddIssueRelationAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    ActionMessages errors = new ActionMessages();

    Integer issueId = null;/* w  ww  . j  a  v  a2  s . c o m*/
    String caller = "index";

    UserService userService = ServletContextUtils.getItrackerServices().getUserService();

    try {

        IssueService issueService = ServletContextUtils.getItrackerServices().getIssueService();

        caller = (String) PropertyUtils.getSimpleProperty(form, "caller");
        issueId = (Integer) PropertyUtils.getSimpleProperty(form, "issueId");
        Integer relatedIssueId = (Integer) PropertyUtils.getSimpleProperty(form, "relatedIssueId");
        IssueRelation.Type relationType = (IssueRelation.Type) PropertyUtils.getSimpleProperty(form,
                "relationType");

        HttpSession session = request.getSession(true);
        User currUser = (User) session.getAttribute(Constants.USER_KEY);

        Map<Integer, Set<PermissionType>> usersMapOfProjectIdsAndSetOfPermissionTypes = userService
                .getUsersMapOfProjectIdsAndSetOfPermissionTypes(currUser,
                        AuthenticationConstants.REQ_SOURCE_WEB);

        Integer currUserId = currUser.getId();

        Issue issue = issueService.getIssue(issueId);
        if (issue == null || issue.getProject() == null || !IssueUtilities.canEditIssue(issue, currUserId,
                usersMapOfProjectIdsAndSetOfPermissionTypes)) {
            return mapping.findForward("unauthorized");
        }

        Issue relatedIssue = issueService.getIssue(relatedIssueId);
        if (relatedIssue == null) {
            errors.add(ActionMessages.GLOBAL_MESSAGE,
                    new ActionMessage("itracker.web.error.relation.invalidissue"));
        } else if (relatedIssue.getProject() == null || !IssueUtilities.canEditIssue(relatedIssue, currUserId,
                usersMapOfProjectIdsAndSetOfPermissionTypes)) {
            return mapping.findForward("unauthorized");
        } else {
            if (IssueUtilities.hasIssueRelation(issue, relatedIssueId)) {
                errors.add(ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage("itracker.web.error.relation.exists", relatedIssueId));
            }
            if (!issueService.addIssueRelation(issueId, relatedIssueId, relationType, currUser.getId())) {
                errors.add(ActionMessages.GLOBAL_MESSAGE,
                        new ActionMessage("itracker.web.error.relation.adderror"));
            }
        }
    } catch (RuntimeException e) {
        log.info("execute: caught exception ", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (IllegalAccessException e) {
        log.info("execute: caught exception ", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (InvocationTargetException e) {
        log.info("execute: caught exception ", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (NoSuchMethodException e) {
        log.info("execute: caught exception ", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    }

    if (!errors.isEmpty()) {
        saveErrors(request, errors);
    }

    return new ActionForward(mapping.findForward(caller).getPath() + (issueId != null ? "?id=" + issueId : ""));
}

From source file:org.itracker.web.actions.project.AssignIssueAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {

    ActionMessages errors = new ActionMessages();

    try {//  w w w  .ja v a  2s.  c o m
        IssueService issueService = ServletContextUtils.getItrackerServices().getIssueService();
        ProjectService projectService = ServletContextUtils.getItrackerServices().getProjectService();

        Integer defaultValue = -1;
        IntegerConverter converter = new IntegerConverter(defaultValue);
        Integer issueId = (Integer) converter.convert(Integer.class,
                (String) PropertyUtils.getSimpleProperty(form, "issueId"));
        Integer projectId = (Integer) converter.convert(Integer.class,
                (String) PropertyUtils.getSimpleProperty(form, "projectId"));
        Integer userId = (Integer) converter.convert(Integer.class,
                (String) PropertyUtils.getSimpleProperty(form, "userId"));

        HttpSession session = request.getSession(true);
        User currUser = (User) session.getAttribute(Constants.USER_KEY);
        Map<Integer, Set<PermissionType>> userPermissions = RequestHelper.getUserPermissions(session);
        Integer currUserId = currUser.getId();

        Project project = projectService.getProject(projectId);
        if (project == null) {
            return mapping.findForward("unauthorized");
        }

        if (!userId.equals(currUserId) && !UserUtilities.hasPermission(userPermissions, projectId,
                UserUtilities.PERMISSION_ASSIGN_OTHERS)) {
            return mapping.findForward("unauthorized");
        } else if (!UserUtilities.hasPermission(userPermissions, projectId,
                UserUtilities.PERMISSION_ASSIGN_SELF)) {
            return mapping.findForward("unauthorized");
        }

        if (project.getStatus() != Status.ACTIVE) {
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.projectlocked"));
        } else {
            issueService.assignIssue(issueId, userId, currUserId);
        }
    } catch (RuntimeException e) {
        log.warn("execute: caught exception", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (IllegalAccessException e) {
        log.warn("execute: caught exception", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (InvocationTargetException e) {
        log.warn("execute: caught exception", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    } catch (NoSuchMethodException e) {
        log.warn("execute: caught exception", e);
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
    }

    if (!errors.isEmpty()) {
        saveErrors(request, errors);
        saveToken(request);
    }
    return mapping.findForward("index");
}