com.vmware.connectors.common.utils.CommonUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of connectors-config Show documentation
Show all versions of connectors-config Show documentation
Common config code for developing connectors
package com.vmware.connectors.common.utils;
import com.vmware.connectors.common.payloads.response.Card;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpRequest;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.web.util.UriComponentsBuilder;
import javax.servlet.http.HttpServletRequest;
/**
* Common utility functions to be used across connectors parent.
*/
public final class CommonUtils {
public static final String APPROVAL_ACTIONS = "approval-actions";
private static final String DEFAULT_IMAGE_PATH = "/images/connector.png";
private CommonUtils() {
// Utility class.
}
public static void buildConnectorImageUrl(final Card.Builder card, final HttpServletRequest request) {
final String uri = buildConnectorImageUrl(request);
if (StringUtils.isNotBlank(uri)) {
card.setImageUrl(uri);
}
}
public static String buildConnectorImageUrl(final HttpRequest request) {
return buildConnectorUrl(request, DEFAULT_IMAGE_PATH);
}
public static String buildConnectorImageUrl(final HttpServletRequest request) {
return buildConnectorUrl(request, DEFAULT_IMAGE_PATH);
}
public static String buildConnectorUrl(final HttpRequest request, final String path) {
return UriComponentsBuilder.fromHttpRequest(request).replacePath(path).build().toString();
}
public static String buildConnectorUrl(final HttpServletRequest request, final String path) {
return buildConnectorUrl(new ServletServerHttpRequest(request), path);
}
}