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 May 5, 2024
2 parents fa299f9 + fe71ce3 commit ddd8ada
Show file tree
Hide file tree
Showing 64 changed files with 801 additions and 1,268 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<show>private</show>
<source>8</source>
</configuration>
<executions>
<execution>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Steinar Bang
* Copyright 2016-2024 Steinar Bang
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,8 @@
*/
package no.priv.bang.ukelonn.db.liquibase.production;

import java.sql.Connection;
import static liquibase.command.core.helpers.DbUrlConnectionArgumentsCommandStep.DATABASE_ARG;

import java.sql.SQLException;
import java.util.Map;

Expand All @@ -35,7 +36,6 @@
import liquibase.command.CommandScope;
import liquibase.command.core.UpdateCommandStep;
import liquibase.command.core.helpers.DatabaseChangelogCommandStep;
import liquibase.command.core.helpers.DbUrlConnectionCommandStep;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.resource.ClassLoaderResourceAccessor;
Expand All @@ -62,7 +62,7 @@ public void activate(Map<String, Object> config) {
@Override
public void prepare(DataSource datasource) throws SQLException {
try {
UkelonnLiquibase liquibase = createUkelonnLiquibase();
var liquibase = createUkelonnLiquibase();
liquibase.createInitialSchema(datasource);
insertInitialDataInDatabase(datasource);
liquibase.updateSchema(datasource);
Expand All @@ -72,14 +72,14 @@ public void prepare(DataSource datasource) throws SQLException {
}

boolean insertInitialDataInDatabase(DataSource datasource) {
try(Connection connect = datasource.getConnection()) {
try(var connect = datasource.getConnection()) {
try (var database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connect))) {
Map<String, Object> scopeObjects = Map.of(
Scope.Attr.database.name(), database,
Scope.Attr.resourceAccessor.name(), new ClassLoaderResourceAccessor(getClass().getClassLoader()));

Scope.child(scopeObjects, (ScopedRunner<?>) () -> new CommandScope("update")
.addArgumentValue(DbUrlConnectionCommandStep.DATABASE_ARG, database)
.addArgumentValue(DATABASE_ARG, database)
.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, initialDataResourceName())
.addArgumentValue(DatabaseChangelogCommandStep.CHANGELOG_PARAMETERS, new ChangeLogParameters(database))
.execute());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Steinar Bang
* Copyright 2016-2024 Steinar Bang
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,8 +15,8 @@
*/
package no.priv.bang.ukelonn.db.liquibase.test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import static liquibase.command.core.helpers.DbUrlConnectionArgumentsCommandStep.DATABASE_ARG;

import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
Expand All @@ -41,9 +41,6 @@
import liquibase.command.CommandScope;
import liquibase.command.core.UpdateCommandStep;
import liquibase.command.core.helpers.DatabaseChangelogCommandStep;
import liquibase.command.core.helpers.DbUrlConnectionCommandStep;
import liquibase.database.Database;
import liquibase.database.DatabaseConnection;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.DatabaseException;
Expand All @@ -69,7 +66,7 @@ public void activate(Map<String, Object> config) {

@Override
public void prepare(DataSource datasource) throws SQLException {
UkelonnLiquibase liquibase = new UkelonnLiquibase();
var liquibase = new UkelonnLiquibase();
try {
liquibase.createInitialSchema(datasource);
insertMockData(datasource);
Expand All @@ -80,14 +77,14 @@ public void prepare(DataSource datasource) throws SQLException {
}

public boolean insertMockData(DataSource datasource) {
try(Connection connect = datasource.getConnection()) {
try(var connect = datasource.getConnection()) {
try (var database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connect))) {
Map<String, Object> scopeObjects = Map.of(
Scope.Attr.database.name(), database,
Scope.Attr.resourceAccessor.name(), new ClassLoaderResourceAccessor(getClass().getClassLoader()));

Scope.child(scopeObjects, (ScopedRunner<?>) () -> new CommandScope("update")
.addArgumentValue(DbUrlConnectionCommandStep.DATABASE_ARG, database)
.addArgumentValue(DATABASE_ARG, database)
.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, dummyDataResourceName())
.addArgumentValue(DatabaseChangelogCommandStep.CHANGELOG_PARAMETERS, new ChangeLogParameters(database))
.execute());
Expand All @@ -101,16 +98,16 @@ public boolean insertMockData(DataSource datasource) {
}

public boolean rollbackMockData(DataSource datasource) {
try(Connection connect = datasource.getConnection()) {
DatabaseConnection databaseConnection = new JdbcConnection(connect);
try(var connect = datasource.getConnection()) {
var databaseConnection = new JdbcConnection(connect);
try(var classLoaderResourceAccessor = new ClassLoaderResourceAccessor(getClass().getClassLoader())) {
try(PreparedStatement statement = connect.prepareStatement("delete from user_roles")) {
try(var statement = connect.prepareStatement("delete from user_roles")) {
statement.executeUpdate();
}
try(PreparedStatement statement = connect.prepareStatement("delete from users")) {
try(var statement = connect.prepareStatement("delete from users")) {
statement.executeUpdate();
}
Liquibase liquibase = new Liquibase(dummyDataResourceName(), classLoaderResourceAccessor, databaseConnection);
var liquibase = new Liquibase(dummyDataResourceName(), classLoaderResourceAccessor, databaseConnection);
liquibase.rollback(3, "");
}
return true;
Expand All @@ -129,9 +126,9 @@ public boolean rollbackMockData(DataSource datasource) {
* @throws SQLException
*/
List<RanChangeSet> getChangeLogHistory(DataSource datasource) throws DatabaseException, SQLException {
try(Connection connect = datasource.getConnection()) {
try(var connect = datasource.getConnection()) {
try(var databaseConnection = new JdbcConnection(connect)) {
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(databaseConnection);
var database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(databaseConnection);
var logHistoryService = Scope.getCurrentScope().getSingleton(ChangeLogHistoryServiceFactory.class).getChangeLogService(database);
return logHistoryService.getRanChangeSets();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import liquibase.command.CommandScope;
import liquibase.command.core.UpdateCommandStep;
import liquibase.command.core.helpers.DatabaseChangelogCommandStep;
import liquibase.command.core.helpers.DbUrlConnectionCommandStep;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.DatabaseException;
Expand All @@ -55,6 +54,8 @@
import no.priv.bang.osgi.service.mocks.logservice.MockLogService;
import no.priv.bang.ukelonn.UkelonnException;
import no.priv.bang.ukelonn.db.liquibase.UkelonnLiquibase;

import static liquibase.command.core.helpers.DbUrlConnectionArgumentsCommandStep.DATABASE_ARG;
import static no.priv.bang.ukelonn.db.liquibase.test.TestLiquibaseRunner.*;

class TestLiquibaseRunnerTest {
Expand Down Expand Up @@ -416,7 +417,7 @@ void addUkelonnSchemaAndDataToDerbyServer() throws SQLException, LiquibaseExcept
Scope.Attr.resourceAccessor.name(), new ClassLoaderResourceAccessor(getClass().getClassLoader()));

Scope.child(scopeObjects, (ScopedRunner<?>) () -> new CommandScope("update")
.addArgumentValue(DbUrlConnectionCommandStep.DATABASE_ARG, database)
.addArgumentValue(DATABASE_ARG, database)
.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, "sql/data/db-changelog.xml")
.addArgumentValue(DatabaseChangelogCommandStep.CHANGELOG_PARAMETERS, new ChangeLogParameters(database))
.execute());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Steinar Bang
* Copyright 2016-2024 Steinar Bang
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,8 @@
*/
package no.priv.bang.ukelonn.db.liquibase;

import static liquibase.command.core.helpers.DbUrlConnectionArgumentsCommandStep.DATABASE_ARG;

import java.util.Map;

import javax.sql.DataSource;
Expand All @@ -25,7 +27,6 @@
import liquibase.command.CommandScope;
import liquibase.command.core.UpdateCommandStep;
import liquibase.command.core.helpers.DatabaseChangelogCommandStep;
import liquibase.command.core.helpers.DbUrlConnectionCommandStep;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.LiquibaseException;
Expand All @@ -47,7 +48,7 @@ public void createInitialSchema(DataSource datasource) throws LiquibaseException
Scope.Attr.resourceAccessor.name(), new ClassLoaderResourceAccessor(getClass().getClassLoader()));

Scope.child(scopeObjects, (ScopedRunner<?>) () -> new CommandScope(UPDATE)
.addArgumentValue(DbUrlConnectionCommandStep.DATABASE_ARG, database)
.addArgumentValue(DATABASE_ARG, database)
.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, "ukelonn-db-changelog/db-changelog-1.0.0.xml")
.addArgumentValue(DatabaseChangelogCommandStep.CHANGELOG_PARAMETERS, new ChangeLogParameters(database))
.execute());
Expand All @@ -67,7 +68,7 @@ public void updateSchema(DataSource datasource) throws LiquibaseException {
Scope.Attr.resourceAccessor.name(), new ClassLoaderResourceAccessor(getClass().getClassLoader()));

Scope.child(scopeObjects, (ScopedRunner<?>) () -> new CommandScope(UPDATE)
.addArgumentValue(DbUrlConnectionCommandStep.DATABASE_ARG, database)
.addArgumentValue(DATABASE_ARG, database)
.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, "ukelonn-db-changelog/db-changelog-1.0.1.xml")
.addArgumentValue(DatabaseChangelogCommandStep.CHANGELOG_PARAMETERS, new ChangeLogParameters(database))
.execute());
Expand All @@ -79,7 +80,7 @@ public void updateSchema(DataSource datasource) throws LiquibaseException {
}

try (var connect = datasource.getConnection()) {
AuthserviceLiquibase authserviceLiquibase = new AuthserviceLiquibase();
var authserviceLiquibase = new AuthserviceLiquibase();
authserviceLiquibase.createInitialSchema(connect);
} catch (LiquibaseException | AuthserviceException e) {
throw e;
Expand All @@ -94,7 +95,7 @@ public void updateSchema(DataSource datasource) throws LiquibaseException {
Scope.Attr.resourceAccessor.name(), new ClassLoaderResourceAccessor(getClass().getClassLoader()));

Scope.child(scopeObjects, (ScopedRunner<?>) () -> new CommandScope(UPDATE)
.addArgumentValue(DbUrlConnectionCommandStep.DATABASE_ARG, database)
.addArgumentValue(DATABASE_ARG, database)
.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, "ukelonn-db-changelog/db-changelog.xml")
.addArgumentValue(DatabaseChangelogCommandStep.CHANGELOG_PARAMETERS, new ChangeLogParameters(database))
.execute());
Expand Down
6 changes: 0 additions & 6 deletions ukelonn.services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@
<artifactId>beans.immutable</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>no.priv.bang.beans</groupId>
<artifactId>beans.immutable</artifactId>
<type>xml</type>
<classifier>features</classifier>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 Steinar Bang
* Copyright 2016-2024 Steinar Bang
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,105 +17,69 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import no.priv.bang.beans.immutable.Immutable;

@JsonIgnoreProperties(ignoreUnknown=true)
public class Account extends Immutable { // NOSONAR Immutable handles added fields
private int accountId;
private String username;
private String firstName;
private String lastName;
private double balance;

private Account() {
// No-arg constructor required by jackson
}

public int getAccountId() {
return accountId;
}

public String getUsername() {
return username;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}
public record Account(int accountId, String username,String firstName, String lastName, double balance) {

public String getFullName() {
if (getFirstName() != null && getLastName() != null) {
return getFirstName() + " " + getLastName();
if (firstName() != null && lastName() != null) {
return firstName() + " " + lastName();
}

if (getFirstName() != null) {
return getFirstName();
if (firstName() != null) {
return firstName();
}

return getUsername();
}

public double getBalance() {
return balance;
}

public void setBalance(double balance) {
this.balance = balance;
return username();
}

@Override
public String toString() {
return "Account [getAccountId()=" + getAccountId() + ", getUsername()=" + getUsername() + ", getFirstName()=" + getFirstName() + ", getLastName()=" + getLastName() + "]";
public static Builder with() {
return new Builder();
}

public static AccountBuilder with() {
return new AccountBuilder();
public static Builder with(Account account) {
var builder = new Builder();
builder.accountid = account.accountId;
builder.username = account.username;
builder.firstName = account.firstName;
builder.lastName = account.lastName;
builder.balance = account.balance;
return builder;
}

public static class AccountBuilder {
public static class Builder {
private int accountid;
private String username;
private String firstName;
private String lastName;
private double balance;

private AccountBuilder() {}
private Builder() {}

public Account build() {
Account account = new Account();
account.accountId = this.accountid;
account.username = this.username;
account.firstName = this.firstName;
account.lastName = this.lastName;
account.balance = this.balance;
return account;
return new Account(this.accountid, this.username, this.firstName, this.lastName, this.balance);
}

public AccountBuilder accountid(int accountid) {
public Builder accountid(int accountid) {
this.accountid = accountid;
return this;
}

public AccountBuilder username(String username) {
public Builder username(String username) {
this.username = username;
return this;
}

public AccountBuilder firstName(String firstName) {
public Builder firstName(String firstName) {
this.firstName = firstName;
return this;
}

public AccountBuilder lastName(String lastName) {
public Builder lastName(String lastName) {
this.lastName = lastName;
return this;
}

public AccountBuilder balance(double balance) {
public Builder balance(double balance) {
this.balance = balance;
return this;
}
Expand Down
Loading

0 comments on commit ddd8ada

Please sign in to comment.