use of com.infiniteautomation.mango.rest.latest.model.modules.UpdateLicensePayloadModel in project ma-modules-public by infiniteautomation.
the class ModulesRestController method getUpdateLicensePayload.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "Get the update license payload, to make requests to store", notes = "Admin Only")
@RequestMapping(method = RequestMethod.GET, value = "/update-license-payload")
public ResponseEntity<UpdateLicensePayloadModel> getUpdateLicensePayload(@ApiParam(value = "Set content disposition to attachment", required = false, defaultValue = "true", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean download, HttpServletRequest request) {
Map<String, String> jsonModules = new HashMap<>();
List<Module> modules = ModuleRegistry.getModules();
Module.sortByName(modules);
for (Module module : modules) {
if (!module.isMarkedForDeletion())
jsonModules.put(module.getName(), module.getVersion().toString());
}
// Add in the unloaded modules so we don't re-download them if we don't have to
for (Module module : ModuleRegistry.getUnloadedModules()) if (!module.isMarkedForDeletion())
jsonModules.put(module.getName(), module.getVersion().toString());
String storeUrl = Common.envProps.getString("store.url");
int upgradeVersionState = SystemSettingsDao.getInstance().getIntValue(SystemSettingsDao.UPGRADE_VERSION_STATE);
int currentVersionState = UpgradeVersionState.DEVELOPMENT;
Properties props = new Properties();
File propFile = Common.MA_HOME_PATH.resolve("release.properties").toFile();
try {
if (propFile.exists()) {
InputStream in;
in = new FileInputStream(propFile);
try {
props.load(in);
} finally {
in.close();
}
String versionState = props.getProperty("versionState");
try {
if (versionState != null)
currentVersionState = Integer.valueOf(versionState);
} catch (NumberFormatException e) {
}
}
} catch (IOException e1) {
// Ignore
}
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set(HttpHeaders.CONTENT_DISPOSITION, download ? "attachment" : "inline");
return new ResponseEntity<>(new UpdateLicensePayloadModel(Providers.get(ICoreLicense.class).getGuid(), SystemSettingsDao.getInstance().getValue(SystemSettingsDao.INSTANCE_DESCRIPTION), Common.envProps.getString("distributor"), jsonModules, storeUrl, upgradeVersionState, currentVersionState), responseHeaders, HttpStatus.OK);
}
Aggregations