use of org.apache.qpid.server.model.preferences.UserPreferencesImpl in project qpid-broker-j by apache.
the class PreferencesRecoverer method setUserPreferences.
private void setUserPreferences(ConfiguredObject<?> associatedObject, Map<UUID, Collection<PreferenceRecord>> objectToRecordMap, PreferenceStore preferenceStore, final Set<UUID> corruptedRecords) {
final Collection<PreferenceRecord> preferenceRecords = objectToRecordMap.remove(associatedObject.getId());
Collection<Preference> recoveredPreferences = new ArrayList<>();
if (preferenceRecords != null) {
for (PreferenceRecord preferenceRecord : preferenceRecords) {
Map<String, Object> attributes = preferenceRecord.getAttributes();
try {
Preference recoveredPreference = PreferenceFactory.fromAttributes(associatedObject, attributes);
validateRecoveredPreference(recoveredPreference);
recoveredPreferences.add(recoveredPreference);
} catch (IllegalArgumentException e) {
LOGGER.info(String.format("Cannot recover preference '%s/%s'", preferenceRecord.getId(), attributes.get(Preference.NAME_ATTRIBUTE)), e);
corruptedRecords.add(preferenceRecord.getId());
}
}
}
associatedObject.setUserPreferences(new UserPreferencesImpl(_executor, associatedObject, preferenceStore, recoveredPreferences));
if (!(associatedObject instanceof PreferencesRoot)) {
Collection<Class<? extends ConfiguredObject>> childrenCategories = associatedObject.getModel().getChildTypes(associatedObject.getCategoryClass());
for (Class<? extends ConfiguredObject> childCategory : childrenCategories) {
Collection<? extends ConfiguredObject> children = associatedObject.getChildren(childCategory);
for (ConfiguredObject<?> child : children) {
setUserPreferences(child, objectToRecordMap, preferenceStore, corruptedRecords);
}
}
}
}
use of org.apache.qpid.server.model.preferences.UserPreferencesImpl in project qpid-broker-j by apache.
the class PreferencesTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
final String objectName = getTestName();
_testObject = _model.getObjectFactory().create(TestSingleton.class, Collections.<String, Object>singletonMap(ConfiguredObject.NAME, objectName), null);
_preferenceTaskExecutor = new CurrentThreadTaskExecutor();
_preferenceTaskExecutor.start();
PreferenceStore preferenceStore = mock(PreferenceStore.class);
_testObject.setUserPreferences(new UserPreferencesImpl(_preferenceTaskExecutor, _testObject, preferenceStore, Collections.<Preference>emptySet()));
_testSubject = TestPrincipalUtils.createTestSubject(TEST_USERNAME);
}
use of org.apache.qpid.server.model.preferences.UserPreferencesImpl in project qpid-broker-j by apache.
the class RestUserPreferenceHandlerTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
_configuredObject = mock(ConfiguredObject.class);
_preferenceStore = mock(PreferenceStore.class);
_preferenceTaskExecutor = new CurrentThreadTaskExecutor();
_preferenceTaskExecutor.start();
_userPreferences = new UserPreferencesImpl(_preferenceTaskExecutor, _configuredObject, _preferenceStore, Collections.<Preference>emptyList());
_subject = TestPrincipalUtils.createTestSubject(MYUSER, MYGROUP);
_groupPrincipal = _subject.getPrincipals(GroupPrincipal.class).iterator().next();
_userPrincipal = _subject.getPrincipals(AuthenticatedPrincipal.class).iterator().next();
when(_configuredObject.getUserPreferences()).thenReturn(_userPreferences);
}
Aggregations