Skip to content

Commit

Permalink
Issue 51573: Mechanism to avoid showing upgrade banner (#6045)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-jeckels authored Nov 12, 2024
1 parent 7a84f7d commit d742573
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 108 deletions.
16 changes: 13 additions & 3 deletions api/src/org/labkey/api/jsp/LabKeyJspWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,25 @@ public class LabKeyJspWriter extends JspWriterWrapper
}

@Override
public void print(char[] s)
public void print(char[] c)
{
throwException("A JSP is attempting to render a character array!");
String s = new String(c);
throwException("A JSP is attempting to render a character array! " + truncateAndQuote(s));
}

private String truncateAndQuote(String s)
{
if (s == null)
{
return null;
}
return "'" + (s.length() < 50 ? s : (s.substring(0, 50) + "...")) + "'";
}

@Override
public void print(String s) throws IOException
{
throwException("A JSP is attempting to render a string!");
throwException("A JSP is attempting to render a string! " + truncateAndQuote(s));
}

@Override
Expand Down
140 changes: 84 additions & 56 deletions api/src/org/labkey/api/util/UsageReportingLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,75 +52,103 @@
public enum UsageReportingLevel implements SafeToRenderEnum
{
NONE
{
@Override
protected void addExtraParams(MothershipReport report, Map<String, Object> metrics)
{
// no op
}
{
@Override
protected void addExtraParams(MothershipReport report, Map<String, Object> metrics)
{
// no op
}

@Override
protected boolean doGeneration()
{
return false;
}
},
@Override
public boolean showUpgradeBanner()
{
return false;
}

@Override
protected boolean doGeneration()
{
return false;
}
},

/**
* Captures basic User info, container count information and Site Settings info to help identify the organization
* running the installation, and more detailed stats about how many items exist or actions have been invoked.
*
* <p>
* May capture site-wide usage information, including counts for certain data types, such as assay designs,
* reports of a specific type, or lists. May also capture the number of times a certain feature was used in a
* given time window, such as since the server was last restarted.
*
* <p>
* Per policy, this should not capture the names of specific objects like container names, dataset names, etc.
*
* <p>
* Also per policy, this should not capture metrics at a container or other similar granularity. For example,
* metrics should not break down the number of lists defined in each folder (even if that folder was de-identified).
*/
ON
{
@Override
protected void addExtraParams(MothershipReport report, Map<String, Object> metrics)
{
report.addParam("userCount", UserManager.getActiveUserCount());

report.addParam("containerCount", ContainerManager.getContainerCount());
report.addParam("projectCount", ContainerManager.getRoot().getChildren().size());
metrics.put("droppedExceptionCount", MothershipReport.getDroppedExceptionCount());

// Users within the last 30 days
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DATE, -30);
Date startDate = cal.getTime();
report.addParam("recentUserCount", UserManager.getRecentUserCount(startDate));
// Other counts within the last 30 days
metrics.put("recentLoginCount", UserManager.getRecentLoginCount(startDate));
metrics.put("recentLogoutCount", UserManager.getRecentLogOutCount(startDate));
metrics.put("activeDayCount", UserManager.getActiveDaysCount(startDate));
metrics.put("recentAvgSessionDuration", UserManager.getAverageSessionDuration());
metrics.put("mostRecentLogin", DateUtil.formatIsoDate(UserManager.getMostRecentLogin()));

LookAndFeelProperties laf = LookAndFeelProperties.getInstance(ContainerManager.getRoot());
report.addParam("logoLink", laf.getLogoHref());
report.addParam("organizationName", laf.getCompanyName());
report.addParam("systemDescription", laf.getDescription());
report.addParam("systemShortName", laf.getShortName());
report.addParam("administratorEmail", AppProps.getInstance().getAdministratorContactEmail(true));

@SuppressWarnings("unchecked")
Map<String, Map<String, Object>> modulesMap = (Map<String, Map<String, Object>>)metrics.computeIfAbsent("modules", s -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER));

putModulesMetrics(modulesMap);
putModulesBuildInfo(modulesMap);

metrics.put("folderTypeCounts", ContainerManager.getFolderTypeNameContainerCounts(ContainerManager.getRoot()));
metrics.put("auditCommentsRequiredContainerCount", ContainerManager.getAuditCommentRequiredCount());

report.addHostName();
}
};
{
@Override
protected void addExtraParams(MothershipReport report, Map<String, Object> metrics)
{
report.addParam("userCount", UserManager.getActiveUserCount());

report.addParam("containerCount", ContainerManager.getContainerCount());
report.addParam("projectCount", ContainerManager.getRoot().getChildren().size());
metrics.put("droppedExceptionCount", MothershipReport.getDroppedExceptionCount());

// Users within the last 30 days
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DATE, -30);
Date startDate = cal.getTime();
report.addParam("recentUserCount", UserManager.getRecentUserCount(startDate));
// Other counts within the last 30 days
metrics.put("recentLoginCount", UserManager.getRecentLoginCount(startDate));
metrics.put("recentLogoutCount", UserManager.getRecentLogOutCount(startDate));
metrics.put("activeDayCount", UserManager.getActiveDaysCount(startDate));
metrics.put("recentAvgSessionDuration", UserManager.getAverageSessionDuration());
metrics.put("mostRecentLogin", DateUtil.formatIsoDate(UserManager.getMostRecentLogin()));

LookAndFeelProperties laf = LookAndFeelProperties.getInstance(ContainerManager.getRoot());
report.addParam("logoLink", laf.getLogoHref());
report.addParam("organizationName", laf.getCompanyName());
report.addParam("systemDescription", laf.getDescription());
report.addParam("systemShortName", laf.getShortName());
report.addParam("administratorEmail", AppProps.getInstance().getAdministratorContactEmail(true));

@SuppressWarnings("unchecked")
Map<String, Map<String, Object>> modulesMap = (Map<String, Map<String, Object>>) metrics.computeIfAbsent("modules", s -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER));

putModulesMetrics(modulesMap);
putModulesBuildInfo(modulesMap);

metrics.put("folderTypeCounts", ContainerManager.getFolderTypeNameContainerCounts(ContainerManager.getRoot()));
metrics.put("auditCommentsRequiredContainerCount", ContainerManager.getAuditCommentRequiredCount());

report.addHostName();
}

@Override
public boolean showUpgradeBanner()
{
return true;
}
},
ON_WITHOUT_UPGRADE_MESSAGE
{
@Override
protected void addExtraParams(MothershipReport report, Map<String, Object> metrics)
{
ON.addExtraParams(report, metrics);
}

@Override
public boolean showUpgradeBanner()
{
return false;
}
};

public abstract boolean showUpgradeBanner();

protected abstract void addExtraParams(MothershipReport report, Map<String, Object> metrics);

Expand Down
Loading

0 comments on commit d742573

Please sign in to comment.