use of com.pratilipi.data.type.gae.NavigationEntity in project pratilipi by Pratilipi.
the class DataAccessorMockImpl method getNavigationList.
// NAVIGATION Table
@Override
public List<Navigation> getNavigationList(Language language) {
ArrayList<Navigation> navigationList = null;
List<String> lines = null;
try {
String fileName = CURATED_DATA_FOLDER + "/navigation." + language.getCode();
InputStream inputStream = DataAccessor.class.getResource(fileName).openStream();
lines = IOUtils.readLines(inputStream, "UTF-8");
inputStream.close();
} catch (NullPointerException | IOException e) {
logger.log(Level.SEVERE, "Failed to fetch " + language.getNameEn() + " navigation list.", e);
lines = new ArrayList<>(0);
}
navigationList = new ArrayList<>(lines.size());
Navigation navigation = null;
for (String line : lines) {
line = line.trim();
if (navigation == null && line.isEmpty())
continue;
else if (navigation == null && !line.isEmpty())
navigation = new NavigationEntity(line);
else if (navigation != null && line.isEmpty()) {
navigationList.add(navigation);
navigation = null;
} else if (navigation != null && !line.isEmpty()) {
String url = null;
String title = null;
String categoryName = null;
String imageName = null;
String apiName = null;
String apiRequest = null;
if (line.contains("App#")) {
String appInfo = line.substring(line.indexOf("App#")).trim();
imageName = appInfo.substring("App#imageName::".length(), appInfo.lastIndexOf("App#")).trim();
apiName = appInfo.substring(appInfo.lastIndexOf("App#") + 4, appInfo.lastIndexOf("::")) + "Api";
apiRequest = line.substring(line.indexOf('{'), line.indexOf('}') + 1);
line = line.substring(0, line.indexOf("App#")).trim();
}
if (line.contains("Analytics#")) {
String analyticsInfo = line.substring(line.indexOf("Analytics#")).trim();
categoryName = analyticsInfo.substring("Analytics#categoryName::".length()).trim();
line = line.substring(0, line.indexOf("Analytics#")).trim();
}
if (line.indexOf(' ') != -1) {
url = line.substring(0, line.indexOf(' '));
title = line.substring(line.indexOf(' ') + 1).trim();
}
navigation.addLink(new Navigation.Link(title, url, apiName, categoryName, apiRequest, imageName));
}
}
if (navigation != null)
navigationList.add(navigation);
return navigationList;
}
use of com.pratilipi.data.type.gae.NavigationEntity in project pratilipi by Pratilipi.
the class DataAccessorGaeImpl method getNavigationList.
// curated/navigation.<lang>
@Override
public List<Navigation> getNavigationList(Language language) {
String memcacheId = "CuratedData.NavigationList-" + language.getCode() + "?" + (new Date().getTime() / TimeUnit.MINUTES.toMillis(15)) + "/" + SystemProperty.STAGE;
ArrayList<Navigation> navigationList = memcache.get(memcacheId);
if (navigationList != null)
return navigationList;
List<String> lines = null;
try {
String fileName = CURATED_DATA_FOLDER + "/navigation." + language.getCode();
InputStream inputStream = DataAccessor.class.getResource(fileName).openStream();
lines = IOUtils.readLines(inputStream, "UTF-8");
inputStream.close();
} catch (NullPointerException | IOException e) {
logger.log(Level.SEVERE, "Failed to fetch " + language.getNameEn() + " navigation list.", e);
lines = new ArrayList<>(0);
}
navigationList = new ArrayList<>(lines.size());
Navigation navigation = null;
for (String line : lines) {
line = line.trim();
if (navigation == null && line.isEmpty())
continue;
else if (navigation == null && !line.isEmpty())
navigation = new NavigationEntity(line);
else if (navigation != null && line.isEmpty()) {
navigationList.add(navigation);
navigation = null;
} else if (navigation != null && !line.isEmpty()) {
String url = null;
String title = null;
String categoryName = null;
String imageName = null;
String apiName = null;
String apiRequest = null;
if (line.contains("App#")) {
String appInfo = line.substring(line.indexOf("App#")).trim();
imageName = appInfo.substring("App#imageName::".length(), appInfo.lastIndexOf("App#")).trim();
apiName = appInfo.substring(appInfo.lastIndexOf("App#") + 4, appInfo.lastIndexOf("::")) + "Api";
apiRequest = line.substring(line.indexOf('{'), line.indexOf('}') + 1);
line = line.substring(0, line.indexOf("App#")).trim();
}
if (line.contains("Analytics#")) {
String analyticsInfo = line.substring(line.indexOf("Analytics#")).trim();
categoryName = analyticsInfo.substring("Analytics#categoryName::".length()).trim();
line = line.substring(0, line.indexOf("Analytics#")).trim();
}
if (line.indexOf(' ') != -1) {
url = line.substring(0, line.indexOf(' '));
title = line.substring(line.indexOf(' ') + 1).trim();
}
navigation.addLink(new Navigation.Link(title, url, apiName, categoryName, apiRequest, imageName));
}
}
if (navigation != null)
navigationList.add(navigation);
memcache.put(memcacheId, navigationList);
return navigationList;
}
Aggregations