Skip to content

Commit

Permalink
Upgrade Spring and Jackson depencency versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikbjork committed Jun 15, 2022
1 parent 3c781f8 commit b018105
Show file tree
Hide file tree
Showing 29 changed files with 98 additions and 125 deletions.
2 changes: 1 addition & 1 deletion core-bc/composites/db-migration-svc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.7</version>
<version>2.13.3</version>
</dependency>


Expand Down
18 changes: 3 additions & 15 deletions core-bc/composites/svc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,19 @@
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.1.4.RELEASE</version>
<version>5.5.2</version>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.1.4.RELEASE</version>
<version>5.5.2</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.0.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>2.6.1.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
<version>2.6.1.RELEASE</version>
<version>2.5.5</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private <T> List<T> query(Class<T> clazz, String jpql, Pageable pageable, List w
}

if (pageable != null) {
typedQuery.setFirstResult(pageable.getOffset()).setMaxResults(pageable.getPageSize());
typedQuery.setFirstResult((int) pageable.getOffset()).setMaxResults(pageable.getPageSize());
}
List<T> results = typedQuery.getResultList();
return results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Page<Prodn3> findProdn3s(Set<Integer> notInProdn3Ids, Collection<Prodn2>
TypedQuery<Prodn3> typedQuery = entityManager.createQuery(criteriaQuery);

if (pageable != null) {
typedQuery.setFirstResult(pageable.getOffset()).setMaxResults(pageable.getPageSize());
typedQuery.setFirstResult((int) pageable.getOffset()).setMaxResults(pageable.getPageSize());
}

List<Prodn3> resultList = typedQuery.getResultList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public boolean hasRole(Authentication authentication, String role) {
static ThreadLocal<User> currentUser = new ThreadLocal<>();

public boolean hasProdn1Access(Authentication authentication, Prodn1 prodn1) {
User user = userRepository.findOne((String) authentication.getPrincipal());
User user = userRepository.findById((String) authentication.getPrincipal()).orElse(null);
currentUser.set(user);
return Role.ADMIN.equals(user.getRole()) || user.getProdn1s().contains(prodn1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import se.vgregion.arbetsplatskoder.domain.jpa.ArchivedData;
Expand All @@ -15,6 +16,7 @@
import se.vgregion.arbetsplatskoder.repository.DataRepository;

import java.io.IOException;
import java.util.Optional;

@Component
public class DataOperations {
Expand Down Expand Up @@ -42,21 +44,21 @@ public class DataOperations {

@Transactional(value = "exportTransactionManager")
public void unexport(Integer withThatId) {
dataExportRepository.delete(withThatId);
viewApkForSesamLmnRepository.delete(withThatId.longValue());
viewapkHsaidRepository.delete(withThatId);
viewapkwithao3Repository.delete(withThatId);
dataExportRepository.deleteById(withThatId);
viewApkForSesamLmnRepository.deleteById(withThatId.longValue());
viewapkHsaidRepository.deleteById(withThatId);
viewapkwithao3Repository.deleteById(withThatId);
}

@Transactional
public Data saveAndArchive(Data that) {
ObjectMapper mapper = new ObjectMapper();

try {
Data currentlyStoredData = dataRepository.findOne(that.getId());
Optional<Data> currentlyStoredData = dataRepository.findById(that.getId());

if (currentlyStoredData != null) {
String json = mapper.writeValueAsString(currentlyStoredData);
if (currentlyStoredData.isPresent()) {
String json = mapper.writeValueAsString(currentlyStoredData.get());

ArchivedData archivedData = mapper.readValue(json, ArchivedData.class);

Expand All @@ -81,7 +83,7 @@ public void export(Data that) {
if (viewapkforsesamlmn.isOkToAppearInExportView()) {
viewApkForSesamLmnRepository.save(viewapkforsesamlmn);
} else {
if (viewApkForSesamLmnRepository.exists(viewapkforsesamlmn.getId())) {
if (viewApkForSesamLmnRepository.existsById(viewapkforsesamlmn.getId())) {
viewApkForSesamLmnRepository.delete(viewapkforsesamlmn);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public User loginWithoutPassword(String username) throws FailedLoginException {
try {
return login(username, null, false);
} catch (Exception e) {
return userRepository.findOne(username);
return userRepository.findById(username).orElse(null);
}
}

public User loginOffline(String username) throws FailedLoginException {
return userRepository.findOne(username);
return userRepository.findById(username).orElse(null);
}

private User login(String username, String password, boolean verifyPassword) throws FailedLoginException {
Expand All @@ -81,14 +81,14 @@ private User login(String username, String password, boolean verifyPassword) thr
user.setDisplayName("Admin");
user.setRole(Role.ADMIN);

if (userRepository.findOne(user.getId()) == null) {
if (userRepository.findById(user.getId()).isEmpty()) {
userRepository.save(user);
}

return user;
}

if (userRepository.findOne(username) == null) {
if (userRepository.findById(username).isEmpty()) {
throw new FailedLoginException("The user is not registered in the application.");
}

Expand Down Expand Up @@ -186,7 +186,7 @@ private InitialDirContext createInitialDirContext() throws NamingException {

private User syncUser(User user) throws NamingException {

User foundUser = userRepository.findOne(user.getId());
User foundUser = userRepository.findById(user.getId()).orElse(null);

if (foundUser != null) {
// Keep these...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void populateLokeTable() {
.collect(Collectors.toMap(Ao3::getAo3id, ao3 -> ao3));

stopWatch.start();
ao3ExportRepository.save(ao3Map.values());
ao3ExportRepository.saveAll(ao3Map.values());
stopWatch.stop();
LOGGER.info("Copied all ao3 from main db into export db: " + stopWatch.getTotalTimeMillis() + " ms");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package se.vgregion.arbetsplatskoder.spring;

import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.Trigger;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -107,7 +108,7 @@ CronTriggerFactoryBean getCronTriggerFactoryBean(JobDetail job, String cronExpre
return trigger;
}

JobDetailFactoryBean getJobDetailFactoryBean(String description, Class<?> jobClass) {
JobDetailFactoryBean getJobDetailFactoryBean(String description, Class<? extends Job> jobClass) {
JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
jobDetailFactory.setJobClass(jobClass);
jobDetailFactory.setDescription(description);
Expand Down
2 changes: 1 addition & 1 deletion core-bc/composites/types/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Generation time : 2015-01-14 09:02:50 CET
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.7</version>
<version>2.13.3</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ <h3>Concise SumNivå</h3>
<div class="apk-details-item">
<div class="apk-details-item-label">Concise SumNivå 2:</div>
<div class="apk-details-item-data">
{{data.prodn3.prodn2.kortnamn}}
{{data.prodn3 ? data.prodn3.prodn2?.kortnamn : ''}}
</div>
</div>

<div class="apk-details-item">
<div class="apk-details-item-label">Concise SumNivå 3:</div>
<div class="apk-details-item-data">
{{data.prodn3.kortnamn}}
{{data.prodn3 ? data.prodn3.kortnamn : ''}}
</div>
</div>
</div>
Expand Down
15 changes: 1 addition & 14 deletions core-bc/modules/intsvc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@
<!--
<spring.version>3.2.2.RELEASE</spring.version>
-->
<spring.fw.version>4.3.6.RELEASE</spring.fw.version>
<spring.version>4.3.6.RELEASE</spring.version>
<jackson.version>1.9.10</jackson.version>
<jdk.version>1.8</jdk.version>
</properties>

<dependencies>

<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
Expand Down Expand Up @@ -93,15 +89,6 @@
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.tomcat.maven</groupId>
Expand All @@ -116,4 +103,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ResponseEntity<String> renewJwt(@RequestBody String jwt) {
try {
DecodedJWT decodedJWT = JwtUtil.verify(jwt);

User user = userRepository.findOne(decodedJWT.getSubject());
User user = userRepository.findById(decodedJWT.getSubject()).orElseThrow();

String[] roles = getRoles(user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public Page<Ao3> getAo3s(@RequestParam(value = "pageSize", required = false) Int
@RequestParam(value = "page", required = false) Integer page) {

Sort.Order order = new Sort.Order(Sort.Direction.ASC, "foretagsnamn").ignoreCase();
Sort sort = new Sort(order);
Sort sort = Sort.by(order);

Pageable pageable = null;

if (pageSize != null && page != null) {
pageable = new PageRequest(page, pageSize, sort);
pageable = PageRequest.of(page, pageSize, sort);
} else {
pageable = new PageRequest(0, Integer.MAX_VALUE, sort);
pageable = PageRequest.of(0, Integer.MAX_VALUE, sort);
}

return ao3Repository.findAll(pageable);
Expand All @@ -53,7 +53,7 @@ public Page<Ao3> getAo3s(@RequestParam(value = "pageSize", required = false) Int
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public Ao3 getAo3(@PathVariable("id") Integer id) {
return ao3Repository.findOne(id);
return ao3Repository.findById(id).orElse(null);
}

@RequestMapping(value = "", method = RequestMethod.PUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class ArchivedDataController {
@RequestMapping(value = "/{dataId}", method = RequestMethod.GET)
@ResponseBody
public List<ArchivedData> findByReplacer(@PathVariable("dataId") Integer dataId) {
return archivedDataRepository.findAllByReplacerEqualsOrderByAndringsdatumDesc(dataRepository.getOne(dataId));
return archivedDataRepository.findAllByReplacerEqualsOrderByAndringsdatumDesc(
dataRepository.findById(dataId).orElseThrow()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ContentController {
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody
public Content getContent(@PathVariable("id") String id) {
Content content = contentRepository.findOne(id);
Content content = contentRepository.findById(id).orElse(null);

if (content == null) {
content = new Content(id, "<p>Redigera innehåll</p>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public Page<Data> getDatas(@RequestParam(value = "page", required = false) Integ
} else {
dynamicSort = new Sort.Order(asc ? Sort.Direction.ASC : Sort.Direction.DESC, sort);
}
finalSort = new Sort(dynamicSort, sorteringskodProd, arbetsplatskod);
finalSort = Sort.by(dynamicSort, sorteringskodProd, arbetsplatskod);
} else {
finalSort = new Sort(sorteringskodProd, arbetsplatskod);
finalSort = Sort.by(sorteringskodProd, arbetsplatskod);
}

Pageable pageable = new PageRequest(page == null ? 0 : page, pageSize,
Pageable pageable = PageRequest.of(page == null ? 0 : page, pageSize,
finalSort);

Page<Data> result;
Expand Down Expand Up @@ -122,7 +122,7 @@ private Set<Prodn1> getUserProdn1s() {
private User getUser() {
String userIdFromRequest = HttpUtil.getUserIdFromRequest(request);

return userRepository.findOne(userIdFromRequest);
return userRepository.findById(userIdFromRequest).orElse(null);
}

@RequestMapping(value = "/arbetsplatskodlan/{arbetsplatskodlan}", method = RequestMethod.GET)
Expand Down Expand Up @@ -167,7 +167,7 @@ public ResponseEntity<List<Data>> findHighestBeginningWith(@PathVariable("arbets
@ResponseBody
@PreAuthorize("@authService.isLoggedIn(authentication)")
public Data getData(@PathVariable("id") Integer id) {
return dataRepository.findOne(id);
return dataRepository.findById(id).orElse(null);
}

@RequestMapping(value = "users", method = RequestMethod.GET)
Expand All @@ -181,13 +181,13 @@ public List<String> findAllUserIdsWithData() {
@ResponseBody
@PreAuthorize("@authService.isLoggedIn(authentication)")
public ResponseEntity deleteData(@PathVariable("id") Integer id) {
if (!(getUser().getProdn1s().contains(dataRepository.findOne(id).getProdn1())
if (!(getUser().getProdn1s().contains(dataRepository.findById(id).orElseThrow().getProdn1())
|| getUser().getRole().equals(Role.ADMIN))) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}

dataOperations.unexport(id);
dataRepository.delete(id);
dataRepository.deleteById(id);

return ResponseEntity.ok().build();
}
Expand All @@ -205,7 +205,7 @@ public ResponseEntity<Object> saveData(@RequestBody Data data) {

if (data.getId() != null) {
// Already persisted entity. Check that the user has permission to that entity.
Data persisted = dataRepository.findOne(data.getId());
Data persisted = dataRepository.findById(data.getId()).orElseThrow();
if (!(user.getProdn1s().contains(persisted.getProdn1()) || user.getRole().equals(Role.ADMIN))) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
Expand Down
Loading

0 comments on commit b018105

Please sign in to comment.