/
EntityReport.java
156 lines (125 loc) · 4.02 KB
/
EntityReport.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package org.ecoinformatics.datamanager.quality;
import java.util.ArrayList;
import org.ecoinformatics.datamanager.parser.Entity;
/**
* Represents an quality report for an entity.
*
* @author dcosta
*
*/
public class EntityReport {
/*
* Class variables
*/
/*
* Instance variables
*/
// The Entity objects that this EntityReport is reporting on
private Entity entity;
// List of quality checks that have been performed on this entity
private ArrayList<QualityCheck> qualityChecks = null;
/*
* Constructors
*/
public EntityReport(Entity entity) {
this.entity = entity;
qualityChecks = new ArrayList<QualityCheck>();
}
/*
* Class methods
*/
/*
* Instance methods
*/
/**
* Adds a quality check to the list of quality checks that have been
* performed on this entity.
*
* @param qualityCheck the new quality check to add to the list
*/
public void addQualityCheck(QualityCheck qualityCheck) {
String identifier = qualityCheck.getIdentifier();
/*
* Filter out duplicate cases of the same quality check.
* (We need a better approach to specifying these cases.)
*/
if (identifier.equalsIgnoreCase("onlineURLs")) {
if (hasQualityCheck(qualityCheck)) {
return;
}
}
qualityChecks.add(qualityCheck);
}
/**
* Retrieves the list of quality checks that have been performed on this
* entity.
*
* @return an ArrayList of QualityCheck objects
*/
public ArrayList<QualityCheck> getQualityChecks() {
return qualityChecks;
}
/**
* Boolean to determine whether this entity report has at
* least one entity-level quality error.
*
* @return true if one or more entity quality errors are found,
* else false
*/
public boolean hasEntityQualityError() {
boolean hasError = false;
for (QualityCheck qualityCheck : qualityChecks) {
if (qualityCheck.hasErrorStatus()) {
hasError = true;
}
}
return hasError;
}
/**
* Boolean to determine whether a copy of a quality check already
* exists in the list of quality checks for this entity. There are
* occasions where we wish not to add duplicate copies of the same
* quality check. This method makes it possible to determine whether
* the entity already has a copy in its collection.
*
* @param qualityCheck the quality check that we're want to know
* whether it's already in this entity's list
* @return true if found in this entity, else false
*/
private boolean hasQualityCheck(QualityCheck qualityCheck) {
for (QualityCheck qc : qualityChecks) {
if (qualityCheck.equals(qc)) {
return true;
}
}
return false;
}
/**
* Generate an XML entity report structure from the quality check objects
* stored in the entity.
*
* @return an XML string representation of the <entityReport> XML fragment.
*/
public String toXML() {
String xmlString = null;
if (entity != null) {
String entityName = entity.getName();
String entityId = entity.getId();
StringBuffer stringBuffer = new StringBuffer("");
stringBuffer.append(" <entityReport>\n");
stringBuffer.append(" <entityName>" + entityName + "</entityName>\n");
if (entityId != null && !entityId.equals("")) {
stringBuffer.append(" <entityId>" + entityId + "</entityId>\n");
}
if (qualityChecks != null && qualityChecks.size() > 0) {
for (QualityCheck aQualityCheck : qualityChecks) {
String qualityCheckXML = aQualityCheck.toXML();
stringBuffer.append(qualityCheckXML);
}
}
stringBuffer.append(" </entityReport>\n");
xmlString = stringBuffer.toString();
}
return xmlString;
}
}