Skip to content

Commit

Permalink
snd/packages and snd/categories schema (#250)
Browse files Browse the repository at this point in the history
* SND/Packages schema

* SubjectId, Date, SequenceNum

* EventData.objectid column

* objectid FK

* Filter on eventdata. Add qcstate.

* Categories schema

* Categories schema

* Avoid lookup joins for perf

* Bump schema versions to 25.000 (#248)

* Remove commented out code

---------

Co-authored-by: Marty Pradere <martyp@labkey.com>
Co-authored-by: Adam Rauch <adam@labkey.com>
  • Loading branch information
3 people authored Jan 7, 2025
1 parent 0d488ed commit fc50f56
Show file tree
Hide file tree
Showing 15 changed files with 676 additions and 52 deletions.
24 changes: 24 additions & 0 deletions api-src/org/labkey/api/snd/SNDDomainKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
*/
package org.labkey.api.snd;

import org.labkey.api.data.CompareType;
import org.labkey.api.data.Container;
import org.labkey.api.data.CoreSchema;
import org.labkey.api.data.SQLFragment;
import org.labkey.api.data.dialect.SqlDialect;
import org.labkey.api.exp.property.Domain;
import org.labkey.api.gwt.client.model.GWTPropertyDescriptor;
import org.labkey.api.query.ExtendedTableDomainKind;
import org.labkey.api.security.User;
import org.labkey.api.security.permissions.AdminPermission;
import org.labkey.api.settings.AppProps;
import org.labkey.data.xml.domainTemplate.DomainTemplateType;
import org.labkey.data.xml.domainTemplate.SNDTemplateType;

Expand Down Expand Up @@ -89,4 +94,23 @@ public boolean matchesTemplateXML(String templateName, DomainTemplateType templa
{
return template instanceof SNDTemplateType;
}


public static String formatSndDomainURI(int containerRowId, int packageId)
{
return String.format("urn:lsid:%s:package-snd.Folder-%d:Package-%d",
AppProps.getInstance().getDefaultLsidAuthority(),
containerRowId,
packageId);
}

public static SQLFragment likeSndDomainURI(Integer containerRowId, Integer packageId)
{
String pattern = String.format("urn:lsid:%s:package-snd.Folder-%s:Package-%s",
CompareType.escapeLikePattern(AppProps.getInstance().getDefaultLsidAuthority(), '!'),
null==containerRowId ? "%" : Integer.toString(containerRowId),
null==packageId ? "%" : Integer.toString(packageId)
);
return new SQLFragment("LIKE ").appendValue(pattern).append(" ESCAPE '!'");
}
}
20 changes: 16 additions & 4 deletions resources/schemas/snd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,24 @@
<deleteUrl></deleteUrl>
<columns>
<column columnName="EventDataId"/>
<column columnName="EventId"/>
<column columnName="SuperPkgId"/>
<column columnName="EventId">
<displayColumnFactory>
<className>NOLOOKUP</className>
</displayColumnFactory>
</column>
<column columnName="SuperPkgId">
<displayColumnFactory>
<className>NOLOOKUP</className>
</displayColumnFactory>
</column>
<column columnName="ParentEventDataId"/>
<column columnName="SortOrder"/>
<column columnName="ObjectURI"/>
<column columnName="Container"/>
<column columnName="ObjectURI">
<isHidden>true</isHidden>
</column>
<column columnName="Container">
<isHidden>true</isHidden>
</column>
<column columnName="Lsid">
<datatype>lsidtype</datatype>
<isReadOnly>true</isReadOnly>
Expand Down
76 changes: 76 additions & 0 deletions src/org/labkey/snd/CategoryUserSchema.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.labkey.snd;

import org.jetbrains.annotations.Nullable;
import org.labkey.api.collections.CaseInsensitiveHashSet;
import org.labkey.api.collections.CaseInsensitiveTreeSet;
import org.labkey.api.data.ContainerFilter;
import org.labkey.api.data.SQLFragment;
import org.labkey.api.data.SqlSelector;
import org.labkey.api.data.TableInfo;
import org.labkey.api.query.QuerySchema;
import org.labkey.api.query.SchemaKey;
import org.labkey.api.query.UserSchema;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class CategoryUserSchema extends UserSchema
{
public static final String SCHEMA_NAME = "Categories";

final SNDUserSchema _sndSchema;
final QuerySchema _packageSchema;

public CategoryUserSchema(SNDUserSchema parent)
{
super(new SchemaKey(parent.getSchemaPath(), SCHEMA_NAME), null, parent.getUser(), parent.getContainer(), parent.getDbSchema(), null);
_sndSchema = parent;
_packageSchema = _sndSchema.getSchema(PackageUserSchema.SCHEMA_NAME);
}

@Override
public Set<String> getSchemaNames()
{
return Set.of();
}

@Override
public Set<String> getTableNames()
{
var sql = new SQLFragment("SELECT Description FROM snd.PkgCategories WHERE Active=1 AND Container=").appendValue(getContainer());
List<String> list = new SqlSelector(getDbSchema(), sql).getArrayList(String.class);

// check for duplicates
Set<String> duplicates = new CaseInsensitiveHashSet();
Set<String> ret = new CaseInsensitiveTreeSet();
for (String s : list)
if (!ret.add(s))
duplicates.add(s);
ret.removeAll(duplicates);

return ret;
}

@Override
public @Nullable TableInfo createTable(String name, ContainerFilter cf)
{
var sql = new SQLFragment("SELECT CategoryId, Description FROM snd.PkgCategories WHERE Active=1 AND Container=").appendValue(getContainer())
.append(" AND lower(description) = lower(").appendValue(name).append(")");
Map<String,Object>[] rs = new SqlSelector(getDbSchema(), sql).getMapArray();
if (rs.length != 1)
return null;
int categoryId = (Integer)rs[0].get("CategoryId");
name = (String)rs[0].get("Description");

PackageUserSchema packageUserSchema = (PackageUserSchema)_sndSchema.getUserSchema(PackageUserSchema.SCHEMA_NAME);
if (null == packageUserSchema)
return null;

/* NOTE createCategoryTable() is implemented by PackageUserSchema for implementation sharing.
* I suppose you could argue since we're casting anyway that we could just make the required/shared
* methods public, but this works.
*/
return packageUserSchema.createCategoryTable(this, categoryId, name);
}
}
Loading

0 comments on commit fc50f56

Please sign in to comment.