All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vmware.connectors.common.utils.CommonUtils Maven / Gradle / Ivy

There is a newer version: 2.9.8
Show newest version
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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy