Skip to content

Commit

Permalink
#29711 sonarq feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jdotcms committed Sep 18, 2024
1 parent 98ab406 commit 543a1cd
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 47 deletions.
9 changes: 4 additions & 5 deletions dotCMS/src/main/java/com/dotcms/analytics/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
*/
public class Util {

private Util() {
// Singleton
}
/**
* Based on the specified URL Map Context, determines whether a given incoming URL maps to a URL
* Mapped content or not.
*
* @param pageMode The {@link PageMode} used to display/render an HTML Page.
* @param languageId The language ID used to display an HTML Page.
* @param uri The URI of the incoming request.
* @param site The {@link Host} where the HTML Page lives.
*
* @param urlMapContext UrlMapContext object containing the following information:
* @return If the URL maps to URL Mapped content, returns {@code true}.
*/
public static boolean isUrlMap(final UrlMapContext urlMapContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.dotmarketing.beans.Host;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.filters.CMSFilter;
import com.dotmarketing.filters.Constants;
import com.dotmarketing.portlets.contentlet.business.HostAPI;
import com.dotmarketing.util.UtilMethods;
import io.vavr.control.Try;
Expand All @@ -15,13 +16,12 @@

/**
* This asynchronized collector collects the page/asset information based on the vanity URL previous loaded on the
* {@link CollectionCollectorPayloadBean}
* @author jsanca
*/
public class AsyncVanitiesCollector implements Collector {

private final HostAPI hostAPI;
private Map<CMSFilter.IAm, Collector> match = new HashMap<>();
private final Map<CMSFilter.IAm, Collector> match = new HashMap<>();

public AsyncVanitiesCollector() {
this(APILocator.getHostAPI());
Expand Down Expand Up @@ -49,7 +49,6 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa
final CollectorPayloadBean collectorPayloadBean) {

// this will be a new event

final CachedVanityUrl cachedVanityUrl = (CachedVanityUrl) collectorContextMap.get(Constants.VANITY_URL_OBJECT);

final Host currentHost = (Host)collectorContextMap.get("currentHost");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa
collectorPayloadBean.put("request_id", requestId);
collectorPayloadBean.put("utc_time", FORMATTER.format(zonedDateTimeUTC));
collectorPayloadBean.put("cluster",
FunctionUtils.getOrDefault(Objects.nonNull(clusterId), ()->clusterId,()->ClusterFactory.getClusterId()));
FunctionUtils.getOrDefault(Objects.nonNull(clusterId), ()->clusterId, ClusterFactory::getClusterId));
collectorPayloadBean.put("server",
FunctionUtils.getOrDefault(Objects.nonNull(serverId), ()->serverId,()->APILocator.getServerAPI().readServerId()));
collectorPayloadBean.put("sessionId", sessionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.fileassets.business.FileAssetAPI;
import com.liferay.util.StringPool;
import io.vavr.control.Try;

import java.util.HashMap;
import java.util.Objects;
Expand All @@ -23,19 +22,16 @@
public class FilesCollector implements Collector {

private final FileAssetAPI fileAssetAPI;
private final HostAPI hostAPI;
private final ContentletAPI contentletAPI;

public FilesCollector() {
this(APILocator.getFileAssetAPI(),
APILocator.getHostAPI(), APILocator.getContentletAPI());
this(APILocator.getFileAssetAPI(), APILocator.getContentletAPI());
}

public FilesCollector(final FileAssetAPI fileAssetAPI,
final HostAPI hostAPI, final ContentletAPI contentletAPI) {
final ContentletAPI contentletAPI) {

this.fileAssetAPI = fileAssetAPI;
this.hostAPI = hostAPI;
this.contentletAPI = contentletAPI;
}

Expand Down Expand Up @@ -69,7 +65,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa
collectorPayloadBean.put("url", uri);
collectorPayloadBean.put("host", host);
collectorPayloadBean.put("language", language);
collectorPayloadBean.put("site", site.getIdentifier());
collectorPayloadBean.put("site", null != site?site.getIdentifier():"unknown");
collectorPayloadBean.put("event_type", EventType.FILE_REQUEST.getType());

return collectorPayloadBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import com.dotcms.analytics.Util;
import com.dotcms.contenttype.model.type.ContentType;
import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.Identifier;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.IdentifierAPI;
import com.dotmarketing.cms.urlmap.URLMapAPIImpl;
import com.dotmarketing.cms.urlmap.URLMapInfo;
import com.dotmarketing.cms.urlmap.UrlMapContext;
import com.dotmarketing.portlets.contentlet.business.HostAPI;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.htmlpageasset.business.HTMLPageAssetAPI;
import com.dotmarketing.portlets.htmlpageasset.model.IHTMLPage;
Expand All @@ -18,7 +15,6 @@
import io.vavr.control.Try;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

Expand Down Expand Up @@ -66,24 +62,26 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa
final Optional<URLMapInfo> urlMappedContent =
Try.of(() -> this.urlMapAPI.processURLMap(urlMapContext)).get();

final URLMapInfo urlMapInfo = urlMappedContent.get();
final Contentlet urlMapContentlet = urlMapInfo.getContentlet();
final ContentType urlMapContentType = urlMapContentlet.getContentType();

final IHTMLPage detailPageContent = Try.of(() ->
this.pageAPI.findByIdLanguageFallback(urlMapContentType.detailPage(), languageId, true, APILocator.systemUser(), DONT_RESPECT_FRONT_END_ROLES))
.onFailure(e -> Logger.error(this, String.format("Error finding detail page " +
"'%s': %s", urlMapContentType.detailPage(), getErrorMessage(e)), e))
.getOrNull();

final HashMap<String, String> pageObject = new HashMap<>();
pageObject.put("id", detailPageContent.getIdentifier());
pageObject.put("title", detailPageContent.getTitle());
pageObject.put("url", uri);
pageObject.put("detail_page_url", urlMapContentType.detailPage());
if (urlMappedContent.isPresent()) {
final URLMapInfo urlMapInfo = urlMappedContent.get();
final Contentlet urlMapContentlet = urlMapInfo.getContentlet();
final ContentType urlMapContentType = urlMapContentlet.getContentType();

final IHTMLPage detailPageContent = Try.of(() ->
this.pageAPI.findByIdLanguageFallback(urlMapContentType.detailPage(), languageId, true, APILocator.systemUser(), DONT_RESPECT_FRONT_END_ROLES))
.onFailure(e -> Logger.error(this, String.format("Error finding detail page " +
"'%s': %s", urlMapContentType.detailPage(), getErrorMessage(e)), e))
.getOrNull();

final HashMap<String, String> pageObject = new HashMap<>();
pageObject.put("id", detailPageContent.getIdentifier());
pageObject.put("title", detailPageContent.getTitle());
pageObject.put("url", uri);
pageObject.put("detail_page_url", urlMapContentType.detailPage());
collectorPayloadBean.put("object", pageObject);
}

collectorPayloadBean.put("event_type", EventType.PAGE_REQUEST.getType());
collectorPayloadBean.put("object", pageObject);
collectorPayloadBean.put("url", uri);
collectorPayloadBean.put("language", language);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.dotmarketing.cms.urlmap.URLMapAPIImpl;
import com.dotmarketing.cms.urlmap.URLMapInfo;
import com.dotmarketing.cms.urlmap.UrlMapContext;
import com.dotmarketing.portlets.contentlet.business.HostAPI;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.htmlpageasset.business.HTMLPageAssetAPI;
import com.dotmarketing.portlets.htmlpageasset.model.IHTMLPage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
public class SyncVanitiesCollector implements Collector {


public static final String VANITY_URL_KEY = "vanity_url";

public SyncVanitiesCollector() {
}

Expand All @@ -40,7 +42,7 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa
collectorPayloadBean.put("response_code", vanityRequest.getResponseCode());
}

collectorPayloadBean.put("vanity_url", vanityUrl);
collectorPayloadBean.put(VANITY_URL_KEY, vanityUrl);
collectorPayloadBean.put("vanity_query_string", vanityQueryString);
}

Expand All @@ -55,14 +57,15 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa

vanityObject.put("id", cachedVanityUrl.vanityUrlId);
vanityObject.put("forward_to",
collectorPayloadBean.get("vanity_url")!=null?(String)collectorPayloadBean.get("vanity_url"):cachedVanityUrl.forwardTo);
collectorPayloadBean.get(VANITY_URL_KEY)!=null?(String)collectorPayloadBean.get(VANITY_URL_KEY):cachedVanityUrl.forwardTo);
vanityObject.put("url", uri);
vanityObject.put("response", String.valueOf(cachedVanityUrl.response));
}

collectorPayloadBean.put("object", vanityObject);
collectorPayloadBean.put("url", uri);
collectorPayloadBean.put("language", language);
collectorPayloadBean.put("language_id", languageId);
collectorPayloadBean.put("site", site.getIdentifier());
collectorPayloadBean.put("event_type", EventType.VANITY_REQUEST.getType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import com.dotmarketing.filters.Constants;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;
import org.jetbrains.annotations.NotNull;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;

Expand All @@ -24,6 +27,8 @@
*/
public class WebEventsCollectorServiceFactory {

private WebEventsCollectorServiceFactory () {}

private final WebEventsCollectorService webEventsCollectorService = new WebEventsCollectorServiceImpl();

private static class SingletonHolder {
Expand Down
2 changes: 0 additions & 2 deletions dotCMS/src/main/java/com/dotcms/jitsu/EventLogRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.dotcms.http.CircuitBreakerUrl.Response;
import com.dotcms.http.CircuitBreakerUrlBuilder;
import com.dotcms.jitsu.EventsPayload.EventPayload;
import com.dotcms.util.ConversionUtils;
import com.dotmarketing.beans.Host;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.json.JSONObject;
Expand All @@ -20,7 +19,6 @@
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.dotcms.enterprise.cluster.ClusterFactory;
import com.dotcms.uuid.shorty.ShortyIdAPI;
import com.dotcms.visitor.domain.Visitor;

import com.dotcms.visitor.filter.servlet.VisitorFilter;
import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.Identifier;
Expand All @@ -16,14 +15,13 @@
import com.dotmarketing.portlets.languagesmanager.model.Language;
import com.dotmarketing.util.WebKeys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Optional;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseCharacter extends AbstractCharacter {

private final static String CLUSTER_ID;
Expand Down

0 comments on commit 543a1cd

Please sign in to comment.