package info.interactivesystems.gamificationengine.entities.rewards; import info.interactivesystems.gamificationengine.dao.GoalDAO; import info.interactivesystems.gamificationengine.dao.RuleDAO; import info.interactivesystems.gamificationengine.entities.Organisation; import info.interactivesystems.gamificationengine.entities.Player; import info.interactivesystems.gamificationengine.entities.PlayerGroup; import info.interactivesystems.gamificationengine.entities.goal.Goal; import java.util.List; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.validation.constraints.NotNull; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonManagedReference; /** * The super class of all rewards. Here are general information of the reward * like to which organisation the reward belongs to or the goal to which it * is associated. * * A Reward will be awarded in dependent of the goal for a group or one person * after a person fulfilled a task. It can be chosen between one or more of * the following rewards for a task: A permanent reward like a badge or * achievement which can be obtained only once, or a volatile reward such as * coins, points or a particular level which can be changed by getting for * example more coins or be decreased by giving a bid for an offer in the * marketplace. */ @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "REWARD_TYPE", discriminatorType = DiscriminatorType.STRING) @JsonIgnoreProperties({ "belongsTo", "goals" }) public abstract class Reward { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @NotNull @ManyToOne private Organisation belongsTo; private String name; private String description; private int timeToLive; @ManyToMany(fetch = FetchType.EAGER, mappedBy = "rewards") @JsonManagedReference private List<Goal> goals; public abstract void addReward(Player player, GoalDAO goalDao, RuleDAO ruleDao); public abstract void addReward(PlayerGroup group, GoalDAO goalDao, RuleDAO ruleDao); /** * Gets the id of the reward which was generated by the creation. * * @return The reward's id as int. */ public int getId() { return id; } /** * Sets the id of the reward. * * @param id * The id of the reward. */ public void setId(int id) { this.id = id; } /** * Gets the organisation the reward belongs to. * * @return The organisation of the reward as an object. The organisation must not be * null. */ public Organisation getBelongsTo() { return belongsTo; } /** * Sets the organisation to which this reward belongs to. * * @param belongsTo * The reward's organisation. This parameter must not be null. */ public void setBelongsTo(Organisation belongsTo) { this.belongsTo = belongsTo; } /** * Gets the information about how long the reward can exist. * * @return The value for how long the reward exist. */ public int getTimeToLive() { return timeToLive; } /** * Sets the information about how long the reward can exist. * * @param timeToLive * Time how long the reward can exist as int. */ public void setTimeToLive(int timeToLive) { this.timeToLive = timeToLive; } /** * This method tests if a reward belongs to a specific organisation. Therefore * it is tested if the organisation's API key matchs the reward's API key of the * assigned organisation. * * @param organisation * The organisation object a reward may belongs to. * @return * Boolean value if the API key of the group is the same * of the tested organisation (true) or not (false). */ public boolean belongsTo(Organisation organisation) { return getBelongsTo().getApiKey().equals(organisation.getApiKey()); } /** * Gets the description of an achievement. This could contains for example the * different tasks which have to be completed to get this achievement. * * @return the achievement's description */ public String getDescription() { return description; } /** * Sets the description of an achievement. This contains for example further * information about how the achievement can be earned, like all requirements to * get the achievement or the process to award the achievement. * * @param description * of the achievement */ public void setDescription(String description) { this.description = description; } /** * Gets the name of an achievement which can describe the success in a short * way and can be displayed in the application. * * @return The achievement's name as String. */ public String getName() { return name; } /** * Sets the name of an achievement, which can describe the success in a short * way and can be displayed in the application. * * @param name * The name of the achievement as a String. */ public void setName(String name) { this.name = name; } /** * Gets the list of goals to which this reward is assigned. * * @return All goals with this reward as List of Goals. */ public List<Goal> getGoals() { return goals; } /** * Sets the list of goals to which this reward is assigned. * * @param goals * The goals to which this reward should be assigned. */ public void setGoals(List<Goal> goals) { this.goals = goals; } }