Skip to content

Commit

Permalink
Upgrade to Spring Boot 2.0.x (#388)
Browse files Browse the repository at this point in the history
* upgrade to 2.0.x

* findOne() → findById()

* delete() → deleteById()

* save() → saveAll()

* UriUtils.encode no longer throws exception

* update configuration

* upgrade to Flyway 5.0

* fix build file name
  • Loading branch information
jaroldwong authored Nov 13, 2023
1 parent de8b830 commit d7fa9af
Show file tree
Hide file tree
Showing 60 changed files with 87 additions and 138 deletions.
21 changes: 10 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.22.RELEASE")
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.9.RELEASE")
}
}

plugins {
id 'java'
id 'org.springframework.boot' version '1.5.22.RELEASE'
id 'checkstyle'
id 'idea'
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'checkstyle'
apply plugin: 'idea'

checkstyle {
configFile file("checkstyle.xml")
}

jar {
baseName = 'ipa-api'
version = '0.1.0'
bootJar {
archiveBaseName = 'ipa-api'
archiveVersion = '0.1.0'
}

repositories {
Expand Down Expand Up @@ -54,7 +53,7 @@ dependencies {
compile("org.slf4j:slf4j-api:1.7.25")
compile("org.apache.commons:commons-lang3:3.7")
compile("javax.mail:mail:1.4.7")
compile("org.flywaydb:flyway-core:4.2.0")
compile("org.flywaydb:flyway-core:5.0.7")
compile("org.apache.httpcomponents:httpclient:4.5.9")
compile("org.javers:javers-core:2.4.1")
compile("javax.xml.bind:jaxb-api:2.3.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
import org.springframework.data.repository.CrudRepository;

public interface BudgetRepository extends CrudRepository<Budget, Long> {
Budget findById(Long id);

Budget findByScheduleId(Long scheduleId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.List;

public interface BudgetScenarioRepository extends CrudRepository<BudgetScenario, Long> {
BudgetScenario findById(Long id);

BudgetScenario findByBudgetIdAndName(long id, String budgetScenarioName);

@Query( " SELECT DISTINCT bs" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public interface ExpenseItemRepository extends CrudRepository<ExpenseItem, Long>
" AND bs.id = :budgetScenarioId ")
List<ExpenseItem> findByBudgetScenarioId(@Param("budgetScenarioId") Long budgetScenarioId);

ExpenseItem findById(Long expenseItemId);

void deleteById(long expenseItemId);

@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
import org.springframework.data.repository.CrudRepository;

public interface ExpenseItemTypeRepository extends CrudRepository<ExpenseItemType, Long> {
ExpenseItemType findById(long ExpenseItemTypeId);

ExpenseItemType findByDescription(String description);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import java.util.List;

public interface InstructorCostRepository extends CrudRepository<InstructorCost, Long> {
InstructorCost findById(Long lineItemId);

void deleteById(long lineItemId);

List<InstructorCost> findByBudgetId(Long budgetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import edu.ucdavis.dss.ipa.entities.Instructor;

public interface InstructorRepository extends CrudRepository<Instructor, Long> {

Instructor findById(Long id);

Instructor findByUcdStudentSID(String ucdStudentSID);

Instructor findByLoginIdIgnoreCase(String loginId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.List;

public interface InstructorSupportCallResponseRepository extends CrudRepository<InstructorSupportCallResponse, Long> {
InstructorSupportCallResponse findById (long instructorSupportCallResponseId);

List<InstructorSupportCallResponse> findByScheduleId (long scheduleId);

InstructorSupportCallResponse findByScheduleIdAndInstructorIdAndTermCode(long scheduleId, long instructorId, String termCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ public interface InstructorSupportPreferenceRepository extends CrudRepository<In

List<InstructorSupportPreference> findByInstructorId(long instructorId);

InstructorSupportPreference findById(long preferenceId);

List<InstructorSupportPreference> findByInstructorIdAndSectionGroupId(Long instructorId, Long sectionGroupId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import java.util.List;

public interface InstructorTypeCostRepository extends CrudRepository<InstructorTypeCost, Long> {
InstructorTypeCost findById(Long instructorTypeId);

void deleteById(long instructorTypeCostId);

InstructorTypeCost findByInstructorTypeIdAndBudgetId(long instructorTypeId, long budgetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
import org.springframework.data.repository.CrudRepository;

public interface InstructorTypeRepository extends CrudRepository<InstructorType, Long> {
InstructorType findById(Long instructorTypeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@
import java.util.List;

public interface LineItemCategoryRepository extends CrudRepository<LineItemCategory, Long> {
LineItemCategory findById(long lineItemCategoryId);

LineItemCategory findByDescription(String description);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public interface LineItemRepository extends CrudRepository<LineItem, Long> {
" AND b.id = :budgetId ")
List<LineItem> findByBudgetId(@Param("budgetId") Long budgetId);

LineItem findById(Long lineItemId);

void deleteById(long lineItemId);

@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
import org.springframework.data.repository.CrudRepository;

public interface LineItemTypeRepository extends CrudRepository<LineItemType, Long> {
LineItemType findById(long LineItemTypeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
import org.springframework.data.repository.CrudRepository;

public interface ReasonCategoryRepository extends CrudRepository<ReasonCategory, Long> {
ReasonCategory findById(long reasonCategoryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.util.List;

public interface SectionGroupCostInstructorRepository extends CrudRepository<SectionGroupCostInstructor, Long> {
SectionGroupCostInstructor findById(long sectionGroupCostInstructorId);

@Query( " SELECT DISTINCT sgci" +
" FROM SectionGroupCostInstructor sgci, SectionGroupCost sgc, BudgetScenario bs, Budget b" +
" WHERE b.id = :budgetId" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public interface SectionGroupCostRepository extends CrudRepository<SectionGroupC
" AND b.id = :budgetId ")
List<SectionGroupCost> findByBudgetId(@Param("budgetId") Long budgetId);

SectionGroupCost findById(long sectionGroupCostId);

@Query( " SELECT DISTINCT sgc" +
" FROM Schedule s, Workgroup w, Budget b, BudgetScenario bs, SectionGroupCost sgc" +
" WHERE sgc.budgetScenario = bs" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.List;

public interface SectionGroupRepository extends CrudRepository<SectionGroup, Long> {
SectionGroup findById(Long id);

List<SectionGroup> findByCourseScheduleWorkgroupIdAndCourseScheduleYear(long workgroupId, long year);

@Query( " SELECT DISTINCT sg" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import java.util.List;

public interface SectionRepository extends CrudRepository<Section, Long> {

Section findById(Long id);

/**
* Finds sections that do have sections and those sections have the
* visible flag set to true or Null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@
import org.springframework.transaction.annotation.Transactional;

public interface SupportAssignmentRepository extends CrudRepository<SupportAssignment, Long> {

SupportAssignment findById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
import org.springframework.data.repository.CrudRepository;

public interface SupportStaffRepository extends CrudRepository<SupportStaff, Long> {

SupportStaff findById(Long id);

SupportStaff findByLoginIdIgnoreCase(String loginId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
import java.util.List;

public interface TeachingAssignmentRepository extends CrudRepository<TeachingAssignment, Long> {

TeachingAssignment findById(Long id);

TeachingAssignment findOneBySectionGroupAndInstructorAndTermCode(SectionGroup sectionGroup, Instructor instructor, String termCode);

TeachingAssignment findOneByInstructorIdAndScheduleIdAndTermCodeAndBuyoutAndAndCourseReleaseAndSabbaticalAndInResidenceAndWorkLifeBalanceAndLeaveOfAbsenceAndSabbaticalInResidenceAndJointAppointmentAndInterdisciplinaryTeachingAndWorkLoadCredit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public interface UserRepository extends CrudRepository<User, Long> {

User findByToken(String token);

User findById(Long id);

@Query("SELECT u FROM User u WHERE u.loginId LIKE :query% OR u.firstName LIKE :query% OR u.lastName LIKE :query%")
List<User> findByFirstNameOrLastNameOrLoginId(@Param("query") String query);

Expand Down
8 changes: 2 additions & 6 deletions src/main/java/edu/ucdavis/dss/ipa/security/CasEntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ public CasEntryPoint(String preLoginPath, String casLoginUrl, String returnUrl)
public String getReturnUrl() { return returnUrl; }

public String getCasLoginUrl() {
try {
return casLoginUrl + (casLoginUrl.contains("?") ? "&" : "?")
+ ServiceProperties.DEFAULT_CAS_SERVICE_PARAMETER + "=" + UriUtils.encode(getReturnUrl(), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
return casLoginUrl + (casLoginUrl.contains("?") ? "&" : "?")
+ ServiceProperties.DEFAULT_CAS_SERVICE_PARAMETER + "=" + UriUtils.encode(getReturnUrl(), "UTF-8");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public Activity saveActivity(Activity activity) {

@Override
public Activity findOneById(Long id) {
return this.activityRepository.findOne(id);
return this.activityRepository.findById(id).orElse(null);
}

@Override
@Transactional
public void deleteActivityById(Long id) {
activityRepository.delete(id);
activityRepository.deleteById(id);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public BudgetScenario findOrCreate(Budget budget, String budgetScenarioName) {
@Transactional
@Override
public BudgetScenario createFromExisting(Long workgroupId, Long scenarioId, String name, boolean copyFunds) {
BudgetScenario originalBudgetScenario = budgetScenarioRepository.findById(scenarioId);
BudgetScenario originalBudgetScenario = budgetScenarioRepository.findById(scenarioId).orElse(null);

if (originalBudgetScenario == null) {
return null;
Expand Down Expand Up @@ -165,7 +165,7 @@ public BudgetScenario createFromExisting(Long workgroupId, Long scenarioId, Stri
}

public BudgetScenario createBudgetRequestScenario(long workgroupId, long scenarioId) {
BudgetScenario originalScenario = budgetScenarioRepository.findById(scenarioId);
BudgetScenario originalScenario = budgetScenarioRepository.findById(scenarioId).orElse(null);

if (originalScenario == null) { return null; }

Expand Down Expand Up @@ -223,7 +223,7 @@ public BudgetScenario createBudgetRequestScenario(long workgroupId, long scenari

@Override
public BudgetScenario approveBudgetRequestScenario(long workgroupId, long scenarioId) {
BudgetScenario approvedScenario = budgetScenarioRepository.findById(scenarioId);
BudgetScenario approvedScenario = budgetScenarioRepository.findById(scenarioId).orElse(null);

// only one budget request should be approved at a time
List<BudgetScenario> budgetRequestScenarios = budgetScenarioRepository.findbyWorkgroupIdAndYear(workgroupId,
Expand Down Expand Up @@ -370,11 +370,11 @@ private BudgetScenario updateFromLiveData(BudgetScenario liveDataScenario, Boole

@Override
public BudgetScenario findById(long budgetScenarioId) {
return budgetScenarioRepository.findById(budgetScenarioId);
return budgetScenarioRepository.findById(budgetScenarioId).orElse(null);
}

@Override
public void deleteById(long budgetScenarioId) {
budgetScenarioRepository.delete(budgetScenarioId);
budgetScenarioRepository.deleteById(budgetScenarioId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Budget findOrCreateByWorkgroupIdAndYear(long workgroupId, long year) {

@Override
public Budget findById(long budgetId) {
return budgetRepository.findById(budgetId);
return budgetRepository.findById(budgetId).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class JpaCourseService implements CourseService {

@Override
public Course getOneById(Long id) {
return this.courseRepository.findOne(id);
return this.courseRepository.findById(id).orElse(null);
}

private Course save(Course course) {
Expand Down Expand Up @@ -121,7 +121,7 @@ public boolean delete(Long id) {
try {
course.setTags(new ArrayList<Tag>());
this.save(course);
this.courseRepository.delete(id);
this.courseRepository.deleteById(id);

return true;
} catch (EmptyResultDataAccessException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public List<ExpenseItem> findByBudgetScenarioId(Long budgetScenarioId) {

@Override
public ExpenseItem findById(Long expenseItemId) {
return expenseItemRepository.findById(expenseItemId);
return expenseItemRepository.findById(expenseItemId).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public List<ExpenseItemType> findAll() {

@Override
public ExpenseItemType findById(long ExpenseItemTypeId) {
return ExpenseItemTypeRepository.findById(ExpenseItemTypeId);
return ExpenseItemTypeRepository.findById(ExpenseItemTypeId).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public InstructorCost findByInstructorIdAndBudgetId(Long instructorId, Long budg

@Override
public InstructorCost findById(Long lineItemId) {
return instructorCostRepository.findById(lineItemId);
return instructorCostRepository.findById(lineItemId).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Instructor save(Instructor instructor) {

@Override
public Instructor getOneById(Long id) {
return this.instructorRepository.findById(id);
return this.instructorRepository.findById(id).orElse(null);
}

@Override
Expand Down Expand Up @@ -93,7 +93,7 @@ public void removeOrphanedByLoginId(String loginId) {
if (instructor.getTeachingAssignments().size() == 0 &&
instructor.getTeachingCallResponses().size() == 0 &&
instructor.getTeachingCallReceipts().size() == 0) {
instructorRepository.delete(instructor.getId());
instructorRepository.deleteById(instructor.getId());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class JpaInstructorSupportCallResponseService implements InstructorSuppor

@Override
public InstructorSupportCallResponse findOneById(long instructorInstructionalSupportCallResponseId) {
return instructorSupportCallResponseRepository.findById(instructorInstructionalSupportCallResponseId);
return instructorSupportCallResponseRepository.findById(instructorInstructionalSupportCallResponseId).orElse(null);
}

@Override
Expand All @@ -48,7 +48,7 @@ public List<InstructorSupportCallResponse> findByScheduleId(long scheduleId) {

@Override
public void delete(long instructorInstructionalSupportCallResponseId) {
instructorSupportCallResponseRepository.delete(instructorInstructionalSupportCallResponseId);
instructorSupportCallResponseRepository.deleteById(instructorInstructionalSupportCallResponseId);
}

@Override
Expand Down
Loading

0 comments on commit d7fa9af

Please sign in to comment.