Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #31 from admin-ch/feature/clean-up
Browse files Browse the repository at this point in the history
Feature/clean up
  • Loading branch information
ubhaller authored Jul 14, 2021
2 parents 1b09cba + 89a471e commit d338627
Show file tree
Hide file tree
Showing 63 changed files with 725 additions and 251 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.data;

import ch.admin.bag.covidcertificate.backend.verifier.model.AppToken;
Expand All @@ -8,8 +18,6 @@
*/
public interface AppTokenDataService {

/**
* Fetches all app tokens contained in the database
*/
/** Fetches all app tokens contained in the database */
public List<AppToken> getAppTokens();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch>
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -20,47 +20,47 @@
public interface VerifierDataService {

/** inserts the given CSCAs into the db */
public void insertCSCAs(List<DbCsca> cscas);
public void insertCscas(List<DbCsca> cscas);

/**
* removes all csas with key ids in the given list that haven't been added manually
*
* @param keyIds
* @return number of removed CSCAs
*/
public int removeCSCAs(List<String> keyIds);
public int removeCscas(List<String> keyIds);

/**
* finds all CSCAs of the given origin country
*
* @param origin abbreviation for country of origin (e.g. "CH")
* @return list of all CSCAs with the corresponding origin
*/
public List<DbCsca> findCSCAs(String origin);
public List<DbCsca> findCscas(String origin);

/** returns a list of key ids of all active CSCAs */
public List<String> findActiveCSCAKeyIds();
public List<String> findActiveCscaKeyIds();

/** inserts the given DSC into the db */
public void insertDSCs(List<DbDsc> dsc);
public void insertDscs(List<DbDsc> dsc);

/** removes all DSCs with key ids not in the given list that haven't been added manually */
public int removeDSCsNotIn(List<String> keyIdsToKeep);
public int removeDscsNotIn(List<String> keyIdsToKeep);

/** removes all DSCs signed by a CSCA in the given list that haven't been added manually */
public int removeDSCsWithCSCAIn(List<String> cscaKidsToRemove);
public int removeDscsWithCscaIn(List<String> cscaKidsToRemove);

/**
* returns the next batch of DSCs after `since` but before `importedBefore` in the requested
* format
*/
public List<ClientCert> findDSCs(Long since, CertFormat certFormat, Date importedBefore);
public List<ClientCert> findDscs(Long since, CertFormat certFormat, Date importedBefore);

/** returns a list of key ids of all active DSCs before a certain timestamp */
public List<String> findActiveDSCKeyIds(Date importedBefore);
public List<String> findActiveDscKeyIds(Date importedBefore);

/** returns the highest DSC pk id */
public long findMaxDSCPkId();
public long findMaxDscPkId();

public int getMaxDSCBatchCount();
public int getMaxDscBatchCount();
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.data.impl;

import ch.admin.bag.covidcertificate.backend.verifier.data.AppTokenDataService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
package ch.admin.bag.covidcertificate.backend.verifier.data.impl;

import ch.admin.bag.covidcertificate.backend.verifier.data.VerifierDataService;
import ch.admin.bag.covidcertificate.backend.verifier.data.mapper.CSCARowMapper;
import ch.admin.bag.covidcertificate.backend.verifier.data.mapper.ClientCertRowMapper;
import ch.admin.bag.covidcertificate.backend.verifier.data.mapper.CscaRowMapper;
import ch.admin.bag.covidcertificate.backend.verifier.model.CertSource;
import ch.admin.bag.covidcertificate.backend.verifier.model.cert.CertFormat;
import ch.admin.bag.covidcertificate.backend.verifier.model.cert.ClientCert;
Expand Down Expand Up @@ -55,14 +55,14 @@ public JdbcVerifierDataServiceImpl(DataSource dataSource) {

@Override
@Transactional
public void insertCSCAs(List<DbCsca> cscas) {
public void insertCscas(List<DbCsca> cscas) {
logger.debug(
"Inserting CSCA certificates with kid's: {}",
cscas.stream().map(DbCsca::getKeyId).collect(Collectors.toList()));
List<SqlParameterSource> batchParams = new ArrayList<>();
if (!cscas.isEmpty()) {
for (DbCsca dbCsca : cscas) {
batchParams.add(getCSCAParams(dbCsca));
batchParams.add(getCscaParams(dbCsca));
}
cscaInsert.executeBatch(
batchParams.toArray(new SqlParameterSource[batchParams.size()]));
Expand All @@ -71,7 +71,7 @@ public void insertCSCAs(List<DbCsca> cscas) {

@Override
@Transactional
public int removeCSCAs(List<String> keyIds) {
public int removeCscas(List<String> keyIds) {
if (!keyIds.isEmpty()) {
var sql =
"delete from t_country_specific_certificate_authority"
Expand All @@ -88,36 +88,36 @@ public int removeCSCAs(List<String> keyIds) {

@Override
@Transactional(readOnly = true)
public List<DbCsca> findCSCAs(String origin) {
public List<DbCsca> findCscas(String origin) {
final var sql =
"select * from t_country_specific_certificate_authority where origin = :origin";
final var params = new MapSqlParameterSource();
params.addValue("origin", origin);
return jt.query(sql, params, new CSCARowMapper());
return jt.query(sql, params, new CscaRowMapper());
}

@Override
@Transactional(readOnly = true)
public List<String> findActiveCSCAKeyIds() {
public List<String> findActiveCscaKeyIds() {
final var sql = "select key_id from t_country_specific_certificate_authority";
return jt.queryForList(sql, new MapSqlParameterSource(), String.class);
}

@Override
@Transactional
public void insertDSCs(List<DbDsc> dsc) {
public void insertDscs(List<DbDsc> dsc) {
List<SqlParameterSource> batchParams = new ArrayList<>();
if (!dsc.isEmpty()) {
for (DbDsc dbDsc : dsc) {
batchParams.add(getDSCParams(dbDsc));
batchParams.add(getDscParams(dbDsc));
}
dscInsert.executeBatch(batchParams.toArray(new SqlParameterSource[batchParams.size()]));
}
}

@Override
@Transactional
public int removeDSCsNotIn(List<String> keyIdsToKeep) {
public int removeDscsNotIn(List<String> keyIdsToKeep) {
var sql = "delete from t_document_signer_certificate";
final var params = new MapSqlParameterSource();
if (!keyIdsToKeep.isEmpty()) {
Expand All @@ -130,7 +130,7 @@ public int removeDSCsNotIn(List<String> keyIdsToKeep) {

@Override
@Transactional
public int removeDSCsWithCSCAIn(List<String> cscaKidsToRemove) {
public int removeDscsWithCscaIn(List<String> cscaKidsToRemove) {
if (!cscaKidsToRemove.isEmpty()) {
var sql =
"delete from t_document_signer_certificate"
Expand Down Expand Up @@ -159,7 +159,7 @@ private List<Long> findCscaPksForKids(List<String> cscaKids) {

@Override
@Transactional(readOnly = true)
public List<ClientCert> findDSCs(Long since, CertFormat certFormat, Date importedBefore) {
public List<ClientCert> findDscs(Long since, CertFormat certFormat, Date importedBefore) {
String sql =
"select pk_dsc_id,"
+ " key_id,"
Expand Down Expand Up @@ -187,7 +187,7 @@ public List<ClientCert> findDSCs(Long since, CertFormat certFormat, Date importe

@Override
@Transactional(readOnly = true)
public List<String> findActiveDSCKeyIds(Date importedBefore) {
public List<String> findActiveDscKeyIds(Date importedBefore) {
String sql =
"select key_id from t_document_signer_certificate where imported_at < :before order by pk_dsc_id";
MapSqlParameterSource params = new MapSqlParameterSource();
Expand All @@ -197,7 +197,7 @@ public List<String> findActiveDSCKeyIds(Date importedBefore) {

@Override
@Transactional(readOnly = true)
public long findMaxDSCPkId() {
public long findMaxDscPkId() {
try {
String sql =
"select pk_dsc_id from t_document_signer_certificate"
Expand All @@ -210,11 +210,11 @@ public long findMaxDSCPkId() {
}

@Override
public int getMaxDSCBatchCount() {
public int getMaxDscBatchCount() {
return MAX_DSC_BATCH_COUNT;
}

private MapSqlParameterSource getCSCAParams(DbCsca dbCsca) {
private MapSqlParameterSource getCscaParams(DbCsca dbCsca) {
var params = new MapSqlParameterSource();
params.addValue("key_id", dbCsca.getKeyId());
params.addValue("certificate_raw", dbCsca.getCertificateRaw());
Expand All @@ -224,7 +224,7 @@ private MapSqlParameterSource getCSCAParams(DbCsca dbCsca) {
return params;
}

private MapSqlParameterSource getDSCParams(DbDsc dbDsc) {
private MapSqlParameterSource getDscParams(DbDsc dbDsc) {
var params = new MapSqlParameterSource();
params.addValue("key_id", dbDsc.getKeyId());
params.addValue("fk_csca_id", dbDsc.getFkCsca());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.data.mapper;

import ch.admin.bag.covidcertificate.backend.verifier.model.AppToken;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.data.mapper;

import ch.admin.bag.covidcertificate.backend.verifier.model.cert.Algorithm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.data.mapper;

import ch.admin.bag.covidcertificate.backend.verifier.model.cert.db.DbCsca;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;

public class CSCARowMapper implements RowMapper<DbCsca> {
public class CscaRowMapper implements RowMapper<DbCsca> {

@Override
public DbCsca mapRow(ResultSet rs, int rowNum) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.data;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -7,7 +17,6 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;

class AppTokenDataServiceTest extends BaseDataServiceTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.data;

import ch.admin.bag.covidcertificate.backend.verifier.data.config.FlywayConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.data;

import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
Loading

0 comments on commit d338627

Please sign in to comment.