Skip to content

Commit

Permalink
#813 - more package changes to jakarta and spring batch method signat…
Browse files Browse the repository at this point in the history
…ure changes
  • Loading branch information
petmongrels committed Oct 31, 2024
1 parent 8b6872f commit c6f3caa
Show file tree
Hide file tree
Showing 38 changed files with 78 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.NoRepositoryBean;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;

import javax.persistence.QueryHint;
import jakarta.persistence.QueryHint;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import javax.persistence.QueryHint;
import jakarta.persistence.QueryHint;
import jakarta.validation.constraints.NotNull;
import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.NoRepositoryBean;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.Date;
import java.util.Calendar;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root;
import java.util.Date;
import java.util.List;
import java.util.stream.Stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.stereotype.Repository;

import javax.persistence.EntityNotFoundException;
import javax.persistence.QueryHint;
import jakarta.persistence.QueryHint;
import java.util.List;
import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.avni.server.dao.SyncParameters;

import javax.persistence.criteria.From;
import javax.persistence.criteria.Join;
import jakarta.persistence.criteria.From;
import jakarta.persistence.criteria.Join;

public class TransactionDataCriteriaBuilderUtil {
public static Join<Object, Object> joinUserSubjectAssignment(From fromSubject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.stereotype.Repository;

import javax.persistence.criteria.*;
import jakarta.persistence.criteria.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.sql.Types;

public class CHSPostgreSQL94Dialect extends PostgreSQL94Dialect {

private static final String JSONB = "jsonb";
private static final String JSON = "json";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.and()
.addFilter(new AuthenticationFilter(authService, idpType, defaultUserName, avniBlacklistedUrlsFile, errorBodyBuilder))
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
return httpSecurity.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import javax.transaction.Transactional;
import jakarta.validation.constraints.NotNull;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;

Expand Down Expand Up @@ -50,16 +52,16 @@ public JobService(JobExplorer jobExplorer, JobRepository jobRepository, Job impo
public void retryJobsFailedInLast2Hours() throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
for (JobExecution jobExecution : jobExplorer.findRunningJobExecutions(importJob.getName())) {
BatchStatus status = jobExecution.getStatus();
Date lastUpdated = jobExecution.getLastUpdated();
Date nowMinus2Hours = new DateTime().minusHours(2).toDate();
if (nowMinus2Hours.before(lastUpdated) && Arrays.asList(STARTING, STARTED, UNKNOWN).contains(status)) {
LocalDateTime lastUpdated = jobExecution.getLastUpdated();
LocalDateTime nowMinus2Hours = LocalDateTime.now().minusHours(2);
if (nowMinus2Hours.isBefore(lastUpdated) && Arrays.asList(STARTING, STARTED, UNKNOWN).contains(status)) {
jobExecution.upgradeStatus(BatchStatus.FAILED);
jobExecution.setEndTime(new Date());
jobExecution.setEndTime(LocalDateTime.now());
jobRepository.update(jobExecution);
for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
if (Arrays.asList(STARTING, STARTED, UNKNOWN).contains(stepExecution.getStatus())) {
stepExecution.upgradeStatus(BatchStatus.FAILED);
stepExecution.setEndTime(new Date());
stepExecution.setEndTime(LocalDateTime.now());
jobRepository.update(stepExecution);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.avni.server.framework.security.AuthService;
import org.avni.server.importer.batch.model.Row;
import org.springframework.batch.core.configuration.annotation.JobScope;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -57,9 +58,9 @@ private ItemWriter<Row> getWriter() {
}

@Override
public void write(List<? extends Row> rows) throws Exception {
public void write(Chunk<? extends Row> chunk) throws Exception {
authService.authenticateByUserId(userId, organisationUUID);
getWriter().write(rows);
getWriter().write(chunk);
}

public Long getUserId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.avni.server.service.EncounterService;
import org.avni.server.service.ObservationService;
import org.avni.server.service.OrganisationConfigService;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -66,8 +67,8 @@ public EncounterWriter(EncounterRepository encounterRepository,
}

@Override
public void write(List<? extends Row> rows) throws Exception {
for (Row row : rows) write(row);
public void write(Chunk<? extends Row> chunk) throws Exception {
for (Row row : chunk.getItems()) write(row);
}

private void write(Row row) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.avni.server.service.GroupSubjectService;
import org.avni.server.service.HouseholdService;
import org.joda.time.LocalDate;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -55,8 +56,8 @@ public GroupSubjectWriter(GroupSubjectRepository groupSubjectRepository,
}

@Override
public void write(List<? extends Row> rows) throws Exception {
for (Row row : rows) write(row);
public void write(Chunk<? extends Row> chunk) throws Exception {
for (Row row : chunk.getItems()) write(row);
}

private void write(Row row) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.avni.server.importer.batch.model.Row;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -27,11 +28,11 @@ public LocationWriter(BulkLocationCreator bulkLocationCreator, BulkLocationEdito
}

@Override
public void write(List<? extends Row> rows) {
public void write(Chunk<? extends Row> chunk) throws Exception {
if (LocationUploadMode.isCreateMode(locationUploadMode)) {
this.bulkLocationCreator.write(rows, locationHierarchy);
this.bulkLocationCreator.write(chunk.getItems(), locationHierarchy);
} else {
this.bulkLocationEditor.write(rows);
this.bulkLocationEditor.write(chunk.getItems());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.avni.server.service.ObservationService;
import org.avni.server.service.OrganisationConfigService;
import org.avni.server.service.ProgramEncounterService;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -70,8 +71,8 @@ public ProgramEncounterWriter(ProgramEncounterRepository programEncounterReposit
}

@Override
public void write(List<? extends Row> rows) throws Exception {
for (Row row : rows) write(row);
public void write(Chunk<? extends Row> chunk) throws Exception {
for (Row row : chunk.getItems()) write(row);
}

private void write(Row row) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.avni.server.service.OrganisationConfigService;
import org.avni.server.service.ProgramEnrolmentService;
import org.joda.time.LocalDate;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -69,8 +70,8 @@ public ProgramEnrolmentWriter(ProgramEnrolmentRepository programEnrolmentReposit
}

@Override
public void write(List<? extends Row> rows) throws Exception {
for (Row row : rows) write(row);
public void write(Chunk<? extends Row> chunk) throws Exception {
for (Row row : chunk.getItems()) write(row);
}

private void write(Row row) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.joda.time.LocalDate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -76,8 +77,8 @@ public SubjectWriter(IndividualRepository individualRepository,
}

@Override
public void write(List<? extends Row> rows) throws Exception {
for (Row row : rows) write(row);
public void write(Chunk<? extends Row> chunk) throws Exception {
for (Row row : chunk.getItems()) write(row);
}

private void write(Row row) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.avni.server.util.RegionUtil;
import org.avni.server.util.S;
import org.avni.server.web.request.syncAttribute.UserSyncSettings;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -79,7 +80,8 @@ public UserAndCatchmentWriter(CatchmentService catchmentService,

@Transactional(Transactional.TxType.REQUIRES_NEW)
@Override
public void write(List<? extends Row> rows) throws IDPException {
public void write(Chunk<? extends Row> chunk) throws IDPException {
List<? extends Row> rows = chunk.getItems();
if (!CollectionUtils.isEmpty(rows)) {
validateHeaders(rows.get(0).getHeaders());
for (Row row : rows) write(row);
Expand Down
Loading

0 comments on commit c6f3caa

Please sign in to comment.