io.rocketbase.commons.holder.PreviewSizeContextHolder Maven / Gradle / Ivy
The newest version!
package io.rocketbase.commons.holder;
import io.rocketbase.commons.converter.QueryPreviewSizeConverter;
import io.rocketbase.commons.dto.asset.PreviewSize;
import io.rocketbase.commons.util.Nulls;
import org.springframework.util.MultiValueMap;
import java.util.List;
public final class PreviewSizeContextHolder {
private static ThreadLocal> currentPreviewSizes = new ThreadLocal<>();
/**
* will never be null
*/
public static List getCurrent() {
return Nulls.notNull(currentPreviewSizes.get(), QueryPreviewSizeConverter.DEFAULT);
}
public static void setCurrent(List previewSizes) {
currentPreviewSizes.set(previewSizes);
}
/**
* true when ThreadLocal is not null
*/
public static boolean hasValueSet() {
return currentPreviewSizes.get() != null;
}
/**
* when key previewSize exists in params updates context
*/
public static void update(MultiValueMap params) {
update("previewSize", params);
}
/**
* update context when key and params exists and not empty list
*/
public static void update(String key, MultiValueMap params) {
List sizes = QueryPreviewSizeConverter.getPreviewSizes(key, params, null);
if (sizes != null && !sizes.isEmpty()) {
setCurrent(sizes);
}
}
}