private Annotation createAnnotation(String note, String date) throws ParseException {
    Annotation ann = new Annotation();

    ann.setDate(sdf.parse(date));
    ann.setNote(note);
    ann.setUser(AuthUtil.getRemoteUserObject());
    return ann;
  }
Example #2
0
  @Override
  protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp)
      throws Exception {
    ModelAndView mav = new ModelAndView();

    User user = AuthUtil.getRemoteUserObject();

    int notificationCount = inTrayManager.countNotifications(user);
    int taskCount = inTrayManager.countTasks(user);
    int siteCount = siteManager.countSites();
    int targetCount = targetManager.countTargets(user);
    int groupCount = targetManager.countTargetGroups(user);

    ArrayList<String> states = new ArrayList<String>();
    states.add(TargetInstance.STATE_SCHEDULED);
    int schedCount = targetInstanceManager.countTargetInstances(user, states);

    states.clear();
    states.add(TargetInstance.STATE_HARVESTED);
    int qaCount = targetInstanceManager.countTargetInstances(user, states);

    mav.addObject(MDL_CNT_NOTIFICATION, new Integer(notificationCount));
    mav.addObject(MDL_CNT_TASK, new Integer(taskCount));
    mav.addObject(MDL_CNT_SITE, new Integer(siteCount));
    mav.addObject(MDL_CNT_TARGET, new Integer(targetCount));
    mav.addObject(MDL_CNT_GROUPS, new Integer(groupCount));
    mav.addObject(MDL_CNT_SCHEDULED, new Integer(schedCount));
    mav.addObject(MDL_CNT_QR, new Integer(qaCount));
    if (!enableQaModule) {
      mav.setViewName(Constants.VIEW_HOME);
    } else {
      mav.setViewName(Constants.VIEW_QA_HOME);
    }

    return mav;
  }
  @Override
  protected ModelAndView processFormSubmission(
      HttpServletRequest aReq, HttpServletResponse aRes, Object aCommand, BindException aError)
      throws Exception {

    ModelAndView mav = null;
    CreateFlagCommand flagCmd = (CreateFlagCommand) aCommand;

    if (flagCmd != null) {
      if (aError.hasErrors()) {
        mav = new ModelAndView();
        List agencies = agencyUserManager.getAgenciesForLoggedInUser();
        mav.addObject(CreateFlagCommand.MDL_AGENCIES, agencies);

        String mode = flagCmd.getMode();
        if (CreateFlagCommand.ACTION_EDIT.equals(mode)) {
          mav.addObject(CreateFlagCommand.ACTION_EDIT, mode);
        }
        mav.addObject(Constants.GBL_CMD_DATA, aError.getTarget());
        mav.addObject(Constants.GBL_ERRORS, aError);
        mav.setViewName("newFlag");

      } else if (CreateFlagCommand.ACTION_NEW.equals(flagCmd.getAction())) {
        mav = new ModelAndView();
        List agencies = agencyUserManager.getAgenciesForLoggedInUser();
        mav.addObject(CreateFlagCommand.MDL_AGENCIES, agencies);
        mav.setViewName("newFlag");

      } else if (CreateFlagCommand.ACTION_VIEW.equals(flagCmd.getAction())
          || CreateFlagCommand.ACTION_EDIT.equals(flagCmd.getAction())) {
        // View/Edit an existing flag
        mav = new ModelAndView();
        Long flagOid = flagCmd.getOid();
        Flag flag = agencyUserManager.getFlagByOid(flagOid);
        CreateFlagCommand editCmd = new CreateFlagCommand();
        editCmd.setOid(flagOid);
        editCmd.setAgencyOid(flag.getAgency().getOid());
        editCmd.setName(flag.getName());
        editCmd.setRgb(flag.getRgb());
        editCmd.setMode(flagCmd.getAction());

        List agencies = agencyUserManager.getAgenciesForLoggedInUser();
        mav.addObject(CreateFlagCommand.MDL_AGENCIES, agencies);
        mav.addObject(Constants.GBL_CMD_DATA, editCmd);
        mav.setViewName("newFlag");

      } else if (CreateFlagCommand.ACTION_SAVE.equals(flagCmd.getAction())) {

        try {
          Flag flag = new Flag();
          boolean update = (flagCmd.getOid() != null);
          if (update == true) {
            // Update an existing flag object by loading it in first
            flag = agencyUserManager.getFlagByOid(flagCmd.getOid());
          } else {
            // Save the newly created flag object

            // load Agency
            Long agencyOid = flagCmd.getAgencyOid();
            Agency agency = agencyUserManager.getAgencyByOid(agencyOid);
            flag.setAgency(agency);
          }

          flag.setRgb(flagCmd.getRgb());
          String complementColour = null;
          if (flagCmd.getRgb().equals("000000")) {
            complementColour = "ffffff";
          } else {
            complementColour = getComplementColour(flagCmd.getRgb());
          }
          flag.setComplementRgb(complementColour);
          flag.setName(flagCmd.getName());

          agencyUserManager.updateFlag(flag, update);

          List flags = agencyUserManager.getFlagForLoggedInUser();
          List agencies = null;
          if (authorityManager.hasPrivilege(Privilege.MANAGE_FLAGS, Privilege.SCOPE_ALL)) {
            agencies = agencyUserManager.getAgencies();
          } else {
            User loggedInUser = AuthUtil.getRemoteUserObject();
            Agency usersAgency = loggedInUser.getAgency();
            agencies = new ArrayList<Agency>();
            agencies.add(usersAgency);
          }

          mav = new ModelAndView();
          String message;
          if (update == true) {
            message =
                messageSource.getMessage(
                    "flag.updated", new Object[] {flagCmd.getName()}, Locale.getDefault());
          } else {
            message =
                messageSource.getMessage(
                    "flag.created", new Object[] {flagCmd.getName()}, Locale.getDefault());
          }
          String agencyFilter =
              (String) aReq.getSession().getAttribute(FlagCommand.MDL_AGENCYFILTER);
          if (agencyFilter == null) {
            agencyFilter = AuthUtil.getRemoteUserObject().getAgency().getName();
          }
          mav.addObject(FlagCommand.MDL_AGENCYFILTER, agencyFilter);
          mav.addObject(FlagCommand.MDL_LOGGED_IN_USER, AuthUtil.getRemoteUserObject());
          mav.addObject(FlagCommand.MDL_FLAGS, flags);
          mav.addObject(FlagCommand.MDL_AGENCIES, agencies);

          mav.addObject(Constants.GBL_MESSAGES, message);

          mav.setViewName("viewFlags");
        } catch (DataAccessException e) {
          e.printStackTrace();
        }
      }
    } else {
      log.warn("No Action provided for CreateFlagController.");
    }

    return mav;
  }