Skip to content

Commit

Permalink
feature/heightmap-scanner; persist coordinateXYZ in specific columns …
Browse files Browse the repository at this point in the history
…+ entity fields; configured logging (dev)
  • Loading branch information
svencc committed Nov 11, 2023
1 parent b70b69e commit 9cb985e
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 42 deletions.
8 changes: 4 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# TODO LIST

* Refactor Coordinates (in client necessary? probably not)
* Cache Reset Map Exists!
* TODO/BUG MapMetaDataService.mapExists cache gets not deleted after map was imported!

* tidy up unfinished MapTransactions @Scheduled

* ParallelTaskExecutor

* TODO/BUG MapMetaDataService.mapExists cache gets not deleted after map was imported!


* map scanner, forest heatmap, military heatmap, industrial heatmap, civil heatmap
* x heatmaps generator
* unit scanner: run regularly
* persist?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;

import java.util.Locale;
import java.util.TimeZone;

@Slf4j
@Configuration
public class LocaleLoggerConfiguration implements AsyncConfigurer {
public class LocaleLoggerConfiguration {

@PostConstruct
public void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;

import java.util.Locale;
import java.util.TimeZone;

@Slf4j
@Configuration
public class TimezoneLoggerConfiguration implements AsyncConfigurer {
public class TimezoneLoggerConfiguration {

@PostConstruct
public void init() {
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/com/recom/entity/MapEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.data.domain.Persistable;

import java.io.Serializable;
import java.math.BigDecimal;

@Getter
@Setter
Expand All @@ -22,7 +23,12 @@
@Index(name = "IDX_mapName_prefabName", columnList = "mapName, prefabName", unique = false),
@Index(name = "IDX_mapName_resourceName", columnList = "mapName, resourceName", unique = false),
@Index(name = "IDX_mapName_mapDescriptorType", columnList = "mapName, mapDescriptorType", unique = false),
@Index(name = "IDX_mapName_name", columnList = "mapName, name", unique = false)
@Index(name = "IDX_mapName_name", columnList = "mapName, name", unique = false),
@Index(name = "IDX_mapName_coordinates", columnList = "mapName, coordinateX, coordinateY, coordinateZ", unique = false),
@Index(name = "IDX_mapName_coordinateX", columnList = "mapName, coordinateX", unique = false),
@Index(name = "IDX_mapName_coordinateY", columnList = "mapName, coordinateY", unique = false),
@Index(name = "IDX_mapName_coordinateZ", columnList = "mapName, coordinateZ", unique = false),
@Index(name = "IDX_mapName_coordinate_map", columnList = "mapName, coordinateX, coordinateZ,", unique = false)
})
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
Expand Down Expand Up @@ -56,11 +62,7 @@ public class MapEntity implements Persistable<Long>, Serializable, MapLocatedEnt
@Lob
@Nationalized
@Column(insertable = true, updatable = false, nullable = true)
private String resourceName; // -> @ TODO add reference to classification table?

// @ManyToOne
// @JoinColumn(name="resourceType", nullable=true)
// private ResourceType resourceType;
private String resourceName;

@Column(insertable = true, updatable = false, nullable = true)
private String mapDescriptorType;
Expand All @@ -81,11 +83,21 @@ public class MapEntity implements Persistable<Long>, Serializable, MapLocatedEnt
@Column(insertable = true, updatable = false, nullable = true)
private String coordinates;

@Column(insertable = true, updatable = false, nullable = true)
private BigDecimal coordinateX;

@Column(insertable = true, updatable = false, nullable = true)
private BigDecimal coordinateY;

@Column(insertable = true, updatable = false, nullable = true)
private BigDecimal coordinateZ;

@Override
public int hashCode() {
return MapEntity.class.hashCode();
}


@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/recom/entity/MapTopographyEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.data.domain.Persistable;

import java.io.Serializable;
import java.math.BigDecimal;

@Getter
@Setter
Expand All @@ -18,7 +19,11 @@
@AllArgsConstructor
@Table(indexes = {
@Index(name = "IDX_mapName", columnList = "mapName", unique = false),
@Index(name = "IDX_mapName_coordinates", columnList = "mapName, coordinates", unique = true)
@Index(name = "IDX_mapName_coordinates", columnList = "mapName, coordinateX, coordinateY, coordinateZ", unique = true),
@Index(name = "IDX_mapName_coordinateX", columnList = "mapName, coordinateX", unique = false),
@Index(name = "IDX_mapName_coordinateY", columnList = "mapName, coordinateY", unique = false),
@Index(name = "IDX_mapName_coordinateZ", columnList = "mapName, coordinateZ", unique = false),
@Index(name = "IDX_mapName_coordinate_map", columnList = "mapName, coordinateX, coordinateZ,", unique = false)
})
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
Expand Down Expand Up @@ -46,6 +51,16 @@ public class MapTopographyEntity implements Persistable<Long>, Serializable, Map
@Column(insertable = true, updatable = false, nullable = true)
private String coordinates;

@Column(insertable = true, updatable = false, nullable = true)
private BigDecimal coordinateX;

@Column(insertable = true, updatable = false, nullable = true)
private BigDecimal coordinateY;

@Column(insertable = true, updatable = false, nullable = true)
private BigDecimal coordinateZ;


@Override
public int hashCode() {
return MapTopographyEntity.class.hashCode();
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/recom/event/BaseRecomEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@
@Slf4j
public abstract class BaseRecomEventListener {

protected void logEvent(@NonNull final RecomAsyncEvent event) {
protected void infoEvent(@NonNull final RecomAsyncEvent event) {
log.info("****** handle ASYNCHRONOUS {} created {}", event.getClass().getSimpleName(), event.getCreationDate());
}
protected void debugEvent(@NonNull final RecomAsyncEvent event) {
log.debug("****** handle ASYNCHRONOUS {} created {}", event.getClass().getSimpleName(), event.getCreationDate());
}
protected void traceEvent(@NonNull final RecomAsyncEvent event) {
log.trace("****** handle ASYNCHRONOUS {} created {}", event.getClass().getSimpleName(), event.getCreationDate());
}

protected void logEvent(@NonNull final RecomSyncEvent event) {
protected void infoEvent(@NonNull final RecomSyncEvent event) {
log.info("****** handle SYNCHRONOUS {} created {}", event.getClass().getSimpleName(), event.getCreationDate());
}
protected void debugEvent(@NonNull final RecomSyncEvent event) {
log.debug("****** handle SYNCHRONOUS {} created {}", event.getClass().getSimpleName(), event.getCreationDate());
}
protected void traceEvent(@NonNull final RecomSyncEvent event) {
log.trace("****** handle SYNCHRONOUS {} created {}", event.getClass().getSimpleName(), event.getCreationDate());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CacheResetEventListener extends BaseRecomEventListener {
@EventListener(classes = CacheResetAsyncEvent.class)
public void handleCacheResetAsyncEvent(@NonNull final CacheResetAsyncEvent event) {
clearAllCaches();
logEvent(event);
debugEvent(event);
}

private void clearAllCaches() {
Expand All @@ -40,7 +40,7 @@ private void clearAllCaches() {
@EventListener(classes = CacheResetSyncEvent.class)
public void handleCacheResetSyncEvent(@NonNull final CacheResetSyncEvent event) {
clearAllCaches();
logEvent(event);
debugEvent(event);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.recom.event.event.async.map.addmappackage.AddMapPackageAsyncEvent;
import com.recom.event.event.async.map.commit.CommitMapTransactionAsyncEvent;
import com.recom.event.event.async.map.open.OpenMapTransactionAsyncEvent;
import com.recom.event.listener.generic.TransactionalMapPackageBaseEventListener;
import com.recom.event.listener.generic.TransactionalMapPackageBaseEventListenerBase;
import com.recom.mapper.MapEntityMapper;
import com.recom.persistence.mapEntity.MapEntityPersistenceLayer;
import com.recom.service.map.MapTransactionValidatorService;
Expand All @@ -20,7 +20,7 @@

@Slf4j
@Component
public class MapEntityScannerTransactionEventListener extends TransactionalMapPackageBaseEventListener<TransactionalMapEntityPackageDto, MapEntity, MapEntityDto> {
public class MapEntityScannerTransactionEventListener extends TransactionalMapPackageBaseEventListenerBase<TransactionalMapEntityPackageDto, MapEntity, MapEntityDto> {

public MapEntityScannerTransactionEventListener(
@NonNull final TransactionTemplate transactionTemplate,
Expand All @@ -34,21 +34,21 @@ public MapEntityScannerTransactionEventListener(
@Async("AsyncMapTransactionExecutor")
@EventListener(classes = OpenMapTransactionAsyncEvent.class)
public void handleOpenTransactionEvent(@NonNull final OpenMapTransactionAsyncEvent event) {
logEvent(event);
infoEvent(event);
handleOpenTransaction(event.getTransactionIdentifierDto());
}

@Async("AsyncMapTransactionExecutor")
@EventListener(classes = AddMapPackageAsyncEvent.class)
public void handleAddMapPackageEvent(@NonNull final AddMapPackageAsyncEvent event) {
logEvent(event);
traceEvent(event);
handleAddMapPackage(event.getTransactionalMapEntityPackage());
}

@Async("AsyncMapTransactionExecutor")
@EventListener(classes = CommitMapTransactionAsyncEvent.class)
public void handleCommitTransactionEvent(@NonNull final CommitMapTransactionAsyncEvent event) {
logEvent(event);
infoEvent(event);
handleCommitTransaction(event.getTransactionIdentifierDto());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.recom.event.event.async.map.addmappackage.AddMapTopographyPackageAsyncEvent;
import com.recom.event.event.async.map.commit.CommitMapTopographyTransactionAsyncEvent;
import com.recom.event.event.async.map.open.OpenMapTopographyTransactionAsyncEvent;
import com.recom.event.listener.generic.TransactionalMapPackageBaseEventListener;
import com.recom.event.listener.generic.TransactionalMapPackageBaseEventListenerBase;
import com.recom.mapper.MapTopographyEntityMapper;
import com.recom.persistence.mapTopographyEntity.MapTopographyEntityPersistenceLayer;
import com.recom.service.map.MapTransactionValidatorService;
Expand All @@ -20,7 +20,7 @@

@Slf4j
@Component
public class MapTopographyEntityScannerTransactionEventListener extends TransactionalMapPackageBaseEventListener<TransactionalMapTopographyEntityPackageDto, MapTopographyEntity, MapTopographyEntityDto> {
public class MapTopographyEntityScannerTransactionEventListener extends TransactionalMapPackageBaseEventListenerBase<TransactionalMapTopographyEntityPackageDto, MapTopographyEntity, MapTopographyEntityDto> {

public MapTopographyEntityScannerTransactionEventListener(
@NonNull final TransactionTemplate transactionTemplate,
Expand All @@ -34,21 +34,21 @@ public MapTopographyEntityScannerTransactionEventListener(
@Async("AsyncMapTopographyTransactionExecutor")
@EventListener(classes = OpenMapTopographyTransactionAsyncEvent.class)
public void handleOpenTransactionEvent(@NonNull final OpenMapTopographyTransactionAsyncEvent event) {
logEvent(event);
debugEvent(event);
handleOpenTransaction(event.getTransactionIdentifierDto());
}

@Async("AsyncMapTopographyTransactionExecutor")
@EventListener(classes = AddMapTopographyPackageAsyncEvent.class)
public void handleAddMapPackageEvent(@NonNull final AddMapTopographyPackageAsyncEvent event) {
logEvent(event);
traceEvent(event);
handleAddMapPackage(event.getTransactionalMapEntityPackage());
}

@Async("AsyncMapTopographyTransactionExecutor")
@EventListener(classes = CommitMapTopographyTransactionAsyncEvent.class)
public void handleCommitTransactionEvent(@NonNull final CommitMapTopographyTransactionAsyncEvent event) {
logEvent(event);
debugEvent(event);
handleCommitTransaction(event.getTransactionIdentifierDto());
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/recom/event/listener/generic/MapLocatedDto.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
package com.recom.event.listener.generic;

import lombok.NonNull;

import java.math.BigDecimal;
import java.util.List;

public interface MapLocatedDto {

List<BigDecimal> getCoordinates();

void setCoordinates(@NonNull final List<BigDecimal> coordinates);

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
package com.recom.event.listener.generic;

import lombok.NonNull;
import org.springframework.lang.Nullable;

import java.math.BigDecimal;

public interface MapLocatedEntity {

void setMapName(@Nullable final String mapName);

String getMapName();

String getCoordinates();

void setCoordinates(@NonNull final String coordinates);

BigDecimal getCoordinateX();

void setCoordinateX(@NonNull final BigDecimal coordinateX);

BigDecimal getCoordinateY();

void setCoordinateY(@NonNull final BigDecimal coordinateY);

BigDecimal getCoordinateZ();

void setCoordinateZ(@NonNull final BigDecimal coordinateZ);

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
@Slf4j
@RequiredArgsConstructor
public abstract class TransactionalMapPackageBaseEventListener<
public abstract class TransactionalMapPackageBaseEventListenerBase<
PACKAGE_TYPE extends TransactionalMapEntityPackable<DTO_TYPE>,
ENTITY_TYPE extends MapLocatedEntity,
DTO_TYPE extends MapLocatedDto>
Expand All @@ -49,13 +49,13 @@ protected void handleOpenTransaction(@NonNull final TransactionIdentifierDto tra
final MapTransaction<DTO_TYPE, PACKAGE_TYPE> existingTransaction = transactions.get(sessionIdentifier);
resetSession(existingTransaction);
existingTransaction.setOpenTransactionIdentifier(transactionIdentifier);
log.debug("Re-Open / clear transaction named {}!", transactionIdentifier.getSessionIdentifier());
log.info("Re-Open / clear transaction named {}!", transactionIdentifier.getSessionIdentifier());
} else {
final MapTransaction<DTO_TYPE, PACKAGE_TYPE> newTransaction = MapTransaction.<DTO_TYPE, PACKAGE_TYPE>builder()
.openTransactionIdentifier(transactionIdentifier)
.build();
transactions.put(sessionIdentifier, newTransaction);
log.debug("Open new transaction named {}!", transactionIdentifier.getSessionIdentifier());
log.info("Open new transaction named {}!", transactionIdentifier.getSessionIdentifier());
}
}

Expand All @@ -70,7 +70,7 @@ protected void handleAddMapPackage(@NonNull final PACKAGE_TYPE transactionalMapE
if (transactions.containsKey(sessionIdentifier)) {
final MapTransaction<DTO_TYPE, PACKAGE_TYPE> existingTransaction = transactions.get(sessionIdentifier);
existingTransaction.getPackages().add(transactionalMapEntityPackage);
log.debug("Added map entity package to transaction named {}!", sessionIdentifier);
log.trace("Added map entity package to transaction named {}!", sessionIdentifier);

// EDGE CASE: If transaction is already committed, process it immediately
// Try to process already committed transaction, in case that transaction-commit-message took over a data package!
Expand All @@ -93,7 +93,7 @@ protected void handleCommitTransaction(@NonNull final TransactionIdentifierDto t
if (transactions.containsKey(sessionIdentifier)) {
final MapTransaction<DTO_TYPE, PACKAGE_TYPE> existingTransaction = transactions.get(sessionIdentifier);
if (existingTransaction.getCommitTransactionIdentifier() == null) {
log.debug("Commit transaction named {}!", transactionIdentifier.getSessionIdentifier());
log.info("Commit transaction named {}!", transactionIdentifier.getSessionIdentifier());
existingTransaction.setCommitTransactionIdentifier(transactionIdentifier);
processTransaction(sessionIdentifier);
} else {
Expand All @@ -108,18 +108,20 @@ private boolean processTransaction(@NonNull final String sessionIdentifier) {
if (transactions.containsKey(sessionIdentifier)) {
final MapTransaction<DTO_TYPE, PACKAGE_TYPE> existingTransaction = transactions.get(sessionIdentifier);
if (mapTransactionValidator.isValidTransaction(existingTransaction)) {
log.debug("Process transaction named {}!", sessionIdentifier);
log.info("Process transaction named {}!", sessionIdentifier);
final List<ENTITY_TYPE> distinctEntities = existingTransaction.getPackages().stream()
.flatMap(packageDto -> packageDto.getEntities().stream())
.distinct()
.map(entityMapper::toEntity)
.peek(mapEntity -> mapEntity.setMapName(sessionIdentifier))
.collect(Collectors.toList());

log.info("... persist {} entities.", distinctEntities.size());

final Boolean transactionExecuted = transactionTemplate.execute(status -> {
entityPersistenceLayer.deleteMapEntities(sessionIdentifier);
entityPersistenceLayer.saveAll(distinctEntities);
log.debug("Transaction named {} persisted!", sessionIdentifier);
log.info("Transaction named {} persisted!", sessionIdentifier);

return true;
});
Expand Down
Loading

0 comments on commit 9cb985e

Please sign in to comment.