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;
}
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);
}
}
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);
}
}
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);
}
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);
}
}
}
Aggregations