38 lines
1.2 KiB
Java
38 lines
1.2 KiB
Java
package eu.eudat.service.reference.external;
|
|
|
|
import eu.eudat.service.reference.external.config.ExternalUrls;
|
|
import eu.eudat.service.storage.StorageFileService;
|
|
import jakarta.xml.bind.JAXBContext;
|
|
import jakarta.xml.bind.Unmarshaller;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
@Service
|
|
public class ExternalUrlConfigProvider {
|
|
private static final Logger logger = LoggerFactory.getLogger(ExternalUrlConfigProvider.class);
|
|
|
|
private ExternalUrls externalUrls;
|
|
private final StorageFileService storageFileService;
|
|
|
|
public ExternalUrlConfigProvider(StorageFileService storageFileService) {
|
|
this.storageFileService = storageFileService;
|
|
}
|
|
|
|
public ExternalUrls getExternalUrls() {
|
|
if (externalUrls == null) {
|
|
byte[] bytes = this.storageFileService.getExternalUrlsFile();
|
|
try {
|
|
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
|
|
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
|
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(new ByteArrayInputStream(bytes));
|
|
} catch (Exception ex) {
|
|
logger.error("Cannot find resource", ex);
|
|
}
|
|
}
|
|
return externalUrls;
|
|
}
|
|
}
|