Search in sources :

Example 1 with UpdateLicensePayloadModel

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JsonString(com.serotonin.json.type.JsonString) IOException(java.io.IOException) Properties(java.util.Properties) ICoreLicense(com.serotonin.m2m2.ICoreLicense) FileInputStream(java.io.FileInputStream) ResponseEntity(org.springframework.http.ResponseEntity) UpdateLicensePayloadModel(com.infiniteautomation.mango.rest.latest.model.modules.UpdateLicensePayloadModel) Module(com.serotonin.m2m2.module.Module) CoreModule(com.serotonin.m2m2.module.ModuleRegistry.CoreModule) InvalidModule(com.infiniteautomation.mango.rest.latest.model.modules.UpgradeUploadResult.InvalidModule) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UpdateLicensePayloadModel (com.infiniteautomation.mango.rest.latest.model.modules.UpdateLicensePayloadModel)1 InvalidModule (com.infiniteautomation.mango.rest.latest.model.modules.UpgradeUploadResult.InvalidModule)1 JsonString (com.serotonin.json.type.JsonString)1 ICoreLicense (com.serotonin.m2m2.ICoreLicense)1 Module (com.serotonin.m2m2.module.Module)1 CoreModule (com.serotonin.m2m2.module.ModuleRegistry.CoreModule)1 ApiOperation (io.swagger.annotations.ApiOperation)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 ZipInputStream (java.util.zip.ZipInputStream)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1