Search in sources :

Example 1 with SemanticVersion

use of org.nzbhydra.mapping.SemanticVersion in project nzbhydra2 by theotherp.

the class NewsProviderTest method getNewsJson.

protected List<NewsEntry> getNewsJson() throws ParseException, JsonProcessingException {
    NewsEntry entry1 = new NewsEntry(new SemanticVersion("1.0.0"), "news1.0.0");
    NewsEntry entry2 = new NewsEntry(new SemanticVersion("2.0.0"), "news2.0.0");
    NewsEntry entry3 = new NewsEntry(new SemanticVersion("3.0.0"), "news3.0.0");
    List<NewsEntry> entries = Arrays.asList(entry2, entry1, entry3);
    return entries;
}
Also used : NewsEntry(org.nzbhydra.news.NewsProvider.NewsEntry) SemanticVersion(org.nzbhydra.mapping.SemanticVersion)

Example 2 with SemanticVersion

use of org.nzbhydra.mapping.SemanticVersion in project nzbhydra2 by theotherp.

the class FromPythonMigration method migrateFromUrl.

@Transactional
public MigrationResult migrateFromUrl(String nzbhydra1BaseUrl, boolean doMigrateDatabase, boolean checkForDocker) {
    logger.info("Received request to migrate from URL " + nzbhydra1BaseUrl);
    if (checkForDocker && DebugInfosProvider.isRunInDocker()) {
        return MigrationResult.requirementsNotMet("You seem to be running NZBHydra2 in a docker container. Please copy the files from your v1 data folder to the v2 data folder and provide the correct file paths in the file based migration");
    }
    OkHttpResponse versionsResponse = callHydraUrl(nzbhydra1BaseUrl, "get_versions");
    if (!versionsResponse.isSuccessful()) {
        String msg = "Unable to connect to NZBHydra 1: " + versionsResponse.getMessage();
        logger.error(msg);
        return MigrationResult.requirementsNotMet(msg);
    }
    Map<String, String> migrationData = null;
    try {
        Map<String, String> versionsData = new ObjectMapper().readValue(versionsResponse.getBody(), mapTypeReference);
        String currentVersionString = versionsData.get("currentVersion");
        SemanticVersion currentVersion = new SemanticVersion(currentVersionString);
        if (currentVersion.compareTo(new SemanticVersion("0.2.220")) < 0) {
            String msg = "Unable to migrate from NZBHydra 1 version " + currentVersionString + ". Must be at least 0.2.220";
            logger.error(msg);
            return MigrationResult.requirementsNotMet(msg);
        }
        OkHttpResponse migrationResponse = callHydraUrl(nzbhydra1BaseUrl, "migration");
        migrationData = new ObjectMapper().readValue(migrationResponse.getBody(), mapTypeReference);
        migrationData.put("doMigrateDatabase", String.valueOf(doMigrateDatabase));
    } catch (Exception e) {
        logger.error("Unexpected error while migrating", e);
        return MigrationResult.requirementsNotMet("Unexpected error while migrating: " + e.getMessage());
    }
    return startMigration(migrationData);
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) SemanticVersion(org.nzbhydra.mapping.SemanticVersion) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SemanticVersion

use of org.nzbhydra.mapping.SemanticVersion in project nzbhydra2 by theotherp.

the class NewsProvider method getNewsForCurrentVersionAndAfter.

public List<NewsEntry> getNewsForCurrentVersionAndAfter() throws IOException {
    List<ShownNews> shownNews = shownNewsRepository.findAll();
    SemanticVersion from = shownNews.size() == 1 ? new SemanticVersion(shownNews.get(0).getVersion()) : null;
    SemanticVersion to = new SemanticVersion(updateManager.getCurrentVersionString());
    List<NewsEntry> news = getNews();
    return news.stream().filter(x -> !(from != null && from.isSameOrNewer(x.getShowForVersion()) || x.getShowForVersion().isUpdateFor(to))).collect(Collectors.toList());
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Value(org.springframework.beans.factory.annotation.Value) UpdateManager(org.nzbhydra.update.UpdateManager) Component(org.springframework.stereotype.Component) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) Data(lombok.Data) TypeReference(com.fasterxml.jackson.core.type.TypeReference) AllArgsConstructor(lombok.AllArgsConstructor) SemanticVersion(org.nzbhydra.mapping.SemanticVersion) Comparator(java.util.Comparator) WebAccess(org.nzbhydra.okhttp.WebAccess) SemanticVersion(org.nzbhydra.mapping.SemanticVersion)

Example 4 with SemanticVersion

use of org.nzbhydra.mapping.SemanticVersion in project nzbhydra2 by theotherp.

the class UpdateManager method getLatestVersion.

private SemanticVersion getLatestVersion() throws UpdateException {
    Release latestRelease = latestReleaseCache.get();
    latestVersion = new SemanticVersion(latestRelease.getTagName());
    return latestVersion;
}
Also used : Release(org.nzbhydra.mapping.github.Release) SemanticVersion(org.nzbhydra.mapping.SemanticVersion)

Example 5 with SemanticVersion

use of org.nzbhydra.mapping.SemanticVersion in project nzbhydra2 by theotherp.

the class UpdateManager method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    if (Objects.equals(currentVersionString, "@project.version@")) {
        currentVersionString = "1.0.0";
        logger.warn("Version string not found. Using 1.0.0");
    }
    currentVersion = new SemanticVersion(currentVersionString);
}
Also used : SemanticVersion(org.nzbhydra.mapping.SemanticVersion)

Aggregations

SemanticVersion (org.nzbhydra.mapping.SemanticVersion)11 IOException (java.io.IOException)2 Test (org.junit.Test)2 ChangelogVersionEntry (org.nzbhydra.mapping.changelog.ChangelogVersionEntry)2 NewsEntry (org.nzbhydra.news.NewsProvider.NewsEntry)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Data (lombok.Data)1 Release (org.nzbhydra.mapping.github.Release)1 WebAccess (org.nzbhydra.okhttp.WebAccess)1 UpdateManager (org.nzbhydra.update.UpdateManager)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1