Search in sources :

Example 41 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.

the class MaintenanceEventVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    String text = jsonObject.getString("dataSourceXid");
    if (text != null) {
        DataSourceVO<?> ds = DataSourceDao.instance.getDataSource(text);
        if (ds == null)
            throw new TranslatableJsonException("emport.error.maintenanceEvent.invalid", "dataSourceXid", text);
        dataSourceId = ds.getId();
    }
    text = jsonObject.getString("alarmLevel");
    if (text != null) {
        alarmLevel = AlarmLevels.CODES.getId(text);
        if (!AlarmLevels.CODES.isValidId(alarmLevel))
            throw new TranslatableJsonException("emport.error.maintenanceEvent.invalid", "alarmLevel", text, AlarmLevels.CODES.getCodeList());
    }
    text = jsonObject.getString("scheduleType");
    if (text != null) {
        scheduleType = TYPE_CODES.getId(text);
        if (!TYPE_CODES.isValidId(scheduleType))
            throw new TranslatableJsonException("emport.error.maintenanceEvent.invalid", "scheduleType", text, TYPE_CODES.getCodeList());
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 42 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.

the class ViewComponent method jsonReadDataPoint.

protected void jsonReadDataPoint(JsonValue jsonXid, PointComponent comp) throws JsonException {
    if (jsonXid != null) {
        String xid = jsonXid.toString();
        DataPointVO dataPoint = DataPointDao.instance.getDataPoint(xid);
        if (dataPoint == null)
            throw new TranslatableJsonException("emport.error.missingPoint", xid);
        if (!comp.definition().supports(dataPoint.getPointLocator().getDataTypeId()))
            throw new TranslatableJsonException("emport.error.component.incompatibleDataType", xid, definition().getExportName());
        comp.tsetDataPoint(dataPoint);
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 43 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.

the class MBusDataSourceVO method jsonRead.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.vo.dataSource.DataSourceVO#jsonRead(com.serotonin.json.JsonReader, com.serotonin.json.type.JsonObject)
     */
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    Integer value = readUpdatePeriodType(jsonObject);
    if (value != null)
        updatePeriodType = value;
    String s = jsonObject.getString("connectionType");
    if (s == null) {
        List<String> codes = new ArrayList<String>();
        codes.add("mbusSerial");
        codes.add("mbusTcpIp");
        throw new TranslatableJsonException("emport.error.missing", "connectionType", codes);
    } else {
        int bitPerSecond = jsonObject.getInt("bitPerSecond");
        int responseTimeoutOffset = jsonObject.getInt("responseTimeoutOffset");
        switch(s) {
            case "mbusSerial":
                String portName = jsonObject.getString("portName");
                connection = new SerialPortConnection(portName, bitPerSecond, responseTimeoutOffset);
                break;
            case "mbusTcpIp":
                String host = jsonObject.getString("host");
                int port = jsonObject.getInt("port");
                connection = new TcpIpConnection(host, port, bitPerSecond, responseTimeoutOffset);
                break;
        }
    }
}
Also used : TcpIpConnection(net.sf.mbus4j.TcpIpConnection) ArrayList(java.util.ArrayList) SerialPortConnection(net.sf.mbus4j.SerialPortConnection) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 44 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.

the class MaintenanceEventType method jsonRead.

// 
// 
// Serialization
// 
@Override
public void jsonRead(JsonReader reader, com.serotonin.json.type.JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    String xid = jsonObject.getString("XID");
    if (xid == null)
        throw new TranslatableJsonException("emport.error.eventType.missing.reference", "XID");
    MaintenanceEventVO me = new MaintenanceEventDao().getMaintenanceEvent(xid);
    if (me == null)
        throw new TranslatableJsonException("emport.error.eventType.invalid.reference", "XID", xid);
    maintenanceId = me.getId();
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 45 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.

the class ReportEmportDefinition method doImport.

@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
    JsonObject reportJson = jsonValue.toJsonObject();
    String xid = reportJson.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = ReportDao.instance.generateUniqueXid();
    ReportVO report = null;
    try {
        report = ReportDao.instance.getReport(xid);
    } catch (IncorrectResultSizeDataAccessException e) {
        importContext.getResult().addGenericMessage("reports.emport.duplicateXids", xid);
        return;
    }
    if (report == null) {
        report = new ReportVO();
        report.setXid(xid);
    }
    try {
        importContext.getReader().readInto(report, reportJson);
        // Now validate it. Use a new response object so we can distinguish errors in this user from other
        // errors.
        ProcessResult reportResponse = new ProcessResult();
        report.validate(reportResponse);
        if (reportResponse.getHasMessages())
            // Too bad. Copy the errors into the actual response.
            importContext.copyValidationMessages(reportResponse, "emport.report.prefix", xid);
        else {
            // Sweet. Save it.
            boolean isnew = report.getId() == Common.NEW_ID;
            ReportDao.instance.saveReport(report);
            importContext.addSuccessMessage(isnew, "emport.report.prefix", xid);
        }
    } catch (TranslatableJsonException e) {
        importContext.getResult().addGenericMessage("emport.report.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        importContext.getResult().addGenericMessage("emport.report.prefix", xid, importContext.getJsonExceptionMessage(e));
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO)

Aggregations

TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)79 JsonObject (com.serotonin.json.type.JsonObject)24 JsonException (com.serotonin.json.JsonException)21 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)17 JsonValue (com.serotonin.json.type.JsonValue)15 JsonArray (com.serotonin.json.type.JsonArray)14 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)8 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)8 User (com.serotonin.m2m2.vo.User)7 ArrayList (java.util.ArrayList)5 ExportCodes (com.serotonin.m2m2.util.ExportCodes)4 IntStringPair (com.serotonin.db.pair.IntStringPair)3 TypeDefinition (com.serotonin.json.util.TypeDefinition)3 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)3 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)3 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)3 IOException (java.io.IOException)3 List (java.util.List)3 JsonBoolean (com.serotonin.json.type.JsonBoolean)2 JsonString (com.serotonin.json.type.JsonString)2