Skip to content

Commit

Permalink
Merge branch 'release/2.46.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
msqr committed Oct 18, 2023
2 parents e1e040c + 677dfd5 commit fd0d42c
Show file tree
Hide file tree
Showing 18 changed files with 443 additions and 53 deletions.
2 changes: 1 addition & 1 deletion solarnet/datum/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencyManagement {
}

description = 'SolarNet: Datum'
version = '1.14.0'
version = '1.15.0'

base {
archivesName = 'solarnet-datum'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public String toString() {
if ( sourceIds != null && sourceIds.length > 0 ) {
builder.append("sourceIds=");
builder.append(Arrays.toString(sourceIds));
builder.append(", ");
}
builder.append("mostRecent=");
builder.append(mostRecent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
import java.time.temporal.IsoFields;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Pattern;
import net.solarnetwork.central.datum.export.biz.DatumExportOutputFormatService;

/**
* A complete configuration for a scheduled export job.
*
* @author matt
* @version 1.0
* @version 1.1
* @since 1.23
*/
public interface Configuration {
Expand Down Expand Up @@ -109,6 +110,29 @@ public interface Configuration {
/** A runtime property for a filename extension. */
String PROP_FILENAME_EXTENSION = "ext";

/**
* A runtime property for the configuration name.
*
* @since 1.1
*/
String PROP_JOB_NAME = "jobName";

/**
* A regular expression to remove unfriendly characters from file names
* (like the {@link #PROP_JOB_NAME} parameter).
*
* @since 1.1
*/
Pattern PROP_NAME_SANITIZER = Pattern.compile("(?U)[^\\w\\._-]+");

/**
* A runtime property for the job export process time, as a millisecond Unix
* epoch integer.
*
* @since 1.1
*/
String PROP_CURRENT_TIME = "now";

// @formatter:off
/** A formatter for week, in {@literal YYYY'W'WWD} form. */
DateTimeFormatter WEEK_DATE = new DateTimeFormatterBuilder()
Expand Down Expand Up @@ -164,6 +188,12 @@ default Map<String, Object> createRuntimeProperties(Instant exportTime,
result.put(PROP_FILENAME_EXTENSION, ext);
}

if ( getName() != null ) {
result.put(PROP_JOB_NAME, PROP_NAME_SANITIZER.matcher(getName()).replaceAll("_"));
}

result.put(PROP_CURRENT_TIME, System.currentTimeMillis());

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,18 @@ private void sqlSelect(StringBuilder buf) {
buf.append("SELECT ");
if ( combine != null ) {
buf.append("s.vstream_id AS stream_id,\n");
buf.append(" s.obj_rank,\n");
buf.append(" s.source_rank,\n");
buf.append(" s.names_i,\n");
buf.append(" s.names_a,\n");
if ( aggregation == Aggregation.Week ) {
buf.append(" solarcommon.first(s.obj_rank) AS obj_rank,\n");
buf.append(" solarcommon.first(s.source_rank) AS source_rank,\n");
buf.append(" solarcommon.first(s.names_i) AS names_i,\n");
buf.append(" solarcommon.first(s.names_a) AS names_a,\n");

} else {
buf.append(" s.obj_rank,\n");
buf.append(" s.source_rank,\n");
buf.append(" s.names_i,\n");
buf.append(" s.names_a,\n");
}
} else {
buf.append(" datum.stream_id,\n");
}
Expand Down Expand Up @@ -361,8 +369,14 @@ private void sqlCore(StringBuilder buf, boolean ordered) {
sqlFrom(buf);
sqlWhere(buf);
if ( aggregation == Aggregation.Week ) {
buf.append("GROUP BY ");
if ( combine != null ) {
buf.append("s.vstream_id");
} else {
buf.append("datum.stream_id");
}
buf.append(
"GROUP BY datum.stream_id, date_trunc('week', datum.ts_start AT TIME ZONE s.time_zone) AT TIME ZONE s.time_zone\n");
", date_trunc('week', datum.ts_start AT TIME ZONE s.time_zone) AT TIME ZONE s.time_zone\n");
}
if ( combine != null ) {
if ( isMinuteAggregation() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ filenameTemplate.desc = A template filename to use. \
This template is allowed to contain parameters in the form \
<code>{key}</code>, which are replaced at runtime by the value of a \
parameter <code>key</code>, or an empty string if no such parameter \
exists. The supported parameters are <code>{date}</code> and \
<code>{ext}</code> (file extension).
exists. The supported parameters are: <code>{date}</code>, \
<code>{ext}</code> (file extension), and <code>{jobName}</code> \
(the export job configuration name), and <code>{now}</code> \
(the export process time as a millisecond Unix epoch).
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -181,7 +182,7 @@ private String getObjectKeyPrefix() {

@Test
public void export() throws IOException {
// given
// GIVEN
AmazonS3 client = getS3Client();
cleanS3Folder(client);

Expand All @@ -191,6 +192,7 @@ public void export() throws IOException {
.toInstant();

BasicConfiguration config = new BasicConfiguration();
config.setName(UUID.randomUUID().toString());

BasicDestinationConfiguration destConfig = new BasicDestinationConfiguration();
destConfig.setServiceIdentifier(service.getId());
Expand All @@ -204,7 +206,7 @@ public void export() throws IOException {

DatumExportResource rsrc = getTestResource();

// when
// WHEN
List<Double> progress = new ArrayList<>(8);
service.export(config, Collections.singleton(rsrc), runtimeProps,
new ProgressListener<DatumExportService>() {
Expand All @@ -216,7 +218,7 @@ public void progressChanged(DatumExportService context, double amountComplete) {
}
});

// then
// THEN
assertThat("Progress was made", progress, not(hasSize(0)));
assertThat("Progress complete", progress.get(progress.size() - 1), equalTo((Double) 1.0));

Expand Down
Loading

0 comments on commit fd0d42c

Please sign in to comment.