Skip to content

Commit

Permalink
Refactored default parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
samie committed Feb 21, 2024
1 parent b6ec4a6 commit 4b19ebd
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.vaadin.flow.router.Route;
import com.vaadin.flow.theme.lumo.LumoUtility.Margin;

import java.io.File;

import org.vaadin.addons.nps.NPS;

@PageTitle("Feedback")
Expand All @@ -22,6 +24,11 @@ public class NPSView extends VerticalLayout {
public static final String DEFAULT_QUESTION = NPS.DEFAULT_NPS_QUESTION;
public static final String DEFAULT_THANK_YOU = "Thank you. We appreciate your feedback.";

private static final String PRODUCTION_CREDENTIAL_FILE = "/local/nps-feedback-demo";
private static final String DEVELOPMENT_CREDENTIAL_FILE = "/workspaces/nps/.devcontainer/local/service_account_credentials.json";

private static final String DEFAULT_SHEET_ID = "1aTfU2_XuZU-HgUhSBu4_oB_gB4hhro-RzNsdN9_8YX8";

NPS nps = new NPS();
H2 header = new H2(DEFAULT_HEADER);
Paragraph thankYou = new Paragraph(DEFAULT_THANK_YOU);
Expand All @@ -42,9 +49,11 @@ public NPSView() {
replace(nps, thankYou);
add(closeLink);

String credentialFileName = getCredentialFileName();
String sheetId = getSheetId();
// Store the results into a Google Sheet
FeedbackSheet feedbackSheet = new FeedbackSheet("1aTfU2_XuZU-HgUhSBu4_oB_gB4hhro-RzNsdN9_8YX8",
"/workspaces/nps/.devcontainer/local/service_account_credentials.json");
FeedbackSheet feedbackSheet = new FeedbackSheet(sheetId,
credentialFileName);
feedbackSheet.append(productName,"" + UI.getCurrent().hashCode(), e.getValue());
});

Expand All @@ -54,6 +63,28 @@ public NPSView() {
header.addClassNames(Margin.Top.XLARGE, Margin.Bottom.MEDIUM);
}

/** Get the ID of the Google Sheet where to store the results.
*
* @return
*/
protected String getSheetId() {
return DEFAULT_SHEET_ID;
}

/** Find the name of credential file used to authenticate to Google Sheets.
*
* By default we use Google Secret Manager to mount file in Cloud Run and local directory
* in development.
*
*/
protected String getCredentialFileName() {

// Try production location first
File f = new File(PRODUCTION_CREDENTIAL_FILE);
if (f.exists() && f.canRead()) return PRODUCTION_CREDENTIAL_FILE;
return DEVELOPMENT_CREDENTIAL_FILE;
}

public String getProductName() {
return productName;
}
Expand Down

0 comments on commit 4b19ebd

Please sign in to comment.