Skip to content

Commit

Permalink
Support for including causative agent
Browse files Browse the repository at this point in the history
  • Loading branch information
fanavarro committed Nov 4, 2024
1 parent 6184c59 commit 024e9dd
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>es.um.dis.tecnomod</groupId>
<artifactId>oquo-instance-creator</artifactId>
<version>0.0.3-SNAPSHOT</version>
<version>0.0.3</version>

<properties>
<jena.version>3.17.0</jena.version>
Expand Down Expand Up @@ -62,7 +62,7 @@
<profile>
<id>java17</id>
<activation>
<activeByDefault>true</activeByDefault>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<profile.name>java17</profile.name>
Expand All @@ -73,7 +73,7 @@
<profile>
<id>java8</id>
<activation>
<activeByDefault>false</activeByDefault>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profile.name>java8</profile.name>
Expand Down
98 changes: 93 additions & 5 deletions src/main/java/es/um/dis/tecnomod/oquo/dto/IssueInfoDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class IssueInfoDTO implements Serializable {
/** The message. */
private String message;

/** The causative asset. */
private String causativeAsset;

/** The host asset. */
private String hostAsset;

/**
* Instantiates a new issue info DTO.
*/
Expand All @@ -25,17 +31,41 @@ public IssueInfoDTO(){}
/**
* Instantiates a new issue info DTO.
*
* @param observation the observation
* @param issueType the issue type
* @param message the message
*/
public IssueInfoDTO(String issueType, String message) {
this(issueType, null, null, message);
}


/**
* Instantiates a new issue info DTO.
*
* @param issueType the issue type
* @param message the message
* @param hostAsset the host asset
*/
public IssueInfoDTO(String issueType, String hostAsset, String message) {
this(issueType, hostAsset, null, message);
}

/**
* Instantiates a new issue info DTO.
*
* @param issueType the issue type
* @param message the message
* @param causativeAsset the causative asset
* @param hostAsset the host asset
*/
public IssueInfoDTO(String issueType, String hostAsset, String causativeAsset, String message) {
super();
this.issueType = issueType;
this.message = message;
this.causativeAsset = causativeAsset;
this.hostAsset = hostAsset;
}


/**
* Gets the issue type.
*
Expand Down Expand Up @@ -72,11 +102,58 @@ public void setMessage(String message) {
this.message = message;
}

/**
* Gets the causative asset.
*
* @return the causative asset
*/
public String getCausativeAsset() {
return causativeAsset;
}

/**
* Sets the causative asset.
*
* @param causativeAsset the new causative asset
*/
public void setCausativeAsset(String causativeAsset) {
this.causativeAsset = causativeAsset;
}

/**
* Gets the host asset.
*
* @return the host asset
*/
public String getHostAsset() {
return hostAsset;
}

/**
* Sets the host asset.
*
* @param hostAsset the new host asset
*/
public void setHostAsset(String hostAsset) {
this.hostAsset = hostAsset;
}

/**
* Hash code.
*
* @return the int
*/
@Override
public int hashCode() {
return Objects.hash(issueType, message);
return Objects.hash(causativeAsset, hostAsset, issueType, message);
}

/**
* Equals.
*
* @param obj the obj
* @return true, if successful
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
Expand All @@ -86,20 +163,31 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass())
return false;
IssueInfoDTO other = (IssueInfoDTO) obj;
return Objects.equals(issueType, other.issueType) && Objects.equals(message, other.message);
return Objects.equals(causativeAsset, other.causativeAsset) && Objects.equals(hostAsset, other.hostAsset)
&& Objects.equals(issueType, other.issueType) && Objects.equals(message, other.message);
}

/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("IssueInfoDTO [issueType=");
builder.append(issueType);
builder.append(", message=");
builder.append(message);
builder.append(", causativeAsset=");
builder.append(causativeAsset);
builder.append(", hostAsset=");
builder.append(hostAsset);
builder.append("]");
return builder.toString();
}





}
19 changes: 16 additions & 3 deletions src/main/java/es/um/dis/tecnomod/oquo/service/InstanceCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class InstanceCreator {

private static final String HAS_HOST_ASSET = Namespaces.IPO_NS + "hasHostAsset";
private static final String HOST_ASSET_OF = Namespaces.IPO_NS + "hostAssetOf";
private static final String HAS_CAUSATIVE_ASSET = Namespaces.IPO_NS + "hasCausativeAsset";
private static final String CAUSATIVE_ASSET_OF = Namespaces.IPO_NS + "causativeAssetOf";
private static final String INDICATES = Namespaces.IPO_NS + "indicates";
private static final String INDICATED_BY = Namespaces.IPO_NS + "indicatedBy";

Expand Down Expand Up @@ -210,9 +212,9 @@ public static void createObservation(Model rdfModel, ObservationInfoDTO observat

List<IssueInfoDTO> issuesInfoDTO = observationInfo.getIssues();
if (issuesInfoDTO != null && !issuesInfoDTO.isEmpty()) {
rdfModel.add(evaluationSubject, RDF.type, rdfModel.createResource(ASSET));
rdfModel.add(observation, RDF.type, rdfModel.createResource(SYMPTOM));
for (IssueInfoDTO issueInfoDTO : issuesInfoDTO) {
Resource hostAsset = rdfModel.createResource(issueInfoDTO.getHostAsset(), rdfModel.createResource(ASSET));
/* Issue */
String issueIRI = Namespaces.OQUO_NS + "issue-" + UUID.randomUUID().toString();
String message = issueInfoDTO.getMessage();
Expand All @@ -222,10 +224,10 @@ public static void createObservation(Model rdfModel, ObservationInfoDTO observat
rdfModel.add(issue, RDFS.comment, message);

/* Issue hasHostAsset Asset */
rdfModel.add(issue, rdfModel.createProperty(HAS_HOST_ASSET), evaluationSubject);
rdfModel.add(issue, rdfModel.createProperty(HAS_HOST_ASSET), hostAsset);

/* Asset hostAssetOf Issue */
rdfModel.add(evaluationSubject, rdfModel.createProperty(HOST_ASSET_OF), issue);
rdfModel.add(hostAsset, rdfModel.createProperty(HOST_ASSET_OF), issue);

/* Evaluation hasDetectedIssue Issue */
rdfModel.add(evaluation, rdfModel.createProperty(HAS_DETECTED_ISSUE), issue);
Expand All @@ -235,6 +237,17 @@ public static void createObservation(Model rdfModel, ObservationInfoDTO observat

/* issue indicated by observation */
rdfModel.add(issue, rdfModel.createProperty(INDICATED_BY), observation);

/* If there is causative asset... */
if (issueInfoDTO.getCausativeAsset() != null && !issueInfoDTO.getCausativeAsset().isEmpty()) {
Resource causativeAsset = rdfModel.createResource(issueInfoDTO.getCausativeAsset(), rdfModel.createResource(ASSET));

/* Issue hasCausativeAsset Asset */
rdfModel.add(issue, rdfModel.createProperty(HAS_CAUSATIVE_ASSET), causativeAsset);

/* Asset causativeAssetOf Issue */
rdfModel.add(causativeAsset, rdfModel.createProperty(CAUSATIVE_ASSET_OF), issue);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ void testValidate1() {
assertFalse(model.isEmpty());

ValidationReport report = RDFValidator.validate(model);
ShLib.printReport(report);
assertTrue(report.conforms());
//ShLib.printReport(report);
}

@Test
Expand Down

0 comments on commit 024e9dd

Please sign in to comment.