Skip to content

Commit

Permalink
[MODAUD-174] - Fixed Code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
azizbekxm committed Nov 9, 2023
1 parent 3a35fb9 commit dbaaf9f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@
public class OrderEventsDaoImpl implements OrderEventsDao {

private static final Logger LOGGER = LogManager.getLogger();

private static final String TABLE_NAME = "acquisition_order_log";

private static final String GET_BY_ORDER_ID_SQL = "SELECT id, action, order_id, user_id, event_date, action_date, modified_content_snapshot," +
" (SELECT count(*) AS total_records FROM %s WHERE order_id = $1) FROM %s WHERE order_id = $1 %s LIMIT $2 OFFSET $3";

private static final String INSERT_SQL = "INSERT INTO %s (id, action, order_id, user_id, event_date, action_date, modified_content_snapshot)" +
" VALUES ($1, $2, $3, $4, $5, $6, $7)";

@Autowired
private final PostgresClientFactory pgClientFactory;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,13 @@
public class OrderLineEventsDaoImpl implements OrderLineEventsDao {

private static final Logger LOGGER = LogManager.getLogger();

private static final String TABLE_NAME = "acquisition_order_line_log";

private static final String GET_BY_ORDER_LINE_ID_SQL = "SELECT id, action, order_id, order_line_id, user_id, event_date, action_date, modified_content_snapshot," +
" (SELECT count(*) AS total_records FROM %s WHERE order_line_id = $1) " +
" FROM %s WHERE order_line_id = $1 %s LIMIT $2 OFFSET $3";

private static final String INSERT_SQL = "INSERT INTO %s (id, action, order_id, order_line_id, user_id, event_date, action_date, modified_content_snapshot) " +
"VALUES ($1, $2, $3, $4, $5, $6, $7, $8)";

@Autowired
private final PostgresClientFactory pgClientFactory;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ public class AuditDataAcquisitionImpl implements AuditDataAcquisition {

private static final Logger LOGGER = LogManager.getLogger();

@Autowired
private OrderAuditEventsService orderAuditEventsService;
@Autowired
private OrderLineAuditEventsService orderLineAuditEventsService;
@Autowired
private PieceAuditEventsService pieceAuditEventsService;
private final OrderAuditEventsService orderAuditEventsService;
private final OrderLineAuditEventsService orderLineAuditEventsService;
private final PieceAuditEventsService pieceAuditEventsService;

public AuditDataAcquisitionImpl() {
@Autowired
public AuditDataAcquisitionImpl(OrderAuditEventsService orderAuditEventsService,
OrderLineAuditEventsService orderLineAuditEventsService,
PieceAuditEventsService pieceAuditEventsService) {
this.orderAuditEventsService = orderAuditEventsService;
this.orderLineAuditEventsService = orderLineAuditEventsService;
this.pieceAuditEventsService = pieceAuditEventsService;
SpringContextUtil.autowireDependencies(this, Vertx.currentContext());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class PieceAuditEventsServiceImpl implements PieceAuditEventsService {
private static final Logger LOGGER = LogManager.getLogger();
private static final String UNIQUE_CONSTRAINT_VIOLATION_CODE = "23505";
private PieceEventsDao pieceEventsDao;
private final PieceEventsDao pieceEventsDao;

@Autowired
public PieceAuditEventsServiceImpl(PieceEventsDao pieceEventsDao) {
Expand All @@ -40,15 +40,9 @@ public Future<PieceAuditEventCollection> getAuditEventsByPieceId(String pieceId,

private <T> Future<T> handleFailures(Throwable throwable, String id) {
LOGGER.debug("handleFailures:: Handling Failures with id={}", id);
return (throwable instanceof PgException && ((PgException) throwable).getCode().equals(UNIQUE_CONSTRAINT_VIOLATION_CODE)) ?
return (throwable instanceof PgException pgException && pgException.getCode().equals(UNIQUE_CONSTRAINT_VIOLATION_CODE)) ?
Future.failedFuture(new DuplicateEventException(String.format("Event with id=%s is already processed.", id))) :
Future.failedFuture(throwable);
}

private <T> Future<T> handleFailuress(Throwable throwable, String id) {
LOGGER.debug("handleFailures:: Handling Failures with Id : {}", id);
return (throwable instanceof PgException && ((PgException) throwable).getCode().equals(UNIQUE_CONSTRAINT_VIOLATION_CODE)) ?
Future.failedFuture(new DuplicateEventException(String.format("Event with Id=%s is already processed.", id))) :
Future.failedFuture(throwable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
@Component
public class PieceEventConsumersVerticle extends AbstractConsumersVerticle {

private final KafkaConfig kafkaConfig;
private final AsyncRecordHandler<String, String> orderLineEventsHandler;

@Autowired
private KafkaConfig kafkaConfig;
@Autowired
private AsyncRecordHandler<String, String> orderLineEventsHandler;
public PieceEventConsumersVerticle(KafkaConfig kafkaConfig, AsyncRecordHandler<String, String> orderLineEventsHandler) {
this.kafkaConfig = kafkaConfig;
this.orderLineEventsHandler = orderLineEventsHandler;
}

@Override
public List<String> getEvents() {
Expand Down
35 changes: 35 additions & 0 deletions ramls/acquisition-events.raml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,38 @@ traits:
example:
strict: false
value: !include raml-util/examples/errors.sample

/piece/{id}/unique-status:
get:
description: Get list of piece events by piece_id
is: [
pageable,
validate
]
queryParameters:
sortBy:
description: "sorting by field: actionDate"
type: string
default: action_date
sortOrder:
description: "sort order: asc or desc"
enum: [asc, desc]
type: string
default: desc
limit:
default: 2147483647
offset:
default: 0
responses:
200:
body:
application/json:
type: piece-audit-event-collection
500:
description: "Internal server error"
body:
application/json:
type: errors
example:
strict: false
value: !include raml-util/examples/errors.sample

0 comments on commit dbaaf9f

Please sign in to comment.