44 lines
1.6 KiB
Java
44 lines
1.6 KiB
Java
package io.github.jhipster.sample.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-jhipsterSampleApplicationApp-alert", message);
|
|
headers.add("X-jhipsterSampleApplicationApp-params", param);
|
|
return headers;
|
|
}
|
|
|
|
public static HttpHeaders createEntityCreationAlert(String entityName, String param) {
|
|
return createAlert("jhipsterSampleApplicationApp." + entityName + ".created", param);
|
|
}
|
|
|
|
public static HttpHeaders createEntityUpdateAlert(String entityName, String param) {
|
|
return createAlert("jhipsterSampleApplicationApp." + entityName + ".updated", param);
|
|
}
|
|
|
|
public static HttpHeaders createEntityDeletionAlert(String entityName, String param) {
|
|
return createAlert("jhipsterSampleApplicationApp." + entityName + ".deleted", param);
|
|
}
|
|
|
|
public static HttpHeaders createFailureAlert(String entityName, String errorKey, String defaultMessage) {
|
|
log.error("Entity creation failed, {}", defaultMessage);
|
|
HttpHeaders headers = new HttpHeaders();
|
|
headers.add("X-jhipsterSampleApplicationApp-error", "error." + errorKey);
|
|
headers.add("X-jhipsterSampleApplicationApp-params", entityName);
|
|
return headers;
|
|
}
|
|
}
|