SPRINT-20: updated getTablePath to no longer require input param, added some permission checks to widget links, added utils to get zoned starts of day, year, month

This commit is contained in:
Tim Chamberlain
2023-02-08 22:46:49 -06:00
parent 927e7f725a
commit 81f9f4e49a
8 changed files with 238 additions and 20 deletions

View File

@ -26,6 +26,7 @@ import java.io.Serializable;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@ -119,7 +120,7 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
*******************************************************************************/ *******************************************************************************/
public static String linkTableBulkLoad(RenderWidgetInput input, String tableName) throws QException public static String linkTableBulkLoad(RenderWidgetInput input, String tableName) throws QException
{ {
String tablePath = input.getInstance().getTablePath(input, tableName); String tablePath = input.getInstance().getTablePath(tableName);
return (tablePath + "/" + tableName + ".bulkInsert"); return (tablePath + "/" + tableName + ".bulkInsert");
} }
@ -128,8 +129,14 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
public static String linkTableBulkLoadChildren(String tableName) throws QException public static String linkTableBulkLoadChildren(RenderWidgetInput input, String tableName) throws QException
{ {
String tablePath = input.getInstance().getTablePath(tableName);
if(tablePath == null)
{
return (null);
}
return ("#/launchProcess=" + tableName + ".bulkInsert"); return ("#/launchProcess=" + tableName + ".bulkInsert");
} }
@ -140,7 +147,7 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
*******************************************************************************/ *******************************************************************************/
public static String linkTableCreate(RenderWidgetInput input, String tableName) throws QException public static String linkTableCreate(RenderWidgetInput input, String tableName) throws QException
{ {
String tablePath = input.getInstance().getTablePath(input, tableName); String tablePath = input.getInstance().getTablePath(tableName);
return (tablePath + "/create"); return (tablePath + "/create");
} }
@ -151,18 +158,71 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
*******************************************************************************/ *******************************************************************************/
public static String linkTableCreateWithDefaultValues(RenderWidgetInput input, String tableName, Map<String, Serializable> defaultValues) throws QException public static String linkTableCreateWithDefaultValues(RenderWidgetInput input, String tableName, Map<String, Serializable> defaultValues) throws QException
{ {
String tablePath = input.getInstance().getTablePath(input, tableName); String tablePath = input.getInstance().getTablePath(tableName);
return (tablePath + "/create?defaultValues=" + URLEncoder.encode(JsonUtils.toJson(defaultValues), Charset.defaultCharset())); return (tablePath + "/create?defaultValues=" + URLEncoder.encode(JsonUtils.toJson(defaultValues), Charset.defaultCharset()));
} }
/*******************************************************************************
**
*******************************************************************************/
public static String getCountLink(RenderWidgetInput input, String tableName, QQueryFilter filter, int count) throws QException
{
String totalString = QValueFormatter.formatValue(DisplayFormat.COMMAS, count);
String tablePath = input.getInstance().getTablePath(tableName);
if(tablePath == null || filter == null)
{
return (totalString);
}
return ("<a href='" + tablePath + "?filter=" + JsonUtils.toJson(filter) + "'>" + totalString + "</a>");
}
/*******************************************************************************
**
*******************************************************************************/
public static void addTableFilterToListIfPermissed(RenderWidgetInput input, String tableName, List<String> urls, QQueryFilter filter) throws QException
{
String tablePath = input.getInstance().getTablePath(tableName);
if(tablePath == null)
{
return;
}
urls.add(tablePath + "?filter=" + JsonUtils.toJson(filter));
}
/*******************************************************************************
**
*******************************************************************************/
public static String linkTableFilterUnencoded(RenderWidgetInput input, String tableName, QQueryFilter filter) throws QException
{
String tablePath = input.getInstance().getTablePath(tableName);
if(tablePath == null)
{
return (null);
}
return (tablePath + "?filter=" + JsonUtils.toJson(filter));
}
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
public static String linkTableFilter(RenderWidgetInput input, String tableName, QQueryFilter filter) throws QException public static String linkTableFilter(RenderWidgetInput input, String tableName, QQueryFilter filter) throws QException
{ {
String tablePath = input.getInstance().getTablePath(input, tableName); String tablePath = input.getInstance().getTablePath(tableName);
if(tablePath == null)
{
return (null);
}
return (tablePath + "?filter=" + URLEncoder.encode(JsonUtils.toJson(filter), Charset.defaultCharset())); return (tablePath + "?filter=" + URLEncoder.encode(JsonUtils.toJson(filter), Charset.defaultCharset()));
} }
@ -173,8 +233,15 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
*******************************************************************************/ *******************************************************************************/
public static String aHrefTableFilterNoOfRecords(RenderWidgetInput input, String tableName, QQueryFilter filter, Integer noOfRecords, String singularLabel, String pluralLabel) throws QException public static String aHrefTableFilterNoOfRecords(RenderWidgetInput input, String tableName, QQueryFilter filter, Integer noOfRecords, String singularLabel, String pluralLabel) throws QException
{ {
String displayText = QValueFormatter.formatValue(DisplayFormat.COMMAS, noOfRecords) + " " + StringUtils.plural(noOfRecords, singularLabel, pluralLabel);
String tablePath = input.getInstance().getTablePath(tableName);
if(tablePath == null)
{
return (displayText);
}
String href = linkTableFilter(input, tableName, filter); String href = linkTableFilter(input, tableName, filter);
return ("<a href=\"" + href + "\">" + QValueFormatter.formatValue(DisplayFormat.COMMAS, noOfRecords) + " " + StringUtils.plural(noOfRecords, singularLabel, pluralLabel) + "</a>"); return ("<a href=\"" + href + "\">" + displayText + "</a>");
} }
@ -184,6 +251,12 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
*******************************************************************************/ *******************************************************************************/
public static String aHrefViewRecord(RenderWidgetInput input, String tableName, Serializable id, String linkText) throws QException public static String aHrefViewRecord(RenderWidgetInput input, String tableName, Serializable id, String linkText) throws QException
{ {
String tablePath = input.getInstance().getTablePath(tableName);
if(tablePath == null)
{
return (linkText);
}
return ("<a href=\"" + linkRecordView(input, tableName, id) + "\">" + linkText + "</a>"); return ("<a href=\"" + linkRecordView(input, tableName, id) + "\">" + linkText + "</a>");
} }
@ -194,7 +267,7 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
*******************************************************************************/ *******************************************************************************/
public static String linkRecordEdit(AbstractActionInput input, String tableName, Serializable recordId) throws QException public static String linkRecordEdit(AbstractActionInput input, String tableName, Serializable recordId) throws QException
{ {
String tablePath = input.getInstance().getTablePath(input, tableName); String tablePath = input.getInstance().getTablePath(tableName);
return (tablePath + "/" + recordId + "/edit"); return (tablePath + "/" + recordId + "/edit");
} }
@ -205,7 +278,12 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
*******************************************************************************/ *******************************************************************************/
public static String linkRecordView(AbstractActionInput input, String tableName, Serializable recordId) throws QException public static String linkRecordView(AbstractActionInput input, String tableName, Serializable recordId) throws QException
{ {
String tablePath = input.getInstance().getTablePath(input, tableName); String tablePath = input.getInstance().getTablePath(tableName);
if(tablePath == null)
{
return (null);
}
return (tablePath + "/" + recordId); return (tablePath + "/" + recordId);
} }
@ -218,7 +296,7 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
{ {
QProcessMetaData process = input.getInstance().getProcess(processName); QProcessMetaData process = input.getInstance().getProcess(processName);
String tableName = process.getTableName(); String tableName = process.getTableName();
String tablePath = input.getInstance().getTablePath(input, tableName); String tablePath = input.getInstance().getTablePath(tableName);
return (tablePath + "/" + recordId + "/" + processName); return (tablePath + "/" + recordId + "/" + processName);
} }
@ -227,9 +305,9 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
public static String linkTableCreateChild(String childTableName, Map<String, Serializable> defaultValues) public static String linkTableCreateChild(RenderWidgetInput input, String childTableName, Map<String, Serializable> defaultValues) throws QException
{ {
return (linkTableCreateChild(childTableName, defaultValues, defaultValues.keySet())); return (linkTableCreateChild(input, childTableName, defaultValues, defaultValues.keySet()));
} }
@ -237,9 +315,9 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
public static String aHrefTableCreateChild(String childTableName, Map<String, Serializable> defaultValues) public static String aHrefTableCreateChild(RenderWidgetInput input, String childTableName, Map<String, Serializable> defaultValues) throws QException
{ {
return (aHrefTableCreateChild(childTableName, defaultValues, defaultValues.keySet())); return (aHrefTableCreateChild(input, childTableName, defaultValues, defaultValues.keySet()));
} }
@ -247,8 +325,14 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
public static String linkTableCreateChild(String childTableName, Map<String, Serializable> defaultValues, Set<String> disabledFields) public static String linkTableCreateChild(RenderWidgetInput input, String childTableName, Map<String, Serializable> defaultValues, Set<String> disabledFields) throws QException
{ {
String tablePath = input.getInstance().getTablePath(childTableName);
if(tablePath == null)
{
return (null);
}
Map<String, Integer> disabledFieldsMap = disabledFields.stream().collect(Collectors.toMap(k -> k, k -> 1)); Map<String, Integer> disabledFieldsMap = disabledFields.stream().collect(Collectors.toMap(k -> k, k -> 1));
return ("#/createChild=" + childTableName return ("#/createChild=" + childTableName
@ -261,9 +345,15 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/
public static String aHrefTableCreateChild(String childTableName, Map<String, Serializable> defaultValues, Set<String> disabledFields) public static String aHrefTableCreateChild(RenderWidgetInput input, String childTableName, Map<String, Serializable> defaultValues, Set<String> disabledFields) throws QException
{ {
return ("<a href=\"" + linkTableCreateChild(childTableName, defaultValues, defaultValues.keySet()) + "\">Create new</a>"); String tablePath = input.getInstance().getTablePath(childTableName);
if(tablePath == null)
{
return (null);
}
return ("<a href=\"" + linkTableCreateChild(input, childTableName, defaultValues, defaultValues.keySet()) + "\">Create new</a>");
} }
} }

View File

@ -185,7 +185,7 @@ public class ChildRecordListRenderer extends AbstractWidgetRenderer
QueryOutput queryOutput = new QueryAction().execute(queryInput); QueryOutput queryOutput = new QueryAction().execute(queryInput);
QTableMetaData table = input.getInstance().getTable(join.getRightTable()); QTableMetaData table = input.getInstance().getTable(join.getRightTable());
String tablePath = input.getInstance().getTablePath(input, table.getName()); String tablePath = input.getInstance().getTablePath(table.getName());
String viewAllLink = tablePath == null ? null : (tablePath + "?filter=" + URLEncoder.encode(JsonUtils.toJson(filter), Charset.defaultCharset())); String viewAllLink = tablePath == null ? null : (tablePath + "?filter=" + URLEncoder.encode(JsonUtils.toJson(filter), Charset.defaultCharset()));
ChildRecordListData widgetData = new ChildRecordListData(widgetLabel, queryOutput, table, tablePath, viewAllLink); ChildRecordListData widgetData = new ChildRecordListData(widgetLabel, queryOutput, table, tablePath, viewAllLink);

View File

@ -32,10 +32,10 @@ import java.util.Map;
*******************************************************************************/ *******************************************************************************/
public abstract class QWidgetData public abstract class QWidgetData
{ {
private String label; private String label;
private List<String> dropdownNameList; private List<String> dropdownNameList;
private List<String> dropdownLabelList; private List<String> dropdownLabelList;
private Boolean hasPermission;
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
// this is a list of lists, the outer list corresponds to each dropdown (parallel list // // this is a list of lists, the outer list corresponds to each dropdown (parallel list //
@ -222,4 +222,38 @@ public abstract class QWidgetData
return (this); return (this);
} }
/*******************************************************************************
** Getter for hasPermission
**
*******************************************************************************/
public Boolean getHasPermission()
{
return hasPermission;
}
/*******************************************************************************
** Setter for hasPermission
**
*******************************************************************************/
public void setHasPermission(Boolean hasPermission)
{
this.hasPermission = hasPermission;
}
/*******************************************************************************
** Fluent setter for hasPermission
**
*******************************************************************************/
public QWidgetData withHasPermission(Boolean hasPermission)
{
this.hasPermission = hasPermission;
return (this);
}
} }

