Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema update and fix #144

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions api-src/org/labkey/api/snd/EventData.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class EventData
private int _superPkgId;
private int _eventId;
private Integer _parentEventDataId;
private Integer _sortOrder;
private String _narrativeTemplate;
private String _objectURI;
private List<EventData> _subPackages;
Expand All @@ -57,22 +58,26 @@ public class EventData
public static final String EVENT_DATA_OBJECTURI = "objectURI";
public static final String EVENT_DATA_EVENTID = "eventId";
public static final String EVENT_DATA_PARENT_EVENTDATAID = "parentEventDataId";
public static final String EVENT_DATA_SORT_ORDER = "sortOrder";
public static final String EVENT_DATA_CONTAINER = "Container";

public static final String EVENT_DATA_CSS_CLASS = "snd-event-data";

public static final String EVENT_DATA_EXTRA_FIELDS = "extraFields";

public EventData(@Nullable Integer eventDataId, int superPkgId, @Nullable String narrative, @Nullable List<EventData> subPackages, @NotNull List<AttributeData> attributes)
{
this(eventDataId, superPkgId, narrative, subPackages, attributes, null);
}
public EventData(@Nullable Integer eventDataId, int superPkgId, @Nullable String narrative, @Nullable List<EventData> subPackages, @NotNull List<AttributeData> attributes , @Nullable Integer sortOrder)
{
_eventDataId = eventDataId;
_superPkgId = superPkgId;
_narrativeTemplate = narrative;
_subPackages = subPackages;
_sortOrder = sortOrder;

if (attributes != null)
_attributes = attributes;
}

public EventData() {}

@Nullable
Expand Down Expand Up @@ -150,6 +155,16 @@ public void setException(Event event, ValidationException exception)
event.updateExceptionCount(exception);
}

public Integer getSortOrder()
{
return _sortOrder;
}

public void setSortOrder(Integer sortOrder)
{
_sortOrder = sortOrder;
}

@Nullable
public List<EventData> getSubPackages()
{
Expand Down Expand Up @@ -193,6 +208,7 @@ public Map<String, Object> getEventDataRow(Container c)
eventDataValues.put(EVENT_DATA_EVENTID, getEventId());
eventDataValues.put(EVENT_DATA_PARENT_EVENTDATAID, getParentEventDataId());
eventDataValues.put(EVENT_DATA_CONTAINER, c);
eventDataValues.put(EVENT_DATA_SORT_ORDER, getSortOrder());

Map<GWTPropertyDescriptor, Object> extras = getExtraFields();
for (GWTPropertyDescriptor gpd : extras.keySet())
Expand All @@ -210,6 +226,7 @@ public JSONObject toJSON(Container c, User u)
json.put(EVENT_DATA_ID, getEventDataId());
json.put(EVENT_DATA_SUPER_PACKAGE_ID, getSuperPkgId());
json.put(EVENT_DATA_NARRATIVE_TEMPLATE, getNarrativeTemplate());
json.put(EVENT_DATA_SORT_ORDER, getSortOrder());

JSONArray subPackagesJson = new JSONArray();
if (getSubPackages() != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE snd.EventData ADD SortOrder INTEGER NULL;
1 change: 1 addition & 0 deletions resources/schemas/snd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
<column columnName="EventId"/>
<column columnName="SuperPkgId"/>
<column columnName="ParentEventDataId"/>
<column columnName="SortOrder"/>
<column columnName="ObjectURI"/>
<column columnName="Container"/>
<column columnName="Lsid">
Expand Down
13 changes: 7 additions & 6 deletions src/org/labkey/snd/SNDController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1064,21 +1064,22 @@ private List<EventData> parseEventData(JSONArray eventDataJson) throws IOExcepti
{
JSONObject eventDatumJson = (JSONObject) eventDataJson.get(i);

Integer eventDataId = eventDatumJson.has("eventDataId") ? eventDatumJson.getInt("eventDataId") : null;
int superPackageId = eventDatumJson.getInt("superPkgId");
Integer eventDataId = eventDatumJson.has(EventData.EVENT_DATA_ID) ? eventDatumJson.getInt(EventData.EVENT_DATA_ID) : null;
int superPackageId = eventDatumJson.getInt(EventData.EVENT_DATA_SUPER_PACKAGE_ID);
spamhurts marked this conversation as resolved.
Show resolved Hide resolved
Integer sortOrder = eventDatumJson.has(EventData.EVENT_DATA_SORT_ORDER) ? eventDatumJson.getInt(EventData.EVENT_DATA_SORT_ORDER) : null;

List<EventData> eventDataChildren;
JSONArray eventDataChildrenJson = eventDatumJson.has("subPackages") ? eventDatumJson.getJSONArray("subPackages") : null;
JSONArray eventDataChildrenJson = eventDatumJson.has(EventData.EVENT_DATA_SUB_PACKAGES) ? eventDatumJson.getJSONArray(EventData.EVENT_DATA_SUB_PACKAGES) : null;
eventDataChildren = parseEventData(eventDataChildrenJson);

List<AttributeData> attributes;
JSONArray attributesJson = eventDatumJson.has("attributes") ? eventDatumJson.getJSONArray("attributes") : null;
JSONArray attributesJson = eventDatumJson.has(EventData.EVENT_DATA_ATTRIBUTES) ? eventDatumJson.getJSONArray(EventData.EVENT_DATA_ATTRIBUTES) : null;
attributes = parseAttributeData(attributesJson);

EventData eventData = new EventData(eventDataId, superPackageId, null, eventDataChildren, attributes);
EventData eventData = new EventData(eventDataId, superPackageId, null, eventDataChildren, attributes, sortOrder);

// Get extra fields
JSONArray jsonExtras = eventDatumJson.optJSONArray("extraFields");
JSONArray jsonExtras = eventDatumJson.optJSONArray(EventData.EVENT_DATA_EXTRA_FIELDS);
if (null != jsonExtras)
{
eventData.setExtraFields(getExtraFields(jsonExtras));
Expand Down
2 changes: 1 addition & 1 deletion src/org/labkey/snd/SNDModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String getName()
@Override
public @Nullable Double getSchemaVersion()
{
return 23.003;
return 23.004;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/org/labkey/snd/query/PackageAttributeTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public TableInfo getLookupTableInfo() {

private MutableColumnInfo getDefaultColumnInfo()
{
ExprColumn defaultCol = new ExprColumn(this, "defaultValue", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".pkgId"), JdbcType.INTEGER);
ExprColumn defaultCol = new ExprColumn(this, "defaultValue", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".pkgId"), JdbcType.VARCHAR);
defaultCol.setDisplayColumnFactory(new DisplayColumnFactory()
{
@Override
Expand Down
1 change: 1 addition & 0 deletions test/src/org/labkey/test/tests/snd/SNDTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ private static String getPackageWithId(String packageId)
" projectIdRev: '" + PKG_TEST_PROJECT_ID + "|0', \n" +
" eventData: [{ \n" +
" superPkgId: " + TEST_SUPER_PKG_START_ID5 + ", \n" +
" sortOrder: 1, \n" +
" extraFields: [], \n" +
" attributes: [] \n" +
" }] \n" +
Expand Down