1717package org .labkey .targetedms ;
1818
1919import com .google .common .base .Joiner ;
20+ import lombok .Getter ;
21+ import lombok .Setter ;
2022import org .apache .commons .io .FilenameUtils ;
2123import org .apache .commons .lang3 .StringUtils ;
2224import org .apache .logging .log4j .Logger ;
@@ -165,9 +167,18 @@ private TargetedMSManager()
165167 private static final Cache <Container , List <QCMetricConfiguration >> _metricCache = CacheManager .getBlockingCache (1000 , TimeUnit .HOURS .toMillis (1 ), "Enabled QC metric configs" ,
166168 (_ , argument ) ->
167169 {
170+ if (!(argument instanceof TargetedMSSchema schema ))
171+ {
172+ throw new IllegalArgumentException ("Argument must be a TargetedMSSchema but was " + argument );
173+ }
174+
175+ if (getFolderType (schema .getContainer ()) != TargetedMSService .FolderType .QC )
176+ {
177+ return Collections .emptyList ();
178+ }
179+
168180 try
169181 {
170- TargetedMSSchema schema = (TargetedMSSchema ) argument ;
171182 TableInfo metricsTable = schema .getTableOrThrow ("qcMetricsConfig" , null );
172183 List <QCMetricConfiguration > metrics = new TableSelector (metricsTable , null , new Sort (FieldKey .fromParts ("Name" ))).getArrayList (QCMetricConfiguration .class );
173184
@@ -207,7 +218,8 @@ public static TargetedMSManager get()
207218
208219 public static List <SampleFileChromInfo > getSampleFileChromInfos (SampleFile sampleFile )
209220 {
210- return new TableSelector (getTableInfoSampleFileChromInfo (), new SimpleFilter (FieldKey .fromParts ("SampleFileId" ), sampleFile .getId ()), new Sort ("TextId" )).getArrayList (SampleFileChromInfo .class ); }
221+ return new TableSelector (getTableInfoSampleFileChromInfo (), new SimpleFilter (FieldKey .fromParts ("SampleFileId" ), sampleFile .getId ()), new Sort ("TextId" )).getArrayList (SampleFileChromInfo .class );
222+ }
211223
212224 public static SampleFileChromInfo getSampleFileChromInfo (int id , Container c )
213225 {
@@ -548,7 +560,8 @@ public static TableInfo getTableInfoQuantificationSettings()
548560 return getSchema ().getTable (TargetedMSSchema .TABLE_QUANTIIFICATION_SETTINGS );
549561 }
550562
551- public static TableInfo getTableInfoCalibrationCurve () {
563+ public static TableInfo getTableInfoCalibrationCurve ()
564+ {
552565 return getSchema ().getTable (TargetedMSSchema .TABLE_CALIBRATION_CURVE );
553566 }
554567
@@ -628,19 +641,23 @@ public static TableInfo getTableInfoSkylineAuditLogMessage()
628641 return getSchema ().getTable (TargetedMSSchema .TABLE_SKYLINE_AUDITLOG_MESSAGE );
629642 }
630643
631- public static TableInfo getTableInfoListDefinition () {
644+ public static TableInfo getTableInfoListDefinition ()
645+ {
632646 return getSchema ().getTable (TargetedMSSchema .TABLE_LIST_DEFINITION );
633647 }
634648
635- public static TableInfo getTableInfoListColumnDefinition () {
649+ public static TableInfo getTableInfoListColumnDefinition ()
650+ {
636651 return getSchema ().getTable (TargetedMSSchema .TABLE_LIST_COLUMN_DEFINITION );
637652 }
638653
639- public static TableInfo getTableInfoListItem () {
654+ public static TableInfo getTableInfoListItem ()
655+ {
640656 return getSchema ().getTable (TargetedMSSchema .TABLE_LIST_ITEM );
641657 }
642658
643- public static TableInfo getTableInfoListItemValue () {
659+ public static TableInfo getTableInfoListItemValue ()
660+ {
644661 return getSchema ().getTable (TargetedMSSchema .TABLE_LIST_ITEM_VALUE );
645662 }
646663
@@ -1246,7 +1263,7 @@ public List<InstrumentNickname> getNickname(String name, TargetedMSSchema schema
12461263 }
12471264
12481265 List <InstrumentNickname > result = new ArrayList <>(dedupeAcrossContainers .values ());
1249-
1266+
12501267 if (matches .isEmpty ())
12511268 {
12521269 String sql = "SELECT DISTINCT InstrumentNickname, " +
@@ -2516,6 +2533,17 @@ public void moveRun(TargetedMSRun run, Container newContainer, String newRunLSID
25162533
25172534 new SqlExecutor (getSchema ()).execute (updatePrecChromInfoSql );
25182535
2536+ SQLFragment updateSampleFileChromInfoSql = new SQLFragment ("UPDATE " );
2537+ updateSampleFileChromInfoSql .append (getTableInfoSampleFileChromInfo (), "" );
2538+ updateSampleFileChromInfoSql .append (" SET container = ?" ).add (newContainer );
2539+ updateSampleFileChromInfoSql .append (" WHERE sampleFileId IN (" );
2540+ updateSampleFileChromInfoSql .append (" SELECT sf.Id FROM " ).append (getTableInfoSampleFile (), "sf" );
2541+ updateSampleFileChromInfoSql .append (" INNER JOIN " ).append (getTableInfoReplicate (), "rep" ).append (" ON rep.Id = sf.ReplicateId" );
2542+ updateSampleFileChromInfoSql .append (" WHERE rep.runId = ?" ).add (run .getId ());
2543+ updateSampleFileChromInfoSql .append (" )" );
2544+
2545+ new SqlExecutor (getSchema ()).execute (updateSampleFileChromInfoSql );
2546+
25192547 run .setExperimentRunLSID (newRunLSID );
25202548 run .setDataId (newDataRowId );
25212549 run .setContainer (newContainer );
@@ -3047,6 +3075,39 @@ private QueryUpdateService getNicknameUpdateService(User user, Container contain
30473075 return Objects .requireNonNull (table .getUpdateService ());
30483076 }
30493077
3078+ public static class InstrumentDetails
3079+ {
3080+ @ Getter @ Setter
3081+ private String instrumentSerialNumber ;
3082+ @ Getter @ Setter
3083+ private String model ;
3084+
3085+ public InstrumentDetails ()
3086+ {
3087+ }
3088+ }
3089+
3090+ public static List <InstrumentDetails > getInstrumentDetails (Container container )
3091+ {
3092+ SQLFragment sql = new SQLFragment ("SELECT DISTINCT sf.InstrumentSerialNumber, i.Model FROM " );
3093+ sql .append (getTableInfoSampleFile (), "sf" );
3094+ sql .append (" INNER JOIN " );
3095+ sql .append (getTableInfoInstrument (), "i" );
3096+ sql .append (" ON sf.InstrumentId = i.Id " );
3097+ sql .append (" INNER JOIN " );
3098+ sql .append (getTableInfoReplicate (), "rep" );
3099+ sql .append (" ON sf.ReplicateId = rep.Id " );
3100+ sql .append (" INNER JOIN " );
3101+ sql .append (getTableInfoRuns (), "r" );
3102+ sql .append (" ON rep.RunId = r.Id " );
3103+ sql .append (" WHERE r.Container = ?" );
3104+ sql .add (container );
3105+
3106+ return new SqlSelector (getSchema (), sql ).getArrayList (InstrumentDetails .class );
3107+
3108+ }
3109+
3110+
30503111 public void deleteNickname (InstrumentNickname name , User user ) throws SQLException , BatchValidationException , QueryUpdateServiceException , InvalidKeyException
30513112 {
30523113 getNicknameUpdateService (user , name .getContainer ()).
@@ -3072,4 +3133,15 @@ public void saveNickname(InstrumentNickname name, User user) throws SQLException
30723133 insertRows (user , name .getContainer (), Arrays .asList (row ), errors , null , null );
30733134 }
30743135 }
3136+
3137+ public static boolean isQCAnnotationTypeShareable (int qcAnnotationTypeId )
3138+ {
3139+ SQLFragment sql = new SQLFragment ("SELECT Shareable FROM " );
3140+ sql .append (getTableInfoQCAnnotationType ());
3141+ sql .append (" WHERE Id = ?" );
3142+ sql .add (qcAnnotationTypeId );
3143+
3144+ Boolean isShareable = new SqlSelector (getSchema (), sql ).getObject (Boolean .class );
3145+ return isShareable != null && isShareable ;
3146+ }
30753147}
0 commit comments