Skip to content

Commit

Permalink
Fix #1561: Refactor CreateDeviceRequest#platform into enum
Browse files Browse the repository at this point in the history
  • Loading branch information
banterCZ committed Jan 29, 2024
1 parent 750b1ab commit b742e37
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 33 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@
<bcprov-jdk18on.version>1.77</bcprov-jdk18on.version>
<zxing.version>3.5.2</zxing.version>
<passay.version>1.6.4</passay.version>

<!-- Documentation Dependencies -->
<springdoc-openapi-starter-webmvc-ui.version>2.3.0</springdoc-openapi-starter-webmvc-ui.version>
<swagger-annotations-jakarta.version>2.2.20</swagger-annotations-jakarta.version>

<guava.version>33.0.0-jre</guava.version>
<moneta.version>1.4.2</moneta.version>
<owasp-java-html-sanitizer.version>20220608.1</owasp-java-html-sanitizer.version>
Expand Down Expand Up @@ -293,6 +297,12 @@
<scope>provided</scope>
</dependency>

<!-- Documentation -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations-jakarta</artifactId>
<version>${swagger-annotations-jakarta.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
5 changes: 5 additions & 0 deletions powerauth-mtoken-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>

<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations-jakarta</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,41 @@
*/
package io.getlime.security.powerauth.lib.mtoken.model.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

/**
* Request to register for sending push messages.
* @author Petr Dvorak, [email protected]
*/
@Getter
@Setter
public class PushRegisterRequest {

private String platform;
private String token;

/**
* Get mobile platform - "ios" / "android".
* @return Mobile platform.
* Platform
*/
public String getPlatform() {
return platform;
}
@NotNull
@Schema(description = "Platform.")
private Platform platform;

/**
* Set mobile platform - "ios" / "android".
* @param platform Mobile platform.
*
*/
public void setPlatform(String platform) {
this.platform = platform;
}
@NotBlank
@Schema(description = "Push registration token.")
private String token;

/**
* Get push registration token.
* @return Push registration token.
*/
public String getToken() {
return token;
}
public enum Platform {
@JsonProperty("ios")
IOS,

/**
* Set push registration token.
* @param token Push registration token.
*/
public void setToken(String token) {
this.token = token;
@JsonProperty("android")
ANDROID
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ private Response registerDeviceImpl(@RequestBody ObjectRequest<PushRegisterReque
}

// Get the values from the request
String platform = requestObject.getPlatform();
String token = requestObject.getToken();

// Check if the context is authenticated - if it is, add activation ID.
Expand All @@ -154,13 +153,9 @@ private Response registerDeviceImpl(@RequestBody ObjectRequest<PushRegisterReque
throw new PushRegistrationFailedException();
}

// Register the device and return response
MobilePlatform p = MobilePlatform.Android;
if ("ios".equalsIgnoreCase(platform)) {
p = MobilePlatform.iOS;
}
final MobilePlatform platform = convert(requestObject.getPlatform());
try {
boolean result = pushServerClient.createDevice(applicationId, token, p, activationId);
boolean result = pushServerClient.createDevice(applicationId, token, platform, activationId);
if (result) {
logger.info("Push registration succeeded, user ID: {}", apiAuthentication.getUserId());
return new Response();
Expand All @@ -174,4 +169,11 @@ private Response registerDeviceImpl(@RequestBody ObjectRequest<PushRegisterReque
}
}

private static MobilePlatform convert(final PushRegisterRequest.Platform source) {
return switch (source) {
case IOS -> MobilePlatform.IOS;
case ANDROID -> MobilePlatform.ANDROID;
};
}

}

0 comments on commit b742e37

Please sign in to comment.