Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:IntegratedAlarmSystem-Group/ias …
Browse files Browse the repository at this point in the history
…into feature/dockerization
  • Loading branch information
sfehlandt committed Mar 9, 2018
2 parents d083c2c + fbfa01e commit f12844f
Show file tree
Hide file tree
Showing 43 changed files with 1,139 additions and 344 deletions.
142 changes: 108 additions & 34 deletions BasicTypes/src/java/org/eso/ias/types/IASValue.java

Large diffs are not rendered by default.

75 changes: 39 additions & 36 deletions BasicTypes/src/java/org/eso/ias/types/IasValueJsonPojo.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.eso.ias.types;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import org.eso.ias.utils.ISO8601Helper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -85,6 +86,11 @@ public class IasValueJsonPojo {
*/
@JsonInclude(Include.NON_NULL)
private String dasuProductionTStamp;

/**
* @see IASValue#dependentsFullRuningIds
*/
private Set<String> depsFullRunningIds;

/**
* The operational mode
Expand All @@ -111,11 +117,6 @@ public class IasValueJsonPojo {
*/
public IasValueJsonPojo() {}

/**
* Formatter to convert time-stamps to from ISO 8601
*/
private static final SimpleDateFormat iso8601Formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S");

/**
* Constructor
*
Expand All @@ -129,16 +130,15 @@ public IasValueJsonPojo(IASValue<?> iasValue) {
fullRunningId=iasValue.fullRunningId;
valueType=iasValue.valueType;
iasValidity=iasValue.iasValidity;
this.depsFullRunningIds=iasValue.dependentsFullRuningIds;

synchronized(iso8601Formatter) {
this.pluginProductionTStamp=convertTStampToIso8601(iasValue.pluginProductionTStamp);
this.sentToConverterTStamp=convertTStampToIso8601(iasValue.sentToConverterTStamp);
this.receivedFromPluginTStamp=convertTStampToIso8601(iasValue.receivedFromPluginTStamp);
this.convertedProductionTStamp=convertTStampToIso8601(iasValue.convertedProductionTStamp);
this.sentToBsdbTStamp=convertTStampToIso8601(iasValue.sentToBsdbTStamp);
this.readFromBsdbTStamp=convertTStampToIso8601(iasValue.readFromBsdbTStamp);
this.dasuProductionTStamp=convertTStampToIso8601(iasValue.dasuProductionTStamp);
}
this.pluginProductionTStamp=convertTStampToIso8601(iasValue.pluginProductionTStamp);
this.sentToConverterTStamp=convertTStampToIso8601(iasValue.sentToConverterTStamp);
this.receivedFromPluginTStamp=convertTStampToIso8601(iasValue.receivedFromPluginTStamp);
this.convertedProductionTStamp=convertTStampToIso8601(iasValue.convertedProductionTStamp);
this.sentToBsdbTStamp=convertTStampToIso8601(iasValue.sentToBsdbTStamp);
this.readFromBsdbTStamp=convertTStampToIso8601(iasValue.readFromBsdbTStamp);
this.dasuProductionTStamp=convertTStampToIso8601(iasValue.dasuProductionTStamp);

}

Expand All @@ -152,7 +152,7 @@ public IasValueJsonPojo(IASValue<?> iasValue) {
*/
private String convertTStampToIso8601(Optional<Long> tStamp) {
assert(tStamp!=null);
Optional<String> isoTStamp = tStamp.map( stamp -> iso8601Formatter.format(new Date(stamp)));
Optional<String> isoTStamp = tStamp.map( stamp -> ISO8601Helper.getTimestamp(stamp));
return isoTStamp.orElse(null);
}

Expand All @@ -170,11 +170,7 @@ private Optional<Long> convertIso8601ToTStamp(String iso8601Str) {
}

Long tstamp = null;
try {
tstamp = iso8601Formatter.parse(iso8601Str).getTime();
} catch (ParseException pe) {
logger.error("Error parsing ISO-8601 string {} to a date",iso8601Str);
}
tstamp = ISO8601Helper.timestampToMillis(iso8601Str);
return Optional.ofNullable(tstamp);

}
Expand Down Expand Up @@ -264,21 +260,28 @@ public IASValue<?> toIasValue() {
default: throw new UnsupportedOperationException("Unsupported type "+valueType);
}

