// Path: src/main/java/info/interactivesystems/gamificationengine/dao/OrganisationDAO.java
// @Named
// @Stateless
// public class OrganisationDAO {
// 
// 	@PersistenceContext(unitName = PersistenceUnit.PROJECT)
// 	private EntityManager em;
// 
// 	/**
// 	 * Stores a new organisation in the data base.
// 	 * 
// 	 * @param organisation
// 	 *            The {@link Organisation} that should be stored in the data base.
// 	 */
// 	public void insertOrganisation(Organisation organisation) {
// 		em.persist(organisation);
// 	}
// 
// 	/**
// 	 * Gets the organisation from the data base.
// 	 * 
// 	 * @param id
// 	 *           The id of the requsted organisaiton.
// 	 * @return The {@link Organisation} that is associated with the passed id.
// 	 */
// 	public Organisation getOrganisation(int id) {
// 		Query query = em.createQuery("select o from Organisation o where o.id=:id", Organisation.class);
// 		query.setParameter("id", id);
// 		List list = query.getResultList();
// 		if (list.isEmpty()) {
// 			return null;
// 		}
// 		return ((Organisation) list.get(0));
// 	}
// 
// 	/**
// 	 * Gets all organisations which belong to an email address.
// 	 * 
// 	 * @param email
// 	 *            The email address of the requested organisaiton.
// 	 * @return The {@link List} of {@link Organisation}s that are associated with the passed email address.
// 	 */
// 	public List<Organisation> getAllOrganisations(String email) {
// 		Query query = em.createQuery("select entity from Organisation entity join entity.managers m where m.email=:email");
// 		query.setParameter("email", email);
// 
// 		List list = query.getResultList();
// 		if (list.isEmpty()) {
// 			return null;
// 		}
// 
// 		return list;
// 	}
// 
// 	/**
// 	 * Gets all organisations which are associated with the specific API key. The result
// 	 * should only be one organisation.
// 	 * 
// 	 * @param apiKey
// 	 *           The API key to which the organisation belongs to.
// 	 * @return A {@link List} of {@link Organisation}s that are associated to the passed
// 	 * 			API key. 
// 	 */
// 	public Organisation getOrganisationByApiKey(String apiKey) {
// 		Query query = em.createQuery("select entity from Organisation entity where entity.apiKey=:apiKey");
// 		query.setParameter("apiKey", apiKey);
// 
// 		List list = query.getResultList();
// 
// 		if (list.isEmpty()) {
// 			return null;
// 		}
// 
// 		return ((Organisation) list.get(0));
// 	}
// 
// 	/**
// 	 * Checks whether the data base contains the passed API key.
// 	 * 
// 	 * @param apiKey
// 	 *           The API key that is tested. This is represented by a {@link CharSequence} 
// 	 *           or null.
// 	 * @return True if the API key exists in data base, if null false is returned.
// 	 */
// 	public boolean checkApiKey(CharSequence apiKey) {
// 		if (apiKey != null) {
// 			try {
// 				Query query = em.createQuery("select entity from Organisation entity where entity.apiKey=:apiKey");
// 				query.setParameter("apiKey", apiKey);
// 				return query.getSingleResult() != null;
// 			} catch (NoResultException e) {
// 				// don't care
// 			}
// 		}
// 		return false;
// 	}
// }


import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import info.interactivesystems.gamificationengine.dao.OrganisationDAO;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.inject.Inject;
import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;
package info.interactivesystems.gamificationengine.api.validation;





/**
 * The annotated {@code CharSequence} will be checked for existence in the
 * data base.
 * 
 * Note: {@code null} elements are considered as invalid.
 */
@Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = ValidApiKey.ApiKeyValidator.class)
@Documented
public @interface ValidApiKey {

	public static class ApiKeyValidator implements ConstraintValidator<ValidApiKey, CharSequence> {

