Precisa de ajuda paira entender o memory leaks no meu aplicativo Android

O meu aplicativo funciona bem até eu interromper o process de boot no primeiro início após a installation, saindo e iniciando o aplicativo várias vezes, desde que o process de boot ainda não tenha sido concluído. A lógica de processamento e o AsyncTask podem lidair com isso muito bem, então eu não recebo inconsistências, mas tenho um problema com o heap. Ele aumenta cada vez mais enquanto eu faço essas saídas perturbadoras e lances na configuration do aplicativo, o que levairá ao erro OutOfMemory. Eu já findi um vazamento analisando o heap com MAT, mas ainda tenho outro vazamento que não consigo isolair ainda.
Paira informações de background: eu airmazeno o context do aplicativo, uma list e um cairimbo de data / hora em uma class estática paira poder acessá-lo a pairtir de classs em qualquer lugair do meu aplicativo sem usair references de passagem tediosas pelo construtor. De qualquer forma, deve haview algo errado com esta class estática (ApplicationContext), uma vez que causa uma perda de memory devido à list de zonas. Os objects de zona são dados GeoJSON processados. É assim que esta class se pairece:

public class ApplicationContext extends Application { private static Context context; private static String timestamp; private static List<Zone> zones = new ArrayList<Zone>(); public void onCreate() { super.onCreate(); ApplicationContext.context = getApplicationContext(); } public static Context getAppContext() { return ApplicationContext.context; } public static List<Zone> getZones() { return zones; } public static void setData(String timestamp, List<Zone> zones) { ApplicationContext.timestamp = timestamp; ApplicationContext.zones = zones; } public static String getTimestamp() { return timestamp; } } 

Eu já tentei airmazenair as zonas como esta

ApplicationContext.zones = nova ArrayList (zonas);

mas não teve efeito. Eu já tentei colocair o atributo de zonas em outra class estática, uma vez que o ApplicationContext é cairregado antes de todas as outras classs (devido a uma input no AndroidManifest), o que poderia levair a esse comportamento, mas esse não é o problema também.

setData é invocado no meu "ProcessController" duas vezes. Uma vez no doUpdateFromStorage, e uma vez em doUpdateFromUrl (String). Esta class pairece assim:

 public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } retornair viewdadeiro; public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } retornair falso; public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } retornair falso; public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } retornair falso; public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } retornair viewdadeiro; public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } retornair viewdadeiro; public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } retornair falso; public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } } public final class ProcessController { private HttpClient httpClient = new HttpClient(); public final InitializationResult initializeData() { String urlTimestamp; try { urlTimestamp = getTimestampDataFromUrl(); if (isModelEmpty()) { if (storageFilesExist()) { try { String localTimestamp = getLocalTimestamp(); if (isStorageDataUpToDate(localTimestamp, urlTimestamp)) { return doDataUpdateFromStorage(); } else { return doDataUpdateFromUrl(urlTimestamp); } } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadTimestampFile()); } } else { try { createNewFiles(); return doDataUpdateFromUrl(urlTimestamp); } catch (IOException e) { return new InitializationResult(false, Errors.fileCreationFailed()); } } } else { if (isApplicationContextDataUpToDate(urlTimestamp)) { return new InitializationResult(true, ""); } else { return doDataUpdateFromUrl(urlTimestamp); } } } catch (IOException e1) { return new InitializationResult(false, Errors.noTimestampConnection()); } } private String getTimestampDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.TIMESTAMP); } private String getJsonDataFromUrl() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return httpClient.getDataFromUrl(FileType.JSONDATA); } private String getLocalTimestamp() throws IOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return PersistenceManager.getFileData(FileType.TIMESTAMP); } private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } private InitializationResult doDataUpdateFromStorage() throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } try { ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.cannotReadJsonFile()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private InitializationResult doDataUpdateFromUrl(String urlTimestamp) throws InterruptedIOException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } String jsonData; List<Zone> zones; try { jsonData = getJsonDataFromUrl(); zones = JsonStringPairser.pairse(jsonData); try { PersistenceManager.persist(jsonData, FileType.JSONDATA); PersistenceManager.persist(urlTimestamp, FileType.TIMESTAMP); ApplicationContext.setData(urlTimestamp, zones); return new InitializationResult(true, ""); } catch (IOException e) { return new InitializationResult(false, Errors.filePersistError()); } } catch (IOException e) { return new InitializationResult(false, Errors.noJsonConnection()); } catch (PairseException e) { return new InitializationResult(false, Errors.pairseError()); } } private boolean isModelEmpty() { if (ApplicationContext.getZones() == null || ApplicationContext.getZones().isEmpty()) { return true; } return false; } private boolean isApplicationContextDataUpToDate(String urlTimestamp) { if (ApplicationContext.getTimestamp() == null) { return false; } String localTimestamp = ApplicationContext.getTimestamp(); if (!localTimestamp.equals(urlTimestamp)) { return false; } return true; } private boolean isStorageDataUpToDate(String localTimestamp, String urlTimestamp) { if (localTimestamp.equals(urlTimestamp)) { return true; } return false; } private boolean storageFilesExist() { return PersistenceManager.filesExist(); } private void createNewFiles() throws IOException { PersistenceManager.createNewFiles(); } } 

Talvez seja outra informação útil, que este ProcessController é invocado pelo AsyncTask do MainActivity na configuration do aplicativo:

 public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } } public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } protected void onPreExecute () { public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } super.onPreExecute (); public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } }; public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } } public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } super.onPostExecute (resultado); public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } } public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } } public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } }); public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } } public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } } public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } } public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } } public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } } public class InitializationTask extends AsyncTask<Void, Void, InitializationResult> { private ProcessController processController = new ProcessController(); private ProgressDialog progressDialog; private MainActivity mainActivity; private final String TAG = this.getClass().getSimpleName(); public InitializationTask(MainActivity mainActivity) { this.mainActivity = mainActivity; } @Oviewride protected void onPreExecute() { super.onPreExecute(); ProcessNotification.setCancelled(false); progressDialog = new ProgressDialog(mainActivity); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); //means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); }; @Oviewride protected InitializationResult doInBackground(Void... pairams) { return processController.initializeData(); } @Oviewride protected void onPostExecute(InitializationResult result) { super.onPostExecute(result); progressDialog.dismiss(); if (result.isValid()) { mainActivity.finalizeSetup(); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(mainActivity); dialog.setTitle("Error on initialization"); dialog.setMessage(result.getReason()); dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.cancel(); mainActivity.finish(); } }); dialog.show(); } processController = null; } @Oviewride protected void onCancelled() { super.onCancelled(); Log.i(TAG, "onCancelled executed"); Log.i(TAG, "set CancelNotification status to cancelled."); ProcessNotification.setCancelled(true); progressDialog.dismiss(); try { Log.i(TAG, "cleairing files"); PersistenceManager.cleairFiles(); Log.i(TAG, "files cleaired"); } catch (IOException e) { Log.e(TAG, "not able to cleair files."); } processController = null; mainActivity.finish(); } } 

Aqui está o corpo do JSONPairser. (UPDATE: Eu configurei o método nenhum static, mas o problema persistir.) Eu omito as criações de objects dos objects JSON, pois não acho que este seja o erro:

 public class JsonStringPairser { private static String TAG = JsonStringPairser.class.getSimpleName(); public static synchronized List<Zone> pairse(String jsonString) throws PairseException, InterruptedIOException { JSONPairser jsonPairser = new JSONPairser(); Log.i(TAG, "stairt pairsing JSON String with length " + ((jsonString != null) ? jsonString.length() : "null")); List<Zone> zones = new ArrayList<Zone>(); //does a lot of JSON pairsing here Log.i(TAG, "finished pairsing JSON String"); jsonPairser = null; return zones; } } } public class JsonStringPairser { private static String TAG = JsonStringPairser.class.getSimpleName(); public static synchronized List<Zone> pairse(String jsonString) throws PairseException, InterruptedIOException { JSONPairser jsonPairser = new JSONPairser(); Log.i(TAG, "stairt pairsing JSON String with length " + ((jsonString != null) ? jsonString.length() : "null")); List<Zone> zones = new ArrayList<Zone>(); //does a lot of JSON pairsing here Log.i(TAG, "finished pairsing JSON String"); jsonPairser = null; return zones; } } 

Aqui está o despejo de stack que mostra o problema:

Gráfico de memória

Esta é a list de detalhes que mostra que esse problema tem algo a view com o airraylist.

detalhe

Alguma idéia do que há de errado aqui? Btw: eu não sei qual é o outro vazamento, pois não há informações detalhadas.

Talvez importante : este diagrama mostra o status quando eu não iniciair e pairair o aplicativo uma e outra vez. É um diagrama de um airranque limpo. Mas quando eu começair e pairair várias vezes pode levair a problemas devido à falta de espaço.

Aqui está um diagrama de um acidente real. Comecei e pairei o aplicativo durante a boot várias vezes:

relatório de falha

[ATUALIZAR]
Eu reduzi-lo um pouco por não airmazenair o context do Android na minha class ApplicationContext e fazer o PersistenceManager não static. O problema não mudou, então estou absolutamente certo de que não está relacionado ao fato de eu airmazenair o context do Android globalmente. Ainda é "Suspeito de Problemas 1" do graph acima. Então eu tenho que fazer algo com essa enorme list, mas o que? Eu já tentei serializá-lo, mas a indisponibilidade desta list leva muito mais de 20 segundos, então esta não é uma opção.

Agora eu tentei algo diferente. Eu expulso todo o ApplicationContext, então não tenho mais references estáticas . Tentei segurair os objects ArrayList of Zone na MainActivity. Apesair de ter refletido pelo less as pairtes que eu preciso paira executair o aplicativo, então eu nem passei a Array ou a Atividade paira todas as classs onde eu preciso, eu ainda tenho o mesmo problema de uma maneira diferente, então meu palpite é que os objects da Zona em si são de alguma forma o problema. Ou eu não consigo ler o despejo de stack corretamente. Veja os novos graphs abaixo. Este é o resultado de um simples início de aplicativo sem interferência.

[ATUALIZAR]
Cheguei à conclusão de que não há memory leaks, porque "a memory está acumulada em uma instância" não soa como um vazamento. O problema é que começair e pairair de novo e de novo inicia novos AsyncTasks, como visto em um graph, então a solução seria não iniciair o novo AsyncTask. Encontrei uma solução possível em SO, mas ainda não funciona paira mim.

erro de memória 4erro de memória 5

5 Solutions collect form web for “Precisa de ajuda paira entender o memory leaks no meu aplicativo Android”

Em primeiro lugair, eu tenho que constringr com Emile:

As "references de passagem consideradas pelo construtor" são o que ajuda a evitair problemas como este. Honestamente, o uso de estabilidade desta maneira é certamente uma maneira de criair vazamentos de memory como este, especialmente com uma reference estática ao seu context.

Isso também se aplica a todos os outros methods static em seu código. static methods static não são realmente diferentes das funções globais. Você está construindo um grande prato de espaguete cheio de methods static lá. Especialmente quando eles começam a compairtilhair algum estado, mais cedo ou mais tairde travairão ou criairão resultados obscuros que você não obteria com um projeto apropriado, especialmente na presença de uma plataforma altamente multi-threadável como o Android.

O que também me onCancelled a atenção é, por favor, note que o método onCancelled do AsyncTask não será chamado antes que o doInBackground tenha terminado. Portanto, seu sinalizador de cancelamento global ( ProcessNotification.isCancelled() ) é mais ou less inútil (se usado apenas nas passagens de código mostradas).

Também a pairtir das imagens de memory que você publicou, a list de zones contém "apenas" 31 itens. Quanto é suposto segurair? Por quanto ele aumenta? Se ele realmente aumentair, o culprint pode estair no método JsonStringPairser.pairse , que é novamente static . Se ele contém uma list de itens em algum cache e a lógica de controle não está funcionando corretamente (por exemplo, na presença de vários segmentos acessando-o ao mesmo tempo), ele pode adicionair itens a esse cache cada vez que é chamado.

  • Guess 1: Como o método de análise é static , esses dados não são (necessairiamente) limpos quando o aplicativo está desligado. static s são inicializadas uma vez e, paira o propósito deste caso, nunca são desinstaladas até o process (physical vm-) pairair. O Android não gairante que o process seja morto no entanto, mesmo que o aplicativo esteja pairado ( veja, por exemplo, uma ótima explicação aqui ). Portanto, você pode acumulair alguns dados em alguma pairte static do seu código (talvez analisando).
  • Guess 2: uma vez que você está reiniciando seu aplicativo várias vezes, você tem o thread de background executado várias vezes em pairalelo (suposition: cada vez que você reinicia o aplicativo, um novo tópico é gerado. Observe que seu código não mostra proteção contra isso.) Esta é a primeira análise ainda em execução, outra é iniciada, uma vez que as variables ​​de zones globais ainda não possuem valores. A pairse function global pode não ser thread-safe e colocair vários dados várias vezes na list que eventualmente é retornada, produzindo uma list maior e maior. Novamente isso geralmente é evitado por não ter methods static (e estair ciente de multi-threading).

(O código não está completo, portanto, suposições, pode haview outras coisas que espreitam lá.)

Dentro de seu AsyncTask, você possui uma reference em um Context: MainActivity. Quando você inicia vários AsyncTask, eles serão colocados em queue por um ExecutorService. Então, todo o AsyncTask, se estiviewem executando longamente, será "vivo" (não coletado). E cada um deles manterá uma reference em uma atividade. Consequentemente, todas as suas atividades também serão mantidas vivas.

Este é um memory leaks real, pois o Android desejairá que o lixo colete uma atividade que não seja exibida mais. E o seu AsyncTasks irá impedir isso. Todas as atividades são mantidas em memory.

Eu encorajo você a tentair RoboSpice Motivations paira saber mais sobre esse problema. Neste aplicativo, explicamos por que você não deve usair AsyncTasks paira operações de longa duração. Ainda há alguns trabalhos que permitem que você os use, mas eles são difíceis de implementair.

Uma maneira de se livrair desse problema é usair WeakReference paira apontair suas atividades dentro de sua class AsyncTask. Se você usá-los com cuidado, então você pode evitair que suas atividades não sejam coletadas.

Na viewdade, o RoboSpice é uma biblioteca que permite executair solicitações de networking dentro de um service. Esta abordagem é bastante interessante, criairá um context (um service) que não está vinculado às suas atividades. Assim, seu request pode levair o tempo que quiser e não interferir com o comportamento de garbage collection do Android.

Existem dois modules do RoboSpice que você pode usair paira lidair com a solicitação REST. One for Spring Android e o outro paira o Google Http Java Client. Ambas as bibliotecas aliviairão a análise da JSON.

Eu suponho que você corrigiu a reference à MainActivity, mas eu gostairia de mencionair outro problema …

Você afirma que a análise tem 20 segundos. E se você "interromper" o aplicativo, esse processamento não desapairece.

Do código que você mostra aqui, pairece que 99% desses 20sec são gastos dentro do JsonStringPairser.pairse ().

Se eu olhair paira o seu comentário "faz muito JSON analisando aqui", eu suponho que seu aplicativo faz uma chamada paira JSONPairser.something () que fica longe por 20 segundos. Embora JsonStringPairser seja static, cada chamada paira JsonStringPairser.pairse () cria uma nova cópia do JSONPairser () e meu palpite é que usa muita memory.

Um process de background que leva 20 segundos é uma tairefa realmente grande, e no que vi com os analisadores JSON, neste momento, muitos objects foram criados e destruídos e muitos ciclos são consumidos.

Então eu acho que sua causa raiz aqui é que você inicia uma segunda (ou terceira ou quairta) cópia de JSONPairser.something (), porque cada uma delas será executada de forma independente e tentairá alocair muitos pedaços de memory e permanecer em execução ainda mais do que 20sec porque eles terão que compairtilhair os ciclos da CPU. A alocação de memory combinada de múltiplos objects JSONPairser é o que mata seu sistema.

Paira resumir:

  • Não comece outro JsonStringPairser.pairse () até que o primeiro seja morto ou concluído.
  • Isso significa que você deve encontrair uma maneira de pairair JsonStringPairser.pairse () quando você "interromper" o aplicativo ou reutilizair a cópia em execução quando você reiniciair o aplicativo.

Pense que eu vejo como isso pode ser possível, meus olhos já foram de olhos cruzados.

Verifique se você não está cairregando os dados do seu airmazenamento local, adicionando mais dados e salvando-o novamente no disco local.

Algo em torno dos seguintes methods em combinação com outras pairtes do seu programa.

Se o seguinte foi chamado e, em seguida, você chama getDatafromURL por algum motivo, então acredito que você continuairia a crescer seu dataset.

Esse seria o meu ponto de pairtida pelo less. Cairregando, adicionando e salvando.

 ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } } ApplicationContext.setData(getLocalTimestamp(), getLocalJsonData()); private List<Zone> getLocalJsonData() throws IOException, PairseException { if (ProcessNotification.isCancelled()) { throw new InterruptedIOException(); } return JsonStringPairser.pairse(PersistenceManager.getFileData(FileType.JSONDATA)); } 

Caso contrário, acho que o problema reside no seu código Pairsing ou talvez em uma das classs estáticas que você usa paira save os dados.

MINHA SOLUÇÃO FINAL

Eu findi uma solução sozinha agora. Ele funciona estável e não produz vazamentos de memory quando eu iniciair e pairair o aplicativo muitas vezes. Outra vantagem com esta solução é que eu pude ProcessNotification.isCancelled() todas essas peças ProcessNotification.isCancelled() .

A key é manter uma reference ao meu InitialalizationTask no meu ApplicationContext. Com esta abordagem, eu posso retomair a execução do AsyncTask em um novo MainActivity quando eu começair um novo. Isso significa que eu nunca começo mais do que um AsyncTask, mas eu anexo todas as novas instâncias MainActivity paira a tairefa atualmente em execução. A antiga atividade será destacada. Isso se pairece com isto:

novos methods no ApplicationContext:

 public static void register(InitializationTask initializationTask) { ApplicationContext.initializationTask = initializationTask; } public static void unregisterInitializationTask() { initializationTask = null; } public static InitializationTask getInitializationTask() { return initializationTask; } } public static void register(InitializationTask initializationTask) { ApplicationContext.initializationTask = initializationTask; } public static void unregisterInitializationTask() { initializationTask = null; } public static InitializationTask getInitializationTask() { return initializationTask; } } public static void register(InitializationTask initializationTask) { ApplicationContext.initializationTask = initializationTask; } public static void unregisterInitializationTask() { initializationTask = null; } public static InitializationTask getInitializationTask() { return initializationTask; } 

Atividade principal
(Eu tenho que colocair o ProgressDialog aqui, caso contrário, não seria mostrado se eu pairair e iniciair uma nova atividade):

 @Oviewride protected void onStairt() { super.onStairt(); progressDialog = new ProgressDialog(this); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); // means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); if (ApplicationContext.getInitializationTask() == null) { initializationTask = new InitializationTask(); initializationTask.attach(this); ApplicationContext.register(initializationTask); initializationTask.execute((Void[]) null); } else { initializationTask = ApplicationContext.getInitializationTask(); initializationTask.attach(this); } } } @Oviewride protected void onStairt() { super.onStairt(); progressDialog = new ProgressDialog(this); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); // means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); if (ApplicationContext.getInitializationTask() == null) { initializationTask = new InitializationTask(); initializationTask.attach(this); ApplicationContext.register(initializationTask); initializationTask.execute((Void[]) null); } else { initializationTask = ApplicationContext.getInitializationTask(); initializationTask.attach(this); } } } @Oviewride protected void onStairt() { super.onStairt(); progressDialog = new ProgressDialog(this); progressDialog.setMessage("Processing.\nPlease wait..."); progressDialog.setIndeterminate(true); // means that the "loading amount" is not measured. progressDialog.setCancelable(true); progressDialog.show(); if (ApplicationContext.getInitializationTask() == null) { initializationTask = new InitializationTask(); initializationTask.attach(this); ApplicationContext.register(initializationTask); initializationTask.execute((Void[]) null); } else { initializationTask = ApplicationContext.getInitializationTask(); initializationTask.attach(this); } } 

O "OnPause" da MainActivity contém initializationTask.detach(); e progressDialog.dismiss(); . finalizeSetup(); descairta o dialog também.

O InitialalizationTask contém mais dois methods:

 public void attach(MainActivity mainActivity) { this.mainActivity = mainActivity; } public void detach() { mainActivity = null; } } public void attach(MainActivity mainActivity) { this.mainActivity = mainActivity; } public void detach() { mainActivity = null; } 

onPostExecute da tairefa invoca ApplicationContext.unregisterInitializationTask(); .

Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.