mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
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:
@ -26,6 +26,7 @@ import java.io.Serializable;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
@ -119,7 +120,7 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
|
||||
*******************************************************************************/
|
||||
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");
|
||||
}
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
@ -140,7 +147,7 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
|
||||
*******************************************************************************/
|
||||
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");
|
||||
}
|
||||
|
||||
@ -151,18 +158,71 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
|
||||
*******************************************************************************/
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
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
|
||||
{
|
||||
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()));
|
||||
}
|
||||
|
||||
@ -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
|
||||
{
|
||||
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);
|
||||
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
|
||||
{
|
||||
String tablePath = input.getInstance().getTablePath(tableName);
|
||||
if(tablePath == null)
|
||||
{
|
||||
return (linkText);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
String tablePath = input.getInstance().getTablePath(input, tableName);
|
||||
String tablePath = input.getInstance().getTablePath(tableName);
|
||||
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
|
||||
{
|
||||
String tablePath = input.getInstance().getTablePath(input, tableName);
|
||||
String tablePath = input.getInstance().getTablePath(tableName);
|
||||
if(tablePath == null)
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
|
||||
return (tablePath + "/" + recordId);
|
||||
}
|
||||
|
||||
@ -218,7 +296,7 @@ public abstract class AbstractHTMLWidgetRenderer extends AbstractWidgetRenderer
|
||||
{
|
||||
QProcessMetaData process = input.getInstance().getProcess(processName);
|
||||
String tableName = process.getTableName();
|
||||
String tablePath = input.getInstance().getTablePath(input, tableName);
|
||||
String tablePath = input.getInstance().getTablePath(tableName);
|
||||
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));
|
||||
|
||||
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>");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ public class ChildRecordListRenderer extends AbstractWidgetRenderer
|
||||
QueryOutput queryOutput = new QueryAction().execute(queryInput);
|
||||
|
||||
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()));
|
||||
|
||||
ChildRecordListData widgetData = new ChildRecordListData(widgetLabel, queryOutput, table, tablePath, viewAllLink);
|
||||
|
@ -32,10 +32,10 @@ import java.util.Map;
|
||||
*******************************************************************************/
|
||||
public abstract class QWidgetData
|
||||
{
|
||||
|
||||
private String label;
|
||||
private List<String> dropdownNameList;
|
||||
private List<String> dropdownLabelList;
|
||||
private Boolean hasPermission;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,6 +38,15 @@ public class StatisticsData extends QWidgetData
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public StatisticsData()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
@ -41,6 +41,15 @@ public class TableData extends QWidgetData
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public TableData()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
@ -44,7 +44,6 @@ public enum WidgetType
|
||||
PROCESS("process"),
|
||||
QUICK_SIGHT_CHART("quickSightChart"),
|
||||
STATISTICS("statistics"),
|
||||
SIMPLE_STATISTICS("simpleStatistics"),
|
||||
STACKED_BAR_CHART("stackedBarChart"),
|
||||
STEPPER("stepper"),
|
||||
TABLE("table"),
|
||||
|
@ -188,7 +188,7 @@ public class QInstance
|
||||
/*******************************************************************************
|
||||
** 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))
|
||||
{
|
||||
|
@ -34,6 +34,8 @@ import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
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_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);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user