Search in sources :

Example 6 with DataType

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

the class BaseChartRenderer method getImplementations.

public static List<ImplDefinition> getImplementations(int dataType) {
    ensureDefinitions();
    List<ImplDefinition> impls = new ArrayList<ImplDefinition>();
    for (ImplDefinition def : definitions) {
        if (def.supports(dataType))
            impls.add(def);
    }
    return impls;
}
Also used : ImplDefinition(com.serotonin.m2m2.view.ImplDefinition) ArrayList(java.util.ArrayList)

Example 7 with DataType

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

the class AbstractPointLocatorVO method readDataType.

protected Integer readDataType(JsonObject json, int... excludeIds) throws JsonException {
    String text = json.getString("dataType");
    if (text == null)
        return null;
    int dataType = DataTypes.CODES.getId(text);
    if (!DataTypes.CODES.isValidId(dataType, excludeIds))
        throw new TranslatableJsonException("emport.error.invalid", "dataType", text, DataTypes.CODES.getCodeList(excludeIds));
    return dataType;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 8 with DataType

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

the class BaseTextRenderer method getImplementation.

public static List<ImplDefinition> getImplementation(int dataType) {
    ensureDefinitions();
    List<ImplDefinition> impls = new ArrayList<ImplDefinition>(definitions.size());
    for (ImplDefinition def : definitions) {
        if (def.supports(dataType))
            impls.add(def);
    }
    return impls;
}
Also used : ImplDefinition(com.serotonin.m2m2.view.ImplDefinition) ArrayList(java.util.ArrayList)

Example 9 with DataType

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

the class DataPointPropertiesTemplateVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    // Not reading XID so can't do this: super.jsonRead(reader, jsonObject);
    name = jsonObject.getString("name");
    // Not reading XID so can't do this: super.jsonRead(reader, jsonObject);
    String text = jsonObject.getString("templateType");
    if (text != null) {
        dataTypeId = TEMPLATE_TYPE_CODES.getId(text);
        if (dataTypeId == -1)
            throw new TranslatableJsonException("emport.error.invalid", "templateType", text, TEMPLATE_TYPE_CODES.getCodeList());
    }
    text = jsonObject.getString("dataType");
    if (text != null) {
        dataTypeId = DataTypes.CODES.getId(text);
        if (dataTypeId == -1)
            throw new TranslatableJsonException("emport.error.invalid", "dataType", text, DataTypes.CODES.getCodeList());
    }
    // Rollup
    text = jsonObject.getString("rollup");
    if (text != null) {
        rollup = Common.ROLLUP_CODES.getId(text);
        if (rollup == -1)
            throw new TranslatableJsonException("emport.error.chart.invalid", "rollup", text, Common.ROLLUP_CODES.getCodeList());
    }
    text = jsonObject.getString("loggingType");
    if (text != null) {
        loggingType = DataPointVO.LOGGING_TYPE_CODES.getId(text);
        if (loggingType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "loggingType", text, DataPointVO.LOGGING_TYPE_CODES.getCodeList());
    }
    text = jsonObject.getString("intervalLoggingPeriodType");
    if (text != null) {
        intervalLoggingPeriodType = Common.TIME_PERIOD_CODES.getId(text);
        if (intervalLoggingPeriodType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "intervalLoggingPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
    }
    text = jsonObject.getString("intervalLoggingType");
    if (text != null) {
        intervalLoggingType = DataPointVO.INTERVAL_LOGGING_TYPE_CODES.getId(text);
        if (intervalLoggingType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "intervalLoggingType", text, DataPointVO.INTERVAL_LOGGING_TYPE_CODES.getCodeList());
    }
    text = jsonObject.getString("purgeType");
    if (text != null) {
        purgeType = Common.TIME_PERIOD_CODES.getId(text);
        if (purgeType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "purgeType", text, Common.TIME_PERIOD_CODES.getCodeList());
    }
    text = jsonObject.getString("plotType");
    if (text != null) {
        plotType = DataPointVO.PLOT_TYPE_CODES.getId(text);
        if (plotType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "plotType", text, DataPointVO.PLOT_TYPE_CODES.getCodeList());
    }
    // Simplify
    text = jsonObject.getString("simplifyType");
    if (text != null) {
        simplifyType = DataPointVO.SIMPLIFY_TYPE_CODES.getId(text);
        if (simplifyType == -1)
            throw new TranslatableJsonException("emport.error.invalid", "simplifyType", text, DataPointVO.SIMPLIFY_TYPE_CODES.getCodeList());
    }
    int simplifyTarget = jsonObject.getInt("simplifyTarget", Integer.MIN_VALUE);
    if (simplifyTarget != Integer.MIN_VALUE)
        this.simplifyTarget = simplifyTarget;
    double simplifyTolerance = jsonObject.getDouble("simplifyTolerance", Double.NaN);
    if (simplifyTolerance != Double.NaN)
        this.simplifyTolerance = simplifyTolerance;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 10 with DataType

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

the class FileUploadController method parseFile.

/**
 * Parse the Import Files
 * @param input
 * @param model
 * @param translations
 */
protected void parseFile(InputStream input, Map<String, Object> model, Translations translations, HttpServletRequest request) {
    // Get the filename
    String filename = (String) model.get("filename");
    SpreadsheetEmporter emporter;
    if (filename == null)
        return;
    else {
        if (filename.toLowerCase().endsWith(".xls"))
            emporter = new SpreadsheetEmporter(FileType.XLS);
        else if (filename.toLowerCase().endsWith(".xlsx"))
            emporter = new SpreadsheetEmporter(FileType.XLSX);
        else
            return;
    }
    // Switch on the type
    String dataType = (String) model.get("dataType");
    if (dataType != null) {
        if (dataType.equals("pointValue")) {
            // List the sheets and create sheet emporters for each
            for (Sheet sheet : emporter.listSheets(input)) emporter.doImport(input, new PointValueEmporter(sheet.getSheetName()));
        } else
            throw new ShouldNeverHappenException("Unsupported data.");
    }
    model.put("hasImportErrors", emporter.hasErrors());
    // Get the messages
    if (emporter.hasErrors()) {
        List<String> errorMessages = new ArrayList<String>();
        for (TranslatableMessage msg : emporter.getErrorMessages()) {
            errorMessages.add(msg.translate(translations));
        }
        model.put("errorMessages", errorMessages);
    }
    model.put("rowsImported", emporter.getRowsAdded());
    model.put("rowsDeleted", emporter.getRowsDeleted());
    model.put("rowsWithErrors", emporter.getRowErrors());
}
Also used : PointValueEmporter(com.serotonin.m2m2.rt.dataImage.PointValueEmporter) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ArrayList(java.util.ArrayList) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) SpreadsheetEmporter(com.serotonin.m2m2.vo.emport.SpreadsheetEmporter) Sheet(org.apache.poi.ss.usermodel.Sheet)

Aggregations

ArrayList (java.util.ArrayList)24 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)23 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)17 DataType (com.serotonin.m2m2.DataType)14 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)13 HashMap (java.util.HashMap)12 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)11 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)11 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)10 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)10 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)10 DataType (org.osate.aadl2.DataType)10 DataType (ucar.ma2.DataType)10 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)9 DataImplementation (org.osate.aadl2.DataImplementation)9 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)8 IOException (java.io.IOException)8 File (java.io.File)7 ScriptError (com.serotonin.m2m2.rt.script.ScriptError)6 ScriptPermissionsException (com.serotonin.m2m2.rt.script.ScriptPermissionsException)6