Skip to content

Commit

Permalink
Merge 23.7 to 23.8
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-teamcity committed Aug 14, 2023
2 parents 5e4eb0d + 2d4fe8a commit b907b8a
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 78 deletions.
17 changes: 17 additions & 0 deletions resources/queries/snd/LookupSets.query.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<query xmlns="http://labkey.org/data/xml/query">
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="LookupSets" tableDbType="NOT_IN_DB">
<titleColumn>SetName</titleColumn>
<columns>
<column columnName="LookupSetId">
<isHidden>true</isHidden>
</column>
<column columnName="IsInUse">
<isHidden>true</isHidden>
</column>
</columns>
</table>
</tables>
</metadata>
</query>
8 changes: 8 additions & 0 deletions resources/queries/snd/LookupSets/.qview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<columns>
<column name="SetName"/>
</columns>
<sorts>
<sort column="SetName"/>
</sorts>
</customView>
16 changes: 5 additions & 11 deletions resources/queries/snd/Lookups.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ function beforeUpdate(row, errors) {
}

function beforeDelete(row, errors) {
/*
TODO: Need a better way to determine if a lookupset item is in use. Probably need to add the check to
the deleteRows method in LookupsTable.java. NOTE: CAMP allows the lookup item to be deleted if it hasn't
been assigned as a default value or used in an event. tjh
*/
if (row.LookupSetId !== undefined) {

let lookupQuery
Expand Down Expand Up @@ -81,18 +76,17 @@ function beforeDelete(row, errors) {

LABKEY.Query.selectRows({
schemaName: 'snd',
queryName: 'PackageAttribute',
columns: 'LookupQuery',
queryName: 'Lookups',
columns: 'IsInUse',
scope: this,
filterArray: [
LABKEY.Filter.create('LookupQuery', lookupQuery, LABKEY.Filter.Types.EQUAL),
LABKEY.Filter.create('LookupSchema', 'snd', LABKEY.Filter.Types.EQUAL)
LABKEY.Filter.create('LookupId', row["LookupId"], LABKEY.Filter.Types.EQUAL),
LABKEY.Filter.create('IsInUse', 'true', LABKEY.Filter.Types.EQUAL)

],
success: function (data) {
if (data.rows && data.rows.length) {
errors._form = 'Lookup item cannot be deleted - LookupSet is in use.'
return;
errors._form = 'Lookup item cannot be deleted - Lookup is in use.'
}
},
failure: function (error) {
Expand Down
11 changes: 11 additions & 0 deletions resources/queries/snd/Lookups.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
<tables xmlns="http://labkey.org/data/xml">
<table tableName="Lookups" tableDbType="NOT_IN_DB">
<titleColumn>Value</titleColumn>
<columns>
<column columnName="LookupSetId">
<isHidden>true</isHidden>
</column>
<column columnName="LookupId">
<isHidden>true</isHidden>
</column>
<column columnName="IsInUse">
<isHidden>true</isHidden>
</column>
</columns>
</table>
</tables>
</metadata>
Expand Down
11 changes: 11 additions & 0 deletions resources/queries/snd/Lookups/.qview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<customView xmlns="http://labkey.org/data/xml/queryCustomView">
<columns>
<column name="Value"/>
<column name="Displayable"/>
<column name="SortOrder"/>
</columns>
<sorts>
<sort column="SortOrder"/>
<sort column="Value"/>
</sorts>
</customView>
2 changes: 2 additions & 0 deletions resources/schemas/dbscripts/sqlserver/snd-23.001-23.003.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE UNIQUE INDEX IDX_LookupSets_SetName
ON snd.LookupSets (SetName)
2 changes: 1 addition & 1 deletion src/org/labkey/snd/SNDManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3380,5 +3380,5 @@ public List<Map<String, Object>> getProjectItemsList(Container c, User u, int pr

return projectItems;
}

}
2 changes: 1 addition & 1 deletion src/org/labkey/snd/SNDModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String getName()
@Override
public @Nullable Double getSchemaVersion()
{
return 23.001;
return 23.003;
}

@Override
Expand Down
5 changes: 1 addition & 4 deletions src/org/labkey/snd/SNDSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ public TableInfo getTableInfoLookups()
return getSchema().getTable(LOOKUPS_TABLE_NAME);
}

public TableInfo getTableInfoLookupSets()
{
return getSchema().getTable(LOOKUPSETS_TABLE_NAME);
}
public TableInfo getTableInfoLookupSets() { return getSchema().getTable(LOOKUPSETS_TABLE_NAME); }

public TableInfo getTableInfoEventsCache()
{
Expand Down
13 changes: 5 additions & 8 deletions src/org/labkey/snd/SNDUserSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.labkey.snd.query.EventsCacheTable;
import org.labkey.snd.query.EventsTable;
import org.labkey.snd.query.LookupSetsTable;
import org.labkey.snd.query.LookupSetsVirtualTable;
import org.labkey.snd.query.LookupsTable;
import org.labkey.snd.query.PackageAttributeTable;
import org.labkey.snd.query.PackagesTable;
Expand Down Expand Up @@ -203,11 +204,7 @@ public TableInfo createTable(SNDUserSchema schema, ContainerFilter cf)
@Override
public TableInfo createTable(SNDUserSchema schema, ContainerFilter cf)
{
SimpleUserSchema.SimpleTable<SNDUserSchema> table =
new SimpleUserSchema.SimpleTable<>(
schema, SNDSchema.getInstance().getTableInfoLookupSets(), cf).init();

return table;
return new LookupSetsTable(schema, SNDSchema.getInstance().getTableInfoLookupSets(), cf).init();
}
},
EventsCache
Expand Down Expand Up @@ -254,7 +251,7 @@ public TableInfo createTable(String name, ContainerFilter cf)
if (nameMap.containsKey(name))
{
TableInfo table = SNDSchema.getInstance().getTableInfoLookups();
return new LookupSetsTable(this, table, name, nameMap.get(name), cf).init();
return new LookupSetsVirtualTable(this, table, name, nameMap.get(name), cf).init();
}
}
}
Expand All @@ -263,7 +260,7 @@ public TableInfo createTable(String name, ContainerFilter cf)

public Map<String, Map<String, Object>> getLookupSets()
{
Map<String, Map<String, Object>> nameMap = SNDManager.get().getCache().get(LookupSetsTable.getCacheKey(getContainer()));
Map<String, Map<String, Object>> nameMap = SNDManager.get().getCache().get(LookupSetsVirtualTable.getCacheKey(getContainer()));
if (nameMap != null)
return nameMap;

Expand All @@ -283,7 +280,7 @@ public Map<String, Map<String, Object>> getLookupSets()
}

nameMap = Collections.unmodifiableMap(nameMap);
SNDManager.get().getCache().put(LookupSetsTable.getCacheKey(getContainer()), nameMap);
SNDManager.get().getCache().put(LookupSetsVirtualTable.getCacheKey(getContainer()), nameMap);

return nameMap;
}
Expand Down
78 changes: 25 additions & 53 deletions src/org/labkey/snd/query/LookupSetsTable.java
Original file line number Diff line number Diff line change
@@ -1,70 +1,42 @@
/*
* Copyright (c) 2018-2019 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.snd.query;

import org.labkey.api.data.ColumnInfo;
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerFilter;
import org.labkey.api.data.JdbcType;
import org.labkey.api.data.SQLFragment;
import org.labkey.api.data.TableInfo;
import org.labkey.api.query.ExprColumn;
import org.labkey.api.query.SimpleUserSchema.SimpleTable;
import org.labkey.snd.SNDSchema;
import org.labkey.snd.SNDUserSchema;

import java.util.Map;
public class LookupSetsTable extends SimpleTable<SNDUserSchema> {

/**
* Created by marty on 9/17/2017.
*/
public class LookupSetsTable extends SimpleTable<SNDUserSchema>
{
private static final String CACHE_KEY = LookupSetsTable.class.getName() + "||values";
private static final String SETNAME_COL = "SetName";
private static final String LABEL_COL = "Label";
private static final String DESCRIPTION_COL = "Description";
private static final String LOOKUPSETID_COL = "LookupSetId";
private Integer _lookupSetId;


public LookupSetsTable(SNDUserSchema schema, TableInfo table, String setName, Map<String, Object> map, ContainerFilter cf)
{
super(schema, table, cf);

_lookupSetId = (Integer) map.get(LOOKUPSETID_COL);

if (map.containsKey(LABEL_COL))
setTitle((String)map.get(LABEL_COL));

if (map.containsKey(DESCRIPTION_COL))
setDescription((String) map.get(DESCRIPTION_COL));

}

public static String getCacheKey(Container c)
{
return CACHE_KEY + "||" + c.getId();
}
/**
* Create the simple table.
* SimpleTable doesn't add columns until .init() has been called to allow derived classes to fully initialize themselves before adding columns.
*
* @param schema
* @param table
*/
public LookupSetsTable(SNDUserSchema schema, TableInfo table, ContainerFilter cf) { super(schema, table, cf); }

@Override
public LookupSetsTable init()
{
public LookupSetsTable init() {
super.init();

ColumnInfo col = getRealTable().getColumn(LOOKUPSETID_COL);
addCondition(col, _lookupSetId);
SQLFragment isInUseQuery = new SQLFragment();
isInUseQuery.append("(CASE WHEN EXISTS (SELECT ls.SetName FROM ");
isInUseQuery.append(SNDSchema.getInstance().getTableInfoLookupSets(), "ls");
isInUseQuery.append(" INNER JOIN ");
isInUseQuery.append(_userSchema.getTable("PackageAttribute").getFromSQL("pa"));
isInUseQuery.append(" ON ls.SetName = pa.LookupQuery ");
isInUseQuery.append(" WHERE " + ExprColumn.STR_TABLE_ALIAS + ".LookupSetId = ls.LookupSetId) ");
isInUseQuery.append(" THEN 'true' else 'false' END)");
ExprColumn isInUseColumn = new ExprColumn(this, "IsInUse", isInUseQuery, JdbcType.BOOLEAN);
addColumn(isInUseColumn);

return this;
}

}

74 changes: 74 additions & 0 deletions src/org/labkey/snd/query/LookupSetsVirtualTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2018-2019 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.snd.query;

import org.labkey.api.data.ColumnInfo;
import org.labkey.api.data.Container;
import org.labkey.api.data.ContainerFilter;
import org.labkey.api.data.JdbcType;
import org.labkey.api.data.SQLFragment;
import org.labkey.api.data.TableInfo;
import org.labkey.api.query.ExprColumn;
import org.labkey.api.query.SimpleUserSchema.SimpleTable;
import org.labkey.snd.SNDSchema;
import org.labkey.snd.SNDUserSchema;

import java.util.Map;

/**
* Created by marty on 9/17/2017.
*/
public class LookupSetsVirtualTable extends SimpleTable<SNDUserSchema>
{
private static final String CACHE_KEY = LookupSetsVirtualTable.class.getName() + "||values";
private static final String SETNAME_COL = "SetName";
private static final String LABEL_COL = "Label";
private static final String DESCRIPTION_COL = "Description";
private static final String LOOKUPSETID_COL = "LookupSetId";
private Integer _lookupSetId;


public LookupSetsVirtualTable(SNDUserSchema schema, TableInfo table, String setName, Map<String, Object> map, ContainerFilter cf)
{
super(schema, table, cf);

_lookupSetId = (Integer) map.get(LOOKUPSETID_COL);

if (map.containsKey(LABEL_COL))
setTitle((String)map.get(LABEL_COL));

if (map.containsKey(DESCRIPTION_COL))
setDescription((String) map.get(DESCRIPTION_COL));

}

public static String getCacheKey(Container c)
{
return CACHE_KEY + "||" + c.getId();
}

@Override
public LookupSetsVirtualTable init()
{
super.init();

ColumnInfo col = getRealTable().getColumn(LOOKUPSETID_COL);
addCondition(col, _lookupSetId);

return this;
}

}
Loading

0 comments on commit b907b8a

Please sign in to comment.