
org.dspace.matomo.factory.MatomoRequestCustomCookiesEnricher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dspace-api Show documentation
Show all versions of dspace-api Show documentation
DSpace core data model and service APIs.
The newest version!
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.matomo.factory;
import java.util.Set;
import jakarta.servlet.http.Cookie;
import org.dspace.matomo.model.MatomoRequestDetails;
import org.dspace.usage.UsageEvent;
/**
* This class extends the {@code MatomoRequestDetailsEnricher} interface and provides a concrete implementation
* to enrich the {@code MatomoRequestDetails} with custom cookies from the {@code UsageEvent}.
*
customCookies;
public MatomoRequestCustomCookiesEnricher(String customCookies) {
this.customCookies = Set.of(customCookies.split(","));
}
/**
* Enriches the {@code MatomoRequestDetails} with custom cookies from the {@code UsageEvent}.
*
* @param usageEvent The {@code UsageEvent} containing the request.
* @param matomoRequestDetails The {@code MatomoRequestDetails} to be enriched.
* @return The enriched {@code MatomoRequestDetails}.
*/
@Override
public MatomoRequestDetails enrich(UsageEvent usageEvent, MatomoRequestDetails matomoRequestDetails) {
Cookie[] cookies = usageEvent.getRequest().getCookies();
if (cookies == null) {
return matomoRequestDetails;
}
for (Cookie cookie : cookies) {
String cookieName = cookie.getName();
String baseName = null;
if (cookieName != null && cookieName.contains(".")) {
baseName = cookieName.substring(0, cookieName.indexOf("."));
}
if (baseName != null && customCookies.contains(baseName)) {
matomoRequestDetails.addCookie(cookieName, cookie.getValue());
}
}
return matomoRequestDetails;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy