Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bot] Merge 25.1 to develop #252

Merged
merged 4 commits into from
Jan 8, 2025
Merged
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
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
Loading