-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.history.util.subscription;\r
-\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
-\r
-import org.simantics.databoard.annotations.Identifier;\r
-import org.simantics.databoard.type.Datatype;\r
-import org.simantics.databoard.util.Bean;\r
-\r
-/**\r
- * (Utility Class) Item format for HistoryManager, Collector, and meta-data for Simantics subscription configurations.\r
- * \r
- * The items objects the HistoryManager and Collector uses are complete meta-data\r
- * descriptions. Different formats are supported and the content is written to disc\r
- * completely as is. \r
- * \r
- * The "id" is composed with the following aggregation: [subscriptionId] [variableId] [formatId].\r
- * \r
- * @author toni.kalajainen\r
- */\r
-public class SubscriptionItem extends Bean {\r
-\r
- /**\r
- * Create HistoryItem descriptions for collecting one variable with multiple\r
- * sampling formats.\r
- * \r
- * @param item\r
- * the item to use as a template for the created sampled items\r
- * @param groupItemId\r
- * the group item id to use with\r
- * {@link #composeItemName(String, String, String)}\r
- * @param groupId\r
- * the group id to use with\r
- * {@link #composeItemName(String, String, String)}\r
- * @param formats\r
- * the sampling formats to create\r
- * @return an array of history items\r
- */\r
- public static SubscriptionItem[] createItems(\r
- SubscriptionItem item,\r
- String groupItemId,\r
- String groupId,\r
- Collection<SamplingFormat> formats) {\r
- Iterator<SamplingFormat> itr = formats.iterator();\r
- SubscriptionItem[] items = new SubscriptionItem[ formats.size() ];\r
- for (int i=0; i<formats.size(); i++) {\r
- items[i] = createItem( item, groupItemId, groupId, itr.next() );\r
- }\r
- return items;\r
- }\r
-\r
- /**\r
- * Create HistoryItem descriptions for collecting one variable with multiple\r
- * sampling formats.\r
- * \r
- * @param variableId\r
- * @param subscriptionId\r
- * @param formats\r
- * @return an array of history items\r
- */\r
- public static SubscriptionItem[] createItems(\r
- String variableId,\r
- String subscriptionId,\r
- SamplingFormat...formats\r
- ) {\r
- SubscriptionItem[] items = new SubscriptionItem[ formats.length ];\r
- for (int i=0; i<formats.length; i++) {\r
- items[i] = createItem( variableId, subscriptionId, formats[i] );\r
- }\r
- return items;\r
- }\r
- \r
- /**\r
- * Create HistoryItem descriptions for collecting one variable with multiple\r
- * sampling formats.\r
- * \r
- * @param groupItemId\r
- * @param groupId\r
- * @param formats\r
- * @return an array of history items\r
- */\r
- public static SubscriptionItem[] createItems(\r
- String groupItemId,\r
- String groupId,\r
- Collection<SamplingFormat> formats) {\r
- Iterator<SamplingFormat> itr = formats.iterator();\r
- SubscriptionItem[] items = new SubscriptionItem[ formats.size() ];\r
- for (int i=0; i<formats.size(); i++) {\r
- items[i] = createItem( groupItemId, groupId, itr.next() );\r
- }\r
- return items;\r
- }\r
-\r
- /**\r
- * Create HistoryItem description for collecting one variable with one\r
- * sampling format.\r
- * \r
- * @param item\r
- * the subscription item to clone values from\r
- * @param groupItemId\r
- * the group item id to use with\r
- * {@link #composeItemName(String, String, String)}\r
- * @param groupId\r
- * the group id to use with\r
- * {@link #composeItemName(String, String, String)}\r
- * @param format\r
- * @return HistoryItem description.\r
- */\r
- public static SubscriptionItem createItem(\r
- SubscriptionItem item,\r
- String groupItemId,\r
- String groupId,\r
- SamplingFormat format\r
- ) {\r
- SubscriptionItem hi = new SubscriptionItem();\r
- hi.variableId = item.variableId;\r
- hi.groupItemId = item.groupItemId;\r
- hi.id = composeItemName(groupId, groupItemId, format.formatId);\r
- hi.deadband = format.deadband;\r
- hi.interval = format.interval;\r
- hi.gain = item.gain;\r
- hi.bias = item.bias;\r
- hi.formatId = format.formatId;\r
- hi.format = format.format;\r
- hi.groupId = item.groupId;\r
- hi.enabled = item.enabled;\r
- return hi;\r
- }\r
-\r
- /**\r
- * Create HistoryItem description for collecting one variable with one\r
- * sampling format. \r
- * \r
- * @param groupItemId\r
- * the group item id to use with\r
- * {@link #composeItemName(String, String, String)}\r
- * @param groupId\r
- * the group id to use with\r
- * {@link #composeItemName(String, String, String)}\r
- * @param format\r
- * @return HistoryItem description.\r
- */\r
- public static SubscriptionItem createItem(\r
- String groupItemId,\r
- String groupId,\r
- SamplingFormat format\r
- ) {\r
- SubscriptionItem hi = new SubscriptionItem();\r
- hi.variableId = groupItemId;\r
- hi.groupItemId = groupItemId;\r
- hi.id = composeItemName(groupId, groupItemId, format.formatId);\r
- hi.deadband = format.deadband;\r
- hi.interval = format.interval;\r
- hi.formatId = format.formatId;\r
- hi.format = format.format;\r
- hi.groupId = groupId;\r
- hi.enabled = true;\r
- return hi;\r
- }\r
-\r
- public static String composeItemName(String groupId, String groupItemId, String formatId)\r
- {\r
- return groupId+" "+groupItemId+" "+formatId;\r
- }\r
-\r
- /** Item identifier in the HistoryManager */\r
- public @Identifier String id;\r
- \r
- /** Variable Id, Reference of variable in Datasource. This field is used by Collector */\r
- public String variableId;\r
- \r
- /** \r
- * Describes the format of the packed sample. The sample must be a record.\r
- * The record must have any combination of the following named fields.\r
- * The field types must one of: byte, integer, long, float, double.\r
- * \r
- * time, endTime, value - are mandatory fields.\r
- * \r
- * time - Region start time, the time of the 1st sample included into the band\r
- * endTime - Region end time, the time of the last sample included into the band\r
- * \r
- * value - First value in the band\r
- * lastValue - Last value in the band\r
- * avg - Average value of all included samples\r
- * median - Median value of all samples in the band\r
- * min - Lowest value in the band\r
- * max - Highest value in the band\r
- * \r
- * quality - 0 = Good, -1 = No value\r
- * count - The number of included samples in the band\r
- */\r
- public Datatype format;\r
- \r
- // Subscription parameters\r
- public double deadband = Double.NaN;\r
- public double interval = Double.NaN;\r
- public double gain = 1.0;\r
- public double bias = 0.0;\r
- public boolean enabled = true;\r
-\r
- /** Identifier of group or subscription, used by Simantics */\r
- public String groupId = "";\r
- \r
- /** Identifier of the item in the group, used by Simantics */\r
- public String groupItemId = "";\r
- \r
- /** Identifier of the sample format description, used by Simantics */\r
- public String formatId = "";\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.history.util.subscription;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.simantics.databoard.annotations.Identifier;
+import org.simantics.databoard.type.Datatype;
+import org.simantics.databoard.util.Bean;
+
+/**
+ * (Utility Class) Item format for HistoryManager, Collector, and meta-data for Simantics subscription configurations.
+ *
+ * The items objects the HistoryManager and Collector uses are complete meta-data
+ * descriptions. Different formats are supported and the content is written to disc
+ * completely as is.
+ *
+ * The "id" is composed with the following aggregation: [subscriptionId] [variableId] [formatId].
+ *
+ * @author toni.kalajainen
+ */
+public class SubscriptionItem extends Bean {
+
+ /**
+ * Create HistoryItem descriptions for collecting one variable with multiple
+ * sampling formats.
+ *
+ * @param item
+ * the item to use as a template for the created sampled items
+ * @param groupItemId
+ * the group item id to use with
+ * {@link #composeItemName(String, String, String)}
+ * @param groupId
+ * the group id to use with
+ * {@link #composeItemName(String, String, String)}
+ * @param formats
+ * the sampling formats to create
+ * @return an array of history items
+ */
+ public static SubscriptionItem[] createItems(
+ SubscriptionItem item,
+ String groupItemId,
+ String groupId,
+ Collection<SamplingFormat> formats) {
+ Iterator<SamplingFormat> itr = formats.iterator();
+ SubscriptionItem[] items = new SubscriptionItem[ formats.size() ];
+ for (int i=0; i<formats.size(); i++) {
+ items[i] = createItem( item, groupItemId, groupId, itr.next() );
+ }
+ return items;
+ }
+
+ /**
+ * Create HistoryItem descriptions for collecting one variable with multiple
+ * sampling formats.
+ *
+ * @param variableId
+ * @param subscriptionId
+ * @param formats
+ * @return an array of history items
+ */
+ public static SubscriptionItem[] createItems(
+ String variableId,
+ String subscriptionId,
+ SamplingFormat...formats
+ ) {
+ SubscriptionItem[] items = new SubscriptionItem[ formats.length ];
+ for (int i=0; i<formats.length; i++) {
+ items[i] = createItem( variableId, subscriptionId, formats[i] );
+ }
+ return items;
+ }
+
+ /**
+ * Create HistoryItem descriptions for collecting one variable with multiple
+ * sampling formats.
+ *
+ * @param groupItemId
+ * @param groupId
+ * @param formats
+ * @return an array of history items
+ */
+ public static SubscriptionItem[] createItems(
+ String groupItemId,
+ String groupId,
+ Collection<SamplingFormat> formats) {
+ Iterator<SamplingFormat> itr = formats.iterator();
+ SubscriptionItem[] items = new SubscriptionItem[ formats.size() ];
+ for (int i=0; i<formats.size(); i++) {
+ items[i] = createItem( groupItemId, groupId, itr.next() );
+ }
+ return items;
+ }
+
+ /**
+ * Create HistoryItem description for collecting one variable with one
+ * sampling format.
+ *
+ * @param item
+ * the subscription item to clone values from
+ * @param groupItemId
+ * the group item id to use with
+ * {@link #composeItemName(String, String, String)}
+ * @param groupId
+ * the group id to use with
+ * {@link #composeItemName(String, String, String)}
+ * @param format
+ * @return HistoryItem description.
+ */
+ public static SubscriptionItem createItem(
+ SubscriptionItem item,
+ String groupItemId,
+ String groupId,
+ SamplingFormat format
+ ) {
+ SubscriptionItem hi = new SubscriptionItem();
+ hi.variableId = item.variableId;
+ hi.groupItemId = item.groupItemId;
+ hi.id = composeItemName(groupId, groupItemId, format.formatId);
+ hi.deadband = format.deadband;
+ hi.interval = format.interval;
+ hi.gain = item.gain;
+ hi.bias = item.bias;
+ hi.formatId = format.formatId;
+ hi.format = format.format;
+ hi.groupId = item.groupId;
+ hi.enabled = item.enabled;
+ return hi;
+ }
+
+ /**
+ * Create HistoryItem description for collecting one variable with one
+ * sampling format.
+ *
+ * @param groupItemId
+ * the group item id to use with
+ * {@link #composeItemName(String, String, String)}
+ * @param groupId
+ * the group id to use with
+ * {@link #composeItemName(String, String, String)}
+ * @param format
+ * @return HistoryItem description.
+ */
+ public static SubscriptionItem createItem(
+ String groupItemId,
+ String groupId,
+ SamplingFormat format
+ ) {
+ SubscriptionItem hi = new SubscriptionItem();
+ hi.variableId = groupItemId;
+ hi.groupItemId = groupItemId;
+ hi.id = composeItemName(groupId, groupItemId, format.formatId);
+ hi.deadband = format.deadband;
+ hi.interval = format.interval;
+ hi.formatId = format.formatId;
+ hi.format = format.format;
+ hi.groupId = groupId;
+ hi.enabled = true;
+ return hi;
+ }
+
+ public static String composeItemName(String groupId, String groupItemId, String formatId)
+ {
+ return groupId+" "+groupItemId+" "+formatId;
+ }
+
+ /** Item identifier in the HistoryManager */
+ public @Identifier String id;
+
+ /** Variable Id, Reference of variable in Datasource. This field is used by Collector */
+ public String variableId;
+
+ /**
+ * Describes the format of the packed sample. The sample must be a record.
+ * The record must have any combination of the following named fields.
+ * The field types must one of: byte, integer, long, float, double.
+ *
+ * time, endTime, value - are mandatory fields.
+ *
+ * time - Region start time, the time of the 1st sample included into the band
+ * endTime - Region end time, the time of the last sample included into the band
+ *
+ * value - First value in the band
+ * lastValue - Last value in the band
+ * avg - Average value of all included samples
+ * median - Median value of all samples in the band
+ * min - Lowest value in the band
+ * max - Highest value in the band
+ *
+ * quality - 0 = Good, -1 = No value
+ * count - The number of included samples in the band
+ */
+ public Datatype format;
+
+ // Subscription parameters
+ public double deadband = Double.NaN;
+ public double interval = Double.NaN;
+ public double gain = 1.0;
+ public double bias = 0.0;
+ public boolean enabled = true;
+
+ /** Identifier of group or subscription, used by Simantics */
+ public String groupId = "";
+
+ /** Identifier of the item in the group, used by Simantics */
+ public String groupItemId = "";
+
+ /** Identifier of the sample format description, used by Simantics */
+ public String formatId = "";
+
+}