Skip to content

Commit

Permalink
quick hack to update urls - some things still broke
Browse files Browse the repository at this point in the history
  • Loading branch information
pyckle committed Jul 2, 2024
1 parent 63ea18e commit 05930df
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.pyckle.oref.alerts;

import com.github.pyckle.oref.alerts.categories.AlertCategories;
import com.github.pyckle.oref.alerts.categories.dto.AlertCategory;
import com.github.pyckle.oref.alerts.details.AlertDetails;
import com.github.pyckle.oref.alerts.details.AlertDetailsFactory;
import com.github.pyckle.oref.integration.activealerts.ActiveAlert;
Expand All @@ -10,6 +11,7 @@
import com.github.pyckle.oref.integration.config.OrefConfig;
import com.github.pyckle.oref.integration.datetime.OrefDateTimeUtils;
import com.github.pyckle.oref.integration.dto.AlertHistory;
import com.github.pyckle.oref.integration.dto.Category;
import com.github.pyckle.oref.integration.dto.HistoryEventWithParsedDates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -29,6 +31,7 @@ public class AlertsManager {

private final OrefApiCachingService orefApiCachingService;
private final AlertDetailsFactory alertDetailsFactory;
private final OrefConfig orefConfig;
private volatile AlertStatus currentAlerts = emptyStatus();

public static AlertStatus emptyStatus() {
Expand All @@ -38,6 +41,7 @@ public static AlertStatus emptyStatus() {
public AlertsManager(OrefConfig orefConfig, OrefApiCachingService orefApiCachingService) {
this.orefApiCachingService = orefApiCachingService;
this.alertDetailsFactory = new AlertDetailsFactory(orefConfig, orefApiCachingService);
this.orefConfig = orefConfig;
}

/**
Expand Down Expand Up @@ -117,6 +121,22 @@ private void addAlertDetails(boolean historicalEvent, List<String> alertedAreas,
List<AlertDetails> alertDetails, Instant receivedTimestamp, LocalDateTime groupedDateTime) {
if (!alertedAreas.isEmpty()) {
String translatedCategory = orefApiCachingService.getAlertDescriptions().retrievedValue().getAlertStringFromCatId(category, categoryHeb);
// alert descriptions service failed. Try alert categories
if (translatedCategory.equals(categoryHeb)) {

// need to go from cat to matrix id:
int matCat = Integer.MIN_VALUE;
for (Category c : orefApiCachingService.getCategoriesApi().retrievedValue()) {
if (c.id() == category) {
matCat = c.matrix_id();
break;
}
}
translatedCategory = AlertCategories.INSTANCE.getAlertCategory(String.valueOf(matCat))
.map(AlertCategory::alertName)
.map(mls -> mls.inLang(orefConfig.getLang(), categoryHeb))
.orElse(categoryHeb);
}
alertDetails.add(alertDetailsFactory.buildAlertDetailsFromHistory(historicalEvent, AlertCategories.INSTANCE.isDrill(category),
translatedCategory, categoryHeb, receivedTimestamp, groupedDateTime, alertedAreas));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

public class OrefApiUris {
private static final String URI_BASE = "https://www.oref.org.il";
private static final String URI_BASE_HISTORY = "https://alerts-history.oref.org.il";

/**
* Request to fetch history of historical events
Expand Down Expand Up @@ -39,20 +40,24 @@ public class OrefApiUris {
public OrefApiUris(OrefConfig orefConfig) {
String lang = orefConfig.getLang();

alertsUri = URI.create(URI_BASE + "/WarningMessages/alert/alerts.json?v=1");
alertsHistoryUri = URI.create(URI_BASE + "/WarningMessages/History/AlertsHistory.json?v=1");
alertsUri = URI.create(URI_BASE + "/warningMessages/alert/Alerts.json");

// this appears to be removed. Need to replace with something else
alertsHistoryUri = URI.create(URI_BASE_HISTORY + "warningMessages/alert/History/AlertsHistory.json");

// we use this for translation, need to move to: https://www.oref.org.il/alerts/alertsTranslation.json
leftoversUri = URI.create(URI_BASE + "/Leftovers/" + lang.toUpperCase(Locale.ENGLISH) + ".Leftovers.json");

// mode 1 is 1 day.
// mode 2 is 1 week.
// mode 3 is 1 month.
historyUri =
URI.create(URI_BASE + "/Shared/Ajax/GetAlarmsHistory.aspx?lang=he&mode=3");
URI.create(URI_BASE_HISTORY + "/Shared/Ajax/GetAlarmsHistory.aspx?lang=he&mode=3");

categoriesUri = URI.create(URI_BASE + "/Shared/Ajax/GetAlertCategories.aspx");
// this appears to be removed. Need to replace with something else
categoriesUri = URI.create(URI_BASE + "/alerts/alertCategories.json");
districtsUri = URI.create(
URI_BASE + "/Shared/Ajax/GetDistricts.aspx?lang=" + lang);
URI_BASE_HISTORY + "/Shared/Ajax/GetDistricts.aspx?lang=" + lang);
}


Expand Down

0 comments on commit 05930df

Please sign in to comment.