Skip to content

Commit

Permalink
Merge pull request #99 from urbancamo/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
urbancamo authored Jun 18, 2024
2 parents 3e1d9cb + 03d6443 commit 2359cf5
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 234 deletions.
34 changes: 33 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>uk.m0nom</groupId>
<artifactId>adif-processor</artifactId>
<version>1.4.4</version>
<version>1.4.5</version>

<name>ADIF Processor</name>
<url>https://github.com/urbancamo/adif-processor</url>
Expand Down Expand Up @@ -64,6 +64,17 @@
</distributionManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
Expand Down Expand Up @@ -318,12 +329,21 @@
<spring.profiles.active>dev</spring.profiles.active>
</properties>
</profile>

<profile>
<id>test</id>
<properties>
<spring.profiles.active>test</spring.profiles.active>
</properties>
</profile>

<profile>
<id>prod</id>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
</profile>

<profile>
<id>release</id>
<build>
Expand Down Expand Up @@ -441,6 +461,7 @@
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -451,10 +472,21 @@
</configuration>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
</build>
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/uk/m0nom/adifproc/adif3/Adif3Transformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import org.springframework.stereotype.Service;
import uk.m0nom.adifproc.adif3.contacts.Qsos;
import uk.m0nom.adifproc.adif3.control.TransformControl;
import uk.m0nom.adifproc.file.InternalFileService;
import uk.m0nom.adifproc.domain.Log;
import uk.m0nom.adifproc.db.LogRepository;
import uk.m0nom.adifproc.adif3.transform.CommentParsingAdifRecordTransformer;
import uk.m0nom.adifproc.adif3.transform.MyCallsignCheck;
import uk.m0nom.adifproc.adif3.transform.MyCallsignCheckResults;
Expand All @@ -27,15 +28,10 @@
* Main entry into the Adif3 Transformer functionality.
*/
@Service
@AllArgsConstructor
public class Adif3Transformer {
private final CommentParsingAdifRecordTransformer transformer;

private final InternalFileService fileService;

public Adif3Transformer(CommentParsingAdifRecordTransformer transformer, InternalFileService fileService) {
this.transformer = transformer;
this.fileService = fileService;
}
private LogRepository logRepository;

public Qsos transform(Adif3 log, TransformControl control, TransformResults results, ProgressFeedbackHandlerCallback progressFeedbackHandlerCallback, String sessionId) throws UnsupportedHeaderException {
Qsos qsos = new Qsos(log);
Expand All @@ -47,7 +43,8 @@ public Qsos transform(Adif3 log, TransformControl control, TransformResults resu
int theirCallsignIssues = 0;

MyCallsignCheckResults callsigns = MyCallsignCheck.checkForSingleMyCallsign(log);
fileService.logUserAccess(callsigns.getCallsignsForUserLog());
Log logRecord = new Log(callsigns.getCallsignsForUserLog());
logRepository.save(logRecord);

// LOTW export can contain a single APP field that needs stripping as the record isn't valid for processing
log.setRecords(stripLotwEofRecordIfPresent(log.getRecords()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

import com.amihaiemil.eoyaml.Yaml;
import com.amihaiemil.eoyaml.YamlMapping;
import lombok.Getter;
import org.springframework.context.annotation.Configuration;
import uk.m0nom.FileProcessorApplication;

import java.io.IOException;
import java.io.InputStream;

@Getter
@Configuration
public class TransformerConfig {
private final static String configFilePath = "adif-processor.yaml";

private final YamlMapping config;

public TransformerConfig() throws IOException {
InputStream configStream = FileProcessorApplication.class.getClassLoader().
InputStream configStream = TransformerConfig.class.getClassLoader().
getResourceAsStream(configFilePath);

config = Yaml.createYamlInput(configStream).readYamlMapping();
}

public YamlMapping getConfig() { return config; }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package uk.m0nom.adifproc.adif3.transform;

import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.marsik.ham.adif.Adif3Record;
import org.springframework.stereotype.Service;
import uk.m0nom.adifproc.adif3.contacts.Qso;
import uk.m0nom.adifproc.coords.GlobalCoords3D;
import uk.m0nom.adifproc.coords.LocationAccuracy;
Expand All @@ -15,14 +17,12 @@
/**
* Populate our output ADIF record wih information obtained from QRZ.COM
*/
@Service
@AllArgsConstructor
public class AdifQrzEnricher {
private static final Logger logger = Logger.getLogger(AdifQrzEnricher.class.getName());

private final QrzService qrzService;

public AdifQrzEnricher(QrzService qrzService) {
this.qrzService = qrzService;
}
private final QrzService cachingQrzXmlService;

public static String getNameFromQrzData(QrzCallsign qrzData) {
String name = "";
Expand Down Expand Up @@ -51,7 +51,7 @@ public void enrichAdifForMe(Adif3Record rec, QrzCallsign qrzData) {
}
}

public void enrichAdifForThem(TransformResults results, Adif3Record rec, QrzCallsign qrzData) {
public void enrichAdifForThem(Adif3Record rec, QrzCallsign qrzData) {
if (qrzData == null) {
return;
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public void lookupLocationFromQrz(Qso qso) {
String callsign = rec.getCall();

if (callsignData == null) {
callsignData = qrzService.getCallsignData(callsign);
callsignData = cachingQrzXmlService.getCallsignData(callsign);
qso.getTo().setQrzInfo(callsignData);
}

Expand All @@ -99,7 +99,7 @@ public void lookupLocationFromQrz(Qso qso) {
} else if (CallsignUtils.isPortable(callsign)) {
// Try stripping off any portable callsign information and querying that as a last resort
String fixedCallsign = callsign.substring(0, StringUtils.lastIndexOf(callsign, "/"));
callsignData = qrzService.getCallsignData(fixedCallsign);
callsignData = cachingQrzXmlService.getCallsignData(fixedCallsign);
if (callsignData != null) {
logger.info(String.format("Retrieved %s from QRZ.COM using FIXED station callsign %s", callsign, fixedCallsign));
qso.getTo().setQrzInfo(callsignData);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.m0nom.adifproc.adif3.transform;

import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.marsik.ham.adif.Adif3Record;
Expand All @@ -18,14 +19,11 @@
import uk.m0nom.adifproc.adif3.contacts.Qsos;
import uk.m0nom.adifproc.adif3.control.TransformControl;
import uk.m0nom.adifproc.adif3.transform.comment.CommentTransformer;
import uk.m0nom.adifproc.adif3.transform.comment.FieldParserCommentTransformer;
import uk.m0nom.adifproc.adif3.transform.comment.SchemaBasedCommentTransformer;
import uk.m0nom.adifproc.coords.GlobalCoords3D;
import uk.m0nom.adifproc.coords.LocationAccuracy;
import uk.m0nom.adifproc.coords.LocationSource;
import uk.m0nom.adifproc.geocoding.GeocodingProvider;
import uk.m0nom.adifproc.geocoding.GeocodingResult;
import uk.m0nom.adifproc.geocoding.NominatimGeocodingProvider;
import uk.m0nom.adifproc.location.FromLocationDeterminer;
import uk.m0nom.adifproc.location.ToLocationDeterminer;
import uk.m0nom.adifproc.maidenheadlocator.MaidenheadLocatorConversion;
Expand All @@ -43,6 +41,7 @@
import static uk.m0nom.adifproc.adif3.transform.AdifQrzEnricher.getNameFromQrzData;

@Service
@AllArgsConstructor
public class CommentParsingAdifRecordTransformer implements Adif3RecordTransformer {
private static final Logger logger = Logger.getLogger(CommentParsingAdifRecordTransformer.class.getName());

Expand All @@ -57,28 +56,6 @@ public class CommentParsingAdifRecordTransformer implements Adif3RecordTransform
private final CommentTransformer schemaBasedCommentTransformer;
private final ApSatelliteService apSatelliteService;


public CommentParsingAdifRecordTransformer(ActivityDatabaseService activities,
CachingQrzXmlService qrzXmlService,
SchemaBasedCommentTransformer schemaBasedCommentTransformer,
FieldParserCommentTransformer fieldParserCommentTransformer,
FromLocationDeterminer fromLocationDeterminer,
ToLocationDeterminer toLocationDeterminer,
ActivityProcessor activityProcessor,
NominatimGeocodingProvider geocodingProvider,
ApSatelliteService apSatelliteService) {
this.activities = activities;
this.qrzXmlService = qrzXmlService;
this.enricher = new AdifQrzEnricher(qrzXmlService);
this.apSatelliteService = apSatelliteService;
this.fromLocationDeterminer = fromLocationDeterminer;
this.toLocationDeterminer = toLocationDeterminer;
this.activityProcessor = activityProcessor;
this.geocodingProvider = geocodingProvider;
this.fieldParserCommentTransformer = fieldParserCommentTransformer;
this.schemaBasedCommentTransformer = schemaBasedCommentTransformer;
}

private void processSotaRef(Qso qso, TransformResults results) {
Adif3Record rec = qso.getRecord();

Expand Down Expand Up @@ -166,11 +143,11 @@ private void setMyInfoFromQrz(TransformControl control, Qso qso) {
enricher.enrichAdifForMe(qso.getRecord(), myQrzData);
}

private QrzCallsign setTheirInfoFromQrz(TransformResults transformResults, Qso qso) {
private QrzCallsign setTheirInfoFromQrz(Qso qso) {
/* Load QRZ.COM info for the worked station as a fixed station, for information */
QrzCallsign theirQrzData = qrzXmlService.getCallsignData(qso.getTo().getCallsign());
qso.getTo().setQrzInfo(theirQrzData);
enricher.enrichAdifForThem(transformResults, qso.getRecord(), theirQrzData);
enricher.enrichAdifForThem(qso.getRecord(), theirQrzData);
return theirQrzData;
}

Expand Down Expand Up @@ -272,7 +249,7 @@ public void transform(TransformControl control, TransformResults results, Qsos q

qso.getFrom().setAntenna(control.getAntenna());
setMyInfoFromQrz(control, qso);
QrzCallsign theirQrzData = setTheirInfoFromQrz(results, qso);
QrzCallsign theirQrzData = setTheirInfoFromQrz(qso);

// We first use the schema based transformer...
schemaBasedCommentTransformer.transformComment(qso, rec.getComment(), unmapped, results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Data
Expand Down Expand Up @@ -31,7 +33,9 @@ public String getSingleStationCallsign() {
}

public String getCallsignsForUserLog() {
return String.join(", ",operators)
.concat(String.join(", ", stationCallsigns));
List<String> callsigns = new ArrayList<>();
callsigns.addAll(operators);
callsigns.addAll(stationCallsigns);
return String.join(", ",callsigns);
}
}
10 changes: 10 additions & 0 deletions src/main/java/uk/m0nom/adifproc/db/LogRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package uk.m0nom.adifproc.db;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import uk.m0nom.adifproc.domain.Log;

@Repository
public interface LogRepository extends JpaRepository<Log, Long> {
Log findByCallsign(String callsign);
}
27 changes: 27 additions & 0 deletions src/main/java/uk/m0nom/adifproc/domain/Log.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package uk.m0nom.adifproc.domain;

import jakarta.persistence.*;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;

import java.sql.Timestamp;

@Entity
@RequiredArgsConstructor
@Data
public class Log {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;

private String callsign;

@Column(nullable = false, updatable = false)
@CreationTimestamp
private Timestamp timestamp;

public Log(String callsign) {
this.callsign = callsign;
}
}
Loading

0 comments on commit 2359cf5

Please sign in to comment.