<commit_before>package org.openbaton.nfvo.core.api;

import org.openbaton.catalogue.security.HistoryEntity;
import org.openbaton.catalogue.security.User;
import org.openbaton.exceptions.NotFoundException;
import org.openbaton.nfvo.repositories.HistoryEntityRepository;
import org.openbaton.nfvo.security.interfaces.UserManagement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;

import javax.annotation.PostConstruct;

/**
 * Created by lto on 17/10/16.
 */
@Service
public class HistoryManagement implements org.openbaton.nfvo.core.interfaces.HistoryManagement {

  @Autowired private UserManagement userManagement;
  @Autowired private HistoryEntityRepository historyEntityRepository;

  @Value("${nfvo.history.max-entities:250}")
  private int maxHistoryEntities;

  @Value("${nfvo.history.level:1}")
  private int historyLevel;

  private Logger log = LoggerFactory.getLogger(this.getClass());

  @Value("${nfvo.history.clear:false}")
  private boolean clearHistory;

  @PostConstruct
  private void init() {
    if (clearHistory) {
      log.warn("Cleaning history of actions");
      historyEntityRepository.deleteAll();
    }
  }

  @Override
  public void addAction(String method, String path, String result) throws NotFoundException {

    if (historyLevel > 0) {
      if ((historyLevel == 1 && (method.equalsIgnoreCase("get") || method.equalsIgnoreCase("put")))
          || (historyLevel == 2 && method.equalsIgnoreCase("get"))) {
        log.trace("skipping method get or put");
        return;
      }
      User user = userManagement.getCurrentUser();

      HistoryEntity historyEntity = new HistoryEntity();
<commit_msg>Fix: catch exception in history management<commit_after>package org.openbaton.nfvo.core.api;

import org.openbaton.catalogue.security.HistoryEntity;
import org.openbaton.catalogue.security.User;
import org.openbaton.exceptions.NotFoundException;
import org.openbaton.nfvo.repositories.HistoryEntityRepository;
import org.openbaton.nfvo.security.interfaces.UserManagement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;

import javax.annotation.PostConstruct;

/**
 * Created by lto on 17/10/16.
 */
@Service
public class HistoryManagement implements org.openbaton.nfvo.core.interfaces.HistoryManagement {

  @Autowired private UserManagement userManagement;
  @Autowired private HistoryEntityRepository historyEntityRepository;

  @Value("${nfvo.history.max-entities:250}")
  private int maxHistoryEntities;

  @Value("${nfvo.history.level:1}")
  private int historyLevel;

  private Logger log = LoggerFactory.getLogger(this.getClass());

  @Value("${nfvo.history.clear:false}")
  private boolean clearHistory;

  @PostConstruct
  private void init() {
    if (clearHistory) {
      log.warn("Cleaning history of actions");
      historyEntityRepository.deleteAll();
    }
  }

  @Override
  public void addAction(String method, String path, String result) throws NotFoundException {

    if (historyLevel > 0) {
      if ((historyLevel == 1 && (method.equalsIgnoreCase("get") || method.equalsIgnoreCase("put")))
          || (historyLevel == 2 && method.equalsIgnoreCase("get"))) {
        log.trace("skipping method get or put");
        return;
      }
      User user = null;
      try {
        user = userManagement.getCurrentUser();
      } catch (org.openbaton.exceptions.NotFoundException ex) {
        log.warn("Not storing requests from anonymousUser");
        return;
      }

      HistoryEntity historyEntity = new HistoryEntity();

{'fraction_non_alphanumeric': 0.11188290746712974, 'fraction_numerical': 0.007442322004465393, 'mean_word_length': 4.576763485477178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '536690', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1143, 'n_words': 239}