| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import cn.reghao.oss.api.dto.ObjectMeta;
- import cn.reghao.oss.sdk.model.dto.media.ImageInfo;
- import cn.reghao.oss.store.OssMediaApplication;
- import cn.reghao.oss.store.db.mapper.DataBlockMapper;
- import cn.reghao.oss.store.db.mapper.FileMetaMapper;
- import cn.reghao.oss.store.model.po.DataBlock;
- import com.drew.imaging.ImageMetadataReader;
- import com.drew.lang.GeoLocation;
- import com.drew.metadata.Metadata;
- import com.drew.metadata.exif.GpsDirectory;
- import com.fasterxml.jackson.databind.deser.std.StringArrayDeserializer;
- import lombok.extern.slf4j.Slf4j;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.test.context.SpringBootTest;
- import org.springframework.test.context.ActiveProfiles;
- import org.springframework.test.context.junit4.SpringRunner;
- import javax.swing.table.TableCellRenderer;
- import java.io.File;
- import java.util.Collection;
- import java.util.List;
- /**
- * @author reghao
- * @date 2023-07-16 19:19:12
- */
- @Slf4j
- @ActiveProfiles("dev")
- @SpringBootTest(classes = OssMediaApplication.class)
- @RunWith(SpringRunner.class)
- public class FileMetaTest {
- @Autowired
- FileMetaMapper fileMetaMapper;
- // 正则表达式查询测试
- public void regexpTest() {
- String bucket = "";
- String prefix = "abc/d/";
- String startAfter = "abc/d/e";
- Integer maxKeys = 10;
- StringBuilder regex = new StringBuilder();
- regex.append("^").append(prefix).append("([^/])+/?$");
- if (startAfter.isBlank()) {
- fileMetaMapper.findAll0(bucket, maxKeys, regex.toString());
- } else {
- fileMetaMapper.findAll2(bucket, prefix, startAfter, maxKeys);
- }
- }
- @Test
- public void fileTest() {
- int pageSize = 10000;
- int nextId = 0;
- String prefix = "image/p/%";
- List<ObjectMeta> list = fileMetaMapper.findByPrefix(prefix, pageSize, nextId);
- while (!list.isEmpty()) {
- list.forEach(this::process);
- nextId = list.get(list.size()-1).getId();
- list = fileMetaMapper.findByPrefix(prefix, pageSize, nextId);
- log.info("nextId -> {}", nextId);
- }
- }
- private void process(ObjectMeta objectMeta) {
- String objectId = objectMeta.getObjectId();
- String absolutePath = objectMeta.getAbsolutePath();
- File file = new File(absolutePath);
- try {
- Metadata metadata = ImageMetadataReader.readMetadata(file);
- Collection<GpsDirectory> gpsDirectories = metadata.getDirectoriesOfType(GpsDirectory.class);
- for(GpsDirectory gps : gpsDirectories) {
- GeoLocation geoLocation = gps.getGeoLocation();
- if (geoLocation != null) {
- double longitude = geoLocation.getLongitude();
- double latitude = geoLocation.getLatitude();
- log.info("{}: ({}, {})", objectId, longitude, latitude);;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Autowired
- DataBlockMapper dataBlockMapper;
- @Test
- public void dataBlockTest() {
- int pageSize = 10000;
- int nextId = 0;
- List<DataBlock> list = dataBlockMapper.findDataBlocks(pageSize, nextId);
- while (!list.isEmpty()) {
- // process DataBlocks
- nextId = list.get(list.size()-1).getId();
- list = dataBlockMapper.findDataBlocks(pageSize, nextId);
- log.info("nextId -> {}", nextId);
- }
- }
- }
|