Skip to content

Commit 55d6fba

Browse files
Merge branch 'issue-30552-containers-tm-support' of https://github.com/dotCMS/core into issue-30552-containers-tm-support
2 parents 1b6aac5 + 7e20084 commit 55d6fba

File tree

14 files changed

+196
-93
lines changed

14 files changed

+196
-93
lines changed

core-web/libs/sdk/client/README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# DotCMS API Client - `@dotcms/client`
1+
# dotCMS API Client - `@dotcms/client`
22

3-
The `@dotcms/client` is a JavaScript/TypeScript library for interacting with a DotCMS instance. It allows you to easily fetch pages, content, and navigation information in JSON format, as well as to make complex queries on content collections.
3+
The `@dotcms/client` is a JavaScript/TypeScript library for interacting with a dotCMS instance. It allows you to easily fetch pages, content, and navigation information in JSON format, as well as to make complex queries on content collections.
44

55
This client library provides a streamlined, promise-based interface to fetch pages and navigation API.
66

77
## Features
88

9-
- Easy-to-use methods to interact with the [DotCMS Page](https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas) and [Navigation APIs](https://www.dotcms.com/docs/latest/navigation-rest-api).
10-
- Support for custom actions to communicate with the DotCMS page editor.
9+
- Easy-to-use methods to interact with [dotCMS pages](https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas) and the [Navigation API](https://www.dotcms.com/docs/latest/navigation-rest-api).
10+
- Support for custom actions to communicate with the dotCMS page editor.
1111
- Comprehensive TypeScript typings for better development experience.
1212

13-
# DotCMS API Client
13+
# dotCMS API Client
1414

1515
## Installation
1616

@@ -42,7 +42,9 @@ import { DotCmsClient } from '@dotcms/client';
4242
const { DotCmsClient } = require('@dotcms/client');
4343
```
4444

45-
First, initialize the client with your DotCMS instance details.
45+
### Initialization
46+
47+
First, initialize the client with your dotCMS instance details.
4648

4749
```javascript
4850
const client = DotCmsClient.init({
@@ -54,7 +56,7 @@ const client = DotCmsClient.init({
5456

5557
### Fetching a Page
5658

57-
You can retrieve the elements of any page in your DotCMS system in JSON format using the client.page.get() method.
59+
You can retrieve the elements of any page in your dotCMS system in JSON format using the `client.page.get()` method.
5860

5961
```javascript
6062
const pageData = await client.page.get({
@@ -66,7 +68,7 @@ const pageData = await client.page.get({
6668

6769
### Fetching Navigation
6870

69-
Retrieve the DotCMS file and folder tree to get information about the navigation structure.
71+
Retrieve the dotCMS file and folder tree to get information about the navigation structure.
7072

7173
```javascript
7274
const navData = await client.nav.get({
@@ -78,7 +80,7 @@ const navData = await client.nav.get({
7880

7981
### Fetching a Collection of Content
8082

81-
The `getCollection` method allows you to fetch a collection of content items using a builder pattern for complex queries.
83+
The `getCollection` method allows you to fetch a collection of content items (sometimes called "contentlets") using a builder pattern for complex queries.
8284

8385
#### Basic Usage
8486

@@ -125,7 +127,7 @@ const languageFilteredResponse = await client.content
125127

126128
#### Using Complex Queries
127129

128-
You can build more complex queries using the query builder. For example, filter by author and `title`:
130+
You can build more complex queries using the query builder. For example, filter by `author` and `title`:
129131

130132
```typescript
131133
const complexQueryResponse = await client.content
@@ -206,26 +208,27 @@ Detailed documentation of the `@dotcms/client` methods, parameters, and types ca
206208

207209
### `DotCmsClient.init(config: ClientConfig): DotCmsClient`
208210

209-
Initializes the DotCMS client with the specified configuration.
211+
Initializes the dotCMS client with the specified configuration.
210212

211213
### `DotCmsClient.page.get(options: PageApiOptions): Promise<unknown>`
212214

213-
Retrieves the specified page's elements from your DotCMS system in JSON format.
215+
Retrieves the specified page's elements from your dotCMS system in JSON format.
214216

215217
### `DotCmsClient.nav.get(options: NavApiOptions): Promise<unknown>`
216218

217-
Retrieves information about the DotCMS file and folder tree.
219+
Retrieves information about the dotCMS file and folder tree.
218220

219221
### `DotCmsClient.content.getCollection(contentType: string): CollectionBuilder<T>`
220-
Creates a builder to filter and fetch a collection of content items for a specific content type.
222+
223+
Creates a builder to filter and fetches a collection of content items for a specific content type.
221224

222225
#### Parameters
223226

224-
contentType (string): The content type to retrieve.
227+
`contentType` (string): The content type to retrieve.
225228

226229
#### Returns
227230

228-
CollectionBuilder<T>: A builder instance for chaining filters and executing the query.
231+
`CollectionBuilder<T>`: A builder instance for chaining filters and executing the query.
229232

230233
## Contributing
231234

@@ -241,7 +244,7 @@ If you need help or have any questions, please [open an issue](https://github.co
241244

242245
## Documentation
243246

244-
Always refer to the official [DotCMS documentation](https://www.dotcms.com/docs/latest/) for comprehensive guides and API references.
247+
Always refer to the official [dotCMS documentation](https://www.dotcms.com/docs/latest/) for comprehensive guides and API references.
245248

246249
## Getting Help
247250

@@ -252,4 +255,4 @@ Always refer to the official [DotCMS documentation](https://www.dotcms.com/docs/
252255
| Videos | [Helpful Videos](http://dotcms.com/videos/) |
253256
| Forums/Listserv | [via Google Groups](https://groups.google.com/forum/#!forum/dotCMS) |
254257
| Twitter | @dotCMS |
255-
| Main Site | [dotCMS.com](https://dotcms.com/) |
258+
| Main Site | [dotCMS.com](https://dotcms.com/) |

dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa
7373
collectorPayloadBean.put(IS_EXPERIMENT_PAGE, false);
7474
collectorPayloadBean.put(IS_TARGET_PAGE, false);
7575

76-
if (Objects.nonNull(collectorPayloadBean.get(EVENT_SOURCE))) {
76+
if (Objects.isNull(collectorPayloadBean.get(EVENT_SOURCE))) {
7777
// this is the default event source
7878
collectorPayloadBean.put(EVENT_SOURCE, EventSource.DOT_CMS.getName());
7979
}

dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CharacterCollectorContextMap.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.Serializable;
77
import java.util.HashMap;
88
import java.util.Map;
9+
import java.util.Objects;
910

1011
/**
1112
* This Context Map has the character map
@@ -16,6 +17,7 @@ public class CharacterCollectorContextMap implements CollectorContextMap {
1617
private final Map<String, Object> contextMap = new HashMap<>();
1718
private final RequestMatcher requestMatcher;
1819
private final Map<String, Serializable> characterMap;
20+
private final Map<String, Object> customValuesMap;
1921

2022
public CharacterCollectorContextMap(final Character character,
2123
final RequestMatcher requestMatcher,
@@ -24,13 +26,29 @@ public CharacterCollectorContextMap(final Character character,
2426
this.characterMap = character.getMap();
2527
this.requestMatcher = requestMatcher;
2628
this.contextMap.putAll(contextMap);
29+
this.customValuesMap = Map.of();
30+
}
31+
32+
public CharacterCollectorContextMap(final Character character,
33+
final RequestMatcher requestMatcher,
34+
final Map<String, Object> contextMap,
35+
Map<String, Object> customValuesMap) {
36+
37+
this.characterMap = character.getMap();
38+
this.requestMatcher = requestMatcher;
39+
this.contextMap.putAll(contextMap);
40+
this.customValuesMap = Objects.nonNull(customValuesMap)?customValuesMap:Map.of();
2741
}
2842

2943

3044

3145
@Override
3246
public Object get(final String key) {
3347

48+
if (this.customValuesMap.containsKey(key)) {
49+
return this.customValuesMap.get(key);
50+
}
51+
3452
if (this.characterMap.containsKey(key)) {
3553
return this.characterMap.get(key);
3654
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.dotcms.analytics.track.collectors;
2+
3+
import java.io.Serializable;
4+
import java.util.Map;
5+
6+
/**
7+
* This class provides the default implementation for the {@link CollectorPayloadBean}
8+
* interface.
9+
* Concurrent Collector Payload Bean, but using a base map with is the source fo truth,
10+
* means that the map is the one that is going to be used and can not be overriden by any collector
11+
*
12+
* @author jsanca
13+
*/
14+
public class ConcurrentCollectorPayloadBeanWithBaseMap extends ConcurrentCollectorPayloadBean {
15+
16+
private final Map<String, Serializable> baseMap;
17+
18+
public ConcurrentCollectorPayloadBeanWithBaseMap(final Map<String, Serializable> customMap) {
19+
super(customMap);
20+
this.baseMap = customMap;
21+
}
22+
23+
@Override
24+
public CollectorPayloadBean put(final String key, final Serializable value) {
25+
26+
if (baseMap.containsKey(key)) {
27+
return this;
28+
}
29+
30+
super.put(key, value);
31+
return this;
32+
}
33+
34+
35+
public CollectorPayloadBean add(final CollectorPayloadBean other) {
36+
37+
other.toMap().entrySet().stream()
38+
.filter(entry -> !baseMap.containsKey(entry.getKey()))
39+
.forEach(entry -> super.put(entry.getKey(), entry.getValue()));
40+
return this;
41+
}
42+
}

dotCMS/src/main/java/com/dotcms/analytics/track/collectors/RequestCharacterCollectorContextMap.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.dotmarketing.business.web.WebAPILocator;
77

88
import javax.servlet.http.HttpServletRequest;
9+
import java.util.Map;
10+
import java.util.Objects;
911

1012
/**
1113
* This Context Map has the request + character map
@@ -15,21 +17,37 @@ public class RequestCharacterCollectorContextMap implements CollectorContextMap
1517

1618
private final RequestMatcher requestMatcher;
1719
private final Character character;
18-
final HttpServletRequest request;
20+
private final HttpServletRequest request;
21+
private final Map<String, Object> customValuesMap;
22+
23+
public RequestCharacterCollectorContextMap(final HttpServletRequest request,
24+
final Character character,
25+
final RequestMatcher requestMatcher,
26+
final Map<String, Object> customValuesMap) {
27+
this.request = request;
28+
this.character = character;
29+
this.requestMatcher = requestMatcher;
30+
this.customValuesMap = Objects.nonNull(customValuesMap)?customValuesMap:Map.of();
31+
}
1932

2033
public RequestCharacterCollectorContextMap(final HttpServletRequest request,
2134
final Character character,
2235
final RequestMatcher requestMatcher) {
2336
this.request = request;
2437
this.character = character;
2538
this.requestMatcher = requestMatcher;
39+
this.customValuesMap = Map.of();
2640
}
2741

2842

2943

3044
@Override
3145
public Object get(final String key) {
3246

47+
if (this.customValuesMap.containsKey(key)) {
48+
return this.customValuesMap.get(key);
49+
}
50+
3351
if (request.getParameter(key) != null) {
3452
return request.getParameter(key);
3553
}

dotCMS/src/main/java/com/dotcms/analytics/track/collectors/WebEventsCollectorService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ void fireCollectors (final HttpServletRequest request, final HttpServletResponse
3737
* @param requestMatcher The {@link RequestMatcher} that matched the dotCMS object being
3838
* processed, such as: HTML Page, File Asset, URL Mapped Content,
3939
* Vanity URL, etc.
40-
* @param basePayloadMap A Map containing all the properties that were retrieved by a given
41-
* {@link Collector}.
40+
* @param basePayloadMap A Map containing all payload properties that were given user
41+
* @param baseContextMap A Map containing all context the properties that were given user
4242
*/
4343
void fireCollectorsAndEmitEvent(final HttpServletRequest request, final HttpServletResponse response,
44-
final RequestMatcher requestMatcher, final Map<String, Serializable> userEventPayload);
44+
final RequestMatcher requestMatcher, final Map<String, Serializable> basePayloadMap,
45+
Map<String, Object> baseContextMap);
4546

4647
}

dotCMS/src/main/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceFactory.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,16 @@ public void fireCollectors(final HttpServletRequest request,
102102
public void fireCollectorsAndEmitEvent(final HttpServletRequest request,
103103
final HttpServletResponse response,
104104
final RequestMatcher requestMatcher,
105-
final Map<String, Serializable> basePayloadMap) {
105+
final Map<String, Serializable> basePayloadMap,
106+
final Map<String, Object> baseContextMap) {
106107

107108
final Character character = WebAPILocator.getCharacterWebAPI().getOrCreateCharacter(request, response);
108109
final Host site = WebAPILocator.getHostWebAPI().getCurrentHostNoThrow(request);
109110

110111
final CollectorPayloadBean base = UtilMethods.isSet(basePayloadMap)?
111-
new ConcurrentCollectorPayloadBean(basePayloadMap): new ConcurrentCollectorPayloadBean();
112+
new ConcurrentCollectorPayloadBeanWithBaseMap(basePayloadMap): new ConcurrentCollectorPayloadBean();
112113
final CollectorContextMap syncCollectorContextMap =
113-
new RequestCharacterCollectorContextMap(request, character, requestMatcher);
114+
new RequestCharacterCollectorContextMap(request, character, requestMatcher, baseContextMap);
114115

115116
Logger.debug(this, ()-> "Running sync collectors");
116117

@@ -122,7 +123,7 @@ public void fireCollectorsAndEmitEvent(final HttpServletRequest request,
122123
// if there is anything to run async
123124
final PageMode pageMode = PageMode.get(request);
124125
final CollectorContextMap collectorContextMap = new CharacterCollectorContextMap(character, requestMatcher,
125-
getCollectorContextMap(request, pageMode, site));
126+
getCollectorContextMap(request, pageMode, site), baseContextMap);
126127

127128
try {
128129
this.submitter.logEvent(
@@ -138,7 +139,7 @@ public void fireCollectorsAndEmitEvent(final HttpServletRequest request,
138139
.map(CollectorPayloadBean::toMap)
139140
.collect(java.util.stream.Collectors.toList());
140141
}));
141-
} catch (Exception e) {
142+
} catch (Exception e) { // todo: should we catch a more specific exception?
142143
Logger.debug(WebEventsCollectorServiceFactory.class, () -> "Error saving Analytics Events:" + e.getMessage());
143144
}
144145
}
@@ -147,7 +148,7 @@ private void fireCollectorsAndEmitEvent(final HttpServletRequest request,
147148
final HttpServletResponse response,
148149
final RequestMatcher requestMatcher) {
149150

150-
this.fireCollectorsAndEmitEvent(request, response, requestMatcher, Map.of());
151+
this.fireCollectorsAndEmitEvent(request, response, requestMatcher, Map.of(), Map.of());
151152
}
152153

153154
private static Map<String, Object> getCollectorContextMap(final HttpServletRequest request,

0 commit comments

Comments
 (0)