Search in sources :

Example 1 with Module

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

the class ModulesRestController method getCoreModule.

/**
 * Create a Core Module Model
 *
 * @return
 */
private ModuleModel getCoreModule() {
    CoreModuleModel coreModel = new CoreModuleModel(ModuleRegistry.getCoreModule());
    coreModel.setGuid(Providers.get(ICoreLicense.class).getGuid());
    coreModel.setInstanceDescription(SystemSettingsDao.getValue(SystemSettingsDao.INSTANCE_DESCRIPTION));
    coreModel.setDistributor(Common.envProps.getString("distributor"));
    coreModel.setUpgradeVersionState(SystemSettingsDao.getIntValue(SystemSettingsDao.UPGRADE_VERSION_STATE));
    return coreModel;
}
Also used : CoreModuleModel(com.serotonin.m2m2.web.mvc.rest.v1.model.modules.CoreModuleModel)

Example 2 with Module

use of com.serotonin.m2m2.module.Module 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 3 with Module

use of com.serotonin.m2m2.module.Module 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", produces = { "application/json" })
public ResponseEntity<List<ModuleModel>> listModules(HttpServletRequest request) {
    RestProcessResult<List<ModuleModel>> result = new RestProcessResult<List<ModuleModel>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        if (Permissions.hasAdmin(user)) {
            List<ModuleModel> models = new ArrayList<ModuleModel>();
            ModuleModel core = getCoreModule();
            List<Module> modules = ModuleRegistry.getModules();
            models.add(core);
            for (Module module : modules) 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 result.createResponseEntity(models);
        } else {
            result.addRestMessage(this.getUnauthorizedMessage());
        }
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) User(com.serotonin.m2m2.vo.User) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Module(com.serotonin.m2m2.module.Module) 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 4 with Module

use of com.serotonin.m2m2.module.Module in project ma-core-public by infiniteautomation.

the class ModuleRegistry method ensurePermissionDefinitions.

private static void ensurePermissionDefinitions() {
    if (PERMISSION_DEFINITIONS == null) {
        synchronized (LOCK) {
            if (PERMISSION_DEFINITIONS == null) {
                Map<String, PermissionDefinition> map = new HashMap<String, PermissionDefinition>();
                for (PermissionDefinition def : Module.getDefinitions(preDefaults, PermissionDefinition.class)) {
                    map.put(def.getPermissionTypeName(), def);
                }
                for (Module module : MODULES.values()) {
                    for (PermissionDefinition def : module.getDefinitions(PermissionDefinition.class)) map.put(def.getPermissionTypeName(), def);
                }
                for (PermissionDefinition def : Module.getDefinitions(postDefaults, PermissionDefinition.class)) {
                    map.put(def.getPermissionTypeName(), def);
                }
                PERMISSION_DEFINITIONS = map;
            }
        }
    }
}
Also used : LegacyPointDetailsViewPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.LegacyPointDetailsViewPermissionDefinition) PurgeAllEventsActionPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.PurgeAllEventsActionPermissionDefinition) PurgeWithPurgeSettingsActionPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.PurgeWithPurgeSettingsActionPermissionDefinition) CoreFileStoreReadPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.CoreFileStoreReadPermissionDefinition) CoreFileStoreWritePermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.CoreFileStoreWritePermissionDefinition) ConfigurationBackupActionPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.ConfigurationBackupActionPermissionDefinition) PublicFileStoreWritePermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.PublicFileStoreWritePermissionDefinition) DocsFileStoreWritePermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.DocsFileStoreWritePermissionDefinition) SqlRestoreActionPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.SqlRestoreActionPermissionDefinition) PurgeAllPointValuesActionPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.PurgeAllPointValuesActionPermissionDefinition) UsersViewPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.UsersViewPermissionDefinition) SuperadminPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.SuperadminPermissionDefinition) EventsViewPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.EventsViewPermissionDefinition) DocsFileStoreReadPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.DocsFileStoreReadPermissionDefinition) SqlBackupActionPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.SqlBackupActionPermissionDefinition) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 5 with Module

use of com.serotonin.m2m2.module.Module in project ma-core-public by infiniteautomation.

the class ModuleRegistry method getCoreModule.

/**
 * Helper Method to create a Module with Core Information
 * @return
 */
public static Module getCoreModule() {
    Module core = new Module("core", Common.getVersion(), new TranslatableMessage("modules.core.description"), "Infinite Automation Systems, Inc.", "https://www.infiniteautomation.com", null, -1, Common.isCoreSigned());
    if (Common.isInvalid())
        core.setLicenseType("Invalid");
    else
        core.setLicenseType(Common.license() == null ? null : Common.license().getLicenseType());
    core.addDefinition((LicenseDefinition) Providers.get(ICoreLicense.class));
    return core;
}
Also used : TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Aggregations

HashMap (java.util.HashMap)9 Module (com.serotonin.m2m2.module.Module)8 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 User (com.serotonin.m2m2.vo.User)6 JsonString (com.serotonin.json.type.JsonString)5 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 JsonObject (com.serotonin.json.type.JsonObject)4 File (java.io.File)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)3 JsonWriter (com.serotonin.json.JsonWriter)3 CoreModuleModel (com.serotonin.m2m2.web.mvc.rest.v1.model.modules.CoreModuleModel)3 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 Version (com.github.zafarkhaja.semver.Version)2 BadRequestException (com.infiniteautomation.mango.rest.v2.exception.BadRequestException)2