Search in sources :

Example 1 with NotFoundException

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;
}
Also used : UserPreferences(org.apache.qpid.server.model.preferences.UserPreferences) ArrayList(java.util.ArrayList) NotFoundException(org.apache.qpid.server.management.plugin.servlet.rest.NotFoundException) RequestInfo(org.apache.qpid.server.management.plugin.servlet.rest.RequestInfo) Collection(java.util.Collection) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 NotFoundException (org.apache.qpid.server.management.plugin.servlet.rest.NotFoundException)1 RequestInfo (org.apache.qpid.server.management.plugin.servlet.rest.RequestInfo)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 UserPreferences (org.apache.qpid.server.model.preferences.UserPreferences)1