Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions resources/queries/targetedms/qcannotation/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<column name="Date" />
<column name="EndDate" />
<column name="QCAnnotationTypeId" />
<column name="instrumentModel" />
<column name="instrumentSerialNumber" />
<column name="Container" />
<column name="Created" />
<column name="Modified" />
Expand Down
1 change: 1 addition & 0 deletions resources/queries/targetedms/qcannotationtype/.qview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<column name="Description" />
<column name="Color" />
<column name="Container" />
<column name="IsShareable"/>
<column name="Created" />
<column name="Modified" />
</columns>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE targetedms.QCAnnotationType ADD COLUMN isShareable BOOLEAN DEFAULT FALSE;
ALTER TABLE targetedms.QCAnnotation ADD COLUMN instrumentModel VARCHAR(255);
ALTER TABLE targetedms.QCAnnotation ADD COLUMN instrumentSerialNumber VARCHAR(255);
3 changes: 3 additions & 0 deletions resources/schemas/targetedms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@
<column columnName="Name"/>
<column columnName="Description"/>
<column columnName="Color"/>
<column columnName="IsShareable"/>
</columns>
</table>

Expand Down Expand Up @@ -1307,6 +1308,8 @@
<columnTitle>Annotation Type</columnTitle>
<description>The category of the event</description>
</column>
<column columnName="instrumentModel"/>
<column columnName="instrumentSerialNumber"/>
</columns>
</table>
<table tableName="QCMetricConfiguration" tableDbType="TABLE">
Expand Down
68 changes: 61 additions & 7 deletions src/org/labkey/targetedms/TargetedMSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.labkey.targetedms;

import com.google.common.base.Joiner;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -207,7 +209,8 @@ public static TargetedMSManager get()

public static List<SampleFileChromInfo> getSampleFileChromInfos(SampleFile sampleFile)
{
return new TableSelector(getTableInfoSampleFileChromInfo(), new SimpleFilter(FieldKey.fromParts("SampleFileId"), sampleFile.getId()), new Sort("TextId")).getArrayList(SampleFileChromInfo.class); }
return new TableSelector(getTableInfoSampleFileChromInfo(), new SimpleFilter(FieldKey.fromParts("SampleFileId"), sampleFile.getId()), new Sort("TextId")).getArrayList(SampleFileChromInfo.class);
}

public static SampleFileChromInfo getSampleFileChromInfo(int id, Container c)
{
Expand Down Expand Up @@ -548,7 +551,8 @@ public static TableInfo getTableInfoQuantificationSettings()
return getSchema().getTable(TargetedMSSchema.TABLE_QUANTIIFICATION_SETTINGS);
}

public static TableInfo getTableInfoCalibrationCurve() {
public static TableInfo getTableInfoCalibrationCurve()
{
return getSchema().getTable(TargetedMSSchema.TABLE_CALIBRATION_CURVE);
}

Expand Down Expand Up @@ -628,19 +632,23 @@ public static TableInfo getTableInfoSkylineAuditLogMessage()
return getSchema().getTable(TargetedMSSchema.TABLE_SKYLINE_AUDITLOG_MESSAGE);
}

public static TableInfo getTableInfoListDefinition() {
public static TableInfo getTableInfoListDefinition()
{
return getSchema().getTable(TargetedMSSchema.TABLE_LIST_DEFINITION);
}

public static TableInfo getTableInfoListColumnDefinition() {
public static TableInfo getTableInfoListColumnDefinition()
{
return getSchema().getTable(TargetedMSSchema.TABLE_LIST_COLUMN_DEFINITION);
}

public static TableInfo getTableInfoListItem() {
public static TableInfo getTableInfoListItem()
{
return getSchema().getTable(TargetedMSSchema.TABLE_LIST_ITEM);
}

public static TableInfo getTableInfoListItemValue() {
public static TableInfo getTableInfoListItemValue()
{
return getSchema().getTable(TargetedMSSchema.TABLE_LIST_ITEM_VALUE);
}

Expand Down Expand Up @@ -1246,7 +1254,7 @@ public List<InstrumentNickname> getNickname(String name, TargetedMSSchema schema
}

List<InstrumentNickname> result = new ArrayList<>(dedupeAcrossContainers.values());

if (matches.isEmpty())
{
String sql = "SELECT DISTINCT InstrumentNickname, " +
Expand Down Expand Up @@ -3046,6 +3054,41 @@ private QueryUpdateService getNicknameUpdateService(User user, Container contain
return Objects.requireNonNull(table.getUpdateService());
}

public static class InstrumentDetails
{
@Getter @Setter
private String instrumentSerialNumber;
@Getter @Setter
private String model;
@Getter @Setter
private Long instrumentId;

public InstrumentDetails()
{
}
}

public static List<InstrumentDetails> getInstrumentDetails(Container container)
{
SQLFragment sql = new SQLFragment("SELECT DISTINCT sf.InstrumentSerialNumber, i.Model, i.Id AS InstrumentId FROM ");
sql.append(getTableInfoSampleFile(), "sf");
sql.append(" INNER JOIN ");
sql.append(getTableInfoInstrument(), "i");
sql.append(" ON sf.InstrumentId = i.Id ");
sql.append(" INNER JOIN ");
sql.append(getTableInfoReplicate(), "rep");
sql.append(" ON sf.ReplicateId = rep.Id ");
sql.append(" INNER JOIN ");
sql.append(getTableInfoRuns(), "r");
sql.append(" ON rep.RunId = r.Id ");
sql.append(" WHERE r.Container = ?");
sql.add(container);

return new SqlSelector(getSchema(), sql).getArrayList(InstrumentDetails.class);

}


public void deleteNickname(InstrumentNickname name, User user) throws SQLException, BatchValidationException, QueryUpdateServiceException, InvalidKeyException
{
getNicknameUpdateService(user, name.getContainer()).
Expand All @@ -3071,4 +3114,15 @@ public void saveNickname(InstrumentNickname name, User user) throws SQLException
insertRows(user, name.getContainer(), Arrays.asList(row), errors, null, null);
}
}

public static boolean isQCAnnotationTypeShareable(int qcAnnotationTypeId)
{
SQLFragment sql = new SQLFragment("SELECT IsShareable FROM ");
sql.append(getTableInfoQCAnnotationType());
sql.append(" WHERE Id = ?");
sql.add(qcAnnotationTypeId);

Boolean isShareable = new SqlSelector(getSchema(), sql).getObject(Boolean.class);
return isShareable != null && isShareable;
}
}
2 changes: 1 addition & 1 deletion src/org/labkey/targetedms/TargetedMSModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public String getName()
@Override
public Double getSchemaVersion()
{
return 26.002;
return 26.003;
}

@Override
Expand Down
74 changes: 74 additions & 0 deletions src/org/labkey/targetedms/query/QCAnnotationTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,27 @@
*/
package org.labkey.targetedms.query;

import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerFilter;
import org.labkey.api.data.TableInfo;
import org.labkey.api.gwt.client.AuditBehaviorType;
import org.labkey.api.query.BatchValidationException;
import org.labkey.api.query.DefaultQueryUpdateService;
import org.labkey.api.query.DuplicateKeyException;
import org.labkey.api.query.QueryForeignKey;
import org.labkey.api.query.QueryUpdateService;
import org.labkey.api.query.QueryUpdateServiceException;
import org.labkey.api.query.SimpleUserSchema;
import org.labkey.api.query.ValidationException;
import org.labkey.api.security.User;
import org.labkey.targetedms.TargetedMSManager;
import org.labkey.targetedms.TargetedMSSchema;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import static org.labkey.targetedms.query.GuideSetTable.appendFormatLabel;

/**
Expand All @@ -44,4 +58,64 @@ public QCAnnotationTable(TargetedMSSchema schema, ContainerFilter cf)
appendFormatLabel(getMutableColumn("EndDate"));
setAuditBehavior(AuditBehaviorType.DETAILED);
}

@Override
public QueryUpdateService getUpdateService()
{
TableInfo table = getRealTable();
if (table != null)
{
return new DefaultQueryUpdateService(this, getRealTable())
{
@Override
public List<Map<String, Object>> insertRows(User user, Container container, List<Map<String, Object>> rows, BatchValidationException errors, @Nullable Map<Enum, Object> configParameters, @Nullable Map<String, Object> extraScriptContext) throws SQLException, QueryUpdateServiceException, DuplicateKeyException
{
List<Map<String, Object>> resultRows = new java.util.ArrayList<>();
for (Map<String, Object> row : rows)
{
try
{
// Check if the QCAnnotationType is shareable
int qcAnnotationTypeId = (Integer) row.get("QCAnnotationTypeId");
boolean isShareable = TargetedMSManager.isQCAnnotationTypeShareable(qcAnnotationTypeId);

if (isShareable)
{
List<TargetedMSManager.InstrumentDetails> instruments = TargetedMSManager.getInstrumentDetails(getContainer());
if (instruments.isEmpty())
{
resultRows.add(super.insertRow(user, container, row));
}
else
{
for (TargetedMSManager.InstrumentDetails instrument : instruments)
{
Map<String, Object> newRow = new java.util.HashMap<>(row);
newRow.put("instrumentModel", instrument.getModel());
newRow.put("instrumentSerialNumber", instrument.getInstrumentSerialNumber());
newRow.put("Container", getContainer().getId());
resultRows.add(super.insertRow(user, container, newRow));
}
}
}
else
{
resultRows.add(super.insertRow(user, container, row));
}
}
catch (ValidationException e)
{
errors.addRowError(e);
}
}

if (errors.hasErrors())
return null;

return resultRows;
}
};
}
return null;
}
}
Loading