Search in sources :

Example 11 with DataSet

use of org.openmuc.framework.driver.ehz.iec62056_21.DataSet in project openhab1-addons by openhab.

the class Iec6205621MeterBinding method execute.

/**
     * @{inheritDoc
     */
@Override
protected void execute() {
    // the frequently executed code (polling) goes here ...
    Map<String, Map<String, DataSet>> cache = new HashMap<String, Map<String, DataSet>>();
    for (Iec6205621MeterBindingProvider provider : providers) {
        for (String itemName : provider.getItemNames()) {
            for (Entry<String, Meter> entry : meterDeviceConfigurtions.entrySet()) {
                Meter reader = entry.getValue();
                String meterName = provider.getMeterName(itemName);
                if (meterName != null && meterName.equals(entry.getKey())) {
                    Map<String, DataSet> dataSets;
                    if ((dataSets = cache.get(meterName)) == null) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Read meter: {}; {}", meterName, reader.getConfig().getSerialPort());
                        }
                        dataSets = reader.read();
                        cache.put(meterName, dataSets);
                    }
                    String obis = provider.getObis(itemName);
                    if (obis != null && dataSets.containsKey(obis)) {
                        DataSet dataSet = dataSets.get(obis);
                        if (logger.isDebugEnabled()) {
                            logger.debug("Updating item {} with OBIS code {} and value {}", itemName, obis, dataSet.getValue());
                        }
                        Class<? extends Item> itemType = provider.getItemType(itemName);
                        if (itemType.isAssignableFrom(NumberItem.class)) {
                            eventPublisher.postUpdate(itemName, new DecimalType(dataSet.getValue()));
                        }
                        if (itemType.isAssignableFrom(StringItem.class)) {
                            String value = dataSet.getValue();
                            eventPublisher.postUpdate(itemName, new StringType(value));
                        }
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) DataSet(org.openmuc.j62056.DataSet) StringType(org.openhab.core.library.types.StringType) DecimalType(org.openhab.core.library.types.DecimalType) HashMap(java.util.HashMap) Map(java.util.Map) Iec6205621MeterBindingProvider(org.openhab.binding.iec6205621meter.Iec6205621MeterBindingProvider)

Example 12 with DataSet

use of org.openmuc.framework.driver.ehz.iec62056_21.DataSet in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850ClientSSLDEventListener method newReport.

@Override
public void newReport(final Report report) {
    final DateTime timeOfEntry = this.getTimeOfEntry(report);
    final String reportDescription = this.getReportDescription(report, timeOfEntry);
    this.logger.info("newReport for {}", reportDescription);
    boolean skipRecordBecauseOfOldSqNum = false;
    if (report.isBufOvfl()) {
        this.logger.warn("Buffer Overflow reported for {} - entries within the buffer may have been lost.", reportDescription);
    }
    if (this.firstNewSqNum != null && report.getSqNum() != null && report.getSqNum() < this.firstNewSqNum) {
        skipRecordBecauseOfOldSqNum = true;
    }
    this.logReportDetails(report);
    final DataSet dataSet = report.getDataSet();
    if (dataSet == null) {
        this.logger.warn("No DataSet available for {}", reportDescription);
        return;
    }
    final List<FcModelNode> members = dataSet.getMembers();
    if (members == null || members.isEmpty()) {
        this.logger.warn("No members in DataSet available for {}", reportDescription);
        return;
    } else {
        this.logger.debug("Handling {} DataSet members for {}", members.size(), reportDescription);
    }
    for (final FcModelNode member : members) {
        if (member == null) {
            this.logger.warn("Member == null in DataSet for {}", reportDescription);
            continue;
        }
        this.logger.info("Handle member {} for {}", member.getReference(), reportDescription);
        try {
            if (skipRecordBecauseOfOldSqNum) {
                this.logger.warn("Skipping report because SqNum: {} is less than what should be the first new value: {}", report.getSqNum(), this.firstNewSqNum);
            } else {
                this.addEventNotificationForReportedData(member, timeOfEntry, reportDescription);
            }
        } catch (final Exception e) {
            this.logger.error("Error adding event notification for member {} from {}", member.getReference(), reportDescription, e);
        }
    }
}
Also used : DataSet(org.openmuc.openiec61850.DataSet) FcModelNode(org.openmuc.openiec61850.FcModelNode) BdaVisibleString(org.openmuc.openiec61850.BdaVisibleString) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Example 13 with DataSet

use of org.openmuc.framework.driver.ehz.iec62056_21.DataSet in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850ClientSSLDEventListener method logReportDetails.

private void logReportDetails(final Report report) {
    final StringBuilder sb = new StringBuilder("Report details for device ").append(this.deviceIdentification).append(System.lineSeparator());
    sb.append("\t             RptId:\t").append(report.getRptId()).append(System.lineSeparator());
    sb.append("\t        DataSetRef:\t").append(report.getDataSetRef()).append(System.lineSeparator());
    sb.append("\t           ConfRev:\t").append(report.getConfRev()).append(System.lineSeparator());
    sb.append("\t           BufOvfl:\t").append(report.isBufOvfl()).append(System.lineSeparator());
    sb.append("\t           EntryId:\t").append(report.getEntryId()).append(System.lineSeparator());
    sb.append("\tInclusionBitString:\t").append(Arrays.toString(report.getInclusionBitString())).append(System.lineSeparator());
    sb.append("\tMoreSegmentsFollow:\t").append(report.isMoreSegmentsFollow()).append(System.lineSeparator());
    sb.append("\t             SqNum:\t").append(report.getSqNum()).append(System.lineSeparator());
    sb.append("\t          SubSqNum:\t").append(report.getSubSqNum()).append(System.lineSeparator());
    sb.append("\t       TimeOfEntry:\t").append(report.getTimeOfEntry()).append(System.lineSeparator());
    if (report.getTimeOfEntry() != null) {
        sb.append("\t                   \t(").append(new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET)).append(')').append(System.lineSeparator());
    }
    final List<BdaReasonForInclusion> reasonCodes = report.getReasonCodes();
    if (reasonCodes != null && !reasonCodes.isEmpty()) {
        sb.append("\t       ReasonCodes:").append(System.lineSeparator());
        for (final BdaReasonForInclusion reasonCode : reasonCodes) {
            sb.append("\t                   \t").append(reasonCode.getReference() == null ? HexConverter.toHexString(reasonCode.getValue()) : reasonCode).append("\t(").append(new Iec61850BdaReasonForInclusionHelper(reasonCode).getInfo()).append(')').append(System.lineSeparator());
        }
    }
    sb.append("\t           optFlds:").append(report.getOptFlds()).append("\t(").append(new Iec61850BdaOptFldsHelper(report.getOptFlds()).getInfo()).append(')').append(System.lineSeparator());
    final DataSet dataSet = report.getDataSet();
    if (dataSet == null) {
        sb.append("\t           DataSet:\tnull").append(System.lineSeparator());
    } else {
        sb.append("\t           DataSet:\t").append(dataSet.getReferenceStr()).append(System.lineSeparator());
        final List<FcModelNode> members = dataSet.getMembers();
        if (members != null && !members.isEmpty()) {
            sb.append("\t   DataSet members:\t").append(members.size()).append(System.lineSeparator());
            for (final FcModelNode member : members) {
                sb.append("\t            member:\t").append(member).append(System.lineSeparator());
                if (member.getReference().toString().contains("CSLC.EvnRpn")) {
                    sb.append(this.evnRpnInfo("\t                   \t\t", member));
                }
            }
        }
    }
    this.logger.info(sb.append(System.lineSeparator()).toString());
}
Also used : BdaReasonForInclusion(org.openmuc.openiec61850.BdaReasonForInclusion) DataSet(org.openmuc.openiec61850.DataSet) FcModelNode(org.openmuc.openiec61850.FcModelNode) Iec61850BdaOptFldsHelper(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850BdaOptFldsHelper) DateTime(org.joda.time.DateTime)

Example 14 with DataSet

use of org.openmuc.framework.driver.ehz.iec62056_21.DataSet in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850ClientRTUEventListener method logReportDetails.

private void logReportDetails(final Report report) {
    final StringBuilder sb = new StringBuilder("Report details for device ").append(this.deviceIdentification).append(System.lineSeparator());
    sb.append("\t             RptId:\t").append(report.getRptId()).append(System.lineSeparator());
    sb.append("\t        DataSetRef:\t").append(report.getDataSetRef()).append(System.lineSeparator());
    sb.append("\t           ConfRev:\t").append(report.getConfRev()).append(System.lineSeparator());
    sb.append("\t           BufOvfl:\t").append(report.isBufOvfl()).append(System.lineSeparator());
    sb.append("\t           EntryId:\t").append(report.getEntryId()).append(System.lineSeparator());
    sb.append("\tInclusionBitString:\t").append(Arrays.toString(report.getInclusionBitString())).append(System.lineSeparator());
    sb.append("\tMoreSegmentsFollow:\t").append(report.isMoreSegmentsFollow()).append(System.lineSeparator());
    sb.append("\t             SqNum:\t").append(report.getSqNum()).append(System.lineSeparator());
    sb.append("\t          SubSqNum:\t").append(report.getSubSqNum()).append(System.lineSeparator());
    sb.append("\t       TimeOfEntry:\t").append(report.getTimeOfEntry()).append(System.lineSeparator());
    if (report.getTimeOfEntry() != null) {
        sb.append("\t                   \t(").append(new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET)).append(')').append(System.lineSeparator());
    }
    final List<BdaReasonForInclusion> reasonCodes = report.getReasonCodes();
    if ((reasonCodes != null) && !reasonCodes.isEmpty()) {
        sb.append("\t       ReasonCodes:").append(System.lineSeparator());
        for (final BdaReasonForInclusion reasonCode : reasonCodes) {
            sb.append("\t                   \t").append(reasonCode.getReference() == null ? HexConverter.toHexString(reasonCode.getValue()) : reasonCode).append("\t(").append(new Iec61850BdaReasonForInclusionHelper(reasonCode).getInfo()).append(')').append(System.lineSeparator());
        }
    }
    sb.append("\t           optFlds:").append(report.getOptFlds()).append("\t(").append(new Iec61850BdaOptFldsHelper(report.getOptFlds()).getInfo()).append(')').append(System.lineSeparator());
    final DataSet dataSet = report.getDataSet();
    if (dataSet == null) {
        sb.append("\t           DataSet:\tnull").append(System.lineSeparator());
    } else {
        sb.append("\t           DataSet:\t").append(dataSet.getReferenceStr()).append(System.lineSeparator());
        final List<FcModelNode> members = dataSet.getMembers();
        if ((members != null) && !members.isEmpty()) {
            sb.append("\t   DataSet members:\t").append(members.size()).append(System.lineSeparator());
            for (final FcModelNode member : members) {
                sb.append("\t            member:\t").append(member).append(System.lineSeparator());
                sb.append("\t                   \t\t").append(member);
            }
        }
    }
    this.logger.info(sb.append(System.lineSeparator()).toString());
}
Also used : BdaReasonForInclusion(org.openmuc.openiec61850.BdaReasonForInclusion) DataSet(org.openmuc.openiec61850.DataSet) FcModelNode(org.openmuc.openiec61850.FcModelNode) Iec61850BdaOptFldsHelper(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850BdaOptFldsHelper) DateTime(org.joda.time.DateTime)

Example 15 with DataSet

use of org.openmuc.framework.driver.ehz.iec62056_21.DataSet in project idempiere by idempiere.

the class ModelADServiceImpl method queryData.

public WindowTabDataDocument queryData(ModelCRUDRequestDocument req) {
    Trx trx = null;
    try {
        getCompiereService().connect();
        CompiereService m_cs = getCompiereService();
        WindowTabDataDocument ret = WindowTabDataDocument.Factory.newInstance();
        WindowTabData resp = ret.addNewWindowTabData();
        ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
        String serviceType = modelCRUD.getServiceType();
        ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
        String err = login(reqlogin, webServiceName, "queryData", serviceType);
        if (err != null && err.length() > 0) {
            resp.setError(err);
            return ret;
        }
        // Validate parameters vs service type
        validateCRUD(modelCRUD);
        Properties ctx = m_cs.getCtx();
        String tableName = modelCRUD.getTableName();
        Map<String, Object> reqCtx = getRequestCtx();
        MWebServiceType m_webservicetype = getWebServiceType();
        // get the PO for the tablename and record ID
        MTable table = MTable.get(ctx, tableName);
        if (table == null)
            throw new IdempiereServiceFault("Web service type " + m_webservicetype.getValue() + ": table " + tableName + " not found", new QName("queryData"));
        int roleid = reqlogin.getRoleID();
        MRole role = MRole.get(ctx, roleid);
        // start a trx
        String trxName = localTrxName;
        if (trxName == null) {
            trxName = Trx.createTrxName("ws_modelQueryData");
            manageTrx = true;
        }
        trx = Trx.get(trxName, true);
        if (manageTrx)
            trx.setDisplayName(getClass().getName() + "_" + webServiceName + "_queryData");
        StringBuilder sqlBuilder = new StringBuilder(role.addAccessSQL("SELECT * FROM " + tableName, tableName, true, MRole.SQL_RO));
        ArrayList<Object> sqlParaList = new ArrayList<Object>();
        PO holderPo = table.getPO(0, trxName);
        POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
        if (modelCRUD.getDataRow() != null) {
            DataRow dr = modelCRUD.getDataRow();
            DataField[] fields = dr.getFieldArray();
            StandardResponseDocument stdRet = StandardResponseDocument.Factory.newInstance();
            StandardResponse stdResp = stdRet.addNewStandardResponse();
            StandardResponseDocument retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_BEFORE_PARSE, holderPo, fields, trx, reqCtx, stdResp, stdRet);
            if (retResp != null) {
                throw new IdempiereServiceFault(retResp.getStandardResponse().getError(), new QName("queryData"));
            }
            retResp = scanFields(fields, m_webservicetype, holderPo, poinfo, trx, stdResp, stdRet);
            if (retResp != null) {
                throw new IdempiereServiceFault(retResp.getStandardResponse().getError(), new QName("queryData"));
            }
            for (DataField field : modelCRUD.getDataRow().getFieldArray()) {
                if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) {
                    // Jan Thielemann Solution for query using the sentence like
                    X_WS_WebServiceFieldInput inputField = m_webservicetype.getFieldInput(field.getColumn());
                    I_AD_Column col = inputField.getAD_Column();
                    String sqlType = DisplayType.getSQLDataType(col.getAD_Reference_ID(), col.getColumnName(), col.getFieldLength());
                    if (sqlType.contains("CHAR"))
                        sqlBuilder.append(" AND ").append(field.getColumn()).append(" LIKE ?");
                    else
                        sqlBuilder.append(" AND ").append(field.getColumn()).append("=?");
                    sqlParaList.add(holderPo.get_Value(field.getColumn()));
                // End Jan Thielemann Solution for query using the sentence like
                } else if (m_webservicetype.getFieldInput(field.getColumn()) == null) {
                    // If not even ctx variable column
                    throw new IdempiereServiceFault("Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " not allowed", new QName("queryData"));
                }
            }
        }
        if (modelCRUD.getFilter() != null && modelCRUD.getFilter().length() > 0) {
            String sql = parseSQL(" WHERE " + modelCRUD.getFilter(), sqlParaList, holderPo, poinfo, reqCtx);
            sqlBuilder.append(" AND ").append(sql.substring(6));
        }
        int cnt = 0;
        int rowCnt = 0;
        int offset = modelCRUD.getOffset();
        int limit = modelCRUD.getLimit();
        PreparedStatement pstmtquery = null;
        ResultSet rsquery = null;
        try {
            pstmtquery = DB.prepareStatement(sqlBuilder.toString(), trxName);
            DB.setParameters(pstmtquery, sqlParaList);
            rsquery = pstmtquery.executeQuery();
            // Angelo Dabala' (genied) must create just one DataSet, moved outside of the while loop
            DataSet ds = resp.addNewDataSet();
            while (rsquery.next()) {
                cnt++;
                if ((offset >= cnt) || (limit > 0 && offset + limit < cnt))
                    continue;
                rowCnt++;
                DataRow dr = ds.addNewDataRow();
                for (int i = 0; i < poinfo.getColumnCount(); i++) {
                    String columnName = poinfo.getColumnName(i);
                    if (m_webservicetype.isOutputColumnNameAllowed(columnName)) {
                        DataField dfid = dr.addNewField();
                        dfid.setColumn(columnName);
                        if (rsquery.getObject(columnName) instanceof byte[])
                            dfid.setVal(new String(Base64.encodeBase64(rsquery.getBytes(columnName))));
                        else
                            dfid.setVal(rsquery.getString(columnName));
                    }
                }
            }
        } catch (Exception e) {
            log.log(Level.SEVERE, e.getLocalizedMessage(), e);
            throw new IdempiereServiceFault(e);
        } finally {
            DB.close(rsquery, pstmtquery);
            rsquery = null;
            pstmtquery = null;
        }
        resp.setSuccess(true);
        resp.setRowCount(rowCnt);
        resp.setNumRows(rowCnt);
        resp.setTotalRows(cnt);
        resp.setStartRow(offset);
        return ret;
    } finally {
        if (manageTrx && trx != null)
            trx.close();
        getCompiereService().disconnect();
    }
}
Also used : ADLoginRequest(org.idempiere.adInterface.x10.ADLoginRequest) MWebServiceType(org.idempiere.webservices.model.MWebServiceType) DataSet(org.idempiere.adInterface.x10.DataSet) MRole(org.compiere.model.MRole) ArrayList(java.util.ArrayList) Properties(java.util.Properties) DataRow(org.idempiere.adInterface.x10.DataRow) StandardResponseDocument(org.idempiere.adInterface.x10.StandardResponseDocument) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) ModelCRUD(org.idempiere.adInterface.x10.ModelCRUD) ResultSet(java.sql.ResultSet) Trx(org.compiere.util.Trx) X_WS_WebServiceFieldInput(org.idempiere.webservices.model.X_WS_WebServiceFieldInput) StandardResponse(org.idempiere.adInterface.x10.StandardResponse) IdempiereServiceFault(org.idempiere.webservices.fault.IdempiereServiceFault) QName(javax.xml.namespace.QName) I_AD_Column(org.compiere.model.I_AD_Column) WindowTabData(org.idempiere.adInterface.x10.WindowTabData) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) XmlValueOutOfRangeException(org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException) POInfo(org.compiere.model.POInfo) MTable(org.compiere.model.MTable) DataField(org.idempiere.adInterface.x10.DataField) PO(org.compiere.model.PO)

Aggregations

IOException (java.io.IOException)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 PrintStream (java.io.PrintStream)10 Before (org.junit.Before)10 Dataset (com.google.cloud.datalabeling.v1beta1.Dataset)9 ArrayList (java.util.ArrayList)9 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)8 Dataset (com.google.cloud.automl.v1.Dataset)8 LocationName (com.google.cloud.automl.v1.LocationName)7 DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)7 ProjectName (com.google.cloud.datalabeling.v1beta1.ProjectName)7 CreateDatasetOperationMetadata (com.google.cloud.aiplatform.v1.CreateDatasetOperationMetadata)6 Dataset (com.google.cloud.aiplatform.v1.Dataset)6 DatasetServiceClient (com.google.cloud.aiplatform.v1.DatasetServiceClient)6 DatasetServiceSettings (com.google.cloud.aiplatform.v1.DatasetServiceSettings)6 LocationName (com.google.cloud.aiplatform.v1.LocationName)6 OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)6 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)6 Dataset (com.google.cloud.automl.v1beta1.Dataset)6 LocationName (com.google.cloud.automl.v1beta1.LocationName)6