synchronized(iso8601Formatter) {
return new IASValue(
theValue,
mode,
iasValidity,
fullRunningId,
valueType,
convertIso8601ToTStamp(pluginProductionTStamp),
convertIso8601ToTStamp(sentToConverterTStamp),
convertIso8601ToTStamp(receivedFromPluginTStamp),
convertIso8601ToTStamp(convertedProductionTStamp),
convertIso8601ToTStamp(sentToBsdbTStamp),
convertIso8601ToTStamp(readFromBsdbTStamp),
convertIso8601ToTStamp(dasuProductionTStamp));
}
return new IASValue(
theValue,
mode,
iasValidity,
fullRunningId,
valueType,
convertIso8601ToTStamp(pluginProductionTStamp),
convertIso8601ToTStamp(sentToConverterTStamp),
convertIso8601ToTStamp(receivedFromPluginTStamp),
convertIso8601ToTStamp(convertedProductionTStamp),
convertIso8601ToTStamp(sentToBsdbTStamp),
convertIso8601ToTStamp(readFromBsdbTStamp),
convertIso8601ToTStamp(dasuProductionTStamp),
depsFullRunningIds);
}

public Set<String> getDepsFullRunningIds() {
return depsFullRunningIds;
}

public void setDepsFullRunningIds(Set<String> dependentsFullRuningIds) {
this.depsFullRunningIds = dependentsFullRuningIds;
}

}
24 changes: 24 additions & 0 deletions BasicTypes/src/scala/org/eso/ias/types/Identifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,28 @@ extends {
parentID.flatMap(p => p.getIdOfType(idTypeToSearch))
}
}

/**
* canEqual method checks the class of the passed
* @param other the object to compare
*/
def canEqual(other: Any): Boolean = other.isInstanceOf[Identifier]

/**
* Override equals
*
* For equality it is enough to check the fullRuningId
*/
override def equals(other: Any): Boolean = {
other match {
case that: Identifier =>
(that canEqual this) && fullRunningID==that.fullRunningID
case _ => false
}
}

/**
* Override hashCode
*/
override def hashCode: Int = fullRunningID.##
}
70 changes: 55 additions & 15 deletions BasicTypes/src/scala/org/eso/ias/types/InOut.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.eso.ias.types

import java.util.Optional
import scala.collection.JavaConverters

