@SuppressWarnings("unchecked")
  @RequestMapping(
      value = "/" + PageNames.PRIVACY_ASSESSMENT_SETTINGS + ".html",
      method = RequestMethod.POST)
  public ModelAndView privacyAssessmentSettings(
      @Valid PrivacyAssessmentForm assForm, BindingResult result, Map model) {

    LOG.debug(PageNames.PRIVACY_ASSESSMENT_SETTINGS + " HTTP POST");

    if (result.hasErrors()) {
      LOG.warn("BindingResult has errors");
      model.put(RESULT, "privacy assessment form error");
      return new ModelAndView("error", model);
    }

    if (assessment == null) {
      LOG.warn("Privacy Assessment Service reference not avaiable");
      model.put("errormsg", "Privacy Assessment Service reference not avaiable");
      return new ModelAndView("error", model);
    }

    int autoAssessmentPeriod = assForm.getAutoReassessmentInSecs();
    boolean assessNow = assForm.isAssessNow();
    LOG.debug("autoReassessmentInSecs = {}, assessNow = {}", autoAssessmentPeriod, assessNow);

    try {
      if (assessNow) {
        assessment.assessAllNow(null, null);
      }

      if (!assForm.isAutoReassessment()) {
        autoAssessmentPeriod = -1;
      }
      // FIXME: remove this obsolete functionality
      // assessment.setAutoPeriod(autoAssessmentPeriod);
    } catch (Exception ex) {
      LOG.warn("", ex);
    }

    LOG.debug(PageNames.PRIVACY_ASSESSMENT_SETTINGS + " HTTP POST end");
    return privacyAssessment();
  }
  @SuppressWarnings("unchecked")
  @RequestMapping(value = "/" + PageNames.PRIVACY_ASSESSMENT + ".html", method = RequestMethod.POST)
  public ModelAndView privacyAssessment(
      @Valid PrivacyAssessmentForm assForm, BindingResult result, Map model) {

    LOG.debug(PageNames.PRIVACY_ASSESSMENT + " HTTP POST");

    if (result.hasErrors()) {
      LOG.warn("BindingResult has errors");
      model.put(RESULT, "privacy assessment form error");
      return new ModelAndView(PageNames.PRIVACY_ASSESSMENT, model);
    }

    if (assessment == null) {
      LOG.warn("Privacy Assessment Service reference not avaiable");
      model.put("errormsg", "Privacy Assessment Service reference not avaiable");
      return new ModelAndView("error", model);
    }

    String presentationFormat = assForm.getPresentationFormat();
    String subjectType = assForm.getAssessmentSubjectType();
    LOG.debug("presentationFormat = {}, subjectType = {}", presentationFormat, subjectType);
    Collection<PrivacyAssessmentForm> charts = new ArrayList<PrivacyAssessmentForm>();

    if (presentationFormat.equalsIgnoreCase(Presentation.Format.CHART)) {

      String chartFileName = "chart-1.png";

      String title;
      String xlabel;
      String ylabel;
      PlotData[] plotData;
      String[] plotDataLabels;

      if (subjectType.equalsIgnoreCase(Presentation.SubjectTypes.RECEIVER_IDS_KEY)) {

        title = Presentation.SubjectTypes.RECEIVER_IDS;
        xlabel = "Receiver identity";
        ylabel = "Number of data transmissions";

        Map<IIdentity, Integer> identities;
        identities =
            assessment.getNumDataTransmissionEventsForAllReceivers(new Date(0), new Date());
        LOG.debug("Number of identities data has been transmitted to: {}", identities.size());
        plotData = new PlotData[] {mapToArrays(identities)};
        plotDataLabels = new String[] {"data"};
      } else if (subjectType.equalsIgnoreCase(Presentation.SubjectTypes.SENDER_IDS_KEY)) {

        title = Presentation.SubjectTypes.SENDER_IDS;
        xlabel = "Sender identity";
        ylabel = "Correlation of data transmission and data access";

        HashMap<IIdentity, AssessmentResultIIdentity> assResult;
        assResult = assessment.getAssessmentAllIds(null, null);

        int size = assResult.size();
        IIdentity[] labels = new IIdentity[size];
        double[][] data = new double[2][size];
        Iterator<IIdentity> iterator = assResult.keySet().iterator();

        LOG.debug("privacyAssessment(): size = {}", size);

        for (int k = 0; k < size; k++) {
          labels[k] = iterator.next();
          data[0][k] = assResult.get(labels[k]).getCorrWithDataAccessBySender();
          data[1][k] = assResult.get(labels[k]).getCorrWithDataAccessByAll();

          LOG.debug("privacyAssessment(): label[{}] = {}", k, labels[k]);
          LOG.debug("privacyAssessment(): data[0][{}] = {}", k, data[0][k]);
          LOG.debug("privacyAssessment(): data[1][{}] = {}", k, data[1][k]);
        }

        plotData = new PlotData[] {new PlotData(data[0], labels), new PlotData(data[1], labels)};
        plotDataLabels =
            new String[] {
              "Correlation with data access by the sender identity",
              "Correlation with data access by any identity"
            };
      } else if (subjectType.equalsIgnoreCase(Presentation.SubjectTypes.SENDER_CLASSES_KEY)) {

        title = Presentation.SubjectTypes.SENDER_CLASSES;
        xlabel = "Sender class";
        ylabel = "Correlation of data transmission and data access";

        HashMap<String, AssessmentResultClassName> assResult;
        assResult = assessment.getAssessmentAllClasses(true, null, null);

        int size = assResult.size();
        String[] labels = new String[size];
        double[][] data = new double[2][size];
        Iterator<String> iterator = assResult.keySet().iterator();

        LOG.debug("privacyAssessment(): size = {}", size);

        for (int k = 0; k < size; k++) {
          labels[k] = iterator.next();
          data[0][k] = assResult.get(labels[k]).getCorrWithDataAccessBySender();
          data[1][k] = assResult.get(labels[k]).getCorrWithDataAccessByAll();

          LOG.debug("privacyAssessment(): label[{}] = {}", k, labels[k]);
          LOG.debug("privacyAssessment(): data[0][{}] = {}", k, data[0][k]);
          LOG.debug("privacyAssessment(): data[1][{}] = {}", k, data[1][k]);
        }

        plotData = new PlotData[] {new PlotData(data[0], labels), new PlotData(data[1], labels)};
        plotDataLabels =
            new String[] {
              "Correlation with data access by the sender class",
              "Correlation with data access by any class"
            };
      } else if (subjectType.equalsIgnoreCase(Presentation.SubjectTypes.DATA_ACCESS_CLASSES_KEY)) {

        title = Presentation.SubjectTypes.DATA_ACCESS_CLASSES;
        xlabel = "Class";
        ylabel = "Number of accesses to local data";

        Map<String, Integer> dataAccessClasses;
        dataAccessClasses =
            assessment.getNumDataAccessEventsForAllClasses(true, new Date(0), new Date());
        LOG.debug("Number of data access events (by class): {}", dataAccessClasses.size());
        plotData = new PlotData[] {mapToArrays(dataAccessClasses)};
        plotDataLabels = new String[] {"data"};
      } else if (subjectType.equalsIgnoreCase(Presentation.SubjectTypes.DATA_ACCESS_IDS_KEY)) {

        title = Presentation.SubjectTypes.DATA_ACCESS_IDS;
        xlabel = "Identity";
        ylabel = "Number of accesses to local data";

        Map<IIdentity, Integer> identities;
        identities = assessment.getNumDataAccessEventsForAllIdentities(new Date(0), new Date());
        LOG.debug("Number of data access events (by identity): {}", identities.size());
        plotData = new PlotData[] {mapToArrays(identities)};
        plotDataLabels = new String[] {"data"};
      } else {
        LOG.warn("Unexpected {}: {}", Presentation.SubjectTypes.class.getSimpleName(), subjectType);
        return privacyAssessment();
      }

      PrivacyAssessmentForm form1 = new PrivacyAssessmentForm();
      form1.setAssessmentSubject(title);
      //			createBarchart(null, xlabel, ylabel, dataLabels, data, chartFileName);
      createBarchart(null, xlabel, ylabel, plotData, plotDataLabels, chartFileName);
      form1.setChart(chartFileName);
      charts.add(form1);
      //			PrivacyAssessmentForm form2 = new PrivacyAssessmentForm();
      //			form2.setAssessmentSubject(title + " 2");
      //			form2.setChart(chartFileName);
      //			charts.add(form2);
      model.put("assessmentResults", charts);

      LOG.debug(PageNames.PRIVACY_ASSESSMENT + " HTTP POST end");
      return new ModelAndView(PageNames.PRIVACY_ASSESSMENT_CHART, model);
    } else if (presentationFormat.equalsIgnoreCase(Presentation.Format.TABLE)) {

      HashMap<String, AssessmentResultClassName> assResult;
      assResult = assessment.getAssessmentAllClasses(true, null, null);
      model.put("assessmentResults", assResult.values());

      LOG.debug(PageNames.PRIVACY_ASSESSMENT + " HTTP POST end");
      return new ModelAndView(PageNames.PRIVACY_ASSESSMENT_TABLE, model);
    } else {
      LOG.warn("Unexpected {}: {}", Presentation.Format.class.getSimpleName(), presentationFormat);
      return privacyAssessment();
    }
  }