Repository navigation
GH Issue 1640: Use a new key for provided amounts and flag old values in the sample timeline audit log #8164
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4ec48da
Record user-provided amounts under a new audit metadata key, new entr…
cnathe c421761
Flag legacy provided amounts in sample timeline audit metadata
cnathe a4f2fe2
update the tooltip warning message to remove release version number
cnathe a34e2cb
update the tooltip warning message to remove release version number
cnathe 5d5c969
Merge remote-tracking branch 'origin/release26.7-SNAPSHOT' into 26.7_…
cnathe 4309987
update the tooltip warning message
cnathe c51e030
Merge remote-tracking branch 'origin/release26.7-SNAPSHOT' into 26.7_…
cnathe 78da3c5
update sample timeline warning to be more accessible
cnathe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
104 changes: 104 additions & 0 deletions
104
experiment/src/org/labkey/experiment/samples/SampleTimelineMetadataDisplayColumn.java
This file contains hidden or 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,104 @@ | ||
| /* | ||
| * Copyright (c) 2026 LabKey Corporation | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.labkey.experiment.samples; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
| import org.labkey.api.audit.AbstractAuditTypeProvider; | ||
| import org.labkey.api.data.ColumnInfo; | ||
| import org.labkey.api.data.DataColumn; | ||
| import org.labkey.api.data.RenderContext; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import static org.labkey.api.audit.AuditHandler.DELTA_PROVIDED_DATA_PREFIX; | ||
| import static org.labkey.api.audit.AuditHandler.PROVIDED_DATA_PREFIX; | ||
| import static org.labkey.api.audit.AuditHandler.USER_PROVIDED_DATA_PREFIX; | ||
| import static org.labkey.api.audit.SampleTimelineAuditEvent.SAMPLE_TIMELINE_EVENT_TYPE; | ||
| import static org.labkey.api.exp.query.ExpMaterialTable.Column.StoredAmount; | ||
|
|
||
| /** GH Issue 1640: flags metadata that has a provided amount recorded before the large-import fix, which may be wrong. */ | ||
| public class SampleTimelineMetadataDisplayColumn extends DataColumn | ||
|
cnathe marked this conversation as resolved.
|
||
| { | ||
| private static final String LEGACY_PROVIDED_AMOUNT_KEY = PROVIDED_DATA_PREFIX + StoredAmount.label(); | ||
| private static final String WARNING_STYLE = "background-color:#fcf8e3"; | ||
| private static final String WARNING_TITLE = "Provided Amount May Be Inaccurate"; | ||
| private static final String WARNING_MESSAGE = "This provided amount value may be inaccurate if recorded during an import or update of more than 1,000 samples. To confirm the provided amount, check the original import file or source data. The stored sample amount is not affected."; | ||
|
|
||
| public SampleTimelineMetadataDisplayColumn(ColumnInfo col) | ||
| { | ||
| super(col); | ||
| } | ||
|
|
||
| static boolean containsLegacyProvidedAmount(@Nullable Object metadata) | ||
| { | ||
| return metadata instanceof String str | ||
| && AbstractAuditTypeProvider.decodeFromDataMap(str).containsKey(LEGACY_PROVIDED_AMOUNT_KEY); | ||
| } | ||
|
|
||
| private boolean hasLegacyProvidedAmount(RenderContext ctx) | ||
| { | ||
| return containsLegacyProvidedAmount(getValue(ctx)); | ||
| } | ||
|
|
||
| @Override | ||
| public @NotNull String getCssStyle(RenderContext ctx) | ||
| { | ||
| String style = super.getCssStyle(ctx); | ||
| if (!hasLegacyProvidedAmount(ctx)) | ||
| return style; | ||
| return StringUtils.isEmpty(style) ? WARNING_STYLE : style + ";" + WARNING_STYLE; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getHoverContent(RenderContext ctx) | ||
| { | ||
| return hasLegacyProvidedAmount(ctx) ? WARNING_MESSAGE : super.getHoverContent(ctx); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getHoverTitle(RenderContext ctx) | ||
| { | ||
| return hasLegacyProvidedAmount(ctx) ? WARNING_TITLE : super.getHoverTitle(ctx); | ||
| } | ||
|
|
||
| public static class TestCase extends Assert | ||
| { | ||
| private static String metadata(String key, String value) | ||
| { | ||
| return AbstractAuditTypeProvider.encodeForDataMap(Map.of(key, value, SAMPLE_TIMELINE_EVENT_TYPE, "INSERT")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLegacyProvidedAmountIsFlagged() | ||
| { | ||
| assertTrue(containsLegacyProvidedAmount(metadata(PROVIDED_DATA_PREFIX + StoredAmount.label(), "2 L"))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testOtherMetadataIsNotFlagged() | ||
| { | ||
| assertFalse(containsLegacyProvidedAmount(metadata(USER_PROVIDED_DATA_PREFIX + StoredAmount.label(), "2 L"))); | ||
| assertFalse(containsLegacyProvidedAmount(metadata(DELTA_PROVIDED_DATA_PREFIX + StoredAmount.label(), "-1 mL"))); | ||
| assertFalse(containsLegacyProvidedAmount(AbstractAuditTypeProvider.encodeForDataMap(Map.of(SAMPLE_TIMELINE_EVENT_TYPE, "INSERT")))); | ||
| assertFalse(containsLegacyProvidedAmount("")); | ||
| assertFalse(containsLegacyProvidedAmount(null)); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.