View File

@ -38,6 +38,15 @@ public class StatisticsData extends QWidgetData
/*******************************************************************************
**
*******************************************************************************/
public StatisticsData()
{
}
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/

View File

@ -41,6 +41,15 @@ public class TableData extends QWidgetData
/*******************************************************************************
**
*******************************************************************************/
public TableData()
{
}
/******************************************************************************* /*******************************************************************************
** **
*******************************************************************************/ *******************************************************************************/

View File

@ -44,7 +44,6 @@ public enum WidgetType
PROCESS("process"), PROCESS("process"),
QUICK_SIGHT_CHART("quickSightChart"), QUICK_SIGHT_CHART("quickSightChart"),
STATISTICS("statistics"), STATISTICS("statistics"),
SIMPLE_STATISTICS("simpleStatistics"),
STACKED_BAR_CHART("stackedBarChart"), STACKED_BAR_CHART("stackedBarChart"),
STEPPER("stepper"), STEPPER("stepper"),
TABLE("table"), TABLE("table"),

View File

@ -188,7 +188,7 @@ public class QInstance
/******************************************************************************* /*******************************************************************************
** Get the full path to a table ** Get the full path to a table
*******************************************************************************/ *******************************************************************************/
public String getTablePath(AbstractActionInput actionInput, String tableName) throws QException public String getTablePath(String tableName) throws QException
{ {
if(!memoizedTablePaths.containsKey(tableName)) if(!memoizedTablePaths.containsKey(tableName))
{ {

View File

@ -34,6 +34,8 @@ import java.time.ZoneId;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException; import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
@ -50,6 +52,8 @@ public class ValueUtils
private static final DateTimeFormatter dateTimeFormatter_MdyyyyWithSlashes = DateTimeFormatter.ofPattern("M/d/yyyy"); private static final DateTimeFormatter dateTimeFormatter_MdyyyyWithSlashes = DateTimeFormatter.ofPattern("M/d/yyyy");
private static final DateTimeFormatter dateTimeFormatter_yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd"); private static final DateTimeFormatter dateTimeFormatter_yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
public static final String COMPANY_TIMEZONE_ID = "America/New_York";
/******************************************************************************* /*******************************************************************************
@ -653,4 +657,77 @@ public class ValueUtils
case BLOB -> getValueAsByteArray(value); case BLOB -> getValueAsByteArray(value);
}; };
} }
/*******************************************************************************
**
*******************************************************************************/
public static Instant getStartOfTodayInZoneId(String zoneId)
{
///////////////////////////
// get the instant 'now' //
///////////////////////////
ZoneId zone = ZoneId.of(zoneId);
Instant computerTime = Instant.now();
//////////////////////////////////////////////////////////////////////////////
// get date time for now in given zone, truncate it and add offset from utc //
//////////////////////////////////////////////////////////////////////////////
LocalDateTime givenZonesNow = LocalDateTime.ofInstant(Instant.now(), zone);
LocalDateTime startOfDay = givenZonesNow.truncatedTo(ChronoUnit.DAYS);
return (startOfDay.toInstant(zone.getRules().getOffset(computerTime)));
}
/*******************************************************************************
**
*******************************************************************************/
public static Instant getStartOfMonthInZoneId(String zoneId)
{
///////////////////////////
// get the instant 'now' //
///////////////////////////
ZoneId zone = ZoneId.of(zoneId);
Instant computerTime = Instant.now();
//////////////////////////////////////////////////////////////////////////////
// get date time for now in given zone, truncate it and add offset from utc //
//////////////////////////////////////////////////////////////////////////////
LocalDateTime givenZonesNow = LocalDateTime.ofInstant(Instant.now(), zone);
LocalDateTime startOfMonth = givenZonesNow
.withDayOfMonth(1)
.with(ChronoField.HOUR_OF_DAY, 0)
.with(ChronoField.MINUTE_OF_DAY, 0)
.with(ChronoField.SECOND_OF_DAY, 0)
.with(ChronoField.NANO_OF_DAY, 0);
return (startOfMonth.toInstant(zone.getRules().getOffset(computerTime)));
}
/*******************************************************************************
**
*******************************************************************************/
public static Instant getStartOfYearInZoneId(String zoneId)
{
///////////////////////////
// get the instant 'now' //
///////////////////////////
ZoneId zone = ZoneId.of(zoneId);
Instant computerTime = Instant.now();
//////////////////////////////////////////////////////////////////////////////
// get date time for now in given zone, truncate it and add offset from utc //
//////////////////////////////////////////////////////////////////////////////
LocalDateTime givenZonesNow = LocalDateTime.ofInstant(Instant.now(), zone);
LocalDateTime startOfMonth = givenZonesNow
.withDayOfYear(1)
.with(ChronoField.HOUR_OF_DAY, 0)
.with(ChronoField.MINUTE_OF_DAY, 0)
.with(ChronoField.SECOND_OF_DAY, 0)
.with(ChronoField.NANO_OF_DAY, 0);
return (startOfMonth.toInstant(zone.getRules().getOffset(computerTime)));
}
} }