Skip to content

Commit 789ff3e

Browse files
committed
fixing personalization
1 parent 59a2d28 commit 789ff3e

File tree

6 files changed

+30
-56
lines changed

6 files changed

+30
-56
lines changed

.vscode/launch.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4-
54
{
65
"name": "Launch RazorPagesDotCMS",
76
"type": "coreclr",
@@ -18,14 +17,6 @@
1817
},
1918
"env": {
2019
"ASPNETCORE_ENVIRONMENT": "Development"
21-
},
22-
"sourceFileMap": {
23-
"/Views": "${workspaceFolder}/Pages"
24-
},
25-
"pipeTransport": {
26-
"pipeProgram": "/bin/sh",
27-
"pipeArgs": ["-c"],
28-
"debuggerPath": "/Users/${env:USER}/vsdbg/vsdbg"
2920
}
3021
},
3122
{

Controllers/DotCmsUVEController.cs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public async Task<IActionResult> Index(
2929
[FromQuery] string? siteId = null,
3030
[FromQuery] string? mode = null,
3131
[FromQuery] string? language_id = null,
32-
[FromQuery] string? persona = null,
32+
[FromQuery] string? personaId = null,
3333
[FromQuery] bool fireRules = false,
3434
[FromQuery] int depth = 1)
3535
{
@@ -45,7 +45,7 @@ public async Task<IActionResult> Index(
4545

4646
// Log the query parameters
4747
_logger.LogInformation($"Query parameters: siteId={siteId}, mode={mode}, language_id={language_id}, " +
48-
$"persona={persona}, fireRules={fireRules}, depth={depth}");
48+
$"persona={personaId}, fireRules={fireRules}, depth={depth}");
4949

5050
// Create a PageQueryParams object to pass to the service
5151
var queryParams = new PageQueryParams
@@ -54,34 +54,13 @@ public async Task<IActionResult> Index(
5454
Site = siteId,
5555
PageMode = mode,
5656
Language = language_id,
57-
Persona = persona,
57+
Persona = personaId,
5858
FireRules = fireRules,
5959
Depth = depth
6060
};
6161

62-
PageResponse pageResponse;
63-
try
64-
{
65-
// Try to get the page using GraphQL first
66-
_logger.LogInformation("Attempting to get page using GraphQL API");
67-
PageResponse graphqlResponse = await _dotCmsService.GetPageGraphqlAsync(queryParams);
68-
pageResponse = await _dotCmsService.GetPageAsync(queryParams);
69-
string graphJSON = JsonSerializer.Serialize(graphqlResponse);
70-
string restJSON = JsonSerializer.Serialize(pageResponse);
71-
if (graphJSON != restJSON)
72-
{
73-
_logger.LogWarning("GraphQL and REST API responses differ");
74-
_logger.LogWarning("GraphQL response: " + graphJSON);
75-
_logger.LogWarning("REST API response: " + restJSON);
76-
}
77-
78-
}
79-
catch (Exception ex)
80-
{
81-
// If GraphQL fails, fall back to the REST API
82-
_logger.LogWarning(ex, "GraphQL API failed, falling back to REST API:" + ex.Message);
83-
pageResponse = await _dotCmsService.GetPageAsync(queryParams);
84-
}
62+
PageResponse pageResponse = await _dotCmsService.GetPageAsync(queryParams);
63+
8564

8665
// Return the view with the pageResponse
8766
return View("~/Views/DotCmsView/Index.cshtml", pageResponse);

Filters/ProxyActionFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE
5050
var httpClient = _httpClientFactory.CreateClient("ProxyClient");
5151
var targetUri = new Uri(matchingProxy.Target + path.Substring(matchingProxy.Path.Replace("*", "").Length));
5252

53-
_logger.LogInformation($"Proxying request to {targetUri}");
53+
//_logger.LogInformation($"Proxying request to {targetUri}");
5454

5555
// Create the HttpRequestMessage
5656
var proxyRequest = new HttpRequestMessage();

Models/PageQueryParams.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class PageQueryParams
2020
[JsonPropertyName("cacheSeconds")]
2121
public int? CacheSeconds { get; set; }
2222

23-
[JsonPropertyName("persona")]
23+
[JsonPropertyName("personaId")]
2424
public string? Persona { get; set; }
2525

2626
[JsonPropertyName("fireRules")]

Models/Site.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public class Site
8282
[JsonPropertyName("titleImage")]
8383
public string? TitleImage { get; set; }
8484

85-
[JsonPropertyName("persona")]
86-
public bool? Persona { get; set; }
85+
[JsonPropertyName("personaId")]
86+
public bool? PersonaId { get; set; }
8787

8888
[JsonPropertyName("live")]
8989
public bool? Live { get; set; }

Services/DotCmsService.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public DotCmsService(IHttpClientFactory httpClientFactory, IConfiguration config
5656
/// <param name="siteId">Optional site ID</param>
5757
/// <param name="mode">Optional view mode (EDIT_MODE, PREVIEW_MODE, LIVE_MODE)</param>
5858
/// <param name="languageId">Optional language ID</param>
59-
/// <param name="persona">Optional persona ID</param>
59+
/// <param name="personaId">Optional persona ID</param>
6060
/// <param name="fireRules">Whether to fire rules (default: false)</param>
6161
/// <param name="depth">Depth of the content to retrieve (default: 1)</param>
6262
/// <returns>The page response</returns>
@@ -92,7 +92,7 @@ public async Task<PageResponse> GetPageAsync(
9292

9393
if (!string.IsNullOrEmpty(queryParams.Persona))
9494
{
95-
query["persona"] = queryParams.Persona;
95+
query["com.dotmarketing.persona.id"] = queryParams.Persona;
9696
}
9797

9898

@@ -115,29 +115,33 @@ public async Task<PageResponse> GetPageAsync(
115115
}
116116

117117
string finalRequestUrl = uriBuilder.Uri.ToString();
118-
int cacheSeconds = queryParams.CacheSeconds ?? (mode == PageMode.LIVE_MODE ? 60 : 0);
118+
int cacheSeconds = queryParams.CacheSeconds ?? (mode == PageMode.LIVE_MODE ? 10 : 0);
119119
// Use GetOrAddAsync with an async delegate
120120
return await cache.GetOrAdd(finalRequestUrl, async () =>
121121
{
122-
try
122+
try
123+
{
124+
_logger.LogInformation($"Requesting page from: {finalRequestUrl}");
125+
126+
var request = new HttpRequestMessage(HttpMethod.Get, finalRequestUrl);
127+
request.Headers.Add("Authorization", _apiAuth);
128+
129+
// Send the request to dotCMS
130+
var response = await _httpClient.SendAsync(request);
131+
132+
// Check if the response is successful
133+
if (!response.IsSuccessStatusCode)
123134
{
124-
_logger.LogInformation($"Requesting page from: {finalRequestUrl}");
135+
_logger.LogWarning($"dotCMS API returned status code: {response.StatusCode}");
136+
throw new HttpRequestException($"dotCMS API returned status code: {response.StatusCode}");
137+
}
125138

126-
var request = new HttpRequestMessage(HttpMethod.Get, finalRequestUrl);
127-
request.Headers.Add("Authorization", _apiAuth);
139+
// Read the response content
140+
var content = await response.Content.ReadAsStringAsync();
128141

129-
// Send the request to dotCMS
130-
var response = await _httpClient.SendAsync(request);
131142

132-
// Check if the response is successful
133-
if (!response.IsSuccessStatusCode)
134-
{
135-
_logger.LogWarning($"dotCMS API returned status code: {response.StatusCode}");
136-
throw new HttpRequestException($"dotCMS API returned status code: {response.StatusCode}");
137-
}
143+
// _logger.LogInformation($"CONTENT: {content}");
138144

139-
// Read the response content
140-
var content = await response.Content.ReadAsStringAsync();
141145

142146
// Deserialize the response to PageResponse model
143147
var options = new JsonSerializerOptions

0 commit comments

Comments
 (0)