Package com.syzygy.events.database
Class Event
- All Implemented Interfaces:
Database.Dissolvable,Database.Querrier<Event>,Database.UpdateListener
An instance of a event database item
- An event can be edited
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumUsed to store repetition of dates in the databaseclassThe random selected list user and unselected users returned by a lottery call along with a method to execute the lottery.Nested classes/interfaces inherited from class com.syzygy.events.database.DatabaseInstance
DatabaseInstance.DeletionType, DatabaseInstance.InstancePropertyWrapper<W extends DatabaseInstance<W>>, DatabaseInstance.PropertyField<V,W extends DatabaseInstance<W>>, DatabaseInstance.PropertyWrapper<V, W extends DatabaseInstance<W>> Nested classes/interfaces inherited from interface com.syzygy.events.database.Database.Querrier
Database.Querrier.DataListener<S extends Database.Querrier<S>,W extends Database.Querrier.QueryResult<?>>, Database.Querrier.Listener<S extends Database.Querrier<S>>, Database.Querrier.QueryInstanceResult<V extends DatabaseInstance<V>>, Database.Querrier.QueryResult<V> Nested classes/interfaces inherited from interface com.syzygy.events.database.Database.UpdateListener
Database.UpdateListener.Type -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final com.google.firebase.firestore.Queryprivate intThe number of users counting against enrollment.private intThe number of users on the waitlist.private intThe number of users on the waitlist.(package private) static final DatabaseInstance.PropertyField<?,?>[] The list of the fields defined for a UserFields inherited from class com.syzygy.events.database.DatabaseInstance
db, iproperties, properties -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptInvite(User user, Database.Querrier.DataListener<Event, Database.Querrier.QueryResult<EventAssociation>> listener) Adds a user to the enrolled given that the user is currently invitedvoidaddUserToWaitlist(User user, 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.voidcancelAllInvitedUsers(Database.Querrier.DataListener<Event, EventAssociation.NotificationResult> listener) Cancels all invited users who have not accepted.protected Eventcast()Gets this instance casted to the generic typeReturns the name that should be given to the image instance.voidgetAssociatedUsersFromQuery(com.google.firebase.firestore.Query query, Database.Querrier.DataListener<Event, EventAssociation.Methods<Event>> listener) Gets theEventAssociation.Methodsfrom aQuery.voidgetAssociatedUsersFromQuery(DatabaseQuery<EventAssociation> query, Database.Querrier.DataListener<Event, EventAssociation.Methods<Event>> listener) Gets theEventAssociation.Methodsfrom aDatabaseQuery.voidReturns all cancelled userscom.google.firebase.Timestampcom.google.firebase.Timestampintintintcom.google.firebase.TimestampvoidReturns all enrolled usersvoidReturns all invited users who have not acceptedvoidgetLottery(int count, Database.Querrier.DataListener<Event, Event.LotteryResult> listener) Refreshes the current enrolled and waitlist counts then queries the waitlist for a randomcountusers.com.google.firebase.TimestampgetPrice()com.google.firebase.TimestampgetTitle()voidgetUserAssociation(User user, Database.Querrier.DataListener<Event, EventAssociation.Methods<Event>> listener) Gets the association of the uservoidgetUsersByStatus(int statusID, Database.Querrier.DataListener<Event, EventAssociation.Methods<Event>> listener) Returns all associated users with the given association statusvoidReturns all waitlist usersbooleanbooleanbooleanbooleanNewInstance(Database db, String title, android.net.Uri posterImage, 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.voidrefreshData(Database.Querrier.Listener<Event> listener) Refreshes the current enrolled and waitlist countsprotected voidrequiredFirstDelete(int deletionType, Consumer<Boolean> listener) Deletes any sub objects that are not instancesbooleansetDescription(String val) booleansetHasRunLottery(boolean val) voidSets the profile image instance.booleanbooleanbooleanprivate voidshuffleWaitlist(int count, Database.Querrier.DataListener<Event, Event.LotteryResult> listener) Queries the waitlist and shuffles the resultprotected List<android.util.Pair<com.google.firebase.firestore.Query,Database.Collections>> update(String title, String posterID, String description, android.net.Uri posterImage, String qrHash, Double price, Consumer<Boolean> onComplete) Updates all properties of the event.Updates all properties of the event.Methods inherited from class com.syzygy.events.database.DatabaseInstance
addInitializationListener, addListener, assertNotIllegalState, deleteInstance, dereferenceInstance, dissolve, dissolve, doesPropertyLoadInstance, fetch, fetch, fullDissolve, getAssociatedImage, getCollection, getCollectionReference, getData, getDatabaseID, getDocumentID, getDocumentReference, getFields, getPropertyInstance, getPropertyInstanceI, getPropertyValue, getPropertyValueI, initializeData, isDataValid, isDataValid, isLegalState, isPropertyEditable, isPropertyValid, isPropertyValid, isReferenced, modifyData, notifyUpdate, onUpdate, processUpdate, removeListener, setAssociatedImage, setPropertyInstance, setPropertyValue, subDereferenceInstance, subInitialize, toString, updateDataFromDatabase, updateDataFromMap, updateDataFromMap
-
Field Details
-
currentEnrolled
private int currentEnrolledThe number of users counting against enrollment. Only counts Invited users -
currentWaitlist
private int currentWaitlistThe number of users on the waitlist. Only counts Waitlist status -
currentInvited
private int currentInvitedThe number of users on the waitlist. Only counts Invited status -
assocUsersQuery
private final com.google.firebase.firestore.Query assocUsersQuery -
fields
The list of the fields defined for a User
-
-
Constructor Details
-
Event
Checks to make sure the generic type is the type of this instance- Parameters:
db- The databaseeventID- The id of the event- Throws:
ClassCastException
-
-
Method Details
-
requiredFirstDelete
Description copied from class:DatabaseInstanceDeletes any sub objects that are not instances- Overrides:
requiredFirstDeletein classDatabaseInstance<Event>- Parameters:
deletionType- TheDatabaseInstance.DeletionTypereason this instance is being deletedlistener- Called before the instance and sub instances are deleted; they are only deleted if this returns true
-
refreshData
Refreshes the current enrolled and waitlist counts- Specified by:
refreshDatain interfaceDatabase.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 randomcountusers. Returns the selected users and the unselected users.- Parameters:
count- The number of users to randomly select, ifcount <= 0, selects enough users to fill all open spotslistener- The listener to be called on completion.Database.Querrier.DataListener.onCompletion(Database.Querrier, QueryResult, boolean)is called withfalseif the data refresh failed. If there are negative empty spots to be filled,trueis 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
@MustStir public void getInvitedUsers(Database.Querrier.DataListener<Event, EventAssociation.Methods<Event>> listener) Returns all invited users who have not accepted- Parameters:
listener- The listener which is called with the list
-
getEnrolledUsers
@MustStir public void getEnrolledUsers(Database.Querrier.DataListener<Event, EventAssociation.Methods<Event>> listener) 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
@MustStir public void getWaitlistUsers(Database.Querrier.DataListener<Event, EventAssociation.Methods<Event>> listener) Returns all waitlist users- Parameters:
listener- The listener which is called with the list
-
getAssociatedImageLocName
Description copied from class:DatabaseInstanceReturns the name that should be given to the image instance. If no image is associated, returns null- Overrides:
getAssociatedImageLocNamein classDatabaseInstance<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 statuslistener- 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 theEventAssociation.Methodsfrom aQuery.- Parameters:
query- The query to evaluatelistener- The listener that gets called on completion- See Also:
-
getAssociatedUsersFromQuery
@MustStir public void getAssociatedUsersFromQuery(@Stirs DatabaseQuery<EventAssociation> query, Database.Querrier.DataListener<Event, EventAssociation.Methods<Event>> listener) - Parameters:
query- The query to evaluatelistener- The listener that gets called on completion- See Also:
-
cancelAllInvitedUsers
@Stirred public void cancelAllInvitedUsers(Database.Querrier.DataListener<Event, EventAssociation.NotificationResult> listener) 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
Description copied from class:DatabaseInstanceGets this instance casted to the generic type- Specified by:
castin classDatabaseInstance<Event>- Returns:
- This as the generic type
-
getTitle
-
setTitle
-
getPosterID
-
getFacilityID
-
getRequiresLocation
-
getDescription
-
setDescription
-
getCapacity
-
getWaitlistCapacity
-
getQrHash
-
setQrHash
-
getCreatedDate
public com.google.firebase.Timestamp getCreatedDate() -
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 instanceonComplete- called on completion with if the update was successful- See Also:
-
getFacility
-
getOpenRegistrationDate
public com.google.firebase.Timestamp getOpenRegistrationDate() -
getCloseRegistrationDate
public com.google.firebase.Timestamp getCloseRegistrationDate() -
getEventDates
-
getFormattedEventDates
-
getStartDate
public com.google.firebase.Timestamp getStartDate() -
getEndDate
public com.google.firebase.Timestamp getEndDate() -
getPrice
-
setPrice
-
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 addedlocation- 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 nulllistener- The listener for completion. Ownership of the event association is given to the user
-
acceptInvite
@MustStir public void acceptInvite(@Observes User user, Database.Querrier.DataListener<Event, Database.Querrier.QueryResult<EventAssociation>> listener) Adds a user to the enrolled given that the user is currently invitedThe 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 retrievelistener- 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 eventdescription- the description of the eventposterImage- The new Poster imageqrHash- the cashed qr code data for the eventprice- The price of the eventonComplete- 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 eventdescription- the description of the eventqrHash- the cashed qr code data for the eventprice- The price of the eventonComplete- 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:
subInstanceCascadeDeleteQueryin classDatabaseInstance<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 databasetitle- The title of the eventposterImage- The the poster imagefacilityID- the id of the facilityrequiresLocation- If the users geolocation is recorded on signupdescription- the description of the eventcapacity- The max capacity of the eventwaitlistCapacity- the max waitlist capacity of the eventprice- The price of the eventopenRegistrationDate- The date that registration opens, if null uses nowclosedRegistrationDate- The date that registration closes and the lottery opensstartDate- The datetime that the event startsendDate- The datetime that the event storedeventDates- The days of the week that the event occursEvent.Dateslistener- 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:
-