		@Inject
// Path: src/main/java/info/interactivesystems/gamificationengine/dao/OrganisationDAO.java
// @Named
// @Stateless
// public class OrganisationDAO {
// 
// 	@PersistenceContext(unitName = PersistenceUnit.PROJECT)
// 	private EntityManager em;
// 
// 	/**
// 	 * Stores a new organisation in the data base.
// 	 * 
// 	 * @param organisation
// 	 *            The {@link Organisation} that should be stored in the data base.
// 	 */
// 	public void insertOrganisation(Organisation organisation) {
// 		em.persist(organisation);
// 	}
// 
// 	/**
// 	 * Gets the organisation from the data base.
// 	 * 
// 	 * @param id
// 	 *           The id of the requsted organisaiton.
// 	 * @return The {@link Organisation} that is associated with the passed id.
// 	 */
// 	public Organisation getOrganisation(int id) {
// 		Query query = em.createQuery("select o from Organisation o where o.id=:id", Organisation.class);
// 		query.setParameter("id", id);
// 		List list = query.getResultList();
// 		if (list.isEmpty()) {
// 			return null;
// 		}
// 		return ((Organisation) list.get(0));
// 	}
// 
// 	/**
// 	 * Gets all organisations which belong to an email address.
// 	 * 
// 	 * @param email
// 	 *            The email address of the requested organisaiton.
// 	 * @return The {@link List} of {@link Organisation}s that are associated with the passed email address.
// 	 */
// 	public List<Organisation> getAllOrganisations(String email) {
// 		Query query = em.createQuery("select entity from Organisation entity join entity.managers m where m.email=:email");
// 		query.setParameter("email", email);
// 
// 		List list = query.getResultList();
// 		if (list.isEmpty()) {
// 			return null;
// 		}
// 
// 		return list;
// 	}
// 
// 	/**
// 	 * Gets all organisations which are associated with the specific API key. The result
// 	 * should only be one organisation.
// 	 * 
// 	 * @param apiKey
// 	 *           The API key to which the organisation belongs to.
// 	 * @return A {@link List} of {@link Organisation}s that are associated to the passed
// 	 * 			API key. 
// 	 */
// 	public Organisation getOrganisationByApiKey(String apiKey) {
// 		Query query = em.createQuery("select entity from Organisation entity where entity.apiKey=:apiKey");
// 		query.setParameter("apiKey", apiKey);
// 
// 		List list = query.getResultList();
// 
// 		if (list.isEmpty()) {
// 			return null;
// 		}
// 
// 		return ((Organisation) list.get(0));
// 	}
// 
// 	/**
// 	 * Checks whether the data base contains the passed API key.
// 	 * 
// 	 * @param apiKey
// 	 *           The API key that is tested. This is represented by a {@link CharSequence} 
// 	 *           or null.
// 	 * @return True if the API key exists in data base, if null false is returned.
// 	 */
// 	public boolean checkApiKey(CharSequence apiKey) {
// 		if (apiKey != null) {
// 			try {
// 				Query query = em.createQuery("select entity from Organisation entity where entity.apiKey=:apiKey");
// 				query.setParameter("apiKey", apiKey);
// 				return query.getSingleResult() != null;
// 			} catch (NoResultException e) {
// 				// don't care
// 			}
// 		}
// 		return false;
// 	}
// }


// Path: src/main/java/info/interactivesystems/gamificationengine/api/validation/ValidApiKey.java
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import info.interactivesystems.gamificationengine.dao.OrganisationDAO;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.inject.Inject;
import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;

package info.interactivesystems.gamificationengine.api.validation;





/**
 * The annotated {@code CharSequence} will be checked for existence in the
 * data base.
 * 
 * Note: {@code null} elements are considered as invalid.
 */
@Target({ FIELD, METHOD, PARAMETER, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = ValidApiKey.ApiKeyValidator.class)
@Documented
public @interface ValidApiKey {

	public static class ApiKeyValidator implements ConstraintValidator<ValidApiKey, CharSequence> {

		@Inject
		OrganisationDAO organisationDao;