заготовки для зеркалирования Maven Central
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package ru.di9.mirror.controller;
|
package ru.di9.mirror.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@@ -24,7 +25,7 @@ import java.util.Optional;
|
|||||||
public class IndexOfMavenController {
|
public class IndexOfMavenController {
|
||||||
private final StorageService storageService;
|
private final StorageService storageService;
|
||||||
|
|
||||||
public IndexOfMavenController(StorageService storageService) {
|
public IndexOfMavenController(@Qualifier("mirroredStorageService") StorageService storageService) {
|
||||||
this.storageService = storageService;
|
this.storageService = storageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ru.di9.mirror.controller;
|
package ru.di9.mirror.controller;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@@ -25,7 +26,7 @@ import java.util.Optional;
|
|||||||
public class MavenController {
|
public class MavenController {
|
||||||
private final StorageService storageService;
|
private final StorageService storageService;
|
||||||
|
|
||||||
public MavenController(StorageService storageService) {
|
public MavenController(@Qualifier("mirroredStorageService") StorageService storageService) {
|
||||||
this.storageService = storageService;
|
this.storageService = storageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package ru.di9.mirror.services;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.di9.mirror.domain.FileRecord;
|
||||||
|
import ru.di9.mirror.domain.WalkerResult;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class MavenCentralStorageService implements StorageService {
|
||||||
|
@Override
|
||||||
|
public Optional<FileRecord> getFile(String path) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putFile(String path, InputStream inputStream) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<WalkerResult> walker(String path) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package ru.di9.mirror.services;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.di9.mirror.domain.FileRecord;
|
||||||
|
import ru.di9.mirror.domain.WalkerResult;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class MirroredStorageService implements StorageService {
|
||||||
|
|
||||||
|
private final FileStorageService fileStorageService;
|
||||||
|
private final MavenCentralStorageService mavenCentralStorageService;
|
||||||
|
|
||||||
|
public MirroredStorageService(FileStorageService fileStorageService,
|
||||||
|
MavenCentralStorageService mavenCentralStorageService) {
|
||||||
|
this.fileStorageService = fileStorageService;
|
||||||
|
this.mavenCentralStorageService = mavenCentralStorageService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<FileRecord> getFile(String path) {
|
||||||
|
Optional<FileRecord> optional;
|
||||||
|
|
||||||
|
optional = fileStorageService.getFile(path);
|
||||||
|
if (optional.isPresent()) {
|
||||||
|
return optional;
|
||||||
|
}
|
||||||
|
|
||||||
|
mavenCentralStorageService.getFile(path).ifPresent(fileRecord ->
|
||||||
|
fileStorageService.putFile(fileRecord.name(), fileRecord.inputStream()));
|
||||||
|
|
||||||
|
|
||||||
|
return fileStorageService.getFile(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void putFile(String path, InputStream inputStream) {
|
||||||
|
fileStorageService.putFile(path, inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<WalkerResult> walker(String path) {
|
||||||
|
return fileStorageService.walker(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user