-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
163 additions
and
20 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
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
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
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
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,91 @@ | ||
package org.labkey.snd.query; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
import org.labkey.api.data.ColumnInfo; | ||
import org.labkey.api.data.Container; | ||
import org.labkey.api.data.DbScope; | ||
import org.labkey.api.dataiterator.AbstractDataIterator; | ||
import org.labkey.api.dataiterator.DataIterator; | ||
import org.labkey.api.dataiterator.DataIteratorContext; | ||
import org.labkey.api.dataiterator.DataIteratorUtil; | ||
import org.labkey.api.query.BatchValidationException; | ||
import org.labkey.api.query.UserSchema; | ||
import org.labkey.api.security.User; | ||
import org.labkey.api.util.logging.LogHelper; | ||
import org.labkey.snd.SNDManager; | ||
|
||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class EventNotesDataIterator extends AbstractDataIterator | ||
{ | ||
private static final SNDManager _sndManager = SNDManager.get(); | ||
private static final String EVENT_ID_COL = "eventId"; | ||
private User _user; | ||
private Container _container; | ||
private int _eventIdColIndex; | ||
private Set<Integer> _eventIds = new HashSet<>(); | ||
private DataIterator _in; | ||
private Logger log = LogHelper.getLogger(EventNotesDataIterator.class, "Fill out event notes"); | ||
|
||
public static DataIterator wrap(DataIterator in, DataIteratorContext context, Container c, User u) | ||
{ | ||
return new EventNotesDataIterator(in, context, c, u); | ||
} | ||
|
||
private EventNotesDataIterator(DataIterator in, DataIteratorContext context, Container c, User u) | ||
{ | ||
super(context); | ||
_user = u; | ||
_container = c; | ||
_in = in; | ||
|
||
_eventIdColIndex = DataIteratorUtil.createColumnNameMap(in).get(EVENT_ID_COL); | ||
} | ||
|
||
@Override | ||
public int getColumnCount() | ||
{ | ||
return _in.getColumnCount(); | ||
} | ||
|
||
@Override | ||
public ColumnInfo getColumnInfo(int i) | ||
{ | ||
return _in.getColumnInfo(i); | ||
} | ||
|
||
@Override | ||
public boolean next() throws BatchValidationException | ||
{ | ||
boolean hasNext = _in.next(); | ||
if (hasNext) | ||
{ | ||
Integer eventId = (Integer)_in.get(_eventIdColIndex); | ||
_eventIds.add(eventId); | ||
} | ||
else | ||
{ | ||
UserSchema schema = SNDManager.getSndUserSchema(_container, _user); | ||
|
||
// Add a post commit task to update the narrative cache after the transaction updating the notes is committed. | ||
SNDManager.get().getTableInfo(schema, "EventNotes").getSchema().getScope().addCommitTask(() -> { | ||
_sndManager.updateNarrativeCache(_container, _user, _eventIds, log); | ||
}, DbScope.CommitTaskOption.POSTCOMMIT); | ||
} | ||
return hasNext; | ||
} | ||
|
||
@Override | ||
public Object get(int i) | ||
{ | ||
return _in.get(i); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException | ||
{ | ||
_in.close(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/org/labkey/snd/query/EventNotesDataIteratorBuilder.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,33 @@ | ||
package org.labkey.snd.query; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.labkey.api.data.Container; | ||
import org.labkey.api.dataiterator.DataIterator; | ||
import org.labkey.api.dataiterator.DataIteratorBuilder; | ||
import org.labkey.api.dataiterator.DataIteratorContext; | ||
import org.labkey.api.dataiterator.DataIteratorUtil; | ||
import org.labkey.api.security.User; | ||
|
||
public class EventNotesDataIteratorBuilder implements DataIteratorBuilder | ||
{ | ||
private final DataIteratorBuilder in; | ||
private final User user; | ||
private final Container container; | ||
|
||
public EventNotesDataIteratorBuilder(@NotNull DataIteratorBuilder in, User user, Container container) | ||
{ | ||
this.in = in; | ||
this.user = user; | ||
this.container = container; | ||
} | ||
|
||
@Override | ||
public DataIterator getDataIterator(DataIteratorContext context) | ||
{ | ||
DataIterator it = in.getDataIterator(context); | ||
DataIterator in = DataIteratorUtil.wrapMap(it, false); | ||
return EventNotesDataIterator.wrap(in, context, container, user); | ||
} | ||
} | ||
|
||
|
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