@@ -145,12 +145,21 @@ searchRelationship() {
145
145
String refAreaCode = "Relationship/Relationships/AreaCode";
146
146
String refContextId = "Relationship/Relationships/Context_ID";
147
147
148
- String areaCode = getFieldValue(refAreaCode);
148
+ String areaCode = getFieldValue(refAreaCode, true );
149
149
String contextId = getFieldValue(refContextId);
150
150
String parentRole = getSelectedRelationshipComponent(refRelType, "parent");
151
151
String unrelatedQ = "";
152
152
String relatedQ = "";
153
153
154
+ String refContextAreaCode = "Context/General/AreaCode";
155
+ String refLegacyAreaCode = "Legacy/Legacy/AreaCode";
156
+ String refContextContextId = "Context/General/Context_Context_ID";
157
+ String refLegacyContextId = "Legacy/Legacy/Legacy_Context_ID";
158
+ String contextAreaCode = getAttributeName(refContextAreaCode);
159
+ String legacyAreaCode = getAttributeName(refLegacyAreaCode);
160
+ String contextContextId = getAttributeName(refContextContextId);
161
+ String legacyContextId = getAttributeName(refLegacyContextId);
162
+
154
163
if (isNull(areaCode)) {
155
164
msgHead = "Trench required";
156
165
msgBody = "Searching requires that the Trench field is filled in.";
@@ -168,28 +177,34 @@ searchRelationship() {
168
177
unrelatedQ += " FROM latestNonDeletedArchEntFormattedIdentifiers";
169
178
unrelatedQ += " WHERE uuid IN (";
170
179
unrelatedQ += " SELECT uuid";
171
- unrelatedQ += " FROM latestnondeletedaentvalue JOIN attributekey USING (attributeid)";
172
- unrelatedQ += " WHERE attributename = 'AreaCode'";
173
- unrelatedQ += " AND vocabid = '{AreaCode}'";
180
+ unrelatedQ += " FROM latestnondeletedaentvalue";
181
+ unrelatedQ += " JOIN attributekey USING (attributeid)";
182
+ unrelatedQ += " JOIN vocabulary USING (vocabid)";
183
+ unrelatedQ += " WHERE attributename IN ({Context_AreaCode}, {Legacy_AreaCode})";
184
+ unrelatedQ += " AND vocabname = {AreaCode}";
174
185
unrelatedQ += " AND uuid IN (";
175
186
unrelatedQ += " SELECT uuid";
176
187
unrelatedQ += " FROM latestnondeletedaentvalue JOIN attributekey USING (attributeid) ";
177
- unrelatedQ += " WHERE attributename IN ('Context Context ID', 'Legacy Context ID' )";
178
- unrelatedQ += " AND measure = ' {Context_ID}' )";
188
+ unrelatedQ += " WHERE attributename IN ({Context_Context_ID}, {Legacy_Context_ID} )";
189
+ unrelatedQ += " AND measure = {Context_ID})";
179
190
unrelatedQ += " AND uuid NOT IN (";
180
191
unrelatedQ += " SELECT childuuid";
181
192
unrelatedQ += " FROM parentchild";
182
- unrelatedQ += " WHERE parentuuid = ' {parentUuid}' ";
183
- unrelatedQ += " AND parentparticipatesverb = ' {parentRole}' )";
184
- unrelatedQ += " AND uuid != ' {parentUuid}' )";
193
+ unrelatedQ += " WHERE parentuuid = {parentUuid}";
194
+ unrelatedQ += " AND parentparticipatesverb = {parentRole})";
195
+ unrelatedQ += " AND uuid != {parentUuid})";
185
196
unrelatedQ += " AND aenttypename IN ('Context', 'Legacy')";
186
197
unrelatedQ += " ORDER BY response";
187
198
unrelatedQ += " LIMIT ? OFFSET ?";
188
- unrelatedQ = replaceFirst(unrelatedQ, "{AreaCode}", areaCode );
189
- unrelatedQ = replaceFirst(unrelatedQ, "{Context_ID}", contextId );
190
- unrelatedQ = replaceFirst(unrelatedQ, "{parentUuid}", parentUuid);
191
- unrelatedQ = replaceFirst(unrelatedQ, "{parentUuid}", parentUuid);
192
- unrelatedQ = replaceFirst(unrelatedQ, "{parentRole}", parentRole);
199
+ unrelatedQ = dbReplaceFirst(unrelatedQ, "{Context_AreaCode}", contextAreaCode);
200
+ unrelatedQ = dbReplaceFirst(unrelatedQ, "{Legacy_AreaCode}", legacyAreaCode);
201
+ unrelatedQ = dbReplaceFirst(unrelatedQ, "{AreaCode}", areaCode );
202
+ unrelatedQ = dbReplaceFirst(unrelatedQ, "{Context_Context_ID}", contextContextId);
203
+ unrelatedQ = dbReplaceFirst(unrelatedQ, "{Legacy_Context_ID}", legacyContextId);
204
+ unrelatedQ = dbReplaceFirst(unrelatedQ, "{Context_ID}", contextId );
205
+ unrelatedQ = dbReplaceFirst(unrelatedQ, "{parentUuid}", parentUuid);
206
+ unrelatedQ = dbReplaceFirst(unrelatedQ, "{parentUuid}", parentUuid);
207
+ unrelatedQ = dbReplaceFirst(unrelatedQ, "{parentRole}", parentRole);
193
208
194
209
relatedQ += getRelatedChildQuery(parentUuid);
195
210
0 commit comments