/**
* A <code>InOut</code> holds the value of an input or output
Expand Down Expand Up @@ -28,6 +29,10 @@ import java.util.Optional
* only one between pluginProductionTStamp and dasuProductionTStamp
* can be defined (another invariant)
*
* A property of the InOut contains the list of the dependent monitor points.
* Only an output can have dependent monitor points i.e. the InOut in input to the
* DASu that are needed to produce the ouput.
* The InOut in input have an empty set of dependant monitor points.
*
* <code>InOut</code> is immutable.
*
Expand All @@ -38,7 +43,7 @@ import java.util.Optional
* It is None if and only if the value is generated by ASCE
* and in that case fromInputsValidity is defined
* @param fromInputsValidity the validity inherited by the inputs
* It is defined only for the ouputs of an ASCE
* It is defined only for the outputs of an ASCE
* and in that case fromIasValueValidity must be None
* @param iasType: is the IAS type of this InOut
* @param pluginProductionTStamp The point in time when the plugin produced this value
Expand All @@ -49,6 +54,9 @@ import java.util.Optional
* @param sentToBsdbTStamp The point in time when the value has been sent to the BSDB
* @param readFromBsdbTStamp The point in time when the value has been read from the BSDB
* @param dasuProductionTStamp The point in time when the value has been generated by the DASU
* @param idsOfDependants the identifiers of the dependent monitor points i.e.
* the identifier of the inputs if this InOut represents a output
* empty otherwise
*
* @see IASType
*
Expand All @@ -67,9 +75,11 @@ case class InOut[A](
convertedProductionTStamp: Option[Long],
sentToBsdbTStamp: Option[Long],
readFromBsdbTStamp: Option[Long],
dasuProductionTStamp: Option[Long]) {
dasuProductionTStamp: Option[Long],
idsOfDependants: Set[Identifier]) {
require(Option[Identifier](id).isDefined,"The identifier must be defined")
require(Option[IASTypes](iasType).isDefined,"The type must be defined")
require(Option(idsOfDependants).isDefined,"Invalid list of dep. identifiers")

// Check that one and only one validity (from inputs or from IASValue)
// is defined
Expand Down Expand Up @@ -115,6 +125,10 @@ case class InOut[A](
readFromBsdbTStamp.foreach(t => { ret.append(", readFromBsdbTStamp="); ret.append(t); })
dasuProductionTStamp.foreach(t => { ret.append(", dasuProductionTStamp="); ret.append(t); })

ret.append(", Ids of dependants=[")
ret.append(idsOfDependants.map(_.id).mkString(", "))
ret.append(']')

ret.toString()
}

Expand All @@ -124,7 +138,7 @@ case class InOut[A](
* @param newMode: The new mode of the monitor point
*/
def updateMode(newMode: OperationalMode): InOut[A] = {
this.copy(mode=newMode, dasuProductionTStamp=Some(System.currentTimeMillis()))
this.copy(mode=newMode)
}

/**
Expand All @@ -136,7 +150,7 @@ case class InOut[A](
def updateValue[B >: A](newValue: Some[B]): InOut[A] = {
assert(InOut.checkType(newValue.get,iasType))

this.copy(value=newValue, dasuProductionTStamp=Some(System.currentTimeMillis()))
this.copy(value=newValue)
}

/**
Expand All @@ -152,9 +166,9 @@ case class InOut[A](
def updateValueValidity[B >: A](newValue: Some[B], newValidity: Some[Validity]): InOut[A] = {
assert(InOut.checkType(newValue.get,iasType))
if (isOutput()) {
this.copy(value=newValue,fromInputsValidity=newValidity, dasuProductionTStamp=Some(System.currentTimeMillis()))
this.copy(value=newValue,fromInputsValidity=newValidity)
} else {
this.copy(value=newValue,fromIasValueValidity=newValidity, dasuProductionTStamp=Some(System.currentTimeMillis()))
this.copy(value=newValue,fromIasValueValidity=newValidity)
}
}

Expand All @@ -165,7 +179,7 @@ case class InOut[A](
val validityOpt = Option(validity)
require(validityOpt.isDefined)
assert(!isOutput() && fromIasValueValidity.isDefined, "Cannot update the IASValue validity of an output")
this.copy(fromIasValueValidity=validityOpt, dasuProductionTStamp=Some(System.currentTimeMillis()))
this.copy(fromIasValueValidity=validityOpt)
}

/**
Expand All @@ -175,7 +189,7 @@ case class InOut[A](
val validityOpt = Option(validity)
require(validityOpt.isDefined)
assert(isOutput() && fromInputsValidity.isDefined, "Cannot update the validities of inputs of an input")
this.copy(fromInputsValidity=validityOpt, dasuProductionTStamp=Some(System.currentTimeMillis()))
this.copy(fromInputsValidity=validityOpt)
}

/**
Expand All @@ -202,21 +216,35 @@ case class InOut[A](
fromIasValueValidity.getOrElse(fromInputsValidity.get)
}

/**
* Updates the IDs of the dependents
*
* @param idsOfDeps the identifiers of the dependent monitor points
*/
def updateDependentsIds(idsOfDeps: Set[Identifier]): InOut[A] = {
require(Option(idsOfDeps).isDefined,"Cannot update the list of dependents with an empty set of identifiers")
this.copy(idsOfDependants=idsOfDeps)
}

