Search in sources :

Example 1 with CoreModule

use of com.serotonin.m2m2.module.ModuleRegistry.CoreModule in project ma-modules-public by infiniteautomation.

the class ModulesRestController method getCore.

@ApiOperation(value = "Get Core Module", notes = "For checking current licensing and version")
@RequestMapping(method = RequestMethod.GET, value = "/core", produces = { "application/json" })
public ResponseEntity<MappingJacksonValue> getCore(HttpServletRequest request) {
    RestProcessResult<MappingJacksonValue> result = new RestProcessResult<>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        ModuleModel coreModule = getCoreModule();
        MappingJacksonValue jacksonValue = new MappingJacksonValue(coreModule);
        if (Permissions.hasAdmin(user)) {
            jacksonValue.setSerializationView(ModuleModel.AdminView.class);
        } else {
            jacksonValue.setSerializationView(Object.class);
        }
        return result.createResponseEntity(jacksonValue);
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) ModuleModel(com.serotonin.m2m2.web.mvc.rest.v1.model.modules.ModuleModel) CoreModuleModel(com.serotonin.m2m2.web.mvc.rest.v1.model.modules.CoreModuleModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CoreModule

use of com.serotonin.m2m2.module.ModuleRegistry.CoreModule in project ma-modules-public by infiniteautomation.

the class ModulesRestController method listModules.

@ApiOperation(value = "List Current Installed Modules", notes = "List all installed")
@RequestMapping(method = RequestMethod.GET, value = "/list")
public List<ModuleModel> listModules(@AuthenticationPrincipal PermissionHolder user) {
    permissionService.ensureAdminRole(user);
    List<ModuleModel> models = new ArrayList<ModuleModel>();
    List<Module> modules = ModuleRegistry.getModules();
    for (Module module : modules) {
        if (module instanceof CoreModule) {
            CoreModuleModel coreModel = new CoreModuleModel(ModuleRegistry.getModule(ModuleRegistry.CORE_MODULE_NAME));
            coreModel.setGuid(Providers.get(ICoreLicense.class).getGuid());
            coreModel.setInstanceDescription(SystemSettingsDao.getInstance().getValue(SystemSettingsDao.INSTANCE_DESCRIPTION));
            coreModel.setDistributor(Common.envProps.getString("distributor"));
            coreModel.setUpgradeVersionState(SystemSettingsDao.getInstance().getIntValue(SystemSettingsDao.UPGRADE_VERSION_STATE));
            coreModel.setStoreUrl(Common.envProps.getString("store.url"));
            models.add(coreModel);
        } else {
            models.add(new ModuleModel(module));
        }
    }
    // Add the unloaded modules at the end?
    List<Module> unloaded = ModuleRegistry.getUnloadedModules();
    for (Module module : unloaded) {
        ModuleModel model = new ModuleModel(module);
        model.setUnloaded(true);
        models.add(model);
    }
    return models;
}
Also used : CoreModuleModel(com.infiniteautomation.mango.rest.latest.model.modules.CoreModuleModel) ArrayList(java.util.ArrayList) CoreModule(com.serotonin.m2m2.module.ModuleRegistry.CoreModule) Module(com.serotonin.m2m2.module.Module) CoreModule(com.serotonin.m2m2.module.ModuleRegistry.CoreModule) InvalidModule(com.infiniteautomation.mango.rest.latest.model.modules.UpgradeUploadResult.InvalidModule) ModuleModel(com.infiniteautomation.mango.rest.latest.model.modules.ModuleModel) CoreModuleModel(com.infiniteautomation.mango.rest.latest.model.modules.CoreModuleModel) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CoreModuleModel (com.infiniteautomation.mango.rest.latest.model.modules.CoreModuleModel)1 ModuleModel (com.infiniteautomation.mango.rest.latest.model.modules.ModuleModel)1 InvalidModule (com.infiniteautomation.mango.rest.latest.model.modules.UpgradeUploadResult.InvalidModule)1 Module (com.serotonin.m2m2.module.Module)1 CoreModule (com.serotonin.m2m2.module.ModuleRegistry.CoreModule)1 User (com.serotonin.m2m2.vo.User)1 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)1 CoreModuleModel (com.serotonin.m2m2.web.mvc.rest.v1.model.modules.CoreModuleModel)1 ModuleModel (com.serotonin.m2m2.web.mvc.rest.v1.model.modules.ModuleModel)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ArrayList (java.util.ArrayList)1 MappingJacksonValue (org.springframework.http.converter.json.MappingJacksonValue)1