Search in sources :

Example 1 with NavigationData

use of com.pratilipi.data.client.NavigationData in project pratilipi by Pratilipi.

the class NavigationDataUtil method getNavigationDataList.

public static List<NavigationData> getNavigationDataList(Language language) throws UnexpectedServerException {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    List<Navigation> navigationList = dataAccessor.getNavigationList(language);
    List<NavigationData> navigationDataList = new ArrayList<>(navigationList.size());
    for (Navigation navigation : navigationList) navigationDataList.add(new NavigationData(navigation.getTitle(), navigation.getLinkList()));
    return navigationDataList;
}
Also used : Navigation(com.pratilipi.data.type.Navigation) DataAccessor(com.pratilipi.data.DataAccessor) ArrayList(java.util.ArrayList) NavigationData(com.pratilipi.data.client.NavigationData)

Example 2 with NavigationData

use of com.pratilipi.data.client.NavigationData in project pratilipi by Pratilipi.

the class NavigationListApi method get.

@Get
public Response get(GetRequest request) throws UnexpectedServerException {
    Gson gson = new Gson();
    List<NavigationData> navigationList = NavigationDataUtil.getNavigationDataList(request.language);
    if (UxModeFilter.isAndroidApp()) {
        for (NavigationData navigationData : navigationList) {
            for (Navigation.Link link : navigationData.getLinkList()) {
                if (link.getApiRequest() == null)
                    continue;
                JsonObject apiRequest = gson.fromJson((String) link.getApiRequest(), JsonElement.class).getAsJsonObject();
                link.setApiRequest(apiRequest);
            }
        }
        if (navigationList.size() > 2) {
            for (Navigation.Link link : navigationList.get(2).getLinkList()) navigationList.get(0).addLink(link);
            navigationList = navigationList.subList(0, 2);
        }
        NavigationData navigationData = navigationList.remove(0);
        navigationList.add(navigationData);
    } else {
        for (NavigationData navigationData : navigationList) {
            for (Navigation.Link link : navigationData.getLinkList()) {
                link.setApiName(null);
                link.setApiRequest(null);
            }
        }
    }
    return new Response(navigationList);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) Navigation(com.pratilipi.data.type.Navigation) JsonElement(com.google.gson.JsonElement) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) NavigationData(com.pratilipi.data.client.NavigationData) Get(com.pratilipi.api.annotation.Get)

Aggregations

NavigationData (com.pratilipi.data.client.NavigationData)2 Navigation (com.pratilipi.data.type.Navigation)2 Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Get (com.pratilipi.api.annotation.Get)1 GenericResponse (com.pratilipi.api.shared.GenericResponse)1 DataAccessor (com.pratilipi.data.DataAccessor)1 ArrayList (java.util.ArrayList)1