Search in sources :

Example 1 with AngularJSModuleDefinitionGroupModel

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

the class ModulesRestController method getAngularJSModules.

public static AngularJSModuleDefinitionGroupModel getAngularJSModules(boolean developmentMode) {
    AngularJSModuleDefinitionGroupModel model = new AngularJSModuleDefinitionGroupModel();
    URI webUri = Common.MA_HOME_PATH.resolve(Constants.DIR_WEB).toUri();
    for (AngularJSModuleDefinition def : ModuleRegistry.getAngularJSDefinitions()) {
        Module module = def.getModule();
        Version moduleVersion = module.getVersion();
        String version = moduleVersion.toString();
        String preReleaseVersion = moduleVersion.getPreReleaseVersion();
        if ("SNAPSHOT".equals(preReleaseVersion)) {
            Date buildDate = module.getBuildDate();
            if (developmentMode) {
                Path filePath = def.getAbsoluteJavaScriptPath();
                try {
                    buildDate = new Date(Files.getLastModifiedTime(filePath).toMillis());
                } catch (IOException e) {
                // ignore
                }
            }
            String preRelease = PRE_RELEASE_FORMATTER.format(buildDate.toInstant());
            version = moduleVersion.setPreReleaseVersion(preRelease).toString();
        }
        URI uri = webUri.relativize(def.getAbsoluteJavaScriptPath().toUri());
        String urlWithVersion = UriComponentsBuilder.fromUri(uri).queryParam("v", version).build().toUriString();
        ModuleInfo info = new ModuleInfo();
        info.setUrl(uri.toString());
        info.setVersion(version);
        info.setName(module.getName());
        info.setUpgradedDate(module.getUpgradedDate());
        model.add("/" + urlWithVersion, info);
    }
    return model;
}
Also used : Path(java.nio.file.Path) AngularJSModuleDefinitionGroupModel(com.infiniteautomation.mango.rest.latest.model.modules.AngularJSModuleDefinitionGroupModel) AngularJSModuleDefinition(com.serotonin.m2m2.module.AngularJSModuleDefinition) Version(com.github.zafarkhaja.semver.Version) ModuleInfo(com.infiniteautomation.mango.rest.latest.model.modules.AngularJSModuleDefinitionGroupModel.ModuleInfo) JsonString(com.serotonin.json.type.JsonString) IOException(java.io.IOException) Module(com.serotonin.m2m2.module.Module) CoreModule(com.serotonin.m2m2.module.ModuleRegistry.CoreModule) InvalidModule(com.infiniteautomation.mango.rest.latest.model.modules.UpgradeUploadResult.InvalidModule) URI(java.net.URI) Date(java.util.Date)

Aggregations

Version (com.github.zafarkhaja.semver.Version)1 AngularJSModuleDefinitionGroupModel (com.infiniteautomation.mango.rest.latest.model.modules.AngularJSModuleDefinitionGroupModel)1 ModuleInfo (com.infiniteautomation.mango.rest.latest.model.modules.AngularJSModuleDefinitionGroupModel.ModuleInfo)1 InvalidModule (com.infiniteautomation.mango.rest.latest.model.modules.UpgradeUploadResult.InvalidModule)1 JsonString (com.serotonin.json.type.JsonString)1 AngularJSModuleDefinition (com.serotonin.m2m2.module.AngularJSModuleDefinition)1 Module (com.serotonin.m2m2.module.Module)1 CoreModule (com.serotonin.m2m2.module.ModuleRegistry.CoreModule)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 Date (java.util.Date)1