Search in sources :

Example 1 with CoreModuleModel

use of com.infiniteautomation.mango.rest.latest.model.modules.CoreModuleModel in project ma-modules-public by infiniteautomation.

the class ModulesRestController method getCore.

@ApiOperation(value = "Get Core Module", notes = "For checking current licensing and version", response = ModuleModel.class)
@RequestMapping(method = RequestMethod.GET, value = "/core")
public MappingJacksonValue getCore(@AuthenticationPrincipal PermissionHolder user) {
    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"));
    MappingJacksonValue jacksonValue = new MappingJacksonValue(coreModel);
    if (permissionService.hasAdminRole(user)) {
        jacksonValue.setSerializationView(AdminView.class);
    } else {
        jacksonValue.setSerializationView(Object.class);
    }
    return jacksonValue;
}
Also used : CoreModuleModel(com.infiniteautomation.mango.rest.latest.model.modules.CoreModuleModel) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CoreModuleModel

use of com.infiniteautomation.mango.rest.latest.model.modules.CoreModuleModel 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

CoreModuleModel (com.infiniteautomation.mango.rest.latest.model.modules.CoreModuleModel)2 ApiOperation (io.swagger.annotations.ApiOperation)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 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 ArrayList (java.util.ArrayList)1 MappingJacksonValue (org.springframework.http.converter.json.MappingJacksonValue)1