Exemplo n.º 1
0
 @Override
 protected Model blank() {
   log.info("Loading empty model!!");
   final Model mod = new Model(countryService);
   processCommandLine(this.commandLine, mod);
   return mod;
 }
Exemplo n.º 2
0
  /**
   * Reads the state model from disk.
   *
   * @return The {@link Model} instance as read from disk.
   */
  @Override
  public Model read() {
    try {
      final Model read = super.read();
      read.setCountryService(countryService);
      if (!LanternUtils.persistCredentials()) {
        if (read.getModal() != Modal.welcome) {
          read.setModal(Modal.authorize);
        }
      }

      // Make sure all peers are considered offline at startup.
      final Peers peers = read.getPeerCollector();
      peers.reset();
      if (read.getModal() == Modal.settingsLoadFailure) {
        read.setModal(Modal.none);
      }
      boolean isCensored = false;
      String countryCode = read.getLocation().getCountry();
      if (countryCode != null) {
        Country country = countryService.getCountryByCode(countryCode);
        if (country != null) {
          isCensored = country.isCensors();
        }
      }
      if (!isCensored && read.getModal() == Modal.giveModeForbidden) {
        read.setModal(Modal.none);
      }
      LanternUtils.setModel(read);
      processCommandLine(this.commandLine, read);
      return read;
    } catch (final ModelReadFailedException e) {
      log.error("Failed to read model", e);
      Model blank = blank();
      blank.setModal(Modal.settingsLoadFailure);
      return blank;
    } catch (final Exception e) {
      log.error("Failed to read model for some other reason", e);
      Model blank = blank();
      return blank;
    }
  }