use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.preferences.UserPreferencesService in project webanno by webanno.
the class PreferencesUtil method loadPreferences.
/**
* Set annotation preferences of users for a given project such as window size, annotation
* layers,... reading from the file system.
*
* @param aAnnotationService
* the annotation service.
* @param aState
* The {@link AnnotatorState} that will be populated with preferences from the file
* @param aUsername
* The {@link User} for whom we need to read the preference (preferences are stored
* per user)
*
* @throws BeansException
* hum?
* @throws IOException
* hum?
*/
public static void loadPreferences(UserPreferencesService aPrefService, AnnotationSchemaService aAnnotationService, AnnotatorState aState, String aUsername) throws BeansException, IOException {
AnnotationPreference preference = aPrefService.loadPreferences(aState.getProject(), aUsername, aState.getMode());
aState.setPreferences(preference);
// set layers according to preferences
List<AnnotationLayer> allLayers = aAnnotationService.listAnnotationLayer(aState.getProject());
aState.setAllAnnotationLayers(allLayers);
aState.setAnnotationLayers(allLayers.stream().filter(l -> !Token.class.getName().equals(l.getName())).filter(l -> l.isEnabled()).filter(l -> !preference.getHiddenAnnotationLayerIds().contains(l.getId())).collect(Collectors.toList()));
// set default layer according to preferences
Optional<AnnotationLayer> defaultLayer = aState.getAnnotationLayers().stream().filter(layer -> Objects.equals(layer.getId(), preference.getDefaultLayer())).findFirst();
if (defaultLayer.isPresent()) {
aState.setDefaultAnnotationLayer(defaultLayer.get());
aState.setSelectedAnnotationLayer(defaultLayer.get());
}
}
Aggregations