2020import org .jetbrains .annotations .Nullable ;
2121import org .labkey .api .collections .CaseInsensitiveHashMap ;
2222import org .labkey .api .data .Container ;
23+ import org .labkey .api .exp .api .ExperimentService ;
2324import org .labkey .api .qc .DataState ;
2425import org .labkey .api .qc .SampleStatusService ;
2526import org .labkey .api .query .QueryService ;
@@ -224,46 +225,42 @@ public Map<String, Object> getAuditLogMessageElements()
224225 return elements ;
225226 }
226227
227- /**
228- * If the sample state changed, explicitly add in the Status Label value to the map so that it will render in the
229- * audit log timeline event even if the DataState row is later deleted. Also, remove the aliquot rollup calculated
230- * fields from the data.
231- */
232228 @ Override
233229 public void setOldRecordMap (String oldRecordMap , Container container )
234230 {
235- if (oldRecordMap != null )
236- {
237- Map <String , String > row = new CaseInsensitiveHashMap <>(AbstractAuditTypeProvider .decodeFromDataMap (oldRecordMap ));
238- EXCLUDED_DETAIL_FIELDS .forEach (row ::remove );
239- String label = getStatusLabel (row , container );
240- if (label != null )
241- {
242- row .put ("samplestatelabel" , label );
243- oldRecordMap = AbstractAuditTypeProvider .encodeForDataMap (row );
244- }
245- }
246- super .setOldRecordMap (oldRecordMap );
231+ super .setOldRecordMap (withResolvedLabels (oldRecordMap , container ));
247232 }
248233
249- /**
250- * If the sample state changed, explicitly add in the Status Label value to the map so that it will render in the
251- * audit log timeline event even if the DataState row is later deleted. Also, remove the aliquot rollup calculated
252- * fields from the data.
253- */
254234 @ Override
255235 public void setNewRecordMap (String newRecordMap , Container container )
256236 {
257- if (newRecordMap != null )
237+ super .setNewRecordMap (withResolvedLabels (newRecordMap , container ), container );
238+ }
239+
240+ /**
241+ * If the sample state or color changed, explicitly add the resolved Status/Color label to the map so it renders in
242+ * the audit log timeline event even if the DataState/DataColor row is later deleted. Also removes the aliquot rollup
243+ * calculated fields from the data.
244+ */
245+ private String withResolvedLabels (String recordMap , Container container )
246+ {
247+ if (recordMap == null )
248+ return null ;
249+
250+ Map <String , String > row = new CaseInsensitiveHashMap <>(AbstractAuditTypeProvider .decodeFromDataMap (recordMap ));
251+ EXCLUDED_DETAIL_FIELDS .forEach (row ::remove );
252+
253+ String statusLabel = getStatusLabel (row , container );
254+ if (row .containsKey ("samplestate" ))
255+ row .put ("samplestatelabel" , statusLabel );
256+
257+ if (row .containsKey (ExpMaterialColor .name ()))
258258 {
259- Map <String , String > row = new CaseInsensitiveHashMap <>(AbstractAuditTypeProvider .decodeFromDataMap (newRecordMap ));
260- EXCLUDED_DETAIL_FIELDS .forEach (row ::remove );
261- String label = getStatusLabel (row , container );
262- if (label != null )
263- row .put ("samplestatelabel" , label );
264- newRecordMap = AbstractAuditTypeProvider .encodeForDataMap (row );
259+ String colorLabel = getColorLabel (row , container );
260+ row .put ("expmaterialcolorlabel" , colorLabel );
265261 }
266- super .setNewRecordMap (newRecordMap , container );
262+
263+ return AbstractAuditTypeProvider .encodeForDataMap (row );
267264 }
268265
269266 private String getStatusLabel (Map <String , String > row , Container container )
@@ -276,4 +273,12 @@ private String getStatusLabel(Map<String, String> row, Container container)
276273 }
277274 return null ;
278275 }
276+
277+ private String getColorLabel (Map <String , String > row , Container container )
278+ {
279+ String value = row .get (ExpMaterialColor .name ());
280+ if (!StringUtils .isBlank (value ))
281+ return ExperimentService .get ().getDataColorLabel (container , Long .parseLong (value ));
282+ return null ;
283+ }
279284}
0 commit comments