Search in sources :

Example 1 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.

the class DataSourceDwr method get.

@DwrPermission(user = true)
@Override
public ProcessResult get(int id) {
    ProcessResult response;
    try {
        if (id > 0) {
            response = super.get(id);
            // Kludge for modules to be able to use a default edit point for some of their tools (Bacnet for example needs this for adding lots of points)
            // This is an issue for opening AllDataPoints Point because it opens the Datasource too.
            // TODO to fix this we need to fix DataSourceEditDwr to not save the editing DataPoint state in the User, this will propogate into existing modules...
            DataSourceVO<?> vo = (DataSourceVO<?>) response.getData().get("vo");
            // Quick fix to ensure we don't keep the edit point around if we have switched data sources
            if ((Common.getUser().getEditPoint() == null) || (Common.getUser().getEditPoint().getDataSourceId() != vo.getId()) || (Common.getUser().getEditPoint().getDataSourceTypeName() != vo.getDefinition().getDataSourceTypeName())) {
                DataPointVO dp = new DataPointVO();
                dp.setXid(DataPointDao.instance.generateUniqueXid());
                dp.setDataSourceId(vo.getId());
                dp.setDataSourceTypeName(vo.getDefinition().getDataSourceTypeName());
                dp.setDeviceName(vo.getName());
                dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
                dp.defaultTextRenderer();
                dp.setXid(DataPointDao.instance.generateUniqueXid());
                dp.setPointLocator(vo.createPointLocator());
                Common.getUser().setEditPoint(dp);
            }
        } else {
            throw new ShouldNeverHappenException("Unable to get a new DataSource.");
        }
        // Setup the page info
        response.addData("editPagePath", ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getModule().getWebPath() + "/" + ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getEditPagePath());
        response.addData("statusPagePath", ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getModule().getWebPath() + "/" + ((DataSourceVO<?>) response.getData().get("vo")).getDefinition().getStatusPagePath());
    } catch (Exception e) {
        LOG.error(e.getMessage());
        response = new ProcessResult();
        response.addMessage(new TranslatableMessage("table.error.dwr", e.getMessage()));
    }
    return response;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.

the class EmportDwr method export.

public static String export(Map<String, Object> data, int prettyIndent) {
    StringWriter stringWriter = new StringWriter();
    JsonWriter writer = new JsonWriter(Common.JSON_CONTEXT, stringWriter);
    writer.setPrettyIndent(prettyIndent);
    writer.setPrettyOutput(true);
    try {
        writer.writeObject(data);
        return stringWriter.toString();
    } catch (JsonException e) {
        throw new ShouldNeverHappenException(e);
    } catch (IOException e) {
        throw new ShouldNeverHappenException(e);
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) StringWriter(java.io.StringWriter) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) IOException(java.io.IOException) JsonWriter(com.serotonin.json.JsonWriter)

Example 3 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException 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 4 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.

the class AnalogChangeDetectorVO method getConfigurationDescription.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO#getConfigurationDescription()
	 */
@Override
protected TranslatableMessage getConfigurationDescription() {
    if (dataPoint == null)
        dataPoint = DataPointDao.instance.getDataPoint(sourceId);
    String prettyLimit = dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC);
    TranslatableMessage durationDescription = getDurationDescription();
    if (checkIncrease && checkDecrease)
        return new TranslatableMessage("event.detectorVo.analogChangePeriod", prettyLimit, durationDescription);
    else if (checkIncrease)
        return new TranslatableMessage("event.detectorVo.analogIncreasePeriod", prettyLimit, durationDescription);
    else if (checkDecrease)
        return new TranslatableMessage("event.detectorVo.analogDecreasePeriod", prettyLimit, durationDescription);
    else
        throw new ShouldNeverHappenException("Illegal state for analog change detector" + xid);
}
Also used : ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 5 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.

the class H2InMemoryDatabaseProxy method runScript.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.db.DatabaseProxy#runScript(java.io.InputStream, java.io.OutputStream)
     */
@Override
public void runScript(InputStream input, OutputStream out) {
    BufferedReader in = null;
    try {
        in = new BufferedReader(new InputStreamReader(input));
        List<String> lines = new ArrayList<>();
        String line;
        while ((line = in.readLine()) != null) lines.add(line);
        String[] script = new String[lines.size()];
        lines.toArray(script);
        runScript(script, out);
    } catch (Exception ioe) {
        throw new ShouldNeverHappenException(ioe);
    } finally {
        try {
            if (in != null)
                in.close();
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) IOException(java.io.IOException) SQLException(java.sql.SQLException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)83 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)10 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)9 SQLException (java.sql.SQLException)9 ParseException (java.text.ParseException)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)6 FileNotFoundException (java.io.FileNotFoundException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ResultSet (java.sql.ResultSet)5 Statement (java.sql.Statement)5 JsonException (com.serotonin.json.JsonException)4 JsonWriter (com.serotonin.json.JsonWriter)4 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)4 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)4 CronTimerTrigger (com.serotonin.timer.CronTimerTrigger)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StringWriter (java.io.StringWriter)4 HashMap (java.util.HashMap)4