Search in sources :

Example 1 with EventData

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

the class EventApi method get.

@Get
public Response get(GetRequest request) {
    DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
    Event event = dataAccessor.getEvent(request.eventId);
    EventData eventData = EventDataUtil.createEventData(event, true);
    return new Response(eventData);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) DataAccessor(com.pratilipi.data.DataAccessor) Event(com.pratilipi.data.type.Event) EventData(com.pratilipi.data.client.EventData) Get(com.pratilipi.api.annotation.Get)

Example 2 with EventData

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

the class EventApi method post.

@Post
public Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException {
    Gson gson = new Gson();
    EventData eventData = gson.fromJson(gson.toJson(request), EventData.class);
    eventData = EventDataUtil.saveEventData(eventData);
    return new Response(eventData);
}
Also used : GenericResponse(com.pratilipi.api.shared.GenericResponse) Gson(com.google.gson.Gson) EventData(com.pratilipi.data.client.EventData) Post(com.pratilipi.api.annotation.Post)

Example 3 with EventData

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

the class PratilipiSite method createDataModelForEventsPage.

public Map<String, Object> createDataModelForEventsPage(Language language, boolean basicMode) throws InsufficientAccessException, UnexpectedServerException {
    EventData eventData = new EventData();
    eventData.setLanguage(language);
    boolean hasAccessToAdd = EventDataUtil.hasAccessToAddEventData(eventData);
    EventListApi.GetRequest request = new EventListApi.GetRequest();
    request.setLanguage(language);
    EventListApi.GetResponse eventListResponse = ApiRegistry.getApi(EventListApi.class).get(request);
    Map<String, Object> dataModel = new HashMap<String, Object>();
    dataModel.put("title", SEOTitleUtil.getEventsPageTitle(language));
    dataModel.put("hasAccessToAdd", hasAccessToAdd);
    if (basicMode) {
        dataModel.put("eventList", eventListResponse.getEventList());
    } else {
        dataModel.put("eventListJson", new Gson().toJson(eventListResponse.getEventList()));
    }
    return dataModel;
}
Also used : EventListApi(com.pratilipi.api.impl.event.EventListApi) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) EventData(com.pratilipi.data.client.EventData)

Example 4 with EventData

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

the class EventDataUtil method createEventDataList.

public static List<EventData> createEventDataList(List<Event> eventList) {
    List<Long> eventIdList = new ArrayList<>();
    for (Event event : eventList) eventIdList.add(event.getId());
    Map<Long, Page> eventPages = DataAccessorFactory.getDataAccessor().getPages(PageType.EVENT, eventIdList);
    List<EventData> eventDataList = new ArrayList<>();
    for (Event event : eventList) eventDataList.add(createEventData(event, eventPages.get(event.getId()), false));
    return eventDataList;
}
Also used : Event(com.pratilipi.data.type.Event) Page(com.pratilipi.data.type.Page) EventData(com.pratilipi.data.client.EventData)

Example 5 with EventData

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

the class EventDataUtil method createEventData.

public static EventData createEventData(Event event, Page eventPage, Boolean includePratilipiList) {
    EventData eventData = new EventData();
    eventData.setId(event.getId());
    eventData.setName(event.getName());
    eventData.setNameEn(event.getNameEn());
    eventData.setLanguage(event.getLanguage());
    eventData.setDescription(event.getDescription());
    eventData.setPageUrl(eventPage.getUriAlias() == null ? eventPage.getUri() : eventPage.getUriAlias());
    eventData.setBannerImageUrl(createEventBannerUrl(event));
    eventData.setAccessToUpdate(hasAccessToUpdateEventData(event, null));
    if (includePratilipiList) {
        eventData.setPratilipiIdList(event.getPratilipiIdList());
        if (event.getPratilipiIdList() == null || event.getPratilipiIdList().size() == 0) {
            eventData.setPratilipiUrlList(new ArrayList<String>(0));
        } else {
            Map<Long, Page> pratilipiPages = DataAccessorFactory.getDataAccessor().getPages(PageType.PRATILIPI, event.getPratilipiIdList());
            List<String> pratilipiUrlList = new ArrayList<>(event.getPratilipiIdList().size());
            for (Long pratilipiId : event.getPratilipiIdList()) {
                Page pratilipiPage = pratilipiPages.get(pratilipiId);
                if (pratilipiPage != null)
                    pratilipiUrlList.add(pratilipiPage.getUriAlias() == null ? pratilipiPage.getUri() : pratilipiPage.getUriAlias());
            }
            eventData.setPratilipiUrlList(pratilipiUrlList);
        }
    }
    return eventData;
}
Also used : Page(com.pratilipi.data.type.Page) EventData(com.pratilipi.data.client.EventData)

Aggregations

EventData (com.pratilipi.data.client.EventData)5 Gson (com.google.gson.Gson)2 GenericResponse (com.pratilipi.api.shared.GenericResponse)2 Event (com.pratilipi.data.type.Event)2 Page (com.pratilipi.data.type.Page)2 JsonObject (com.google.gson.JsonObject)1 Get (com.pratilipi.api.annotation.Get)1 Post (com.pratilipi.api.annotation.Post)1 EventListApi (com.pratilipi.api.impl.event.EventListApi)1 DataAccessor (com.pratilipi.data.DataAccessor)1 HashMap (java.util.HashMap)1