initial checkin of quicksight dashboard widget POC, updated to remove hard coded credentials

This commit is contained in:
Tim Chamberlain
2022-08-30 11:46:46 -05:00
parent d32538bf45
commit 48b8d295e3
18 changed files with 684 additions and 88 deletions

View File

@ -36,11 +36,26 @@
<!-- noe at this time -->
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.17.259</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- other qqq modules deps -->
<!-- none, this is core. -->
<!-- 3rd party deps specifically for this module -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>quicksight</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>

View File

@ -3,6 +3,7 @@ package com.kingsrook.qqq.backend.core.actions.dashboard;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
import com.kingsrook.qqq.backend.core.model.session.QSession;
@ -15,6 +16,6 @@ public abstract class AbstractWidgetRenderer
/*******************************************************************************
**
*******************************************************************************/
public abstract Object render(QInstance qInstance, QSession session) throws QException;
public abstract Object render(QInstance qInstance, QSession session, QWidgetMetaDataInterface qWidgetMetaData) throws QException;
}

View File

@ -0,0 +1,77 @@
package com.kingsrook.qqq.backend.core.actions.dashboard;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.QuickSightChart;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QuickSightChartMetaData;
import com.kingsrook.qqq.backend.core.model.session.QSession;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.services.quicksight.QuickSightClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.quicksight.model.GenerateEmbedUrlForRegisteredUserRequest;
import software.amazon.awssdk.services.quicksight.model.GenerateEmbedUrlForRegisteredUserResponse;
import software.amazon.awssdk.services.quicksight.model.RegisteredUserDashboardEmbeddingConfiguration;
import software.amazon.awssdk.services.quicksight.model.RegisteredUserEmbeddingExperienceConfiguration;
/*******************************************************************************
**
*******************************************************************************/
public class QuickSightChartRenderer extends AbstractWidgetRenderer
{
/*******************************************************************************
**
*******************************************************************************/
@Override
public Object render(QInstance qInstance, QSession session, QWidgetMetaDataInterface metaData) throws QException
{
try
{
QuickSightChartMetaData quickSightMetaData = (QuickSightChartMetaData) metaData;
QuickSightClient quickSightClient = getQuickSightClient(quickSightMetaData);
final RegisteredUserEmbeddingExperienceConfiguration experienceConfiguration = RegisteredUserEmbeddingExperienceConfiguration.builder()
.dashboard(
RegisteredUserDashboardEmbeddingConfiguration.builder()
.initialDashboardId(quickSightMetaData.getDashboardId())
.build())
.build();
final GenerateEmbedUrlForRegisteredUserRequest generateEmbedUrlForRegisteredUserRequest = GenerateEmbedUrlForRegisteredUserRequest.builder()
.awsAccountId(quickSightMetaData.getAccountId())
.userArn(quickSightMetaData.getUserArn())
.experienceConfiguration(experienceConfiguration)
.build();
final GenerateEmbedUrlForRegisteredUserResponse generateEmbedUrlForRegisteredUserResponse = quickSightClient.generateEmbedUrlForRegisteredUser(generateEmbedUrlForRegisteredUserRequest);
String embedUrl = generateEmbedUrlForRegisteredUserResponse.embedUrl();
return (new QuickSightChart(metaData.getName(), quickSightMetaData.getLabel(), embedUrl));
}
catch(Exception e)
{
throw (new QException("Error rendering widget", e));
}
}
/*******************************************************************************
**
*******************************************************************************/
private QuickSightClient getQuickSightClient(QuickSightChartMetaData metaData)
{
AwsBasicCredentials awsCredentials = AwsBasicCredentials.create(metaData.getAccessKey(), metaData.getSecretKey());
QuickSightClient amazonQuickSightClient = QuickSightClient.builder()
.credentialsProvider(StaticCredentialsProvider.create(awsCredentials))
.region(Region.of(metaData.getRegion()))
.build();
return (amazonQuickSightClient);
}
}

View File

