All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.escalon.hypermedia.sample.event.EventBackend Maven / Gradle / Ivy

There is a newer version: 0.4.2
Show newest version
package de.escalon.hypermedia.sample.event;

import de.escalon.hypermedia.sample.beans.event.Rating;
import de.escalon.hypermedia.sample.beans.event.Review;
import de.escalon.hypermedia.sample.model.event.CreativeWork;
import de.escalon.hypermedia.sample.model.event.EventModel;
import de.escalon.hypermedia.sample.model.event.EventStatusType;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * Created by dschulten on 28.12.2014.
 */
@Component
public class EventBackend {

    Map eventModels = new HashMap();

    Map> reviews = new HashMap>();

    private static int count = 0;

    public EventBackend() {

        count++;
        eventModels.put(count, new EventModel(count, "Walk off the Earth", new CreativeWork("Gang of Rhythm Tour"),
                "Wiesbaden", EventStatusType.EVENT_SCHEDULED));
        reviews.put(count, new ArrayList(Arrays.asList(new Review("Five peeps, one guitar", new Rating(5)))));


        count++;
        eventModels.put(count, new EventModel(count, "Cornelia Bielefeldt", new CreativeWork("Mein letzter Film"),
                "Heilbronn", EventStatusType.EVENT_SCHEDULED));
        reviews.put(count, new ArrayList(Arrays.asList(new Review("Great actress, special atmosphere", new
                Rating(5)))));
    }

    public Collection getEvents() {
        return eventModels.values();
    }

    public int addEvent(EventModel eventModel) {
        count++;
        eventModels.put(count, eventModel.withEventId(count));
        return count;
    }

    public void updateEvent(int eventId, EventStatusType eventStatus) {
        EventModel eventModel = eventModels.get(eventId);
        eventModels.put(eventId, eventModel.withEventStatus(eventStatus));
    }

    public EventModel getEvent(int eventId) {
        return eventModels.get(eventId);
    }

    public void deleteEvent(int eventId) {
        eventModels.remove(eventId);
        reviews.remove(eventId);
    }

    public Map> getReviews() {
        return reviews;
    }

    public void addReview(int eventId, String reviewBody, Rating reviewRating) {
        EventModel eventModel = eventModels.get(eventId);
        if (eventModel != null) {
            List reviewsForEvent = reviews.get(eventId);
            if (reviewsForEvent == null) {
                reviewsForEvent = new ArrayList();
                reviews.put(eventId, reviewsForEvent);
            }
            reviewsForEvent.add(new Review(reviewBody, reviewRating));
        } else {
            throw new NoSuchElementException("not found");
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy