-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2219 from Abhyastamita/DIS-192_Native_Events
DIS-192: Native Events (Part 1 - admin interface for adding events)
- Loading branch information
Showing
42 changed files
with
4,928 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
code/events_indexer/src/com/turning_leaf_technologies/events/NativeEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
package com.turning_leaf_technologies.events; | ||
|
||
import com.turning_leaf_technologies.config.ConfigUtil; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZoneOffset; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import java.time.zone.ZoneRules; | ||
import java.util.*; | ||
|
||
class NativeEvent { | ||
private final long id; | ||
private final long eventId; | ||
private final int eventType; | ||
private final String startDate; | ||
private final String startTime; | ||
private final int length; | ||
private final String name; | ||
private final String description; | ||
private final String cover; | ||
private final long locationId; | ||
private final String locationCode; | ||
private final HashSet<String> libraries = new HashSet<>(); | ||
private final long sublocationId; | ||
private final Boolean status; | ||
private final Boolean nonPublic; | ||
private final ArrayList<EventField> fields = new ArrayList<EventField>(); | ||
|
||
NativeEvent(ResultSet existingEventsRS) throws SQLException{ | ||
this.id = existingEventsRS.getLong("id"); // The event instance ID | ||
this.eventId = existingEventsRS.getLong("eventId"); // The parent event ID | ||
this.eventType = existingEventsRS.getInt("eventTypeId"); | ||
this.startDate = existingEventsRS.getString("date"); | ||
this.startTime = existingEventsRS.getString("time"); | ||
this.length = existingEventsRS.getInt("length"); | ||
this.name = existingEventsRS.getString("title"); | ||
this.description = existingEventsRS.getString("description"); | ||
this.cover = existingEventsRS.getString("cover"); | ||
this.locationId = existingEventsRS.getLong("locationId"); | ||
this.locationCode = existingEventsRS.getString("displayName"); | ||
this.sublocationId = existingEventsRS.getLong("sublocationId"); | ||
this.status = existingEventsRS.getBoolean("status"); | ||
this.nonPublic = existingEventsRS.getBoolean("private"); | ||
} | ||
|
||
void addField(String name, String value, String[] allowableValues, int type, int facet) { | ||
this.fields.add(new EventField(name, value, allowableValues, type, facet)); | ||
} | ||
|
||
void addLibrary(String library) { | ||
libraries.add(library); | ||
} | ||
|
||
HashSet<String> getLibraries() { | ||
return this.libraries; | ||
} | ||
|
||
ArrayList<EventField> getFields() { | ||
return fields; | ||
} | ||
|
||
long getId() { | ||
return id; | ||
} | ||
|
||
long getParentEventId() { return eventId; } | ||
|
||
int getEventType() { return eventType; } | ||
|
||
public String getStartDate() { | ||
return startDate; | ||
} | ||
|
||
public String getStartTime() { | ||
return startTime; | ||
} | ||
|
||
public int getLength() { | ||
return length; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public String getCover() { | ||
return cover; | ||
} | ||
|
||
public String getCoverUrl(String coverPath) { | ||
return coverPath + "/aspenEvents/" + cover; | ||
} | ||
|
||
public long getLocationId() { | ||
return locationId; | ||
} | ||
|
||
public String getLocationCode() { | ||
return locationCode; | ||
} | ||
|
||
public long getSublocationId() { | ||
return sublocationId; | ||
} | ||
|
||
public Boolean getStatus() { | ||
return status; | ||
} | ||
|
||
public Boolean getNonPublic() { | ||
return nonPublic; | ||
} | ||
|
||
private final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
private final ZoneId zoneId = ZoneId.systemDefault(); | ||
private final ZoneRules rules = zoneId.getRules(); | ||
private final ZoneOffset zone = rules.getOffset (Instant.now()); | ||
|
||
public Date getStartDateTime(EventsIndexerLogEntry logEntry) { | ||
try { | ||
LocalDateTime date = LocalDateTime.parse(startDate + " " + startTime, dtf); | ||
return Date.from(date.toInstant(zone)); | ||
} catch (DateTimeParseException e) { | ||
logEntry.incErrors("Error parsing end date from " + startDate, e); | ||
return null; | ||
} | ||
} | ||
|
||
public Date getEndDateTime(EventsIndexerLogEntry logEntry) { | ||
try { | ||
LocalDateTime date = LocalDateTime.parse(startDate + " " + startTime, dtf); | ||
LocalDateTime end = date.plusHours(this.length); | ||
Instant endInstant = end.toInstant(zone); | ||
return Date.from(endInstant); | ||
} catch (DateTimeParseException e) { | ||
logEntry.incErrors("Error parsing end date from " + startDate, e); | ||
return null; | ||
} | ||
} | ||
|
||
class EventField { | ||
private final String name; | ||
private final String value; | ||
private final String[] allowableValues; | ||
private final int type; | ||
private final int facet; | ||
|
||
EventField(String name, String value, String[] allowableValues, int type, int facet) { | ||
this.name = name; | ||
this.value = value; | ||
this.allowableValues = allowableValues; | ||
this.type = type; | ||
this.facet = facet; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getSolrFieldName() { | ||
String sanitized_name = this.name.replaceAll("[^a-zA-Z0-9]", "_"); | ||
switch (this.type) { | ||
case 0: // Text field | ||
return "custom_string_" + sanitized_name; | ||
case 1: // Text area | ||
return "custom_text_" + sanitized_name; | ||
case 2: // Checkbox | ||
return "custom_bool_" + sanitized_name; | ||
case 3: // Select list | ||
case 4: // Email | ||
case 5: // URL | ||
return "custom_string_" + sanitized_name; | ||
} | ||
return sanitized_name; | ||
} | ||
|
||
public String getRawValue() { | ||
return value; | ||
} | ||
|
||
public String getValue() { | ||
if (allowableValues.length > 0 && StringUtils.isNumeric(value)) { | ||
return allowableValues[Integer.parseInt(value)]; | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
public String[] getAllowableValues() { | ||
return allowableValues; | ||
} | ||
|
||
public int getType() { | ||
return type; | ||
} | ||
|
||
public int getFacet() { | ||
return facet; | ||
} | ||
} | ||
} |
Oops, something went wrong.