-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#29711 adding the collectors and refactor
- Loading branch information
Showing
22 changed files
with
342 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
dotCMS/src/main/java/com/dotcms/analytics/track/CollectorContextMap.java
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
dotCMS/src/main/java/com/dotcms/analytics/track/FilesCollector.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...nalytics/track/BasicProfileCollector.java → ...ack/collectors/BasicProfileCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CharacterCollectorContextMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.dotcms.analytics.track.collectors; | ||
|
||
import com.dotcms.analytics.track.matchers.RequestMatcher; | ||
import com.dotcms.visitor.filter.characteristics.Character; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
/** | ||
* This Context Map has the character map | ||
* @author jsanca | ||
*/ | ||
public class CharacterCollectorContextMap implements CollectorContextMap { | ||
|
||
private final RequestMatcher requestMatcher; | ||
private final Character character; | ||
|
||
public CharacterCollectorContextMap(final Character character, | ||
final RequestMatcher requestMatcher) { | ||
this.character = character; | ||
this.requestMatcher = requestMatcher; | ||
} | ||
|
||
|
||
|
||
@Override | ||
public Object get(final String key) { | ||
|
||
|
||
if (this.character.getMap().containsKey(key)) { | ||
return this.character.getMap().get(key); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public RequestMatcher getRequestMatcher() { | ||
return this.requestMatcher; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
dotCMS/src/main/java/com/dotcms/analytics/track/collectors/CollectorContextMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.dotcms.analytics.track.collectors; | ||
|
||
import com.dotcms.analytics.track.matchers.RequestMatcher; | ||
|
||
public interface CollectorContextMap { | ||
|
||
Object get(String key); | ||
RequestMatcher getRequestMatcher(); // since we do not have the previous step phase we need to keep this as an object, but will be a RequestMatcher | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
dotCMS/src/main/java/com/dotcms/analytics/track/collectors/FilesCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.dotcms.analytics.track.collectors; | ||
|
||
import com.dotcms.rest.api.v1.DotObjectMapperProvider; | ||
import com.dotmarketing.beans.Host; | ||
import com.dotmarketing.business.APILocator; | ||
import com.dotmarketing.portlets.contentlet.business.HostAPI; | ||
import com.dotmarketing.portlets.fileassets.business.FileAsset; | ||
import com.dotmarketing.portlets.fileassets.business.FileAssetAPI; | ||
import io.vavr.control.Try; | ||
|
||
import java.io.StringWriter; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class FilesCollector implements Collector { | ||
|
||
private final FileAssetAPI fileAssetAPI; | ||
private final HostAPI hostAPI; | ||
|
||
|
||
public FilesCollector() { | ||
this(APILocator.getFileAssetAPI(), | ||
APILocator.getHostAPI()); | ||
} | ||
|
||
public FilesCollector(final FileAssetAPI fileAssetAPI, | ||
final HostAPI hostAPI) { | ||
|
||
this.fileAssetAPI = fileAssetAPI; | ||
this.hostAPI = hostAPI; | ||
} | ||
|
||
@Override | ||
public boolean test(CollectorContextMap collectorContextMap) { | ||
return "file" == collectorContextMap.getRequestMatcher(); // should compare with the id | ||
} | ||
|
||
|
||
@Override | ||
public CollectorPayloadBean collect(final CollectorContextMap collectorContextMap, | ||
final CollectorPayloadBean collectorPayloadBean) { | ||
|
||
final String uri = (String)collectorContextMap.get("uri"); | ||
final String siteId = (String)collectorContextMap.get("host"); | ||
final Long languageId = (Long)collectorContextMap.get("langId"); | ||
final String language = (String)collectorContextMap.get("lang"); | ||
final Map<String, String> pageObject = new HashMap<>(); | ||
|
||
if (Objects.nonNull(uri) && Objects.nonNull(siteId) && Objects.nonNull(languageId)) { | ||
|
||
final Host site = Try.of(()->this.hostAPI.find(siteId, APILocator.systemUser(), false)).get(); | ||
final FileAsset fileAsset = Try.of(()->this.fileAssetAPI.getFileByPath(uri, site, languageId, true)).get(); | ||
pageObject.put("object_id", fileAsset.getIdentifier()); | ||
pageObject.put("title", fileAsset.getTitle()); | ||
pageObject.put("path", uri); | ||
} | ||
|
||
final StringWriter writer = new StringWriter(); | ||
Try.run(()-> DotObjectMapperProvider.getInstance().getDefaultObjectMapper().writeValue(writer, pageObject)); | ||
collectorPayloadBean.put("objects", writer.toString()); | ||
collectorPayloadBean.put("path", uri); | ||
collectorPayloadBean.put("event", "file"); | ||
collectorPayloadBean.put("language", language); | ||
collectorPayloadBean.put("site", siteId); | ||
|
||
return collectorPayloadBean; | ||
} | ||
|
||
@Override | ||
public boolean isAsync() { | ||
return true; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...otcms/analytics/track/PagesCollector.java → ...tics/track/collectors/PagesCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.