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

events.system.service.EventRatingsBusinessService Maven / Gradle / Ivy

package events.system.service;

import hbm.service.jpa.AbstractBusinessService;

import java.util.List;

import javax.persistence.Query;

import de.alpharogroup.collections.ListExtensions;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import rating.system.enums.RatingVisibility;
import user.management.model.Users;
import events.system.daos.EventRatingsDao;
import events.system.model.EventRatings;
import events.system.model.EventTemplate;
import events.system.model.RatingDescriptions;
import events.system.service.api.EventRatingsService;

@Transactional
@Service("eventRatingsService")
public class EventRatingsBusinessService
		extends
		AbstractBusinessService
		implements EventRatingsService {

	private static final long serialVersionUID = 1L;

	@Autowired
	public void setEventRatingsDao(EventRatingsDao eventRatingsDao) {
		setDao(eventRatingsDao);
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	public List findAllUsersForRatedEvent(final EventTemplate event) {
		final String hqlString = "select distinct er.rater from EventRatings er where er.event=:event";
		final Query query = getQuery(hqlString);
		query.setParameter("event", event);
		List foundUsers = query.getResultList();
		return foundUsers;
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	public List findEventRatings(final EventTemplate event) {
		final String hqlString = "select er from EventRatings er where er.event=:event";
		final Query query = getQuery(hqlString);
		query.setParameter("event", event);
		List foundEventRatings = query.getResultList();
		return foundEventRatings;
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	public List findEventRatings(final Users subscriber) {
		final String hqlString = "select er from EventRatings er where er.rater=:rater";
		final Query query = getQuery(hqlString);
		query.setParameter("rater", subscriber);
		List foundEventRatings = query.getResultList();
		return foundEventRatings;
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	public List findRatedEvents(final Users provider) {
		final String hqlString = "select er from EventRatings er "
				+ "where er.event.provider=:provider "
				+ "and er.visibility=:visibility";
		final Query query = getQuery(hqlString);
		query.setParameter("provider", provider);
		query.setParameter("visibility", RatingVisibility.INVISIBLE);
		List eventRatings = query.getResultList();
		return eventRatings;
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	public RatingDescriptions findRatingDescription(
			final EventRatings eventRating) {
		final String hqlString = "select rd from RatingDescriptions rd where rd.eventRatings=:eventRating";
		final Query query = getQuery(hqlString);
		query.setParameter("eventRating", eventRating);
		List ratingDescriptions = query.getResultList();

		return ListExtensions.getFirst(ratingDescriptions);
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	public List getEventRatingsForEvent(final EventTemplate event) {
		final String hqlString = "select distinct er from EventRatings er where er.event=:event";
		final Query query = getQuery(hqlString);
		query.setParameter("event", event);
		List foundEventRatings = query.getResultList();
		return foundEventRatings;
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	public List getEventRatingsForEventFromSubscriber(
			final EventTemplate event, final Users subscriber) {
		final String hqlString = "select distinct er from EventRatings er where er.event=:event and er.rater=:subscriber";
		final Query query = getQuery(hqlString);
		query.setParameter("event", event);
		query.setParameter("subscriber", subscriber);
		List foundEventRatings = query.getResultList();
		return foundEventRatings;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy