Skip to content

Commit

Permalink
Merge branch 'work/using-react-with-bootstrap4'
Browse files Browse the repository at this point in the history
  • Loading branch information
steinarb committed Jun 1, 2024
2 parents 4742447 + 9e49b72 commit be4454d
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 52 deletions.
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
**/ProductionLiquibaseRunner.java,
**/TestLiquibaseRunner.java
</sonar.cpd.exclusions>
<sonar.issue.ignore.multicriteria>e1</sonar.issue.ignore.multicriteria>
<sonar.issue.ignore.multicriteria.e1.ruleKey>java:S6813</sonar.issue.ignore.multicriteria.e1.ruleKey>
<sonar.issue.ignore.multicriteria.e1.resourceKey>**/ukelonn.web.services/src/main/java/**/resources/*.java</sonar.issue.ignore.multicriteria.e1.resourceKey>
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/../jacoco-coverage-report/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public LogService getLogservice() {
public List<Account> getAccounts() {
var accounts = new ArrayList<Account>();
try(var connection = datasource.getConnection()) {
try(var statement = connection.prepareStatement("select * from accounts_view")) {
try(var statement = connection.prepareStatement("select account_id, username, balance from accounts_view")) {
try(var results = statement.executeQuery()) {
if (results != null) {
while(results.next()) {
Expand All @@ -140,7 +140,7 @@ public List<Account> getAccounts() {
@Override
public Account getAccount(String username) {
try(var connection = datasource.getConnection()) {
try(var statement = connection.prepareStatement("select * from accounts_view where username=?")) {
try(var statement = connection.prepareStatement("select account_id, username, balance from accounts_view where username=?")) {
statement.setString(1, username);
try(var resultset = statement.executeQuery()) {
if (resultset.next())
Expand Down Expand Up @@ -183,7 +183,7 @@ public Account registerPerformedJob(PerformedTransaction job) {
public List<TransactionType> getJobTypes() {
var jobtypes = new ArrayList<TransactionType>();
try(var connection = datasource.getConnection()) {
try(var statement = connection.prepareStatement("select * from transaction_types where transaction_is_work=true")) {
try(var statement = connection.prepareStatement("select transaction_type_id, transaction_type_name, transaction_amount, transaction_is_work, transaction_is_wage_payment from transaction_types where transaction_is_work=true")) {
try(var resultSet = statement.executeQuery()) {
if (resultSet != null) {
while (resultSet.next()) {
Expand Down Expand Up @@ -286,7 +286,7 @@ public List<Transaction> updateJob(UpdatedTransaction editedJob) {
public List<TransactionType> getPaymenttypes() {
var paymenttypes = new ArrayList<TransactionType>();
try(var connection = datasource.getConnection()) {
try(var statement = connection.prepareStatement("select * from transaction_types where transaction_is_wage_payment=true")) {
try(var statement = connection.prepareStatement("select transaction_type_id, transaction_type_name, transaction_amount, transaction_is_work, transaction_is_wage_payment from transaction_types where transaction_is_wage_payment=true")) {
try(var resultSet = statement.executeQuery()) {
if (resultSet != null) {
while (resultSet.next()) {
Expand Down Expand Up @@ -483,7 +483,7 @@ public void notificationTo(String username, Notification notification) {
public List<Bonus> getActiveBonuses() {
var activebonuses = new ArrayList<Bonus>();
try(var connection = datasource.getConnection()) {
try(var statement = connection.prepareStatement("select * from bonuses where enabled and start_date <= ? and end_date >= ?")) {
try(var statement = connection.prepareStatement("select bonus_id, enabled, iconurl, title, description, bonus_factor, start_date, end_date from bonuses where enabled and start_date <= ? and end_date >= ?")) {
var today = Timestamp.from(new Date().toInstant());
statement.setTimestamp(1, today);
statement.setTimestamp(2, today);
Expand All @@ -504,7 +504,7 @@ public List<Bonus> getActiveBonuses() {
public List<Bonus> getAllBonuses() {
var allbonuses = new ArrayList<Bonus>();
try(var connection = datasource.getConnection()) {
try(var statement = connection.prepareStatement("select * from bonuses")) {
try(var statement = connection.prepareStatement("select bonus_id, enabled, iconurl, title, description, bonus_factor, start_date, end_date from bonuses")) {
try (var results = statement.executeQuery()) {
while (results.next()) {
buildBonusFromResultSetAndAddToList(allbonuses, results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.sql.DataSource;

import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -696,7 +694,7 @@ void testUpdateJob() throws Exception {

var updatedJobs = ukelonn.updateJob(editedJob);

var editedJobFromDatabase = updatedJobs.stream().filter(t->t.id() == job.id()).collect(Collectors.toList()).get(0);
var editedJobFromDatabase = updatedJobs.stream().filter(t->t.id() == job.id()).toList().get(0);

assertEquals(editedJob.transactionTypeId(), editedJobFromDatabase.transactionType().id());
assertThat(editedJobFromDatabase.transactionTime().getTime()).isGreaterThan(originalTransactionTime.getTime());
Expand Down Expand Up @@ -725,7 +723,7 @@ void testUpdateJobGetSQLException() throws Exception {
}

private TransactionType findJobTypeWithDifferentIdAndAmount(UkelonnService ukelonn, Integer transactionTypeId, double amount) {
return ukelonn.getJobTypes().stream().filter(t->t.id() != transactionTypeId).filter(t->t.transactionAmount() != amount).collect(Collectors.toList()).get(0);
return ukelonn.getJobTypes().stream().filter(t->t.id() != transactionTypeId).filter(t->t.transactionAmount() != amount).toList().get(0);
}

@Test
Expand Down Expand Up @@ -1196,7 +1194,7 @@ void testJoinIds() {
var ukelonn = getUkelonnServiceSingleton();
ukelonn.setUserAdmin(useradmin);
var account = ukelonn.getAccount("jad");
var jobs = ukelonn.getJobs(account.accountId()).stream().map(Transaction::id).collect(Collectors.toList());
var jobs = ukelonn.getJobs(account.accountId()).stream().map(Transaction::id).toList();
assertEquals("31, 33, 34, 35, 37, 38, 39, 41, 42, 43", UkelonnServiceProvider.joinIds(jobs).toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
*/
package no.priv.bang.ukelonn.beans;