/**
* Update the value of this IASIO with the IASValue.
*
* The validity received from the IASValus will be stored in fromIasValueValidity
* The validity received from the IASValue will be stored in fromIasValueValidity
* if this INOut is an input of a ASCE or in fromInputsValidity if it the the output
* of a ASCE.
*/
def update(iasValue: IASValue[_]): InOut[_] = {
def update(iasValue: IASValue[_]): InOut[A] = {
require(Option(iasValue).isDefined,"Cannot update from a undefined IASValue")
require(Option(iasValue.value).isDefined,"Cannot update when the IASValue has no value")
require(Option(iasValue.dependentsFullRuningIds).isDefined,"Cannot update when the IASValue has no dependent ids")
assert(iasValue.id==this.id.id,"Identifier mismatch: received "+iasValue.id+", expected "+this.id.id)
assert(iasValue.valueType==this.iasType)
assert(InOut.checkType(iasValue.value,iasType))
val validity = Some(Validity(iasValue.iasValidity))

val depIds: Set[String] = Set.empty++JavaConverters.asScalaSet(iasValue.dependentsFullRuningIds)


new InOut(
Some(iasValue.value),
Identifier(iasValue.fullRunningId),
Expand All @@ -230,23 +258,32 @@ case class InOut[A](
if (iasValue.convertedProductionTStamp.isPresent()) Some(iasValue.convertedProductionTStamp.get()) else None,
if (iasValue.sentToBsdbTStamp.isPresent()) Some(iasValue.sentToBsdbTStamp.get()) else None,
if (iasValue.readFromBsdbTStamp.isPresent()) Some(iasValue.readFromBsdbTStamp.get()) else None,
if (iasValue.dasuProductionTStamp.isPresent()) Some(iasValue.dasuProductionTStamp.get()) else None)
if (iasValue.dasuProductionTStamp.isPresent()) Some(iasValue.dasuProductionTStamp.get()) else None,
depIds.map(Identifier(_)))
}

def updateSentToBsdbTStamp(timestamp: Long) = {
def updateSentToBsdbTStamp(timestamp: Long): InOut[A] = {
val newTimestamp = Option(timestamp)
require(newTimestamp.isDefined)

this.copy(sentToBsdbTStamp=newTimestamp)
}

def updateDasuProdTStamp(timestamp: Long): InOut[A] = {
val newTimestamp = Option(timestamp)
require(newTimestamp.isDefined)

this.copy(dasuProductionTStamp=newTimestamp)
}
/**
* Build and return the IASValue representation of this IASIO
*
* @return The IASValue representation of this IASIO
*/
def toIASValue(): IASValue[_] = {

val ids = JavaConverters.setAsJavaSet(idsOfDependants.map(_.fullRunningID))

new IASValue(
value.getOrElse(null),
mode,
Expand All @@ -259,7 +296,8 @@ case class InOut[A](
Optional.ofNullable(if (convertedProductionTStamp.isDefined) convertedProductionTStamp.get else null),
Optional.ofNullable(if (sentToBsdbTStamp.isDefined) sentToBsdbTStamp.get else null),
Optional.ofNullable(if (readFromBsdbTStamp.isDefined) readFromBsdbTStamp.get else null),
Optional.ofNullable(if (dasuProductionTStamp.isDefined) dasuProductionTStamp.get else null))
Optional.ofNullable(if (dasuProductionTStamp.isDefined) dasuProductionTStamp.get else null),
ids)

}

Expand Down Expand Up @@ -320,7 +358,8 @@ object InOut {
None,
None,
None,
None)
None,
Set.empty)
}

/**
Expand Down Expand Up @@ -350,6 +389,7 @@ object InOut {
None,
None,
None,
None)
None,
Set.empty)
}
}
Loading

0 comments on commit f12844f

Please sign in to comment.