Skip to content

Commit 56f22e0

Browse files
Merge pull request #103 from ral-facilities/handle_missing_mechanisms
Use run.properties before downloadRepository for getDownloadTypeStatuses
2 parents e4d167e + ca3a496 commit 56f22e0

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

src/main/java/org/icatproject/topcat/TransportMap.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ public boolean isAllowed(String facility, String transport, String userName, Ica
137137
}
138138
}
139139

140+
/**
141+
* @param facilityName ICAT Facility.name
142+
* @return Map of transport mechanism (AKA DownloadType) name to details of that mechanism
143+
*/
144+
public HashMap<String, TransportMechanism> getFacilityMapping(String facilityName) {
145+
return mapping.get(facilityName);
146+
}
147+
140148
/**
141149
*
142150
* @param facilityName ICAT Facility.name

src/main/java/org/icatproject/topcat/web/rest/UserResource.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.HashMap;
99
import java.util.List;
1010
import java.util.Map;
11-
11+
import java.util.Map.Entry;
1212

1313
import jakarta.ejb.EJB;
1414
import jakarta.ejb.LocalBean;
@@ -1194,22 +1194,31 @@ public Response getDownloadTypeStatuses(@QueryParam("facilityName") String facil
11941194
IcatClient icatClient = new IcatClient(icatUrl, sessionId);
11951195
String userName = icatClient.getUserName();
11961196
TransportMap transportMap = TransportMap.getInstance();
1197+
HashMap<String, TransportMechanism> facilityMapping = transportMap.getFacilityMapping(facilityName);
11971198

11981199
JsonObjectBuilder responseJson = Json.createObjectBuilder();
1199-
List<DownloadType> downloadTypes = downloadTypeRepository.getDownloadTypes(facilityName);
1200-
for (DownloadType downloadType : downloadTypes) {
1201-
String downloadTypeName = downloadType.getDownloadType();
1202-
if (transportMap.isAllowed(facilityName, downloadTypeName, userName, icatClient)) {
1203-
JsonObjectBuilder downloadTypeBuilder = Json.createObjectBuilder();
1204-
downloadTypeBuilder.add("disabled", downloadType.getDisabled());
1205-
downloadTypeBuilder.add("message", downloadType.getMessage());
1206-
TransportMechanism transportMechanism = transportMap.getTransportMechanism(facilityName, downloadTypeName);
1207-
if (transportMechanism != null) {
1208-
downloadTypeBuilder.add("idsUrl", transportMechanism.idsUrl);
1209-
downloadTypeBuilder.add("displayName", transportMechanism.displayName);
1210-
downloadTypeBuilder.add("description", transportMechanism.description);
1200+
if (facilityMapping != null) {
1201+
for (Entry<String, TransportMechanism> entry : facilityMapping.entrySet()) {
1202+
String downloadTypeName = entry.getKey();
1203+
TransportMechanism transportMechanism = entry.getValue();
1204+
if (transportMap.isAllowed(facilityName, downloadTypeName, userName, icatClient)) {
1205+
JsonObjectBuilder downloadTypeBuilder = Json.createObjectBuilder();
1206+
if (transportMechanism != null) {
1207+
downloadTypeBuilder.add("idsUrl", transportMechanism.idsUrl);
1208+
downloadTypeBuilder.add("displayName", transportMechanism.displayName);
1209+
downloadTypeBuilder.add("description", transportMechanism.description);
1210+
}
1211+
1212+
DownloadType downloadType = downloadTypeRepository.getDownloadType(facilityName, downloadTypeName);
1213+
if (downloadType != null) {
1214+
downloadTypeBuilder.add("disabled", downloadType.getDisabled());
1215+
downloadTypeBuilder.add("message", downloadType.getMessage());
1216+
} else {
1217+
downloadTypeBuilder.add("disabled", false);
1218+
downloadTypeBuilder.add("message", "");
1219+
}
1220+
responseJson.add(downloadTypeName, downloadTypeBuilder);
12111221
}
1212-
responseJson.add(downloadTypeName, downloadTypeBuilder);
12131222
}
12141223
}
12151224

src/test/java/org/icatproject/topcat/UserResourceTest.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -728,13 +728,8 @@ public void testGetDownloadTypeStatuses() throws Exception {
728728
downloadTypeRepository.save(httpType);
729729
httpTypeId = httpType.getId();
730730

731-
DownloadType globusType = new DownloadType();
732-
globusType.setFacilityName("LILS");
733-
globusType.setDownloadType("globus");
734-
globusType.setDisabled(false);
735-
globusType.setMessage("");
736-
downloadTypeRepository.save(globusType);
737-
globusTypeId = globusType.getId();
731+
// Do not create globus in the repository, as when absent the response should assume that it is enabled with
732+
// no message
738733

739734
DownloadType lilsType = new DownloadType();
740735
lilsType.setFacilityName("LILS");
@@ -774,7 +769,6 @@ public void testGetDownloadTypeStatuses() throws Exception {
774769
} finally {
775770
// Remove the entries we created to avoid interference with other tests
776771
downloadTypeRepository.remove(httpTypeId);
777-
downloadTypeRepository.remove(globusTypeId);
778772
downloadTypeRepository.remove(lilsTypeId);
779773
}
780774
}

0 commit comments

Comments
 (0)