Skip to content

Commit

Permalink
Use dynamic application name instead of hardcoded service name for wr…
Browse files Browse the repository at this point in the history
…iting tx
  • Loading branch information
openwms committed Mar 5, 2024
1 parent ad8bbf8 commit e42c370
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/openwms/wms/movements/MovementService.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,8 @@ public interface MovementService {
* @param states A list of states to consider
* @return A list of Movements, never {@literal null}
*/
@NotNull List<MovementVO> findForTuAndTypesAndStates(@NotBlank String barcode, @NotEmpty List<MovementType> types, @NotEmpty List<String> states);
@NotNull List<MovementVO> findForTuAndTypesAndStates(
@NotBlank String barcode,
@NotEmpty List<MovementType> types,
@NotEmpty List<String> states);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.ameba.http.identity.IdentityContextHolder;
import org.ameba.i18n.Translator;
import org.openwms.common.location.api.LocationApi;
import org.openwms.common.location.api.LocationVO;
import org.openwms.common.location.api.messages.LocationMO;
import org.openwms.common.transport.api.commands.TUCommand;
import org.openwms.common.transport.api.messages.TransportUnitMO;
Expand All @@ -30,33 +29,35 @@
import org.openwms.transactions.api.commands.AsyncTransactionApi;
import org.openwms.transactions.api.commands.TransactionCommand;
import org.openwms.wms.movements.spi.common.AsyncTransportUnitApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

import java.util.Optional;

import static org.openwms.transactions.api.commands.TransactionCommand.Type.CREATE;
import static org.openwms.wms.movements.MovementsMessages.LOCATION_NOT_FOUND_BY_ERP_CODE;
import static org.openwms.wms.movements.MovementsMessages.MSG_MOVEMENT_COMPLETED;
import static org.openwms.wms.movements.MovementsMessages.MSG_MOVEMENT_MOVED;

/**
* A TransactionWriter.
* A TransactionWriter is a Spring managed bean, activated with {@value SpringProfiles#ASYNCHRONOUS_PROFILE} profile that takes care of
* writing business transactions via the COMMON Transaction service.
*
* @author Heiko Scherrer
*/
@Profile(SpringProfiles.ASYNCHRONOUS_PROFILE)
@Component
class TransactionWriter {

private final String applicationName;
private final Translator translator;
private final LocationApi locationApi;
private final AsyncTransportUnitApi asyncTransportUnitApi;
private final AsyncTransactionApi asyncTransactionApi;

TransactionWriter(Translator translator, LocationApi locationApi, AsyncTransportUnitApi asyncTransportUnitApi,
TransactionWriter(@Value("${spring.application.name}") String applicationName, Translator translator, LocationApi locationApi, AsyncTransportUnitApi asyncTransportUnitApi,
AsyncTransactionApi asyncTransactionApi) {
this.applicationName = applicationName;
this.translator = translator;
this.locationApi = locationApi;
this.asyncTransportUnitApi = asyncTransportUnitApi;
Expand All @@ -71,7 +72,7 @@ public void onEvent(MovementEvent event) {
TransactionBuilder.aTransactionVO()
.withCreatedByUser(IdentityContextHolder.getCurrentIdentity())
.withCategory(CallContextHolder.getOptionalCallContext().map(CallContext::getCaller).orElse(""))
.withSender("movements-service")
.withSender(applicationName)
.withType(MSG_MOVEMENT_MOVED)
.withDescription(translator.translate(MSG_MOVEMENT_MOVED,
event.getSource().getTransportUnitBk(),
Expand All @@ -88,7 +89,7 @@ public void onEvent(MovementEvent event) {
TransactionBuilder.aTransactionVO()
.withCreatedByUser(IdentityContextHolder.getCurrentIdentity())
.withCategory(CallContextHolder.getOptionalCallContext().map(CallContext::getCaller).orElse(""))
.withSender("movements-service")
.withSender(applicationName)
.withType(MSG_MOVEMENT_COMPLETED)
.withDescription(translator.translate(MSG_MOVEMENT_COMPLETED,
event.getSource().getTransportUnitBk(),
Expand All @@ -107,7 +108,7 @@ public void onEvent(MovementEvent event) {

@TransactionalEventListener
public void onEvent(MovementTargetChangedEvent event) {
Optional<LocationVO> locationByErpCode = locationApi.findByErpCode(event.getSource().getTargetLocation());
var locationByErpCode = locationApi.findByErpCode(event.getSource().getTargetLocation());
if (locationByErpCode.isPresent()) {
asyncTransportUnitApi.process(
TUCommand.newBuilder(TUCommand.Type.CHANGE_TARGET)
Expand Down

0 comments on commit e42c370

Please sign in to comment.