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;
}
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;
}
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);
}
}
Aggregations