use of com.vdurmont.semver4j.Semver in project cas by apereo.
the class SystemUtils method injectUpdateInfoIntoBannerIfNeeded.
@SneakyThrows
private static void injectUpdateInfoIntoBannerIfNeeded(final Map<String, Object> info) {
final Properties properties = System.getProperties();
if (!properties.containsKey("CAS_UPDATE_CHECK_ENABLED")) {
return;
}
final URL url = new URL(UPDATE_CHECK_MAVEN_URL);
final Map results = MAPPER.readValue(url, Map.class);
if (!results.containsKey("response")) {
return;
}
final Map response = (Map) results.get("response");
if (!response.containsKey("numFound") && (int) response.get("numFound") != 1) {
return;
}
final List docs = (List) response.get("docs");
if (docs.isEmpty()) {
return;
}
final Map entry = (Map) docs.get(0);
final String latestVersion = (String) entry.get("latestVersion");
if (StringUtils.isNotBlank(latestVersion)) {
final String currentVersion = CasVersion.getVersion();
final Semver latestSem = new Semver(latestVersion);
final Semver currentSem = new Semver(currentVersion);
if (currentSem.isLowerThan(latestSem)) {
final String updateString = String.format("[Latest Version: %s / Stable: %s]", latestVersion, StringUtils.capitalize(BooleanUtils.toStringYesNo(latestSem.isStable())));
info.put("Update Availability", updateString);
}
}
}
use of com.vdurmont.semver4j.Semver in project mule by mulesoft.
the class BundleDescriptorUtils method isCompatibleVersion.
/**
* Determines if a version is compatible with another one
*
* @param availableVersion version that is available to use. Non empty
* @param expectedVersion version that is expected. Non empty
* @return true if versions are compatible, false otherwise
*/
public static boolean isCompatibleVersion(String availableVersion, String expectedVersion) {
checkArgument(!isEmpty(availableVersion), "availableVersion cannot be empty");
checkArgument(!isEmpty(expectedVersion), "expectedVersion cannot be empty");
if (availableVersion.equals(expectedVersion)) {
return true;
}
Semver available = getBundleVersion(availableVersion);
Semver expected = getBundleVersion(expectedVersion);
if (available.isGreaterThan(expected)) {
return available.getMajor().equals(expected.getMajor());
}
return false;
}
use of com.vdurmont.semver4j.Semver in project dhis2-core by dhis2.
the class SystemUpdateService method sendMessageForEachVersion.
public void sendMessageForEachVersion(Map<Semver, Map<String, String>> patchVersions) {
Set<User> recipients = getRecipients();
for (Map.Entry<Semver, Map<String, String>> entry : patchVersions.entrySet()) {
Semver version = entry.getKey();
Map<String, String> message = entry.getValue();
for (User recipient : recipients) {
// Check if message has been sent before using
// version.getValue() as extMessageId
List<MessageConversation> existingMessages = messageService.getMatchingExtId(version.getValue());
if (existingMessages.isEmpty()) {
MessageConversationParams params = new MessageConversationParams.Builder().withRecipients(ImmutableSet.of(recipient)).withSubject(NEW_VERSION_AVAILABLE_MESSAGE_SUBJECT).withText(buildMessageText(message)).withMessageType(MessageType.SYSTEM).withExtMessageId(version.getValue()).build();
messageService.sendMessage(params);
}
}
}
}
use of com.vdurmont.semver4j.Semver in project dhis2-core by dhis2.
the class SystemUpdateService method convertJsonToMap.
/**
* Converts a list of json elements representing patch versions, into a map
* of: SemVer (parsed version) and a map of strings representing the message
* to send to the admin user(s).
*/
protected static Map<Semver, Map<String, String>> convertJsonToMap(List<JsonElement> patchVersions) {
Map<Semver, Map<String, String>> versionsAndMessage = new TreeMap<>();
for (JsonElement patchVersion : patchVersions) {
JsonObject patchJsonObject = patchVersion.getAsJsonObject();
String version = patchJsonObject.getAsJsonPrimitive(FIELD_NAME_NAME).getAsString();
Map<String, String> message = new HashMap<>();
message.put(FIELD_NAME_VERSION, patchJsonObject.getAsJsonPrimitive(FIELD_NAME_NAME).getAsString());
message.put(FIELD_NAME_RELEASE_DATE, patchJsonObject.getAsJsonPrimitive(FIELD_NAME_RELEASE_DATE).getAsString());
message.put(FIELD_NAME_DOWNLOAD_URL, patchJsonObject.getAsJsonPrimitive(FIELD_NAME_URL).getAsString());
versionsAndMessage.put(new Semver(version), message);
}
return versionsAndMessage;
}
use of com.vdurmont.semver4j.Semver in project dhis2-core by dhis2.
the class SystemSoftwareUpdateNotifyController method checkSystemUpdate.
@GetMapping(SystemSoftwareUpdateNotifyController.RESOURCE_PATH)
@ResponseBody
public WebMessage checkSystemUpdate(@RequestParam(value = "forceVersion", required = false) String forceVersion) throws Exception {
Semver currentVersion = SystemUpdateService.getCurrentVersion();
if (forceVersion != null) {
currentVersion = new Semver(forceVersion);
}
Map<Semver, Map<String, String>> newerVersions = SystemUpdateService.getLatestNewerThan(currentVersion);
systemUpdateService.sendMessageForEachVersion(newerVersions);
WebMessage ok = WebMessageUtils.ok();
ok.setResponse(new SoftwareUpdateResponse(newerVersions));
return ok;
}
Aggregations