use of org.apache.qpid.server.management.plugin.servlet.rest.NotFoundException in project qpid-broker-j by apache.
the class LatestManagementController method getPreferences.
@Override
public Object getPreferences(final ConfiguredObject<?> root, final String category, final List<String> path, final Map<String, List<String>> parameters) throws ManagementException {
Object responseObject;
try {
final List<String> hierarchy = getCategoryHierarchy(root, category);
final Collection<ConfiguredObject<?>> allObjects = getTargetObjects(root, category, path, null);
if (allObjects.isEmpty() && isFullPath(root, path, category)) {
throw createNotFoundManagementException("Not Found");
}
final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(path.subList(0, hierarchy.size()), path.subList(hierarchy.size() + 1, path.size()), parameters);
if (path.contains("*")) {
List<Object> preferencesList = new ArrayList<>(allObjects.size());
responseObject = preferencesList;
for (ConfiguredObject<?> target : allObjects) {
try {
final UserPreferences userPreferences = target.getUserPreferences();
final Object preferences = _userPreferenceHandler.handleGET(userPreferences, requestInfo);
if (preferences == null || (preferences instanceof Collection && ((Collection) preferences).isEmpty()) || (preferences instanceof Map && ((Map) preferences).isEmpty())) {
continue;
}
preferencesList.add(preferences);
} catch (NotFoundException e) {
// The case where the preference's type and name is provided, but this particular object does not
// have a matching preference.
}
}
} else {
final ConfiguredObject<?> target = allObjects.iterator().next();
final UserPreferences userPreferences = target.getUserPreferences();
responseObject = _userPreferenceHandler.handleGET(userPreferences, requestInfo);
}
} catch (RuntimeException e) {
throw ManagementException.toManagementException(e, getCategoryMapping(category), path);
} catch (Error e) {
throw ManagementException.handleError(e);
}
return responseObject;
}
Aggregations