From fd56ca5ba1de5a89e7979b2c7cbed3b5ea00a23e Mon Sep 17 00:00:00 2001 From: pobel Date: Wed, 27 Nov 2019 17:08:24 +0100 Subject: [PATCH] added state to location search service added weatherstation as device type --- .../mowesta/api/device/OperatingSystem.java | 8 +- .../api/location/ILocationService.java | 74 ++++++++++++++- .../com/mowesta/api/location/Location.java | 2 +- .../java/com/mowesta/api/location/State.java | 95 +++++++++++++++++++ .../com/mowesta/api/location/StateDigest.java | 46 +++++++++ .../mowesta/api/location/StateDigestPage.java | 19 ++++ .../com/mowesta/api/location/StatePage.java | 19 ++++ 7 files changed, 259 insertions(+), 4 deletions(-) create mode 100644 common-api/src/main/java/com/mowesta/api/location/State.java create mode 100644 common-api/src/main/java/com/mowesta/api/location/StateDigest.java create mode 100644 common-api/src/main/java/com/mowesta/api/location/StateDigestPage.java create mode 100644 common-api/src/main/java/com/mowesta/api/location/StatePage.java diff --git a/common-api/src/main/java/com/mowesta/api/device/OperatingSystem.java b/common-api/src/main/java/com/mowesta/api/device/OperatingSystem.java index c3e934de..063359c7 100644 --- a/common-api/src/main/java/com/mowesta/api/device/OperatingSystem.java +++ b/common-api/src/main/java/com/mowesta/api/device/OperatingSystem.java @@ -14,8 +14,12 @@ public enum OperatingSystem { /** * Apple iOS. */ - IOS; - + IOS, + /** + * Weather Station + */ + WEATHER_STATION_OS; + @Override public String toString() { return name().toLowerCase(); diff --git a/common-api/src/main/java/com/mowesta/api/location/ILocationService.java b/common-api/src/main/java/com/mowesta/api/location/ILocationService.java index a7cf90a8..b411accb 100644 --- a/common-api/src/main/java/com/mowesta/api/location/ILocationService.java +++ b/common-api/src/main/java/com/mowesta/api/location/ILocationService.java @@ -67,7 +67,7 @@ public interface ILocationService { @Path("cities") @ApiOperation(value = "Returns a page of cities.", tags = { Tags.DEFAULT, Tags.LOCATION }) @ApiResponses({ - @ApiResponse(code=HttpServletResponse.SC_OK, message="City digest page retrieved successfully.", response=CityPage.class), + @ApiResponse(code=HttpServletResponse.SC_OK, message="City page retrieved successfully.", response=CityPage.class), @ApiResponse(code=HttpServletResponse.SC_BAD_REQUEST, message="Invalid request parameter.") }) @PermitAll @@ -107,4 +107,76 @@ public interface ILocationService { @Produces({MediaType.APPLICATION_JSON}) Response getCityBoundary(@ApiParam(value = "The city id.", required = true) @PathParam("id") @Valid @Min(0) long id); + + + + /** + * Returns a page of states that match the query. + * + * @param pageConfig The page configuration. + * @param context The search context. + * @param term The search term. + * @return A page of users whose name or login contains the search term. + */ + @GET + @Path("states/search") + @ApiOperation(value = "Returns a page of state digests whose name matches the term.", tags = { Tags.DEFAULT, Tags.LOCATION }) + @ApiResponses({ + @ApiResponse(code=HttpServletResponse.SC_OK, message="State digest page retrieved successfully.", response=StateDigestPage.class), + @ApiResponse(code=HttpServletResponse.SC_BAD_REQUEST, message="Invalid request parameter.") + }) + @PermitAll + Response searchStates(@BeanParam @Valid PageConfig pageConfig, @BeanParam @Valid SearchContext context, + @ApiParam(value="The search term.", required=true) @QueryParam("term") @NotNull @Valid String term); + + + /** + * Returns a page of states. + * + * @param pageConfig The page configuration. + * @return A page of states. + */ + @GET + @Path("states") + @ApiOperation(value = "Returns a page of states.", tags = { Tags.DEFAULT, Tags.LOCATION }) + @ApiResponses({ + @ApiResponse(code=HttpServletResponse.SC_OK, message="State page retrieved successfully.", response=StatePage.class), + @ApiResponse(code=HttpServletResponse.SC_BAD_REQUEST, message="Invalid request parameter.") + }) + @PermitAll + Response getStates(@BeanParam @Valid PageConfig pageConfig); + + /** + * Returns a particular state. + * + * @param id The id of the state. + * @return The state, if exits. + */ + @GET + @Path("states/{id: [0-9]+}") + @ApiOperation(value = "Gets a state with a particular id.", tags = {Tags.DEFAULT, Tags.LOCATION}) + @ApiResponses({ + @ApiResponse(code = HttpServletResponse.SC_OK, message = "State retrieved successfully.", response=State.class), + @ApiResponse(code = HttpServletResponse.SC_NOT_FOUND, message = "The state does not exists."), + }) + @PermitAll + Response getState(@ApiParam(value = "The state id.", required = true) @PathParam("id") @Valid @Min(0) long id); + + /** + * Returns a geojson representation of the state boundaries. + * + * @param id The id of the state. + * @return The boundaries of geojson or an error code. + */ + @GET + @Path("state/{id: [0-9]+}/boundary") + @ApiOperation(value = "Gets the state boundary for a state with a particular id.", tags = {Tags.DEFAULT, Tags.LOCATION}) + @ApiResponses({ + @ApiResponse(code = HttpServletResponse.SC_OK, message = "State boundary retrieved successfully.", response=Geometry.class), + @ApiResponse(code = HttpServletResponse.SC_NO_CONTENT, message = "The state boundary are not available."), + @ApiResponse(code = HttpServletResponse.SC_NOT_FOUND, message = "The state does not exist."), + }) + @PermitAll + @Produces({MediaType.APPLICATION_JSON}) + Response getStateBoundary(@ApiParam(value = "The state id.", required = true) @PathParam("id") @Valid @Min(0) long id); } diff --git a/common-api/src/main/java/com/mowesta/api/location/Location.java b/common-api/src/main/java/com/mowesta/api/location/Location.java index 194a3cee..dc2324bb 100644 --- a/common-api/src/main/java/com/mowesta/api/location/Location.java +++ b/common-api/src/main/java/com/mowesta/api/location/Location.java @@ -17,7 +17,7 @@ import io.swagger.annotations.ApiModelProperty; /** * A base class for cities, states and countries to share common * fields. - * + * * @author Marcus */ @XmlRootElement diff --git a/common-api/src/main/java/com/mowesta/api/location/State.java b/common-api/src/main/java/com/mowesta/api/location/State.java new file mode 100644 index 00000000..21337cd8 --- /dev/null +++ b/common-api/src/main/java/com/mowesta/api/location/State.java @@ -0,0 +1,95 @@ +package com.mowesta.api.location; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Represents a state with full details. + * + * @author Sebastian, Tobias + */ +@XmlRootElement +@ApiModel(description = "Represents a state with all details.", parent = Location.class) +public class State extends StateDigest { + + /** + * The timezone of the state. + */ + @NotNull + @XmlAttribute(required = true) + @ApiModelProperty(value = "The timezone of the state.", required = true) + private String timezone; + + /** + * The optional population of the state. + */ + @XmlAttribute(required = false) + @ApiModelProperty(value = "The population of the state.", required = false) + private Integer population; + + /** + * The optional wikipedia entry. + */ + @XmlAttribute(required = false) + @ApiModelProperty(value = "The optional wikipedia entry of the state.", required = false) + private String wikipedia; + + /** + * Returns the timezone. + * + * @return The timezone. + */ + public String getTimezone() { + return timezone; + } + + /** + * Sets the timezone. + * + * @param timezone The timezone to set. + */ + public void setTimezone(String timezone) { + this.timezone = timezone; + } + + /** + * Returns the population. + * + * @return The population. + */ + public Integer getPopulation() { + return population; + } + + /** + * Sets the population. + * + * @param population The population to set. + */ + public void setPopulation(Integer population) { + this.population = population; + } + + /** + * Returns the wikipedia. + * + * @return The wikipedia. + */ + public String getWikipedia() { + return wikipedia; + } + + /** + * Sets the wikipedia. + * + * @param wikipedia The wikipedia to set. + */ + public void setWikipedia(String wikipedia) { + this.wikipedia = wikipedia; + } + +} diff --git a/common-api/src/main/java/com/mowesta/api/location/StateDigest.java b/common-api/src/main/java/com/mowesta/api/location/StateDigest.java new file mode 100644 index 00000000..58bf7a92 --- /dev/null +++ b/common-api/src/main/java/com/mowesta/api/location/StateDigest.java @@ -0,0 +1,46 @@ +package com.mowesta.api.location; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * A minimal data transfer object for a state that only contains + * the fields required for a fancy search interface. + * + * @author Sebastian, Tobias + */ +@XmlRootElement +@ApiModel(description = "Represents the digest of a state.", parent = Location.class) +public class StateDigest extends Location { + + /** + * The country of the state. + */ + @NotNull + @XmlAttribute(required = true) + @ApiModelProperty(value = "The country of the state.", required = true) + private Location country; + + /** + * Returns the country. + * + * @return The country. + */ + public Location getCountry() { + return country; + } + + /** + * Sets the country. + * + * @param country The country to set. + */ + public void setCountry(Location country) { + this.country = country; + } + +} diff --git a/common-api/src/main/java/com/mowesta/api/location/StateDigestPage.java b/common-api/src/main/java/com/mowesta/api/location/StateDigestPage.java new file mode 100644 index 00000000..835ac871 --- /dev/null +++ b/common-api/src/main/java/com/mowesta/api/location/StateDigestPage.java @@ -0,0 +1,19 @@ +package com.mowesta.api.location; + +import com.mowesta.api.Page; +import io.swagger.annotations.ApiModel; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +/** + * A page of state digests. + * + * @author Sebastian, Tobias + */ +@XmlRootElement +@XmlSeeAlso(StateDigest.class) +@ApiModel(description = "Represents a page of state digests.", parent = Page.class) +public class StateDigestPage extends Page { + +} diff --git a/common-api/src/main/java/com/mowesta/api/location/StatePage.java b/common-api/src/main/java/com/mowesta/api/location/StatePage.java new file mode 100644 index 00000000..a43ad7b5 --- /dev/null +++ b/common-api/src/main/java/com/mowesta/api/location/StatePage.java @@ -0,0 +1,19 @@ +package com.mowesta.api.location; + +import com.mowesta.api.Page; +import io.swagger.annotations.ApiModel; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +/** + * A page of states. + * + * @author Sebastian, Tobias + */ +@XmlRootElement +@XmlSeeAlso(State.class) +@ApiModel(description = "Represents a page of states.", parent = Page.class) +public class StatePage extends Page { + +}