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

com.arextest.web.model.mapper.FSTraceLogMapper Maven / Gradle / Ivy

package com.arextest.web.model.mapper;

import cn.hutool.json.JSONUtil;
import com.arextest.web.common.ZstdUtils;
import com.arextest.web.model.dao.mongodb.FSTraceLogCollection;
import com.arextest.web.model.dto.filesystem.FSItemDto;
import com.arextest.web.model.dto.filesystem.FSNodeDto;
import com.arextest.web.model.dto.filesystem.FSTraceLogDto;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * @author b_yu
 * @since 2023/1/18
 */
@Mapper
public interface FSTraceLogMapper {

  FSTraceLogMapper INSTANCE = Mappers.getMapper(FSTraceLogMapper.class);

  FSTraceLogCollection daoFromDto(FSTraceLogDto dto);

  FSTraceLogDto dtoFromDao(FSTraceLogCollection dao);

  default String map(FSNodeDto dto) {
    return ZstdUtils.compressString(JSONUtil.toJsonStr(dto));
  }

  default FSNodeDto mapNode(String str) {
    if (StringUtils.isBlank(str)) {
      return null;
    }
    return JSONUtil.toBean(ZstdUtils.uncompressString(str), FSNodeDto.class);
  }

  default List mapItems(String str) throws JsonProcessingException {
    if (StringUtils.isBlank(str)) {
      return null;
    }
    ObjectMapper objectMapper = new ObjectMapper();
    return objectMapper.readValue(ZstdUtils.uncompressString(str),
        new TypeReference>() {
        });
  }

  default String map(List items) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper();
    ObjectWriter objectWriter = objectMapper.writerFor(new TypeReference>() {
    });
    return ZstdUtils.compressString(objectWriter.writeValueAsString(items));
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy