Skip to content

Commit

Permalink
Release 3.4.5: Remove unused web endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
dmkeen committed Nov 13, 2024
1 parent a278791 commit 67b6644
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 62 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>org.keen</groupId>
<artifactId>solar</artifactId>
<version>3.4.4</version>
<version>3.4.5</version>

<name>solar</name>
<description>Retrieves solar data from a Fronius inverter and persists it to a data store.</description>
Expand Down Expand Up @@ -104,7 +104,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<excludes>
<!-- Excluding ForecastPersisterIT and ForecastRetrieverIT due to API call limit -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* Retrieves the solar panel output forecasts and persists them
*/
@Profile("!test")
@RestController
@Service
public class ForecastPersister {

@Autowired
Expand All @@ -30,7 +29,6 @@ public void retrieveAndPersistAsync() {
retrieveAndPersist();
}

@PostMapping("/forecast/retrieve")
public void retrieveAndPersist() {
List<GenerationForecast> forecasts = retriever.retrieve();
// Retrieve the id for any existing forecast for the same period so that it gets updated in the database,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.time.*;
Expand All @@ -27,7 +23,6 @@
* See <a href="https://docs.solcast.com.au/#measurements-rooftop-site">Solcast API</a>
*/
@Service
@RestController
public class MeasurementUploader {

private final Logger logger = LoggerFactory.getLogger(MeasurementUploader.class);
Expand All @@ -49,23 +44,6 @@ public MeasurementUploader(RestTemplateBuilder restTemplateBuilder, CurrentPower
this.repository = repository;
}

/**
* Uploads all measurements not yet uploaded to Solcast within the specified date range
*
* @param start start date (inclusive)
* @param end end date (exclusive)
*/
@PostMapping("/upload")
public void uploadByDateRange(@RequestParam("start") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate start,
@RequestParam("end") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate end) {
long startTimestamp = start.atStartOfDay(ZoneOffset.UTC).toEpochSecond();
long endTimestamp = end.atStartOfDay(ZoneOffset.UTC).toEpochSecond();
logger.info(String.format("Retrieving power generation not yet uploaded between %s (%d) and %s (%d)",
start.toString(), startTimestamp, end.toString(), endTimestamp));
List<CurrentPower> currentPowerNotUploaded = repository.findByUploadedAndEpochTimestampBetween(false, startTimestamp, endTimestamp);
doUpload(currentPowerNotUploaded);
}

/**
* Uploads all measurements not yet uploaded to Solcast
*/
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ spring.jackson.deserialization.ADJUST_DATES_TO_CONTEXT_TIME_ZONE=false

# Enable virtual threads
spring.threads.virtual.enabled=true
spring.main.keep-alive=true
spring.main.keep-alive=true

# Disable web server
spring.main.web-application-type=none
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.keen.solar.solcast.measurement;

import org.junit.jupiter.api.Test;
import org.keen.solar.system.dal.CurrentPowerRepository;
import org.keen.solar.system.domain.CurrentPower;
import org.keen.solar.solcast.measurement.domain.Measurement;
import org.mockito.ArgumentCaptor;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.util.Assert;

import java.time.*;
Expand All @@ -17,9 +14,6 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.DoubleStream;

import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

public class MeasurementUploaderTest {

@Test
Expand Down Expand Up @@ -81,33 +75,6 @@ public void givenTwentyMinutesOfCurrentPower_whenConvertToMeasurements_thenConve
}
}

@Test
public void givenDateRange_whenUploadByDateRange_thenCorrectDateRangePassedToRepository() {
// Given
LocalDate startDate = LocalDate.of(2020, 7, 18);
LocalDate endDate = LocalDate.of(2020, 7, 19);
long startDateInUTCEpochSeconds = 1595030400L;
long endDateInUTCEpochSeconds = 1595116800L;

CurrentPowerRepository repository = mock(CurrentPowerRepository.class);
when(repository.findByUploadedAndEpochTimestampBetween(eq(false), anyLong(), anyLong())).thenReturn(new ArrayList<>());
MeasurementUploader measurementUploader = new MeasurementUploader(mock(RestTemplateBuilder.class), repository);

// When
measurementUploader.uploadByDateRange(startDate, endDate);

// Then
ArgumentCaptor<Long> captorStart = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<Long> captorEnd = ArgumentCaptor.forClass(Long.class);
verify(repository).findByUploadedAndEpochTimestampBetween(eq(false), captorStart.capture(), captorEnd.capture());
Long startValue = captorStart.getValue();
Long endValue = captorEnd.getValue();
Assert.state(startValue.equals(startDateInUTCEpochSeconds), String.format("Expected %s to be converted to %d but was %d",
startDate.toString(), startDateInUTCEpochSeconds, startValue));
Assert.state(endValue.equals(endDateInUTCEpochSeconds), String.format("Expected %s to be converted to %d but was %d",
endDate.toString(), endDateInUTCEpochSeconds, endValue));
}

private ArrayList<CurrentPower> generateCurrentPowerList(int listLength, Instant startTime) {
AtomicLong atomicLong = new AtomicLong();
ConcurrentLinkedQueue<CurrentPower> currentPowerQueue = new ConcurrentLinkedQueue<>();
Expand Down

0 comments on commit 67b6644

Please sign in to comment.