Skip to content

Commit

Permalink
Updating tma-utils project according to the unified knowledge model (#19
Browse files Browse the repository at this point in the history
)

* Updated TMA Deployment Instructions
* Starting the knowledge unification
* Final changes in the data model.
* Updated score calculation according to new unified quality model
* Updated score calculation
* Created entity views
  • Loading branch information
jreluiz authored and nmsa committed Oct 31, 2019
1 parent 26af094 commit 7390596
Show file tree
Hide file tree
Showing 48 changed files with 2,583 additions and 14 deletions.
6 changes: 6 additions & 0 deletions common/tma-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.2.Final</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eubr.atmosphere.tma.utils;
package eubr.atmosphere.tma.database;

import java.sql.Connection;
import java.sql.DriverManager;
Expand Down Expand Up @@ -28,7 +28,7 @@ public static Connection getConnectionInstance() {
// Setup the connection with the DB
try {
if ((connection == null) || connection.isClosed()) {
connection = DriverManager
connection = DriverManager
.getConnection("jdbc:mysql://mysql-0.mysql.default.svc.cluster.local:3306/knowledge?"
+ "user=root&password=passtobereplaced");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package eubr.atmosphere.tma.database;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import eubr.atmosphere.tma.entity.qualitymodel.Data;
import eubr.atmosphere.tma.entity.qualitymodel.DataPK;
import eubr.atmosphere.tma.entity.qualitymodel.MetricData;

public class QualityModelManager {

private static final Logger LOGGER = LoggerFactory.getLogger(QualityModelManager.class);

public int saveMetricData(MetricData metricData) {
String sql = "INSERT INTO MetricData(metricId, valueTime, value, resourceId) VALUES (?, ?, ?, ?)";
PreparedStatement ps;
try {
ps = DatabaseManager.getConnectionInstance().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
ps.setInt(1, metricData.getMetricId().getMetricId());
ps.setTimestamp(2, new Timestamp(metricData.getMetricId().getValueTime().getTime()));
ps.setDouble(3, metricData.getValue());
if (metricData.getResourceId() == null) {
ps.setNull(4, Types.INTEGER);
} else {
ps.setInt(4, metricData.getResourceId());
}
DatabaseManager databaseManager = new DatabaseManager();
return databaseManager.execute(ps);
} catch (SQLException e) {
LOGGER.error("[ATMOSPHERE] Error when inserting MetricData in the database.", e);
}
return -1;
}

public List<Data> getLimitedDataListByIdAndTimestamp(Integer descriptionId) {

List<Data> dataList = new ArrayList<>();
PreparedStatement ps = null;
String sql = "SELECT d.probeId, d.descriptionId, d.resourceId, d.valueTime, d.value FROM Data d WHERE d.descriptionId = ?";

try {

ps = DatabaseManager.getConnectionInstance().prepareStatement(sql);
ps.setInt(1, descriptionId);

ResultSet rs = DatabaseManager.executeQuery(ps);
if (rs.next()) {

Data data = new Data();
DataPK dataPK = new DataPK();
dataPK.setProbeId(rs.getInt("probeId"));
dataPK.setDescriptionId(rs.getInt("descriptionId"));
dataPK.setResourceId(rs.getInt("resourceId"));
dataPK.setValueTime(rs.getDate("valueTime"));
data.setId(dataPK);
data.setValue(rs.getDouble("value"));

dataList.add(data);

}

return dataList;
} catch (SQLException e) {
LOGGER.error("[ATMOSPHERE] Error when getting Data list by ID and Timestamp.", e);
}

return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package eubr.atmosphere.tma.entity.qualitymodel;

import java.io.Serializable;
import javax.persistence.*;


/**
* The persistent class for the Action database table.
*
*/
@Entity
@NamedQuery(name="Action.findAll", query="SELECT a FROM Action a")
public class Action implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int actionId;

private String actionName;

private int actuatorId;

private int resourceId;

public Action() {
}

public int getActionId() {
return this.actionId;
}

public void setActionId(int actionId) {
this.actionId = actionId;
}

public String getActionName() {
return this.actionName;
}

public void setActionName(String actionName) {
this.actionName = actionName;
}

public int getActuatorId() {
return this.actuatorId;
}

public void setActuatorId(int actuatorId) {
this.actuatorId = actuatorId;
}

public int getResourceId() {
return this.resourceId;
}

public void setResourceId(int resourceId) {
this.resourceId = resourceId;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package eubr.atmosphere.tma.entity.qualitymodel;

import java.io.Serializable;
import javax.persistence.*;


/**
* The persistent class for the ActionPlan database table.
*
*/
@Entity
@NamedQuery(name="ActionPlan.findAll", query="SELECT a FROM ActionPlan a")
public class ActionPlan implements Serializable {
private static final long serialVersionUID = 1L;

@EmbeddedId
private ActionPlanPK id;

private int executionOrder;

private int status;

public ActionPlan() {
}

public ActionPlanPK getId() {
return this.id;
}

public void setId(ActionPlanPK id) {
this.id = id;
}

public int getExecutionOrder() {
return this.executionOrder;
}

public void setExecutionOrder(int executionOrder) {
this.executionOrder = executionOrder;
}

public int getStatus() {
return this.status;
}

public void setStatus(int status) {
this.status = status;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package eubr.atmosphere.tma.entity.qualitymodel;

import java.io.Serializable;

import javax.persistence.Embeddable;

/**
* The primary key class for the ActionPlan database table.
*
*/
@Embeddable
public class ActionPlanPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;

private int planId;

private int actionId;

public ActionPlanPK() {
}
public int getPlanId() {
return this.planId;
}
public void setPlanId(int planId) {
this.planId = planId;
}
public int getActionId() {
return this.actionId;
}
public void setActionId(int actionId) {
this.actionId = actionId;
}

public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ActionPlanPK)) {
return false;
}
ActionPlanPK castOther = (ActionPlanPK)other;
return
(this.planId == castOther.planId)
&& (this.actionId == castOther.actionId);
}

public int hashCode() {
final int prime = 31;
int hash = 17;
hash = hash * prime + this.planId;
hash = hash * prime + this.actionId;

return hash;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package eubr.atmosphere.tma.entity.qualitymodel;

import java.io.Serializable;
import javax.persistence.*;


/**
* The persistent class for the Actuator database table.
*
*/
@Entity
@NamedQuery(name="Actuator.findAll", query="SELECT a FROM Actuator a")
public class Actuator implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int actuatorId;

private String address;

private String pubKey;

public Actuator() {
}

public int getActuatorId() {
return this.actuatorId;
}

public void setActuatorId(int actuatorId) {
this.actuatorId = actuatorId;
}

public String getAddress() {
return this.address;
}

public void setAddress(String address) {
this.address = address;
}

public String getPubKey() {
return this.pubKey;
}

public void setPubKey(String pubKey) {
this.pubKey = pubKey;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package eubr.atmosphere.tma.entity.qualitymodel;

/**
* Attribute aggregation operator enumeration
* @author JorgeLuiz
*/
public enum AttributeAggregationOperator {

NEUTRALITY(0, "NEUTRALITY"), SIMULTANEITY(1, "SIMULTANEITY"), REPLACEABILITY(2, "REPLACEABILITY");

private Integer valor;
private String label;

private AttributeAggregationOperator(Integer valor, String label) {
this.valor = valor;
this.label = label;
}

public Integer getValor() {
return valor;
}

public String getLabel() {
return label;
}

public static AttributeAggregationOperator getEnumByValor(Integer valor) {
if (valor == null) {
return null;
}
for (AttributeAggregationOperator item : AttributeAggregationOperator.values()) {
if (item.getValor().intValue() == valor.intValue()) {
return item;
}
}
return null;
}

}
Loading

0 comments on commit 7390596

Please sign in to comment.