Class Event

All Implemented Interfaces:
Database.Dissolvable, Database.Querrier<Event>, Database.UpdateListener

@Dissolves public class Event extends DatabaseInstance<Event> implements Database.Querrier<Event>
An instance of a event database item - An event can be edited
  • Field Details

    • currentEnrolled

      private int currentEnrolled
      The number of users counting against enrollment. Only counts Invited users
    • currentWaitlist

      private int currentWaitlist
      The number of users on the waitlist. Only counts Waitlist status
    • currentInvited

      private int currentInvited
      The number of users on the waitlist. Only counts Invited status
    • assocUsersQuery

      private final com.google.firebase.firestore.Query assocUsersQuery
    • fields

      static final DatabaseInstance.PropertyField<?,?>[] fields
      The list of the fields defined for a User
  • Constructor Details

  • Method Details

    • requiredFirstDelete

      protected void requiredFirstDelete(int deletionType, Consumer<Boolean> listener)
      Description copied from class: DatabaseInstance
      Deletes any sub objects that are not instances
      Overrides:
      requiredFirstDelete in class DatabaseInstance<Event>
      Parameters:
      deletionType - The DatabaseInstance.DeletionType reason this instance is being deleted
      listener - Called before the instance and sub instances are deleted; they are only deleted if this returns true
    • refreshData

      public void refreshData(Database.Querrier.Listener<Event> listener)
      Refreshes the current enrolled and waitlist counts
      Specified by:
      refreshData in interface Database.Querrier<Event>
      Parameters:
      listener - The listener that will be called when the counts are loaded
    • getLottery

      @MustStir public void getLottery(int count, Database.Querrier.DataListener<Event,Event.LotteryResult> listener)
      Refreshes the current enrolled and waitlist counts then queries the waitlist for a random count users. Returns the selected users and the unselected users.
      Parameters:
      count - The number of users to randomly select, if count <= 0, selects enough users to fill all open spots
      listener - The listener to be called on completion. Database.Querrier.DataListener.onCompletion(Database.Querrier, QueryResult, boolean) is called with false if the data refresh failed. If there are negative empty spots to be filled, true is returned with empty arrays
    • shuffleWaitlist

      @MustStir private void shuffleWaitlist(int count, Database.Querrier.DataListener<Event,Event.LotteryResult> listener)
      Queries the waitlist and shuffles the result
      Parameters:
      listener - Called on completion with the shuffled list
    • getInvitedUsers

      Returns all invited users who have not accepted
      Parameters:
      listener - The listener which is called with the list
    • getEnrolledUsers

      Returns all enrolled users
      Parameters:
      listener - The listener which is called with the list
    • getCancelledUsers

      @MustStir public void getCancelledUsers(Database.Querrier.DataListener<Event,EventAssociation.Methods<Event>> listener)
      Returns all cancelled users
      Parameters:
      listener - The listener which is called with the list
    • getWaitlistUsers

      Returns all waitlist users
      Parameters:
      listener - The listener which is called with the list
    • getAssociatedImageLocName

      public String getAssociatedImageLocName()
      Description copied from class: DatabaseInstance
      Returns the name that should be given to the image instance. If no image is associated, returns null
      Overrides:
      getAssociatedImageLocName in class DatabaseInstance<Event>
    • getUsersByStatus

      @MustStir public void getUsersByStatus(int statusID, Database.Querrier.DataListener<Event,EventAssociation.Methods<Event>> listener)
      Returns all associated users with the given association status
      Parameters:
      statusID - The res ID of the status
      listener - The listener which is called on completion
    • getAssociatedUsersFromQuery

      @MustStir public void getAssociatedUsersFromQuery(com.google.firebase.firestore.Query query, Database.Querrier.DataListener<Event,EventAssociation.Methods<Event>> listener)
      Gets the EventAssociation.Methods from a Query.
      Parameters:
      query - The query to evaluate
      listener - The listener that gets called on completion
      See Also:
    • getAssociatedUsersFromQuery

      Gets the EventAssociation.Methods from a DatabaseQuery. Dissolves the DatabaseQuery on completion
      Parameters:
      query - The query to evaluate
      listener - The listener that gets called on completion
      See Also:
    • cancelAllInvitedUsers

      Cancels all invited users who have not accepted. Users are set to Cancelled and then notified
      Parameters:
      listener - The listener which is called with the list
    • getCurrentEnrolled

      public int getCurrentEnrolled()
      Returns:
      The number of users that count against enrollment. Includes Enrolled
      See Also:
    • getCurrentWaitlist

      public int getCurrentWaitlist()
      Returns:
      The number of users that count against the waitlist. Includes Waitlist
      See Also:
    • getCurrentInvited

      public int getCurrentInvited()
      Returns:
      The number of users that are invited. Includes Invited
      See Also:
    • cast

      @Observes protected Event cast()
      Description copied from class: DatabaseInstance
      Gets this instance casted to the generic type
      Specified by:
      cast in class DatabaseInstance<Event>
      Returns:
      This as the generic type
    • getTitle

      public String getTitle()
    • setTitle

      public boolean setTitle(String val)
    • getPosterID

      public String getPosterID()
    • getFacilityID

      public String getFacilityID()
    • getRequiresLocation

      public Boolean getRequiresLocation()
    • getDescription

      public String getDescription()
    • setDescription

      public boolean setDescription(String val)
    • getCapacity

      public Long getCapacity()
    • getWaitlistCapacity

      public Long getWaitlistCapacity()
    • getQrHash

      public String getQrHash()
    • setQrHash

      public boolean setQrHash(String val)
    • getCreatedDate

      public com.google.firebase.Timestamp getCreatedDate()
    • getPoster

      @Observes public Image getPoster()
    • setPoster

      @StirsDeep(what="The previous Image") public void setPoster(@Nullable android.net.Uri image, Consumer<Boolean> onComplete)
      Sets the profile image instance. This function will create a new reference to the instance.
      Parameters:
      image - The new instance
      onComplete - called on completion with if the update was successful
      See Also:
    • getFacility

      @Observes public Facility getFacility()
    • getOpenRegistrationDate

      public com.google.firebase.Timestamp getOpenRegistrationDate()
    • getCloseRegistrationDate

      public com.google.firebase.Timestamp getCloseRegistrationDate()
    • getEventDates

      public Long getEventDates()
    • getFormattedEventDates

      public String getFormattedEventDates()
    • getStartDate

      public com.google.firebase.Timestamp getStartDate()
    • getEndDate

      public com.google.firebase.Timestamp getEndDate()
    • getPrice

      public Double getPrice()
    • setPrice

      public boolean setPrice(Double val)
    • setHasRunLottery

      public boolean setHasRunLottery(boolean val)
    • hasRunLottery

      public boolean hasRunLottery()
    • addUserToWaitlist

      @MustStir public void addUserToWaitlist(@Observes User user, @Nullable com.google.firebase.firestore.GeoPoint location, Database.Querrier.DataListener<Event,Database.Querrier.QueryResult<EventAssociation>> listener)
      Adds a user to the waitlist given that the user either does not have an association with the event or the association is cancelled.

      The listener will be returned with false success if an error occurs or the user cannot be added to the waitlist. If the this is because the user is already attached, the association is returned with false success

      Parameters:
      user - The user to be added
      location - The current location of the user. If this event requires geolocation, the location cannot be null. If the event does not require geo, the location is auto set to null
      listener - The listener for completion. Ownership of the event association is given to the user
    • acceptInvite

      Adds a user to the enrolled given that the user is currently invited

      The listener will be returned with false success if an error occurs or the user cannot be enrolled. If the this is because the user in a not invite status, the association is returned with false success

      Parameters:
      user -
      listener -
    • getUserAssociation

      @MustStir public void getUserAssociation(@Observes User user, Database.Querrier.DataListener<Event,EventAssociation.Methods<Event>> listener)
      Gets the association of the user
      Parameters:
      user - The user to retrieve
      listener - Ownership is passed of the event assoc
    • isRegistrationOpen

      public boolean isRegistrationOpen()
      Returns:
      Returns if now is between the closed and open registration date.
    • isAfterRegistration

      public boolean isAfterRegistration()
      Returns:
      Returns if now is after the close date
    • isBeforeRegistration

      public boolean isBeforeRegistration()
      Returns:
      Returns if now is before the open date
    • update

      @StirsDeep(what="The previous image") public Set<Integer> update(String title, @Dilutes String posterID, String description, android.net.Uri posterImage, String qrHash, Double price, Consumer<Boolean> onComplete)
      Updates all properties of the event. If the event changes, a notification is sent to listeners once and the database is updated once
      Parameters:
      title - The title of the event
      description - the description of the event
      posterImage - The new Poster image
      qrHash - the cashed qr code data for the event
      price - The price of the event
      onComplete - called on completion. Not called if properties are invalid
      Returns:
      All invalid ids
      See Also:
    • update

      public Set<Integer> update(String title, String description, String qrHash, Double price, Consumer<Boolean> onComplete)
      Updates all properties of the event. If the event changes, a notification is sent to listeners once and the database is updated once
      Parameters:
      title - The title of the event
      description - the description of the event
      qrHash - the cashed qr code data for the event
      price - The price of the event
      onComplete - will always be true and will be called before return
      Returns:
      All invalid ids
      See Also:
    • subInstanceCascadeDeleteQuery

      protected List<android.util.Pair<com.google.firebase.firestore.Query,Database.Collections>> subInstanceCascadeDeleteQuery()
      Specified by:
      subInstanceCascadeDeleteQuery in class DatabaseInstance<Event>
      Returns:
      A list of all querries that should be run whose instances will be deleted when this instance is deleted
    • NewInstance

      @MustStir public static Set<Integer> NewInstance(Database db, String title, android.net.Uri posterImage, @Dilutes String facilityID, Boolean requiresLocation, String description, Long capacity, Long waitlistCapacity, Double price, com.google.firebase.Timestamp openRegistrationDate, com.google.firebase.Timestamp closedRegistrationDate, com.google.firebase.Timestamp startDate, com.google.firebase.Timestamp endDate, Long eventDates, Database.InitializationListener<Event> listener)
      Validates and creates a new Image instance in the database using the given data.
      Parameters:
      db - The database
      title - The title of the event
      posterImage - The the poster image
      facilityID - the id of the facility
      requiresLocation - If the users geolocation is recorded on signup
      description - the description of the event
      capacity - The max capacity of the event
      waitlistCapacity - the max waitlist capacity of the event
      price - The price of the event
      openRegistrationDate - The date that registration opens, if null uses now
      closedRegistrationDate - The date that registration closes and the lottery opens
      startDate - The datetime that the event starts
      endDate - The datetime that the event stored
      eventDates - The days of the week that the event occurs Event.Dates
      listener - Will be called once the event is initialized. Is not called if the data is invalid
      Returns:
      The property id of all invalid properties
      See Also: