
events.system.service.EventLocationsBusinessService Maven / Gradle / Ivy
package events.system.service;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.persistence.Query;
import hbm.service.jpa.AbstractBusinessService;
import de.alpharogroup.collections.ListExtensions;
import de.alpharogroup.date.CalculateDateUtils;
import de.alpharogroup.jgeohash.GeoHashUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import user.management.model.Users;
import user.management.service.api.UserDataService;
import address.book.model.Addresses;
import events.system.daos.EventLocationsDao;
import events.system.enums.UsereventsRelationType;
import events.system.model.Categories;
import events.system.model.EventLocations;
import events.system.model.EventTemplate;
import events.system.service.api.EventLocationsService;
@Transactional
@Service("eventLocationsService")
public class EventLocationsBusinessService
extends
AbstractBusinessService
implements
EventLocationsService
{
private static final long serialVersionUID = 1L;
/** The users business service. */
@Autowired
private UserDataService userDataService;
@Autowired
public void setEventLocationsDao(EventLocationsDao eventLocationsDao)
{
setDao(eventLocationsDao);
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public List findContactPersonsFromProvider(final Users provider)
{
final String hqlString = "select distinct el.contactperson from EventLocations el, Userevents ue "
+ "where ue.user=:provider and el.event.id=ue.event.id";
final Query query = getQuery(hqlString);
query.setParameter("provider", provider);
final List contactPersons = new ArrayList(new HashSet(
query.getResultList()));
return contactPersons;
}
/**
* {@inheritDoc}.
*/
@SuppressWarnings("unchecked")
public EventLocations findEvent(final Users provider, final EventTemplate event)
{
final String hqlString = "select el from EventLocations el, Userevents ue "
+ " where ue.user=:provider" + " and ue.event=:event" + " and el.event=:event";
final Query query = getQuery(hqlString);
query.setParameter("provider", provider);
query.setParameter("event", event);
final List eventLocations = query.getResultList();
return ListExtensions.getFirst(eventLocations);
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public List findEventLocations(final Addresses userAddress)
{
final String hqlString = "select ev from EventLocations ev where ev.eventLocation=:userAddress";
final Query query = getQuery(hqlString);
query.setParameter("userAddress", userAddress);
final List eventLocations = new ArrayList(
new HashSet(query.getResultList()));
return eventLocations;
}
/**
* {@inheritDoc}.
*/
@SuppressWarnings("unchecked")
public List findEventLocations(final Users user,
final UsereventsRelationType relationtype)
{
final String hqlString = "select distinct el from Userevents ue, EventLocations el "
+ "where ue.user=:user " + "and ue.relationtype=:relationtype "
+ "and el.event=ue.event";
final Query query = getQuery(hqlString);
query.setParameter("user", user);
query.setParameter("relationtype", relationtype);
final List eventLocations = query.getResultList();
return eventLocations;
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public List findEventLocationsFromEvent(final EventTemplate event)
{
final String hqlString = "select ev from EventLocations ev where ev.event=:event";
final Query query = getQuery(hqlString);
query.setParameter("event", event);
final List eventLocations = new ArrayList(
new HashSet(query.getResultList()));
return eventLocations;
}
/**
* {@inheritDoc}
*/
public List findEventLocationsFromProvider(final Users provider)
{
// String hqlString =
// "select ev.eventLocation from EventLocations ev where ev.event.provider=:provider";
// final Query query = getQuery(hqlString);
// query.setParameter("provider", provider);
final List userAdresses = new ArrayList(userDataService.get(
provider.getUserData().getId()).getAddresses());
return userAdresses;
}
/**
* {@inheritDoc}.
*/
@SuppressWarnings("unchecked")
public List findEvents(final EventTemplate event)
{
final String hqlString = "select distinct el from EventLocations el, Userevents ue "
+ " where ue.event=:event " + " and el.event=:event";
final Query query = getQuery(hqlString);
query.setParameter("event", event);
final List eventLocations = new ArrayList(
new HashSet(query.getResultList()));
return eventLocations;
}
/**
* {@inheritDoc}.
*/
@SuppressWarnings("unchecked")
public List findEvents(final String eventname, final Categories category,
final boolean condition)
{
final StringBuilder hqlString = new StringBuilder();
if (null != category)
{
if (condition)
{
hqlString.append("select el from EventLocations el "
+ "where el.event.name like :eventname " + "and el.event.categories=:category");
}
else
{
hqlString.append("select el from EventLocations el "
+ "where el.event.name like :eventname " + "or el.event.categories=:category");
}
}
else
{
hqlString
.append("select el from EventLocations el where el.event.name like :eventname");
}
final Query query = getQuery(hqlString.toString());
query.setParameter("eventname", eventname);
if (null != category)
{
query.setParameter("category", category);
}
final List foundEventLocations = new ArrayList(
new HashSet(query.getResultList()));
return foundEventLocations;
}
/**
* {@inheritDoc}.
*/
@SuppressWarnings("unchecked")
public List findEvents(final String eventname)
{
final StringBuilder sb = new StringBuilder();
Date systime = new Date();
Date start = CalculateDateUtils.addDays(systime, 0);
Date end = CalculateDateUtils.addDays(systime, 30);
sb.append("select el from EventLocations el " + "where el.event.name like :eventname "
+ "or el.event.head like :eventname "
+ "and el.appointment.starttime between :start and :end");
String hqlString = sb.toString();
final Query query = getQuery(hqlString);
query.setParameter("eventname", "%" + eventname + "%");
query.setParameter("start", start);
query.setParameter("end", end);
List result = query.getResultList();
final List foundEventLocations = new ArrayList(
new HashSet(result));
return foundEventLocations;
}
/**
* {@inheritDoc}.
*/
@SuppressWarnings("unchecked")
public List findEvents(final String eventname, final Date start,
final Date end, final String geohash)
{
Map adjacentAreas = null;
if (geohash != null && !geohash.isEmpty())
{
adjacentAreas = GeoHashUtils.getAllAdjacentAreasMap(geohash);
}
else
{
return new ArrayList();
}
final StringBuilder hqlString = new StringBuilder();
hqlString.append("select el from EventLocations el "
+ "where el.event.name like :eventname "
+ "and el.appointment.starttime between :start and :end "
+ "and el.userAddress.address.geohash in ("
+
// Subselect start...
"select address.geohash from Addresses address " + "where address.geohash like :top "
+ "or address.geohash like :topright " + "or address.geohash like :right "
+ "or address.geohash like :bottomright " + "or address.geohash like :bottom "
+ "or address.geohash like :bottomleft " + "or address.geohash like :left "
+ "or address.geohash like :topleft " + "or address.geohash like :center " +
// Subselect end...
")");
String queryString = hqlString.toString();
final Query query = getQuery(queryString);
query.setParameter("eventname", "%" + eventname + "%");
query.setParameter("start", start);
query.setParameter("end", end);
for (Entry entry : adjacentAreas.entrySet())
{
query.setParameter(entry.getKey(), entry.getValue() + "%");
}
final List foundEventLocations = new ArrayList(
new HashSet(query.getResultList()));
return foundEventLocations;
}
/**
* {@inheritDoc}.
*/
@SuppressWarnings("unchecked")
public List findEvents(final Users provider)
{
final String hqlString = "select el from EventLocations el, Userevents ue "
+ " where ue.user=:provider" + " and el.event.id=ue.event.id";
final Query query = getQuery(hqlString);
query.setParameter("provider", provider);
final List eventLocations = new ArrayList(
new HashSet(query.getResultList()));
return eventLocations;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy