Package com.serotonin.m2m2.i18n

Examples of com.serotonin.m2m2.i18n.TranslatableMessage


        this.viewUsers = viewUsers;
    }

    public void validate(ProcessResult response) {
        if (StringUtils.isBlank(name))
            response.addMessage("name", new TranslatableMessage("validate.required"));
        else if (StringValidation.isLengthGreaterThan(name, 100))
            response.addMessage("name", new TranslatableMessage("validate.notLongerThan", 100));

        if (StringUtils.isBlank(xid))
            response.addMessage("xid", new TranslatableMessage("validate.required"));
        else if (StringValidation.isLengthGreaterThan(xid, 50))
            response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
        else if (!new GraphicalViewDao().isXidUnique(xid, id))
            response.addMessage("xid", new TranslatableMessage("validate.xidUsed"));

        for (ViewComponent vc : viewComponents)
            vc.validate(response);
    }
View Full Code Here


   
   
   
        this.file = new File( vo.getFilePath() );
    if ( !file.exists() ) {
      raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.fileNotFound",vo.getFilePath()));
      return false;
    }else if ( !file.canRead() ){
      raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailed",vo.getFilePath()));
      return false;
        }else{
      this.fobs = new FileAlterationObserver(this.file);
      this.fobs.initialize();
      this.fobs.addListener(this);
View Full Code Here

        LOG.debug("Error while initializing data source", e);
        String msg = e.getMessage();
        if(msg == null){
          msg = "Unknown";
        }
      raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailed",msg));
     
      }
     
      if(connected){
        returnToNormal(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis());
View Full Code Here

        if(this.file != null) {
      try {
        this.fobs.destroy();
      } catch (Exception e) {
        LOG.debug("Error destroying file observer");
        raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.obsDestroy", e.getMessage()));
      }
      this.file = null;
    }

    }
View Full Code Here

  }

  private void fileEvent() {
    //Should never happen
    if(this.file == null) {
      raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailedFileNotSetup"));
      return;
    }
   
   
    //The file is modified or we've just started, so read it.
    try{
      BufferedReader reader = new BufferedReader(new FileReader(this.file));

      String msg;
            if(!this.dataPoints.isEmpty()) {
         
              //TODO optimize to be better than numLines*numPoints
              while( (msg = reader.readLine()) != null) {
          //Give all points the chance to find their data
          for(DataPointRT dp: this.dataPoints){
            AsciiFilePointLocatorRT pl = dp.getPointLocator();
            AsciiFilePointLocatorVO plVo = pl.getVo();
            Pattern pointValuePattern = Pattern.compile(plVo.getValueRegex());
            Matcher pointValueMatcher = pointValuePattern.matcher(msg); //Use the index from the above message
            if(pointValueMatcher.find()){
              if(plVo.getPointIdentifier().equals(pointValueMatcher.group(plVo.getPointIdentifierIndex()))) {
                String value = pointValueMatcher.group(plVo.getValueIndex());                 
                PointValueTime newValue;
                Date dt;
                if(plVo.getHasTimestamp() && !plVo.getTimestampFormat().equals(".")) {
                  SimpleDateFormat fmt = new SimpleDateFormat(plVo.getTimestampFormat());
                  dt = fmt.parse(pointValueMatcher.group(plVo.getTimestampIndex()));
                }
                else if(plVo.getHasTimestamp()) {
                  dt = new Date(Long.parseLong(pointValueMatcher.group(plVo.getTimestampIndex())));
                }
                else {
                  dt = new Date();
                }
               
                //Switch on the type
                switch(plVo.getDataTypeId()){
                case DataTypes.ALPHANUMERIC:
                  newValue = new PointValueTime(value, dt.getTime());
                  break;
                case DataTypes.NUMERIC:
                  newValue = new PointValueTime(Double.parseDouble(value), dt.getTime());
                  break;
                case DataTypes.MULTISTATE:
                  newValue = new PointValueTime(Integer.parseInt(value), dt.getTime());
                  break;
                case DataTypes.BINARY:
                  newValue = new PointValueTime(Boolean.parseBoolean(value), dt.getTime());
                  break;
                default:
                  throw new ShouldNeverHappenException("Uknown Data type for point");
                }
               
                if(!plVo.getHasTimestamp())
                  dp.updatePointValue(newValue);
                else
                  dp.savePointValueDirectToCache(newValue, null, true, true);
              }
            }
          }
              }
      }
            reader.close();
            returnToNormal(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis());
        }catch ( FileNotFoundException e ){
      raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.fileNotFound",e.getMessage()));
        } catch (IOException e) {
          raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.readFailed",e.getMessage()));
    } catch (NumberFormatException e) {
      raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.notNumber",e.getMessage()));
    } catch (ParseException e) {
      raiseEvent(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("file.event.dateParseFailed",e.getMessage()));
    }
   
  }
View Full Code Here

            watchList.setName(translate("common.newName"));
        }
        else {
            watchList = new WatchListDao().getWatchList(getWatchList().getId());
            watchList.setId(Common.NEW_ID);
            watchList.setName(translate(new TranslatableMessage("common.copyPrefix", watchList.getName())));
            //Check to see if we are a Shared User (we can't share a watchlist with ourselves)
            List<ShareUser> watchListShared =  new ArrayList<ShareUser>();
            for(ShareUser shareUser : watchList.getWatchListUsers()){
              //Don't add yourself
              if(shareUser.getUserId() != user.getId())
View Full Code Here

        params.setStopBits(vo.getStopBits());
        params.setParity(vo.getParity());
        params.setRecieveTimeout(vo.getReadTimeout());
   
        if ( SerialUtils.portOwned(vo.getCommPortId()) ){
      raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.portInUse",vo.getCommPortId()));
      return false;
        }else{
          try{
                this.port = SerialUtils.openSerialPort(params);
                this.port.addEventListener(this);
                return true;
             
            }catch(Exception e){
          raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.portError",vo.getCommPortId(),e.getLocalizedMessage()));
          return false;
            }
        }

    }
View Full Code Here

        LOG.debug("Error while initializing data source", e);
        String msg = e.getMessage();
        if(msg == null){
          msg = "Unknown";
        }
      raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.connectFailed",msg));
     
      }
     
      if(connected){
        returnToNormal(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis());
View Full Code Here

        if(this.port != null)
      try {
        SerialUtils.close(this.port);
      } catch (SerialPortException e) {
          LOG.debug("Error while closing serial port", e);
        raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.portError",this.port.getParameters().getCommPortId(),e.getLocalizedMessage()));

      }


    }
View Full Code Here

  public void setPointValue(DataPointRT dataPoint, PointValueTime valueTime,
      SetPointSource source) {

    //Are we connected?
    if(this.port == null){
      raiseEvent(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.writeFailedPortNotSetup"));
      return;
    }
   
    try {
      OutputStream os = this.port.getOutputStream();
      //Pin the terminator on the end
      String messageTerminator = ((SerialDataSourceVO)this.getVo()).getMessageTerminator();
         
          //Create Message from Message Start
          SerialPointLocatorRT pl = dataPoint.getPointLocator();
          String identifier = pl.getVo().getPointIdentifier();
         
          //Do we need to or is it already on the end?
          String fullMsg = identifier +  valueTime.getStringValue();
          if(!fullMsg.endsWith(messageTerminator)){
            fullMsg +=  messageTerminator;
          }
      //PointValueTime newValue = new PointValueTime(fullMsg,valueTime.getTime());

      //String output = newValue.getStringValue();
      byte[] data = fullMsg.getBytes();
      for(byte b : data){
        os.write(b);
      }
      os.flush();
      //Finally Set the point value (to the incoming one)
      //dataPoint.setPointValue(valueTime, source);
      returnToNormal(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis());
    } catch (IOException e) {
      raiseEvent(POINT_WRITE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.writeFailed",e.getMessage()));
    }
   
   
  }
View Full Code Here

TOP

Related Classes of com.serotonin.m2m2.i18n.TranslatableMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.