Skip to content

Commit

Permalink
Merge branch 'openmrs:master' into SDK-306
Browse files Browse the repository at this point in the history
  • Loading branch information
wikumChamith committed Jul 6, 2023
2 parents b9f95eb + 12d3ba5 commit 59af0e3
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
platform: [ ubuntu-latest ]
# version selection strategy: use the LTS support versions
java-version: [ 8, 11 ]
java-version: [ 11 ]

runs-on: ${{ matrix.platform }}
env:
Expand Down
2 changes: 1 addition & 1 deletion archetype-module-platform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openmrs.maven</groupId>
<artifactId>openmrs-sdk</artifactId>
<version>4.7.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<groupId>org.openmrs.maven.archetypes</groupId>
Expand Down
2 changes: 1 addition & 1 deletion archetype-module-refapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openmrs.maven</groupId>
<artifactId>openmrs-sdk</artifactId>
<version>4.7.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<groupId>org.openmrs.maven.archetypes</groupId>
Expand Down
2 changes: 1 addition & 1 deletion archetype-submodule-owa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>openmrs-sdk</artifactId>
<groupId>org.openmrs.maven</groupId>
<version>4.7.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion docker-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>openmrs-sdk</artifactId>
<groupId>org.openmrs.maven</groupId>
<version>4.7.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<artifactId>openmrs-sdk-docker-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openmrs.maven</groupId>
<artifactId>openmrs-sdk</artifactId>
<version>4.7.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<artifactId>openmrs-sdk-integration-tests</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>8</target>
<source>8</source>
<target>11</target>
<source>11</source>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>8</target>
<source>8</source>
<target>11</target>
<source>11</source>
</configuration>
</plugin>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.openmrs.maven</groupId>
<artifactId>openmrs-sdk</artifactId>
<version>4.7.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<groupId>org.openmrs.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public class Setup extends AbstractServerTask {
@Parameter(defaultValue = "false", property = "run")
private boolean run;

@Parameter(property = "spaCoreVersion")
private String spaCoreVersion;

private ServerHelper serverHelper;

public Setup() {
Expand Down Expand Up @@ -211,6 +214,9 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu
File file = distroHelper.downloadDistro(server.getServerDirectory(), artifact);
Properties backendProperties = PropertiesUtils.getDistroProperties(file);
Properties spaModuleProperty = PropertiesUtils.getModuleProperty("https://raw.githubusercontent.com/openmrs/openmrs-module-spa/master/pom.xml");
if(spaCoreVersion != null) {
frontendProperties.setProperty("spa.core", spaCoreVersion);
}
Properties allProperties = new Properties();
allProperties.putAll(backendProperties);
allProperties.putAll(spaModuleProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void installFromDistroProperties(File appDataDir, DistroProperties distro
// Three of these properties are not passed to the build tool, but are used to specify the build execution itself
String coreVersion = spaProperties.remove("core");
if (coreVersion == null) {
coreVersion = "latest";
coreVersion = "next";
}
String nodeVersion = spaProperties.remove("node");
if (nodeVersion == null) {
Expand Down
30 changes: 15 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>org.openmrs.maven</groupId>
<artifactId>openmrs-sdk</artifactId>
<packaging>pom</packaging>
<version>4.7.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>

<name>OpenMRS SDK</name>
<description>OpenMRS SDK allows for rapid development of OpenMRS modules.</description>
Expand Down Expand Up @@ -442,31 +442,31 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
<version>2.16.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.1</version>
<version>3.9.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<version>3.0.1</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
Expand All @@ -479,27 +479,27 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<version>1.6.13</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<version>3.5.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.1.2</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
Expand All @@ -516,7 +516,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -529,7 +529,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<version>3.5.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down
2 changes: 1 addition & 1 deletion sdk-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>openmrs-sdk</artifactId>
<groupId>org.openmrs.maven</groupId>
<version>4.7.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.openmrs.maven.plugins.model;

import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile;
import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromResource;

import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
Expand All @@ -16,13 +13,16 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Properties;
import java.util.UUID;

import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromFile;
import static org.openmrs.maven.plugins.utility.PropertiesUtils.loadPropertiesFromResource;

/**
*
*/
Expand All @@ -34,7 +34,7 @@ public class SdkStatistics {

private Properties statistics = new Properties();

private final DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_FORMAT);

public SdkStatistics createSdkStatsFile(boolean agree) throws MojoExecutionException {
loadStatsFromResource(SDK_STATS_FILE_NAME);
Expand Down Expand Up @@ -64,7 +64,7 @@ private SdkStatistics(Properties statistics) {
}

/**
* Checks if there is more then 7 days since last sendReport. If yes, send statistics
* Checks if there is more than 7 days since last sendReport. If yes, send statistics
* @throws MojoExecutionException
*/
public void sendReport(Wizard wizard) throws MojoExecutionException {
Expand All @@ -85,17 +85,11 @@ public void sendReport(Wizard wizard) throws MojoExecutionException {
* @return
*/
private boolean checkIfOneWeekFromLastReport(){
Date lastReport;
try {
lastReport = getLastReported();
} catch (ParseException e) {
lastReport = null;
}

Date currentDate = new Date();
LocalDate lastReport = getLastReported();
LocalDate currentDate = LocalDate.now();

if (lastReport != null) {
return (currentDate.getTime() - lastReport.getTime()) / (60 * 60 * 1000 * 24) % 60 > 7;
return ChronoUnit.DAYS.between(lastReport, currentDate) > 7;
} else {
return true;
}
Expand Down Expand Up @@ -226,13 +220,12 @@ public boolean getStatsEnabled(){
* Get last date that statistics were reported
* @return
*/
private Date getLastReported() throws ParseException {
private LocalDate getLastReported() {
String statsLastReported = statistics.getProperty("statsLastReported");
if (StringUtils.isBlank(statsLastReported)){
return null;
}

return dateFormat.parse(statsLastReported);
return LocalDate.parse(statsLastReported, dateTimeFormatter);
}

public int getGoalCalls(String goal) {
Expand All @@ -243,17 +236,17 @@ public int getGoalCalls(String goal) {
* Get last date that sdk was used
* @return
*/
private Date getLastUsed() throws ParseException {
private LocalDate getLastUsed() throws ParseException {
String statsLastUsed = statistics.getProperty("statsLastUsed");
return dateFormat.parse(statsLastUsed);
return LocalDate.parse(statsLastUsed, dateTimeFormatter);
}

/**
* Get current date as String
* @return String
*/
private String getDate() {
return dateFormat.format(new Date());
return LocalDate.now().format(dateTimeFormatter);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,37 @@
import org.junit.Test;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Properties;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
*
*/
public class SdkStatisticsTest {

private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-M-yyyy");
private SdkStatistics sdkStatistics;
private Properties statistics;
private Method checkIfOneWeekFromLastReportMethod;

@Before
public void loadStatsFile() throws Exception {
public void before() throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
sdkStatistics = new SdkStatistics(new File(classLoader.getResource("sdk-stats.properties").getFile()));
Field statisticsField = sdkStatistics.getClass().getDeclaredField("statistics");
statisticsField.setAccessible(true);
statistics = (Properties) statisticsField.get(sdkStatistics);
checkIfOneWeekFromLastReportMethod = sdkStatistics.getClass().getDeclaredMethod("checkIfOneWeekFromLastReport");
checkIfOneWeekFromLastReportMethod.setAccessible(true);
}

@Test
Expand All @@ -31,10 +47,30 @@ public void shouldIncrementGoal() {
}

@Test
public void shouldSetStatsEnabledMode(){
public void shouldSetStatsEnabledMode() {
sdkStatistics.setStatsEnabled(true);

assertThat(sdkStatistics.getStatsEnabled(), is(true));
}

@Test
public void checkIfOneWeekApart_LessThanOneWeekApart() throws IllegalAccessException, InvocationTargetException {
statistics.setProperty("statsLastReported", LocalDate.now().minusDays(6).format(dateTimeFormatter));
assertFalse((Boolean) checkIfOneWeekFromLastReportMethod.invoke(sdkStatistics));
}


@Test
public void checkIfOneWeekApart_MoreThanOneWeekApart() throws IllegalAccessException, InvocationTargetException {
statistics.setProperty("statsLastReported", LocalDate.now().minusDays(8).format(dateTimeFormatter));
assertTrue((Boolean) checkIfOneWeekFromLastReportMethod.invoke(sdkStatistics));
}

@Test
public void checkIfOneWeekApart_OneWeekApart() throws IllegalAccessException, InvocationTargetException {
statistics.setProperty("statsLastReported", LocalDate.now().minusDays(7).format(dateTimeFormatter));
assertFalse((Boolean) checkIfOneWeekFromLastReportMethod.invoke(sdkStatistics));
}


}
Loading

0 comments on commit 59af0e3

Please sign in to comment.