import static java.util.Optional.ofNullable;

import java.util.Locale;
import java.util.Optional;

public record LocaleBean(String code, String displayLanguage) {

Expand All @@ -30,9 +31,9 @@ public static class Builder {
private Builder() {}

public LocaleBean build() {
String locale = Optional.ofNullable(this.locale).map(l -> l.toString()).orElse(null);
String displayLanguage = Optional.ofNullable(this.locale).map(l -> l.getDisplayLanguage(l)).orElse(null);
return new LocaleBean(locale, displayLanguage);
var localeCode = ofNullable(this.locale).map(Object::toString).orElse(null);
var displayLanguage = ofNullable(this.locale).map(l -> l.getDisplayLanguage(l)).orElse(null);
return new LocaleBean(localeCode, displayLanguage);
}

public Builder locale(Locale locale) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ public static class Builder {
private Builder() {}

public PerformedTransaction build() {
var transactionTypeId = ofNullable(this.transactionTypeId).orElse(-1);
var transactionAmount = ofNullable(this.transactionAmount).orElse(0.0);
var transactionDate = ofNullable(this.transactionDate).orElse(new Date());
return new PerformedTransaction(this.account, transactionTypeId, transactionAmount, transactionDate);
return new PerformedTransaction(
this.account,
ofNullable(this.transactionTypeId).orElse(-1),
ofNullable(this.transactionAmount).orElse(0.0),
ofNullable(this.transactionDate).orElse(new Date()));
}

public Builder account(Account account) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static TransactionType copyTransactionType(TransactionType transactiontyp
}

public static List<TransactionType> copyTransactiontypes(List<TransactionType> transactiontypes) {
return transactiontypes.stream().map(transactiontype -> copyTransactionType(transactiontype)).collect(Collectors.toList());
return transactiontypes.stream().map(transactiontype -> copyTransactionType(transactiontype)).toList();
}

public static Transaction convertUpdatedTransaction(UpdatedTransaction transaction) {
Expand All @@ -202,7 +202,7 @@ public static Transaction copyTransaction(Transaction transaction) {
}

public static List<Transaction> copyTransactions(List<Transaction> transactions) {
return transactions.stream().map(transaction -> copyTransaction(transaction)).collect(Collectors.toList());
return transactions.stream().map(transaction -> copyTransaction(transaction)).toList();
}

public static List<TransactionType> getJobtypes() {
Expand Down Expand Up @@ -242,7 +242,7 @@ public static List<Transaction> getJodJobs() {
}

public static List<Transaction> getFirstJodJob() {
return jodJobs.stream().limit(1).collect(Collectors.toList());
return jodJobs.stream().limit(1).toList();
}

public static List<Account> getDummyAccounts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@
*/
package no.priv.bang.ukelonn.api.beans;

public record LoginResult(String username, String[] roles, String errorMessage) {
import static java.util.Collections.*;

import java.util.List;

public record LoginResult(String username, List<String> roles, String errorMessage) {

public static Builder with() {
return new Builder();
}

public static class Builder {
private String username = "";
private String[] roles = {};
private List<String> roles = emptyList();
private String errorMessage = "";

private Builder() {}
Expand All @@ -37,7 +41,7 @@ public Builder username(String username) {
return this;
}

public Builder roles(String[] roles) {
public Builder roles(List<String> roles) {
this.roles = roles;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package no.priv.bang.ukelonn.api.resources;

import java.util.Arrays;
import java.util.Base64;

import javax.inject.Inject;
Expand Down Expand Up @@ -104,7 +105,7 @@ private LoginResult createLoginResultFromSubject(Subject subject) {
var username = (String) subject.getPrincipal();
return LoginResult.with()
.username(username)
.roles(roles)
.roles(Arrays.asList(roles))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.servlet.ServletConfig;
Expand Down Expand Up @@ -196,7 +195,7 @@ void testLoginUnknownUser() throws Exception {
assertEquals("application/json", response.getContentType());

var result = ServletTestBase.mapper.readValue(response.getOutputStreamContent(), LoginResult.class);
assertEquals(0, result.roles().length);
assertThat(result.roles()).isEmpty();
assertEquals("Unknown account", result.errorMessage());
}

Expand Down Expand Up @@ -231,7 +230,7 @@ void testLoginWrongPassword() throws Exception {
assertEquals("application/json", response.getContentType());

var result = ServletTestBase.mapper.readValue(response.getOutputStreamContent(), LoginResult.class);
assertEquals(0, result.roles().length);
assertThat(result.roles()).isEmpty();
assertEquals("Wrong password", result.errorMessage());
}

Expand Down Expand Up @@ -336,7 +335,7 @@ void testGetLoginStateWhenNotLoggedIn() throws Exception {
assertEquals("application/json", response.getContentType());

var result = ServletTestBase.mapper.readValue(response.getOutputStreamContent(), LoginResult.class);
assertEquals(0, result.roles().length);
assertThat(result.roles()).isEmpty();
assertEquals("", result.errorMessage());
}

Expand Down Expand Up @@ -366,7 +365,7 @@ void testLogoutOk() throws Exception {
assertEquals("application/json", response.getContentType());

var result = ServletTestBase.mapper.readValue(response.getOutputStreamContent(), LoginResult.class);
assertEquals(0, result.roles().length);
assertThat(result.roles()).isEmpty();
assertEquals("", result.errorMessage());
}

Expand Down Expand Up @@ -401,7 +400,7 @@ void testLogoutNotLoggedIn() throws Exception {
assertEquals("application/json", response.getContentType());

var result = ServletTestBase.mapper.readValue(response.getOutputStreamContent(), LoginResult.class);
assertEquals(0, result.roles().length);
assertThat(result.roles()).isEmpty();
assertEquals("", result.errorMessage());
}

Expand Down Expand Up @@ -928,7 +927,7 @@ void testUpdateJob() throws Exception {
assertEquals(200, response.getStatus());
assertEquals("application/json", response.getContentType());
var updatedJobs = mapper.readValue(getBinaryContent(response), new TypeReference<List<Transaction>>() { });
var editedJobFromDatabase = updatedJobs.stream().filter(t->t.id() == job.id()).collect(Collectors.toList()).get(0);
var editedJobFromDatabase = updatedJobs.stream().filter(t->t.id() == job.id()).toList().get(0);

assertEquals(editedJob.transactionTypeId(), editedJobFromDatabase.transactionType().id());
assertThat(editedJobFromDatabase.transactionTime().getTime()).isGreaterThan(job.transactionTime().getTime());
Expand Down Expand Up @@ -1105,7 +1104,7 @@ void testCreateJobtype() throws Exception {
var logservice = new MockLogService();
var useradmin = mock(UserManagementService.class);
var ukelonn = mock(UkelonnService.class);
var updatedjobtypes = Stream.concat(originalJobtypes.stream(), Stream.of(jobtype)).collect(Collectors.toList());
var updatedjobtypes = Stream.concat(originalJobtypes.stream(), Stream.of(jobtype)).toList();
when(ukelonn.createJobtype(any())).thenReturn(updatedjobtypes);

var servlet = simulateDSComponentActivationAndWebWhiteboardConfiguration(ukelonn, logservice, useradmin);
Expand Down Expand Up @@ -1191,7 +1190,7 @@ void testCreatePaymenttype() throws Exception {
var logservice = new MockLogService();
var useradmin = mock(UserManagementService.class);
var ukelonn = mock(UkelonnService.class);
var updatedpaymenttypes = Stream.concat(originalPaymenttypes.stream(), Stream.of(paymenttype)).collect(Collectors.toList());
var updatedpaymenttypes = Stream.concat(originalPaymenttypes.stream(), Stream.of(paymenttype)).toList();
when(ukelonn.createPaymenttype(any())).thenReturn(updatedpaymenttypes);

var servlet = simulateDSComponentActivationAndWebWhiteboardConfiguration(ukelonn, logservice, useradmin);
Expand Down Expand Up @@ -1326,7 +1325,7 @@ void testCreateUser() throws Exception {
var logservice = new MockLogService();
var ukelonn = mock(UkelonnService.class);
var useradmin = mock(UserManagementService.class);
var updatedusers = Stream.concat(getUsersForUserManagement().stream(), Stream.of(user)).collect(Collectors.toList());
var updatedusers = Stream.concat(getUsersForUserManagement().stream(), Stream.of(user)).toList();
when(useradmin.addUser(any())).thenReturn(updatedusers);

var servlet = simulateDSComponentActivationAndWebWhiteboardConfiguration(ukelonn, logservice, useradmin);
Expand Down Expand Up @@ -1855,7 +1854,7 @@ void testDefaultLocale() throws Exception {
void testAvailableLocales() throws Exception {
// Set up REST API servlet with mocked services
var ukelonn = mock(UkelonnService.class);
when(ukelonn.availableLocales()).thenReturn(Collections.singletonList(Locale.forLanguageTag("nb-NO")).stream().map(l -> LocaleBean.with().locale(l).build()).collect(Collectors.toList()));
when(ukelonn.availableLocales()).thenReturn(Collections.singletonList(Locale.forLanguageTag("nb-NO")).stream().map(l -> LocaleBean.with().locale(l).build()).toList());
var logservice = new MockLogService();
var useradmin = mock(UserManagementService.class);

Expand Down Expand Up @@ -1931,7 +1930,7 @@ void testDisplayTextsWithUnknownLocale() throws Exception {
}

private TransactionType findJobTypeWithDifferentIdAndAmount(Integer transactionTypeId, double amount) {
return getJobtypes().stream().filter(t->t.id() != transactionTypeId).filter(t->t.transactionAmount() != amount).collect(Collectors.toList()).get(0);
return getJobtypes().stream().filter(t->t.id() != transactionTypeId).filter(t->t.transactionAmount() != amount).toList().get(0);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Date;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
Expand Down Expand Up @@ -297,7 +295,7 @@ void testUpdateJob() {

var updatedJobs = resource.doUpdateJob(editedJob);

var editedJobFromDatabase = updatedJobs.stream().filter(t->t.id() == job.id()).collect(Collectors.toList()).get(0);
var editedJobFromDatabase = updatedJobs.stream().filter(t->t.id() == job.id()).toList().get(0);

assertEquals(editedJob.transactionTypeId(), editedJobFromDatabase.transactionType().id());
assertThat(editedJobFromDatabase.transactionTime().getTime()).isGreaterThan(originalTransactionTime.getTime());
Expand Down Expand Up @@ -327,7 +325,7 @@ void testUpdateJobGetSQLException() throws Exception {
}

private TransactionType findJobTypeWithDifferentIdAndAmount(UkelonnService ukelonn, Integer transactionTypeId, double amount) {
return getJobtypes().stream().filter(t->!(t.id() == transactionTypeId)).filter(t->t.transactionAmount() != amount).collect(Collectors.toList()).get(0);
return getJobtypes().stream().filter(t->!(t.id() == transactionTypeId)).filter(t->t.transactionAmount() != amount).toList().get(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.stream.Collectors;

import javax.ws.rs.WebApplicationException;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -50,7 +48,7 @@ void testDefaultLocale() {
void testAvailableLocales() {
var ukelonn = mock(UkelonnService.class);
when(ukelonn.defaultLocale()).thenReturn(NB_NO);
when(ukelonn.availableLocales()).thenReturn(Arrays.asList(Locale.forLanguageTag("nb-NO"), Locale.UK).stream().map(l -> LocaleBean.with().locale(l).build()).collect(Collectors.toList()));
when(ukelonn.availableLocales()).thenReturn(Arrays.asList(Locale.forLanguageTag("nb-NO"), Locale.UK).stream().map(l -> LocaleBean.with().locale(l).build()).toList());
var resource = new LocalizationResource();
resource.ukelonn = ukelonn;
var availableLocales = resource.availableLocales();
Expand Down
Loading

0 comments on commit be4454d

Please sign in to comment.