Search in sources :

Example 1 with UpdateLicensePayloadModel

use of com.serotonin.m2m2.web.mvc.rest.v1.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);
    Module core = ModuleRegistry.getCoreModule();
    modules.add(0, core);
    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.getIntValue(SystemSettingsDao.UPGRADE_VERSION_STATE);
    int currentVersionState = UpgradeVersionState.DEVELOPMENT;
    Properties props = new Properties();
    File propFile = new File(Common.MA_HOME + File.separator + "release.properties");
    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.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.serotonin.m2m2.web.mvc.rest.v1.model.modules.UpdateLicensePayloadModel) Module(com.serotonin.m2m2.module.Module) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JsonString (com.serotonin.json.type.JsonString)1 ICoreLicense (com.serotonin.m2m2.ICoreLicense)1 Module (com.serotonin.m2m2.module.Module)1 UpdateLicensePayloadModel (com.serotonin.m2m2.web.mvc.rest.v1.model.modules.UpdateLicensePayloadModel)1 ApiOperation (com.wordnik.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