Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAT-7737 retrieve version number from model #250

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>gov.cms.madie</groupId>
<artifactId>madie-java-models</artifactId>
<version>0.6.68-SNAPSHOT</version>
<version>0.6.69-SNAPSHOT</version>
<name>madie-java-models</name>
<description>Java based models for MADiE microservices</description>
<properties>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/gov/cms/madie/models/common/ModelType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Getter
public enum ModelType {
Expand All @@ -14,6 +16,7 @@ public enum ModelType {
private String value;
private String shortValue;
private static final Map<String, ModelType> MODEL_TYPE_BY_VALUE = new HashMap<>();
private static final Pattern VERSION_PATTERN = Pattern.compile("v(\\d+(\\.\\d+)*)");

static {
for (ModelType mt : values()) {
Expand All @@ -33,6 +36,11 @@ public enum ModelType {
this.shortValue = shortValue;
}

public String getVersionNumber() {
Matcher matcher = VERSION_PATTERN.matcher(this.value);
return matcher.find() ? matcher.group(1) : null;
}

@Override
public String toString() {
return this.getValue();
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/gov/cms/madie/models/common/ModelTypeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gov.cms.madie.models.common;

import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

public class ModelTypeTest {
@Test
void testGetModelVersionNumber() {
assertThat(ModelType.QDM_5_6.getVersionNumber(), is(equalTo("5.6")));
assertThat(ModelType.QI_CORE.getVersionNumber(), is(equalTo("4.1.1")));
assertThat(ModelType.QI_CORE_6_0_0.getVersionNumber(), is(equalTo("6.0.0")));
}
}
Loading