@ -4,7 +4,7 @@ package com.kingsrook.qqq.backend.core.actions.dashboard;
import com.kingsrook.qqq.backend.core.actions.customizers.QCodeLoader;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
import com.kingsrook.qqq.backend.core.model.session.QSession;
@ -19,8 +19,9 @@ public class WidgetDataLoader
*******************************************************************************/
public Object execute(QInstance qInstance, QSession session, String name) throws QException
{
QWidgetMetaData widget = qInstance.getWidget(name);
AbstractWidgetRenderer widgetRenderer = QCodeLoader.getAdHoc(AbstractWidgetRenderer.class, widget.getCodeReference());
return (widgetRenderer.render(qInstance, session));
QWidgetMetaDataInterface widget = qInstance.getWidget(name);
AbstractWidgetRenderer widgetRenderer = QCodeLoader.getAdHoc(AbstractWidgetRenderer.class, widget.getCodeReference());
Object w = widgetRenderer.render(qInstance, session, widget);
return (widgetRenderer.render(qInstance, session, widget));
}
}

View File

@ -7,7 +7,7 @@ import java.util.List;
/*******************************************************************************
**
*******************************************************************************/
public class BarChart
public class BarChart implements QWidget
{
/*
@ -19,9 +19,8 @@ public class BarChart
},
*/
private String type = "barChart";
private String title;
private Data barChartData;
private Data barChartData;
@ -34,12 +33,23 @@ public class BarChart
setBarChartData(new BarChart.Data()
.withLabels(labels)
.withDatasets(new BarChart.Data.DataSet()
.withLabel("Parcel Invoice Lines")
.withLabel(seriesLabel)
.withData(data)));
}
/*******************************************************************************
** Getter for type
**
*******************************************************************************/
public String getType()
{
return "barChart";
}
/*******************************************************************************
** Getter for title
**
@ -108,46 +118,13 @@ public class BarChart
/*******************************************************************************
** Getter for type
**
*******************************************************************************/
public String getType()
{
return type;
}
/*******************************************************************************
** Setter for type
**
*******************************************************************************/
public void setType(String type)
{
this.type = type;
}
/*******************************************************************************
** Fluent setter for type
**
*******************************************************************************/
public BarChart withType(String type)
{
this.type = type;
return (this);
}
/*******************************************************************************
**
*******************************************************************************/
public static class Data
{
private List<String> labels;
private DataSet datasets;
private DataSet datasets;
@ -224,7 +201,7 @@ public class BarChart
*******************************************************************************/
public static class DataSet
{
private String label;
private String label;
private List<Number> data;

View File

@ -0,0 +1,14 @@
package com.kingsrook.qqq.backend.core.model.dashboard.widgets;
/*******************************************************************************
**
*******************************************************************************/
public interface QWidget
{
/*******************************************************************************
** Getter for type
*******************************************************************************/
String getType();
}

View File

@ -0,0 +1,139 @@
package com.kingsrook.qqq.backend.core.model.dashboard.widgets;
/*******************************************************************************
**
*******************************************************************************/
public class QuickSightChart implements QWidget
{
private String label;
private String name;
private String url;
/*******************************************************************************
**
*******************************************************************************/
public QuickSightChart(String name, String label, String url)
{
this.url = url;
this.name = name;
this.label = label;
}
/*******************************************************************************
** Getter for type
**
*******************************************************************************/
public String getType()
{
return "quickSightChart";
}
/*******************************************************************************
** Getter for url
**
*******************************************************************************/
public String getUrl()
{
return url;
}
/*******************************************************************************
** Setter for url
**
*******************************************************************************/
public void setUrl(String url)
{
this.url = url;
}
/*******************************************************************************
** Fluent setter for url
**
*******************************************************************************/
public QuickSightChart withUrl(String url)
{
this.url = url;
return (this);
}
/*******************************************************************************
** Getter for name
**
*******************************************************************************/
public String getName()
{
return name;
}
/*******************************************************************************
** Setter for name
**
*******************************************************************************/
public void setName(String name)
{
this.name = name;
}
/*******************************************************************************
** Fluent setter for name
**
*******************************************************************************/
public QuickSightChart withName(String name)
{
this.name = name;
return (this);
}
/*******************************************************************************
** Getter for label
**
*******************************************************************************/
public String getLabel()
{
return label;
}
/*******************************************************************************
** Setter for label
**
*******************************************************************************/
public void setLabel(String label)
{
this.label = label;
}
/*******************************************************************************
** Fluent setter for label
**
*******************************************************************************/
public QuickSightChart withLabel(String label)
{
this.label = label;
return (this);
}
}

View File

@ -29,7 +29,7 @@ import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.kingsrook.qqq.backend.core.instances.QInstanceValidationKey;
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QAppMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSource;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
@ -60,7 +60,7 @@ public class QInstance
private Map<String, QProcessMetaData> processes = new LinkedHashMap<>();
private Map<String, QAppMetaData> apps = new LinkedHashMap<>();
private Map<String, QWidgetMetaData> widgets = new LinkedHashMap<>();
private Map<String, QWidgetMetaDataInterface> widgets = new LinkedHashMap<>();
// todo - lock down the object (no more changes allowed) after it's been validated?
@ -455,7 +455,7 @@ public class QInstance
** Getter for widgets
**
*******************************************************************************/
public Map<String, QWidgetMetaData> getWidgets()
public Map<String, QWidgetMetaDataInterface> getWidgets()
{
return widgets;
}
@ -466,7 +466,7 @@ public class QInstance
** Setter for widgets
**
*******************************************************************************/
public void setWidgets(Map<String, QWidgetMetaData> widgets)
public void setWidgets(Map<String, QWidgetMetaDataInterface> widgets)
{
this.widgets = widgets;
}
@ -475,7 +475,7 @@ public class QInstance
/*******************************************************************************
**
*******************************************************************************/
public void addWidget(QWidgetMetaData widget)
public void addWidget(QWidgetMetaDataInterface widget)
{
this.addWidget(widget.getName(), widget);
}
@ -485,7 +485,7 @@ public class QInstance
/*******************************************************************************
**
*******************************************************************************/
public void addWidget(String name, QWidgetMetaData widget)
public void addWidget(String name, QWidgetMetaDataInterface widget)
{
if(this.widgets.containsKey(name))
{
@ -499,7 +499,7 @@ public class QInstance
/*******************************************************************************
**
*******************************************************************************/
public QWidgetMetaData getWidget(String name)
public QWidgetMetaDataInterface getWidget(String name)
{
return (this.widgets.get(name));
}

View File

@ -7,10 +7,10 @@ import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
/*******************************************************************************
**
*******************************************************************************/
public class QWidgetMetaData
public class QWidgetMetaData implements QWidgetMetaDataInterface
{
private String name;
private QCodeReference codeReference;
protected String name;
protected QCodeReference codeReference;

View File

@ -0,0 +1,42 @@
package com.kingsrook.qqq.backend.core.model.metadata.dashboard;
import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeReference;
/*******************************************************************************
**
*******************************************************************************/
public interface QWidgetMetaDataInterface
{
/*******************************************************************************
** Getter for name
*******************************************************************************/
String getName();
/*******************************************************************************
** Setter for name
*******************************************************************************/
void setName(String name);
/*******************************************************************************
** Fluent setter for name
*******************************************************************************/
QWidgetMetaDataInterface withName(String name);
/*******************************************************************************
** Getter for codeReference
*******************************************************************************/
QCodeReference getCodeReference();
/*******************************************************************************
** Setter for codeReference
*******************************************************************************/
void setCodeReference(QCodeReference codeReference);
/*******************************************************************************
** Fluent setter for codeReference
*******************************************************************************/
QWidgetMetaDataInterface withCodeReference(QCodeReference codeReference);
}

View File

@ -0,0 +1,305 @@
package com.kingsrook.qqq.backend.core.model.metadata.dashboard;
import java.util.Collection;
/*******************************************************************************
**
*******************************************************************************/
public class QuickSightChartMetaData extends QWidgetMetaData implements QWidgetMetaDataInterface
{
private String label;
private String accessKey;
private String secretKey;
private String dashboardId;
private String accountId;
private String userArn;
private String region;
private Collection<String> allowedDomains;
/*******************************************************************************
** Fluent setter for name
**
*******************************************************************************/
public QuickSightChartMetaData withName(String name)
{
this.name = name;
return (this);
}
/*******************************************************************************
** Getter for accessKey
**
*******************************************************************************/
public String getAccessKey()
{
return accessKey;
}
/*******************************************************************************
** Setter for accessKey
**
*******************************************************************************/
public void setAccessKey(String accessKey)
{
this.accessKey = accessKey;
}
/*******************************************************************************
** Fluent setter for accessKey
**
*******************************************************************************/
public QuickSightChartMetaData withAccessKey(String accessKey)
{
this.accessKey = accessKey;
return (this);
}
/*******************************************************************************
** Getter for label
**
*******************************************************************************/
public String getLabel()
{
return label;
}
/*******************************************************************************
** Setter for label
**
*******************************************************************************/
public void setLabel(String label)
{
this.label = label;
}
/*******************************************************************************
** Fluent setter for label
**
*******************************************************************************/
public QuickSightChartMetaData withLabel(String label)
{
this.label = label;
return (this);
}
/*******************************************************************************
** Getter for secretKey
**
*******************************************************************************/
public String getSecretKey()
{
return secretKey;
}
/*******************************************************************************
** Setter for secretKey
**
*******************************************************************************/
public void setSecretKey(String secretKey)
{
this.secretKey = secretKey;
}
/*******************************************************************************
** Fluent setter for secretKey
**
*******************************************************************************/
public QuickSightChartMetaData withSecretKey(String secretKey)
{
this.secretKey = secretKey;
return (this);
}
/*******************************************************************************
** Getter for dashboardId
**
*******************************************************************************/
public String getDashboardId()
{
return dashboardId;
}
/*******************************************************************************
** Setter for dashboardId
**
*******************************************************************************/
public void setDashboardId(String dashboardId)
{
this.dashboardId = dashboardId;
}
/*******************************************************************************
** Fluent setter for dashboardId
**
*******************************************************************************/
public QuickSightChartMetaData withDashboardId(String dashboardId)
{
this.dashboardId = dashboardId;
return (this);
}
/*******************************************************************************
** Getter for accountId
**
*******************************************************************************/
public String getAccountId()
{
return accountId;
}
/*******************************************************************************
** Setter for accountId
**
*******************************************************************************/
public void setAccountId(String accountId)
{
this.accountId = accountId;
}
/*******************************************************************************
** Fluent setter for accountId
**
*******************************************************************************/
public QuickSightChartMetaData withAccountId(String accountId)
{
this.accountId = accountId;
return this;
}
/*******************************************************************************
** Getter for userArn
**
*******************************************************************************/
public String getUserArn()
{
return userArn;
}
/*******************************************************************************
** Setter for userArn
**
*******************************************************************************/
public void setUserArn(String userArn)
{
this.userArn = userArn;
}
/*******************************************************************************
** Fluent setter for userArn
**
*******************************************************************************/
public QuickSightChartMetaData withUserArn(String userArn)
{
this.userArn = userArn;
return this;
}
/*******************************************************************************
** Getter for region
**
*******************************************************************************/
public String getRegion()
{
return region;
}
/*******************************************************************************
** Setter for region
**
*******************************************************************************/
public void setRegion(String region)
{
this.region = region;
}
/*******************************************************************************
** Fluent setter for region
**
*******************************************************************************/
public QuickSightChartMetaData withRegion(String region)
{
this.region = region;
return this;
}
/*******************************************************************************
** Getter for allowedDomains
**
*******************************************************************************/
public Collection<String> getAllowedDomains()
{
return allowedDomains;
}
/*******************************************************************************
** Setter for allowedDomains
**
*******************************************************************************/
public void setAllowedDomains(Collection<String> allowedDomains)
{
this.allowedDomains = allowedDomains;
}
/*******************************************************************************
** Fluent setter for allowedDomains
**
*******************************************************************************/
public QuickSightChartMetaData withAllowedDomains(Collection<String> allowedDomains)
{
this.allowedDomains = allowedDomains;
return this;
}
}

View File

@ -6,6 +6,7 @@ import java.util.List;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.dashboard.widgets.BarChart;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.dashboard.QWidgetMetaDataInterface;
import com.kingsrook.qqq.backend.core.model.session.QSession;
@ -18,7 +19,7 @@ public class PersonsByCreateDateBarChart extends AbstractWidgetRenderer
**
*******************************************************************************/
@Override
public Object render(QInstance qInstance, QSession session) throws QException
public Object render(QInstance qInstance, QSession session, QWidgetMetaDataInterface metaData) throws QException
{
try
{