Search in sources :

Example 1 with UserPreferencesService

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());
    }
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) AnnotationSchemaService(de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) List(java.util.List) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) AnnotationPreference(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Optional(java.util.Optional) UserPreferencesService(de.tudarmstadt.ukp.clarin.webanno.api.annotation.preferences.UserPreferencesService) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) AnnotationPreference(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Aggregations

AnnotationSchemaService (de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService)1 AnnotationPreference (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference)1 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)1 UserPreferencesService (de.tudarmstadt.ukp.clarin.webanno.api.annotation.preferences.UserPreferencesService)1 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)1 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)1 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)1 IOException (java.io.IOException)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 BeansException (org.springframework.beans.BeansException)1