Skip to content

Commit

Permalink
new feature branch from snapshot (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
jallentxbiomed authored Aug 14, 2024
1 parent cb33b9e commit 8cf8758
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/org/labkey/snd/SNDController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1040,14 +1040,19 @@ public ApiResponse execute(SimpleApiJsonForm form, BindException errors)
}

Event savedEvent = SNDService.get().saveEvent(getContainer(), getUser(), event, validateOnly);
response.put("event", savedEvent.toJSON(getContainer(), getUser()));

if (savedEvent.hasErrors())
{
response.put("success", false);
}
else
{
if (savedEvent != null) {
response.put("event", savedEvent.toJSON(getContainer(), getUser()));
if (savedEvent.hasErrors())
{
response.put("success", false);
}
else
{
response.put("success", true);
}
} else {
response.put("event", null);
response.put("success", true);
}
}
Expand Down
46 changes: 46 additions & 0 deletions src/org/labkey/snd/SNDManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,52 @@ private void deleteExpObjects(Container c, User u, int eventId)
}
}

public Event deleteEvent(Container c, User u, Event event) {

if (!event.hasErrors()) {
UserSchema schema = getSndUserSchemaAdminRole(c, u);
TableInfo eventTable = getTableInfo(schema, SNDSchema.EVENTS_TABLE_NAME);
QueryUpdateService eventQus = getQueryUpdateService(eventTable);

BatchValidationException errors = new BatchValidationException();

try (DbScope.Transaction tx = eventTable.getSchema().getScope().ensureTransaction())
{
deleteEventDatas(c, u, event.getEventId());
deleteEventNotes(c, u, event.getEventId());
deleteEventsCache(c, u, event.getEventId());
NarrativeAuditProvider.addAuditEntry(c, u, event.getEventId(), event.getSubjectId(), event.getDate(), "", event.getQcState(), "Delete event");

Map<String, Object> row;
List<Map<String, Object>> rows = new ArrayList<>();
row = new HashMap<>();
row.put("EventId", event.getEventId());
rows.add(row);
eventQus.deleteRows(u, c, rows, null, null);

tx.commit();

} catch (QueryUpdateServiceException | BatchValidationException | SQLException | InvalidKeyException e) {

event.setException(new ValidationException(e.getMessage(), ValidationException.SEVERITY.ERROR));

} finally
{
if (errors.hasErrors())
{
event.addBatchValidationExceptions(errors);
}
// Errors, warnings and info are embedded in the event so don't override
else if (!event.hasErrorsWarningsOrInfo())
{
event = getEvent(c, u, event.getEventId(), null, null, true, errors);
}
}
}

return event;
}

/**
* Called from SNDService.saveEvent to update an existing event.
*/
Expand Down
12 changes: 11 additions & 1 deletion src/org/labkey/snd/SNDServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,17 @@ public Event saveEvent(Container c, User u, Event event, boolean validateOnly)
{
if (event.getEventId() != null && SNDManager.get().eventExists(c, u, event.getEventId()))
{
event = SNDManager.get().updateEvent(c, u, event, validateOnly);
if ((event.getEventData() == null || event.getEventData().isEmpty()) &&
(!event.getEventNotesRow(c).containsKey("note") ||
event.getEventNotesRow(c).get("note") == null ||
event.getEventNotesRow(c).get("note").toString().trim().length() == 0))
{
event = SNDManager.get().deleteEvent(c, u, event);
}
else
{
event = SNDManager.get().updateEvent(c, u, event, validateOnly);
}
}
else
{
Expand Down

0 comments on commit 8cf8758

Please sign in to comment.