Search in sources :

Example 6 with ProcessMessage

use of com.serotonin.m2m2.i18n.ProcessMessage in project ma-core-public by infiniteautomation.

the class StartupDwr method getStartupProgress.

@DwrPermission(anonymous = true)
public ProcessResult getStartupProgress(long since) {
    ProcessResult result = new ProcessResult();
    IMangoLifecycle lifecycle = Providers.get(IMangoLifecycle.class);
    float progress = lifecycle.getStartupProgress();
    float shutdownProgress = lifecycle.getShutdownProgress();
    List<String> messages = LoggingConsoleRT.instance.getMessagesSince(since);
    StringBuilder builder = new StringBuilder();
    for (String message : messages) {
        builder.append(message);
        builder.append("</br>");
    }
    result.addData("message", builder.toString());
    result.addData("startupProgress", progress);
    result.addData("shutdownProgress", shutdownProgress);
    result.addData("state", getLifecycleStateMessage(lifecycle.getLifecycleState()));
    if ((progress >= 100) && (shutdownProgress == 0)) {
        WebContext ctx = WebContextFactory.get();
        result.addData("startupUri", DefaultPagesDefinition.getLoginUri(ctx.getHttpServletRequest(), ctx.getHttpServletResponse()));
    }
    // Add the message to describe what process we are in
    if ((progress < 100) && (shutdownProgress == 0)) {
        result.addData("processMessage", this.translations.translate("startup.startingUp"));
    } else if ((shutdownProgress > 0) && (lifecycle.isRestarting())) {
        result.addData("processMessage", this.translations.translate("shutdown.restarting"));
    } else if (shutdownProgress > 0) {
        result.addData("processMessage", this.translations.translate("shutdown.shuttingDown"));
    }
    if ((progress == 100) && (shutdownProgress == 0)) {
        result.addData("processMessage", this.translations.translate("startup.state.running"));
    }
    return result;
}
Also used : WebContext(org.directwebremoting.WebContext) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) IMangoLifecycle(com.serotonin.m2m2.IMangoLifecycle) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 7 with ProcessMessage

use of com.serotonin.m2m2.i18n.ProcessMessage in project ma-core-public by infiniteautomation.

the class DefaultDataPointPropertiesTemplateFactory method saveTemplate.

protected void saveTemplate(DataPointPropertiesTemplateVO template) {
    ProcessResult response = new ProcessResult();
    template.validate(response);
    if (!response.getHasMessages()) {
        TemplateDao.instance.save(template);
    } else {
        String output = new String();
        List<ProcessMessage> messages = response.getMessages();
        for (ProcessMessage message : messages) {
            output += message.toString(Common.getTranslations());
            output += "\n";
        }
        throw new ShouldNeverHappenException(output);
    }
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage)

Example 8 with ProcessMessage

use of com.serotonin.m2m2.i18n.ProcessMessage in project ma-core-public by infiniteautomation.

the class MangoTestBase method loadConfiguration.

