Skip to content

GSIP 111

Jody Garnett edited this page Mar 21, 2016 · 4 revisions

GSIP 111 GetLegendGraphicsRequest Cleanup

Overview

Replace HashMaps in GetLegendGraphicsRequest with a data structure

Proposed By

Jody Garnett

Assigned to Release

The release that this proposal will be implemented for 2.8.

State

Choose one of:

  • Under Discussion
  • In Progress
  • Completed
  • Rejected,
  • Deferred

Motivation

In looking at pull request 400 (adding external graphics to GetCapabilities and GetLegendGraphics) i.e. became obvious that more state needed to be passed from the GetLegendGraphicKvpReader to BufferedImageLegendGraphicBuilder.

Rather than add additional HashMaps I have collected what was already there and cleaned it up. This results in an API change so a proposal is required.

Proposal

API Change

Prior to this proposal GetLegendGraphicRequest data structure looks like this:

class GetLegendGraphicsRequest {
  List<FeatureType> layers;
  List<Style> styles;
  List<String> rules;
  Map<Name,String> titles;
  Map<Name,String> legends; // pending

  // accessors
  List<FeatureType> getLayers();
  void setLayers( List<FeatureType> layers );
  List<Style> getStyles();
  void setStyles(List<Style> styles);
  void setStyle( Style style);
  ...
}

After this proposal:

class GetLegendGraphicsRequest {
  public class LegendRequest {
    Name layerName;        
    FeatureType featureType;
    String styleName;
    String title;
    String rule;
    Style style;
    LegendInfo legendInfo;
    LayerInfo layerInfo;
    LayerGroupInfo layerGroupInfo;

    LegendRequest(); // placeholder used for style
    LegendRequest(Featuretype featureType );
    // accessors
  }

  List<LegendRequest> layers;

  // accessors
  List<LegendRequest> getLegends();
  void setStyle( Style style);

  // deprecated accessors
  List<FeatureType> getLayers();
  void setLayers( List<FeatureType> layers );
  List<Style> getStyles();
  void setStyles(List<Style> styles);
}

Refactor

Introduction of this data structure results in both GetLegendGraphicKvpReader and BufferedImageLegendGraphicBuilder being easier to follow and document.

This is just an initial cleanup, there are opportunities for further simplification not covered by this proposal.

Notes:

  • Use of a placeholder LegendRequest provided to allow for GetLegendGraphics code to preview Style
  • Single “layer” methods, such as setStyle above, were marked as unnecessary in the code. I am maintaining them as they are used in test cases.
  • The order in which GetLegendGraphicsRequest is filled in is significant (layers must be created before styles and titles are set). This is now made clear in javadocs.
  • Experimented with using a LinkedHashMap<Name,LegendRequest> but code inspection showed that this information was always accessed in order.

Feedback

This section should contain feedback provided by PSC members who may have a problem with the proposal.

Backwards Compatibility

Several accessors (for style, title and similar) are no longer used and have been deprecated. Compatibility was maintained (now implemented in terms of List).

Voting

  • Alessio Fabiani:
  • Andrea Aime:
  • Ben Caradoc Davies: +1
  • Christian Mueller:
  • Gabriel Roldan: +1
  • Jody Garnett: +1
  • Jukka Rahkonen: +0
  • Justin Deoliveira:
  • Phil Scadden: +1
  • Simone Giannecchini: +0

Links

Previous:

Clone this wiki locally