package <%=packageName%>.web.rest.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;

/**
 * Utility class for HTTP headers creation.
 */
public final class HeaderUtil {

    private static final Logger log = LoggerFactory.getLogger(HeaderUtil.class);

    private HeaderUtil() {
    }

    public static HttpHeaders createAlert(String message, String param) {
        HttpHeaders headers = new HttpHeaders();
        headers.add("X-<%=angularAppName%>-alert", message);
        headers.add("X-<%=angularAppName%>-params", param);
        return headers;
    }
<%
    if(enableTranslation) {
        var createdMessage = '"' + angularAppName + '." + entityName + ".created"';
        var updatedMessage = '"' + angularAppName + '." + entityName + ".updated"';
        var deletedMessage = '"' + angularAppName + '." + entityName + ".deleted"';
        var errorMessage = '"error." + errorKey';
    } else {
        var createdMessage = '"A new " + entityName + " is created with identifier " + param';
        var updatedMessage = '"A " + entityName + " is updated with identifier " + param';
        var deletedMessage = '"A " + entityName + " is deleted with identifier " + param';
        var errorMessage = 'defaultMessage';
    }
%>
    public static HttpHeaders createEntityCreationAlert(String entityName, String param) {
        return createAlert(<%- createdMessage %>, param);
    }

    public static HttpHeaders createEntityUpdateAlert(String entityName, String param) {
        return createAlert(<%- updatedMessage %>, param);
    }

    public static HttpHeaders createEntityDeletionAlert(String entityName, String param) {
        return createAlert(<%- deletedMessage %>, param);
    }

    public static HttpHeaders createFailureAlert(String entityName, String errorKey, String defaultMessage) {
        log.error("Entity creation failed, {}", defaultMessage);
        HttpHeaders headers = new HttpHeaders();
        headers.add("X-<%=angularAppName%>-error", <%- errorMessage %>);
        headers.add("X-<%=angularAppName%>-params", entityName);
        return headers;
    }
}

@@ -302,16 +302,144 @@
 .class);
+%0A    %3C%25_ if (enableTranslation) %7B _%25%3E%0A%0A    private static final String APPLICATION_NAME = %22%3C%25= angularAppName %25%3E%22;%0A    %3C%25_ %7D _%25%3E
 %0A%0A    pr
@@ -749,16 +749,17 @@
 %25%0A    if
+ 
 (enableT
@@ -802,39 +802,36 @@
 sage = '
-%22' + angularAppName + '
+APPLICATION_NAME + %22
 .%22 + ent
@@ -883,39 +883,36 @@
 sage = '
-%22' + angularAppName + '
+APPLICATION_NAME + %22
 .%22 + ent
@@ -968,31 +968,28 @@
  = '
-%22' + angularAppName + '
+APPLICATION_NAME + %22
 .%22 +

Define a constant instead of duplicating a String