Search in sources :

Example 1 with RequestInfo

use of org.apache.qpid.server.management.plugin.servlet.rest.RequestInfo in project qpid-broker-j by apache.

the class LatestManagementController method deletePreferences.

@Override
public int deletePreferences(final ConfiguredObject<?> root, final String category, final List<String> names, final Map<String, List<String>> parameters) throws ManagementException {
    int counter = 0;
    try {
        final List<String> hierarchy = getCategoryHierarchy(root, category);
        final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(names.subList(0, hierarchy.size()), names.subList(hierarchy.size() + 1, names.size()), parameters);
        final Collection<ConfiguredObject<?>> objects = getTargetObjects(root, category, requestInfo.getModelParts(), buildFilterPredicates(parameters));
        if (objects == null) {
            throw createNotFoundManagementException("Not Found");
        }
        // TODO: define format how to report the results for bulk delete, i.e. how to report individual errors and success statuses
        if (objects.size() > 1) {
            throw createBadRequestManagementException("Deletion of user preferences using wildcards is unsupported");
        }
        for (ConfiguredObject o : objects) {
            _userPreferenceHandler.handleDELETE(o.getUserPreferences(), requestInfo);
            counter++;
        }
    } catch (RuntimeException e) {
        throw ManagementException.toManagementException(e, getCategoryMapping(category), names);
    } catch (Error e) {
        throw ManagementException.handleError(e);
    }
    return counter;
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) RequestInfo(org.apache.qpid.server.management.plugin.servlet.rest.RequestInfo)

Example 2 with RequestInfo

use of org.apache.qpid.server.management.plugin.servlet.rest.RequestInfo 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)

Example 3 with RequestInfo

use of org.apache.qpid.server.management.plugin.servlet.rest.RequestInfo in project qpid-broker-j by apache.

the class LatestManagementController method setPreferences.

@Override
public void setPreferences(final ConfiguredObject<?> root, final String category, final List<String> path, final Object providedObject, final Map<String, List<String>> parameters, final boolean isPost) throws ManagementException {
    try {
        final List<String> hierarchy = getCategoryHierarchy(root, category);
        final RequestInfo requestInfo = RequestInfo.createPreferencesRequestInfo(path.subList(0, hierarchy.size()), path.subList(hierarchy.size() + 1, path.size()), parameters);
        final ConfiguredObject<?> target = getTarget(root, category, requestInfo.getModelParts());
        if (isPost) {
            _userPreferenceHandler.handlePOST(target, requestInfo, providedObject);
        } else {
            _userPreferenceHandler.handlePUT(target, requestInfo, providedObject);
        }
    } catch (RuntimeException e) {
        throw ManagementException.toManagementException(e, getCategoryMapping(category), path);
    } catch (Error e) {
        throw ManagementException.handleError(e);
    }
}
Also used : RequestInfo(org.apache.qpid.server.management.plugin.servlet.rest.RequestInfo)

Aggregations

RequestInfo (org.apache.qpid.server.management.plugin.servlet.rest.RequestInfo)3 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)2 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 UserPreferences (org.apache.qpid.server.model.preferences.UserPreferences)1