Skip to content

Commit

Permalink
Merge pull request #4662 from inception-project/bugfix/4602-Project-s…
Browse files Browse the repository at this point in the history
…pecific-user-preferences-may-be-saved-without-a-user

#4602 - Project-specific user preferences may be saved without a user
  • Loading branch information
reckart authored Mar 25, 2024
2 parents adedf78 + eee64f7 commit a7209a1
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Queue;

Expand All @@ -37,16 +36,12 @@
import de.tudarmstadt.ukp.clarin.webanno.api.annotation.preferences.UserPreferencesService;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
import de.tudarmstadt.ukp.clarin.webanno.model.Mode;
import de.tudarmstadt.ukp.inception.rendering.coloring.ColoringRules;
import de.tudarmstadt.ukp.inception.rendering.coloring.ColoringService;
import de.tudarmstadt.ukp.inception.rendering.coloring.ColoringStrategy;
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotationPreference;
import de.tudarmstadt.ukp.inception.rendering.pipeline.RenderStep;
import de.tudarmstadt.ukp.inception.rendering.request.RenderRequest;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VDocument;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VObject;
import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService;
import de.tudarmstadt.ukp.inception.schema.api.adapter.TypeAdapter;

/**
* <p>
Expand Down Expand Up @@ -88,7 +83,7 @@ public String getId()
@Override
public void render(VDocument aVDoc, RenderRequest aRequest)
{
Optional<AnnotationPreference> prefs = getPreferences(aRequest);
var prefs = getPreferences(aRequest);

if (prefs.isEmpty()) {
return;
Expand All @@ -105,9 +100,9 @@ public void render(VDocument aVDoc, RenderRequest aRequest)
.sorted(comparing(AnnotationLayer::getId)) //
.collect(toList());

Map<String[], Queue<String>> colorQueues = new HashMap<>();
for (AnnotationLayer layer : sortedLayers) {
ColoringStrategy coloringStrategy = aRequest.getColoringStrategyOverride()
var colorQueues = new HashMap<String[], Queue<String>>();
for (var layer : sortedLayers) {
var coloringStrategy = aRequest.getColoringStrategyOverride()
.orElse(coloringService.getStrategy(layer, prefs.get(), colorQueues));

// If the layer is not included in the rendering, then we skip here - but only after
Expand All @@ -118,13 +113,13 @@ public void render(VDocument aVDoc, RenderRequest aRequest)
continue;
}

TypeAdapter typeAdapter = schemaService.getAdapter(layer);
var typeAdapter = schemaService.getAdapter(layer);

ColoringRules coloringRules = typeAdapter.getTraits(ColoringRulesTrait.class)
var coloringRules = typeAdapter.getTraits(ColoringRulesTrait.class)
.map(ColoringRulesTrait::getColoringRules) //
.orElse(null);

for (VObject vobj : aVDoc.objects(layer.getId())) {
for (var vobj : aVDoc.objects(layer.getId())) {
vobj.setColorHint(
coloringStrategy.getColor(vobj, vobj.getLabelHint(), coloringRules));
}
Expand All @@ -141,7 +136,7 @@ private Optional<AnnotationPreference> getPreferences(RenderRequest aRequest)
if (userPreferencesService != null) {
try {
return Optional.of(userPreferencesService.loadPreferences(aRequest.getProject(),
aRequest.getAnnotationUser().getUsername(), Mode.ANNOTATION));
aRequest.getSessionOwner().getUsername(), Mode.ANNOTATION));
}
catch (IOException e) {
LOG.error("Cannot load annotation preferences: {}", getRootCauseMessage(e), e);
Expand Down

0 comments on commit a7209a1

Please sign in to comment.