Skip to content
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
129 changes: 0 additions & 129 deletions LDK/src/org/labkey/ldk/LDKController.java
Original file line number Diff line number Diff line change
Expand Up @@ -889,135 +889,6 @@ public void addNavTrail(NavTree root)
}
}

@RequiresPermission(AdminPermission.class)
public static class MoveWorkbookAction extends ConfirmAction<MoveWorkbookForm>
{
private Container _movedWb = null;

@Override
public void validateCommand(MoveWorkbookForm form, Errors errors)
{

}

@Override
public ModelAndView getConfirmView(MoveWorkbookForm form, BindException errors) throws Exception
{
if (!getContainer().isWorkbook())
{
errors.reject(ERROR_MSG, "This is only supported for workbooks");
return new SimpleErrorView(errors);
}

String sb = "This will move this workbook to the selected folder, renaming this workbook to match the series in that container. Note: there are many reasons this can be problematic, so please do this with great care<p>" +
"<input name=\"targetContainer\" type=\"text\"></input>";

return new HtmlView(sb);
}

@Override
public boolean handlePost(MoveWorkbookForm form, BindException errors) throws Exception
{
Container toMove = getContainer();
if (!toMove.isWorkbook())
{
errors.reject(ERROR_MSG, "This is only supported for workbooks");
return false;
}

if (StringUtils.trimToNull(form.getTargetContainer()) == null)
{
errors.reject(ERROR_MSG, "Must provide target container");
return false;
}

Container target = ContainerManager.getForPath(StringUtils.trimToNull(form.getTargetContainer()));
if (target == null)
{
target = ContainerManager.getForId(StringUtils.trimToNull(form.getTargetContainer()));
}

if (target == null)
{
errors.reject(ERROR_MSG, "Unknown container: " + form.getTargetContainer());
return false;
}

if (target.isWorkbook())
{
errors.reject(ERROR_MSG, "Target cannot be a workbook: " + form.getTargetContainer());
return false;
}

if (ContainerManager.isSystemContainer(target))
{
errors.reject(ERROR_MSG, "Cannot move to system containers: " + form.getTargetContainer());
return false;
}

if (target.equals(toMove.getParent()))
{
errors.reject(ERROR_MSG, "Cannot move the workbook to its current parent: " + form.getTargetContainer());
return false;
}

//NOTE: transaction causing problems for larger sites?
//try (DbScope.Transaction transaction = CoreSchema.getInstance().getSchema().getScope().ensureTransaction())
//{
//first rename workbook to make unique
String tempName = new GUID().toString();
int sortOrder = (int)DbSequenceManager.get(target, ContainerManager.WORKBOOK_DBSEQUENCE_NAME).next();
_log.info("renaming workbook to in preparation for move from: " + toMove.getPath() + " to: " + tempName);
ContainerManager.rename(toMove, getUser(), tempName);
toMove = ContainerManager.getForId(toMove.getId());

//then move parent
_log.info("moving workbook from: " + toMove.getPath() + " to: " + target.getPath());
ContainerManager.move(toMove, target, getUser());
toMove = ContainerManager.getForId(toMove.getId());

//finally move to correct name
_log.info("renaming workbook from: " + toMove.getPath() + " to: " + sortOrder);
ContainerManager.rename(toMove, getUser(), String.valueOf(sortOrder));
toMove.setSortOrder(sortOrder);
new SqlExecutor(CoreSchema.getInstance().getSchema()).execute("UPDATE core.containers SET SortOrder = ? WHERE EntityId = ?", toMove.getSortOrder(), toMove.getId());
toMove = ContainerManager.getForId(toMove.getId());

//transaction.commit();
_log.info("workbook move finished");

_movedWb = toMove;
//}

return true;
}

@NotNull
@Override
public URLHelper getSuccessURL(MoveWorkbookForm moveWorkbookForm)
{
if (_movedWb == null)
return getContainer().getStartURL(getUser());
else
return _movedWb.getStartURL(getUser());
}
}

public static class MoveWorkbookForm
{
private String _targetContainer;

public String getTargetContainer()
{
return _targetContainer;
}

public void setTargetContainer(String targetContainer)
{
_targetContainer = targetContainer;
}
}