protected void loadConfiguration(File jsonFile) throws JsonException, IOException, URISyntaxException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(jsonFile), Common.UTF8_CS));
    JsonReader jr = new JsonReader(reader);
    JsonObject jo = jr.read(JsonObject.class);
    ImportTask task = new ImportTask(jo, Common.getTranslations(), null, false);
    task.run(Common.timer.currentTimeMillis());
    if (task.getResponse().getHasMessages()) {
        for (ProcessMessage message : task.getResponse().getMessages()) {
            switch(message.getLevel()) {
                case error:
                case warning:
                    fail(message.toString(Common.getTranslations()));
                case info:
                    LOG.info(message.toString(Common.getTranslations()));
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ImportTask(com.serotonin.m2m2.web.dwr.emport.ImportTask) BufferedReader(java.io.BufferedReader) JsonReader(com.serotonin.json.JsonReader) JsonObject(com.serotonin.json.type.JsonObject) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage) FileInputStream(java.io.FileInputStream)

Example 9 with ProcessMessage

use of com.serotonin.m2m2.i18n.ProcessMessage in project ma-core-public by infiniteautomation.

the class Importer method addFailureMessage.

protected void addFailureMessage(String key, Object... params) {
    success = false;
    failureMessages.add(new ProcessMessage(key, params));
}
Also used : ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage)

Example 10 with ProcessMessage

use of com.serotonin.m2m2.i18n.ProcessMessage in project ma-core-public by infiniteautomation.

the class DataPointImporter method importImpl.

@Override
protected void importImpl() {
    String xid = json.getString("xid");
    DataPointVO vo = null;
    DataSourceVO<?> dsvo = null;
    if (StringUtils.isBlank(xid))
        xid = ctx.getDataPointDao().generateUniqueXid();
    else
        vo = ctx.getDataPointDao().getDataPoint(xid);
    if (vo == null) {
        // Locate the data source for the point.
        String dsxid = json.getString("dataSourceXid");
        dsvo = ctx.getDataSourceDao().getDataSource(dsxid);
        if (dsvo == null)
            addFailureMessage("emport.dataPoint.badReference", xid);
        else {
            vo = new DataPointVO();
            vo.setXid(xid);
            vo.setDataSourceId(dsvo.getId());
            vo.setDataSourceXid(dsxid);
            vo.setPointLocator(dsvo.createPointLocator());
            vo.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
        // Not needed as it will be set via the template or JSON or it exists in the DB already: vo.setTextRenderer(new PlainRenderer());
        }
    }
    if (vo != null) {
        try {
            DataPointPropertiesTemplateVO template = null;
            if (json.containsKey("templateXid")) {
                String templateXid = json.getString("templateXid");
                if (!StringUtils.isEmpty(templateXid))
                    template = (DataPointPropertiesTemplateVO) TemplateDao.instance.getByXid(templateXid);
            }
            // Read into the VO to get all properties
            ctx.getReader().readInto(vo, json);
            // Override the settings if we need to
            if (template != null) {
                template.updateDataPointVO(vo);
            }
            // If the name is not provided, default to the XID
            if (StringUtils.isBlank(vo.getName()))
                vo.setName(xid);
            // If the chart colour is null provide default of '' to handle legacy code that sets colour to null
            if (vo.getChartColour() == null)
                vo.setChartColour("");
            // Now validate it. Use a new response object so we can distinguish errors in this vo from
            // other errors.
            ProcessResult voResponse = new ProcessResult();
            vo.validate(voResponse);
            if (voResponse.getHasMessages())
                setValidationMessages(voResponse, "emport.dataPoint.prefix", xid);
            else {
                // We will always override the DS Info with the one from the XID Lookup
                dsvo = ctx.getDataSourceDao().getDataSource(vo.getDataSourceXid());
                if (dsvo == null)
                    addFailureMessage("emport.dataPoint.badReference", xid);
                else {
                    // Compare this point to the existing point in DB to ensure
                    // that we aren't moving a point to a different type of Data Source
                    DataPointVO oldPoint = ctx.getDataPointDao().getDataPoint(vo.getId(), false);
                    // Does the old point have a different data source?
                    if (oldPoint != null && (oldPoint.getDataSourceId() != dsvo.getId())) {
                        vo.setDataSourceId(dsvo.getId());
                        vo.setDataSourceName(dsvo.getName());
                    }
                }
                boolean isNew = vo.isNew();
                try {
                    if (Common.runtimeManager.getState() == RuntimeManager.RUNNING) {
                        Common.runtimeManager.saveDataPoint(vo);
                        if (hierarchyList != null && json.containsKey(PATH)) {
                            String path = json.getString(PATH);
                            if (StringUtils.isNotEmpty(path))
                                hierarchyList.add(new DataPointSummaryPathPair(new DataPointSummary(vo), path));
                        }
                        addSuccessMessage(isNew, "emport.dataPoint.prefix", xid);
                    } else {
                        addFailureMessage(new ProcessMessage("Runtime Manager not running point with xid: " + xid + " not saved."));
                    }
                } catch (LicenseViolatedException e) {
                    addFailureMessage(new ProcessMessage(e.getErrorMessage()));
                }
            }
        } catch (TranslatableJsonException e) {
            addFailureMessage("emport.dataPoint.prefix", xid, e.getMsg());
        } catch (JsonException e) {
            addFailureMessage("emport.dataPoint.prefix", xid, getJsonExceptionMessage(e));
        }
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) LicenseViolatedException(com.serotonin.m2m2.LicenseViolatedException) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage)

Aggregations

ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)15 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)9 JsonException (com.serotonin.json.JsonException)4 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 User (com.serotonin.m2m2.vo.User)3 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)3 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)3 UserModel (com.serotonin.m2m2.web.mvc.rest.v1.model.user.UserModel)3 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 ArrayList (java.util.ArrayList)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 AccessDeniedException (com.infiniteautomation.mango.rest.v2.exception.AccessDeniedException)2 DataPointPropertiesTemplateVO (com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO)2 RestValidationMessage (com.serotonin.m2m2.web.mvc.rest.v1.message.RestValidationMessage)2 URI (java.net.URI)2 ValueMonitor (com.infiniteautomation.mango.monitor.ValueMonitor)1 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)1 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)1