@RequiresNoPermission
public static class RedirectStartAction extends SimpleViewAction<Object>
{
Expand Down
54 changes: 50 additions & 4 deletions LDK/src/org/labkey/ldk/query/DefaultTableCustomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,24 @@ private void setDetailsUrl(AbstractTableInfo ti)

List<String> keyFields = ti.getPkColumnNames();
assert !keyFields.isEmpty() : "No key fields found for the table: " + ti.getPublicSchemaName() + "." + ti.getPublicName();
if (keyFields.size() != 1)

if (_settings.getPrimaryKeyField() != null)
{
String alternatePK = _settings.getPrimaryKeyField();
if (!keyFields.contains(alternatePK))
{
_log.error("Table: " + ti.getUserSchema().getSchemaName() + "." + ti.getPublicName() + " supplied an alternate primaryKeyField that doesnt match actual PKs: " + alternatePK);
return;
}

keyFields = Collections.singletonList(alternatePK);
}

if (keyFields.isEmpty())
{
return;
}
else if (keyFields.size() > 1)
{
_log.error("Table: " + ti.getUserSchema().getSchemaName() + "." + ti.getPublicName() + " has more than 1 PK: " + StringUtils.join(keyFields, ";") + ", cannot apply custom links - please update the TableCustomizer properties");
return;
Expand Down Expand Up @@ -159,13 +176,30 @@ else if (_settings.isSetEditLinkOverrides())

List<String> keyFields = ti.getPkColumnNames();
assert !keyFields.isEmpty() : "No key fields found for the table: " + ti.getPublicSchemaName() + "." + ti.getPublicName();
if (keyFields.size() != 1)

if (_settings.getPrimaryKeyField() != null)
{
String alternatePK = _settings.getPrimaryKeyField();
if (!keyFields.contains(alternatePK))
{
_log.error("Table: " + ti.getUserSchema().getSchemaName() + "." + ti.getPublicName() + " supplied an alternate primaryKeyField that doesnt match actual PKs: " + alternatePK);
return;
}

keyFields = Collections.singletonList(alternatePK);
}

if (keyFields.isEmpty())
{
return;
}
else if (keyFields.size() != 1)
{
_log.error("Table: " + schemaName + "." + queryName + " has more than 1 PK: " + StringUtils.join(keyFields, ";") + ", cannot apply custom links - please update the TableCustomizer properties");
return;
}

if (schemaName != null && queryName != null && !keyFields.isEmpty())
if (schemaName != null && queryName != null)
{
String keyField = keyFields.get(0);
if (!AbstractTableInfo.LINK_DISABLER_ACTION_URL.equals(ti.getImportDataURL(ti.getUserSchema().getContainer())))
Expand Down Expand Up @@ -444,7 +478,8 @@ public enum PROPERIES
setEditLinkOverrides(Boolean.class, true),
auditMode(String.class, AuditBehaviorType.DETAILED.name()),
disableFacetingForNumericCols(Boolean.class, true),
overrideDetailsUrl(Boolean.class, true);
overrideDetailsUrl(Boolean.class, true),
primaryKeyField(String.class, null);

private final Class _clazz;
private final Object _defaultVal;
Expand Down Expand Up @@ -530,6 +565,17 @@ public AuditBehaviorType getAuditMode()
return AuditBehaviorType.DETAILED;
}

public String getPrimaryKeyField()
{
Object fieldName = getProperty(PROPERIES.primaryKeyField);
if (fieldName != null)
{
return fieldName.toString();
}

return null;
}

public boolean isDisableFacetingForNumericCols()
{
return (boolean)getProperty(PROPERIES.disableFacetingForNumericCols);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.labkey.api.exp.api.ExpProtocol;
import org.labkey.api.exp.api.ExpRun;
import org.labkey.api.laboratory.assay.AssayDataProvider;
import org.labkey.api.laboratory.query.TabbedReportFilterProvider;
import org.labkey.api.ldk.table.ButtonConfigFactory;
import org.labkey.api.module.Module;
import org.labkey.api.query.ValidationException;
Expand Down Expand Up @@ -123,7 +124,13 @@ static public void setInstance(LaboratoryService instance)

abstract public @Nullable DemographicsProvider getDemographicsProviderByName(Container c, User u, String name);

public enum NavItemCategory
abstract public void clearDataProviderCache();

abstract public void registerTabbedReportFilterProvider(TabbedReportFilterProvider provider);

abstract public List<TabbedReportFilterProvider> getTabbedReportFilterProviderProviders(final Container c, final User u);

public static enum NavItemCategory
{
samples(),
misc(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class QueryTabbedReportItem extends TabbedReportItem
{
private String _schemaName;
private String _queryName;
private String _viewName;

public QueryTabbedReportItem(QueryCache cache, DataProvider provider, String schemaName, String queryName, String label, String reportCategory)
{
Expand Down Expand Up @@ -67,6 +68,16 @@ public void setQueryName(String queryName)
_queryName = queryName;
}

public String getViewName()
{
return _viewName;
}

public void setViewName(String viewName)
{
_viewName = viewName;
}

@Override
public JSONObject toJSON(Container c, User u)
{
Expand All @@ -77,12 +88,18 @@ public JSONObject toJSON(Container c, User u)
return null;
}

inferColumnsFromTable(ti);
inferColumnsFromTable(ti, c, u);
JSONObject json = super.toJSON(c, u);

json.put("schemaName", getSchemaName());
json.put("queryName", getQueryName());
String viewName = getDefaultViewName(c, getOwnerKey());

if (getViewName() != null)
{
viewName = getViewName();
}

if (viewName != null)
{
json.put("viewName", viewName);
Expand Down
Loading