Skip to content

Commit

Permalink
* SDM-5 SLA-log fra SDM4-importere følger ikke standarden
Browse files Browse the repository at this point in the history
*  Tilføjet kopi register view, så kopi register service maps nu bliver oprettet automatisk
  • Loading branch information
Kaspar Pedersen committed May 31, 2013
1 parent 84eb53c commit 20057d2
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
6 changes: 5 additions & 1 deletion Changelog.md
Expand Up @@ -15,4 +15,8 @@
* Opgrading til sdm4-core 4.3, der løser * Opgrading til sdm4-core 4.3, der løser
NSPSUPPORT-126: ParserExecutor logger filers absolutte stier og md5-summer inden parser behandler dem NSPSUPPORT-126: ParserExecutor logger filers absolutte stier og md5-summer inden parser behandler dem
* Opgraderet til sdm-core 4.9 for at kunne resette transaction time * Opgraderet til sdm-core 4.9 for at kunne resette transaction time
* SDM-23: Reset transaction time før hver import * SDM-23: Reset transaction time før hver import

## autorisationimporter 4.5
* SDM-5 SLA-log fra SDM4-importere følger ikke standarden
* Tilføjet kopi register view, så kopi register service maps nu bliver oprettet automatisk
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -4,7 +4,7 @@
<parent> <parent>
<groupId>dk.nsi.stamdata4</groupId> <groupId>dk.nsi.stamdata4</groupId>
<artifactId>sdm-parent</artifactId> <artifactId>sdm-parent</artifactId>
<version>4.3</version> <version>4.7</version>
</parent> </parent>


<artifactId>autorisationimporter</artifactId> <artifactId>autorisationimporter</artifactId>
Expand Down Expand Up @@ -58,7 +58,7 @@
<dependency> <dependency>
<groupId>dk.nsi.stamdata4</groupId> <groupId>dk.nsi.stamdata4</groupId>
<artifactId>sdm-core</artifactId> <artifactId>sdm-core</artifactId>
<version>4.9</version> <version>4.10</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
Expand Down
Expand Up @@ -69,7 +69,7 @@ public class AutorisationParser implements Parser {
private int maxAllowedReduction; private int maxAllowedReduction;


@Override @Override
public void process(File dataset) throws ParserException { public void process(File dataset, String identifier) throws ParserException {
Preconditions.checkNotNull(dataset); Preconditions.checkNotNull(dataset);


File[] files = dataset.listFiles(); File[] files = dataset.listFiles();
Expand All @@ -80,9 +80,9 @@ public void process(File dataset) throws ParserException {


// Make sure we update transaction time // Make sure we update transaction time
persister.resetTransactionTime(); persister.resetTransactionTime();

SLALogItem slaLogItem = slaLogger.createLogItem(getHome()+".process", "SDM4."+getHome()+".process");
SLALogItem slaLogItem = slaLogger.createLogItem("AutorisationImporter", "All Files"); slaLogItem.setMessageId(identifier);

slaLogItem.addCallParameter(Parser.SLA_INPUT_NAME, dataset.getAbsolutePath());
try { try {
// Make sure the file set has not been imported before. // Make sure the file set has not been imported before.
// Check what the previous highest version is (the ValidFrom column). // Check what the previous highest version is (the ValidFrom column).
Expand All @@ -101,16 +101,19 @@ public void process(File dataset) throws ParserException {
+ previousVersion + "', new_version='" + currentVersion + "'."); + previousVersion + "', new_version='" + currentVersion + "'.");
} }


int processed = 0;
for (File file : files) { for (File file : files) {
Autorisationsregisterudtraek autRegisterDataset = parse(file, currentVersion); Autorisationsregisterudtraek autRegisterDataset = parse(file, currentVersion);
guardAgainsUnacceptableReduction(file, autRegisterDataset); guardAgainsUnacceptableReduction(file, autRegisterDataset);
processed += autRegisterDataset.size();
persister.persistCompleteDataset(autRegisterDataset); persister.persistCompleteDataset(autRegisterDataset);
} }


// Update the table for the STS. // Update the table for the STS.
jdbcTemplate.execute("TRUNCATE TABLE autreg"); jdbcTemplate.execute("TRUNCATE TABLE autreg");
jdbcTemplate.update("INSERT INTO autreg (cpr, given_name, surname, aut_id, edu_id) SELECT cpr, Fornavn, Efternavn, Autorisationsnummer, UddannelsesKode " + FROMCLAUSE_VALID_AUTORISATIONER); jdbcTemplate.update("INSERT INTO autreg (cpr, given_name, surname, aut_id, edu_id) SELECT cpr, Fornavn, Efternavn, Autorisationsnummer, UddannelsesKode " + FROMCLAUSE_VALID_AUTORISATIONER);


slaLogItem.addCallParameter(Parser.SLA_RECORDS_PROCESSED_MAME, ""+processed);
slaLogItem.setCallResultOk(); slaLogItem.setCallResultOk();
slaLogItem.store(); slaLogItem.store();
} catch (Exception e) { } catch (Exception e) {
Expand Down
@@ -0,0 +1,53 @@
-- -----------------------------------------------------
-- Someone has to create the SKRS tables first time
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `SKRSViewMapping` (
`idSKRSViewMapping` BIGINT(15) NOT NULL AUTO_INCREMENT ,
`register` VARCHAR(255) NOT NULL ,
`datatype` VARCHAR(255) NOT NULL ,
`version` INT NOT NULL ,
`tableName` VARCHAR(255) NOT NULL ,
`createdDate` TIMESTAMP NOT NULL ,
PRIMARY KEY (`idSKRSViewMapping`) ,
INDEX `idx` (`register` ASC, `datatype` ASC, `version` ASC) ,
UNIQUE INDEX `unique` (`register` ASC, `datatype` ASC, `version` ASC) )
ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `SKRSColumns` (
`idSKRSColumns` BIGINT(15) NOT NULL AUTO_INCREMENT ,
`viewMap` BIGINT(15) NOT NULL ,
`isPID` TINYINT NOT NULL ,
`tableColumnName` VARCHAR(255) NOT NULL ,
`feedColumnName` VARCHAR(255) NULL ,
`feedPosition` INT NOT NULL ,
`dataType` INT NOT NULL ,
`maxLength` INT NULL ,
PRIMARY KEY (`idSKRSColumns`) ,
INDEX `viewMap_idx` (`viewMap` ASC) ,
UNIQUE INDEX `viewColumn` (`tableColumnName` ASC, `viewMap` ASC) ,
CONSTRAINT `viewMap`
FOREIGN KEY (`viewMap` )
REFERENCES `SKRSViewMapping` (`idSKRSViewMapping` )
ON DELETE CASCADE
ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- ---------------------------------------------------------------------------------------------------------------------
-- Autorisation
-- ---------------------------------------------------------------------------------------------------------------------
-- Would have been nice if multiple statements where possible so all these subselects could go away
-- ---------------------------------------------------------------------------------------------------------------------

INSERT IGNORE INTO SKRSViewMapping (register, datatype, version, tableName, createdDate)
VALUES ('autorisationsregisteret', 'autorisation', 1, 'Autorisation', NOW());
INSERT IGNORE INTO SKRSColumns (viewMap, isPID, tableColumnName, feedColumnName, feedPosition, dataType, maxLength) VALUES
((SELECT idSKRSViewMapping FROM SKRSViewMapping WHERE register='autorisationsregisteret' AND datatype='autorisation' AND version=1), 1, 'AutorisationPID', NULL, 0, -5, NULL),
((SELECT idSKRSViewMapping FROM SKRSViewMapping WHERE register='autorisationsregisteret' AND datatype='autorisation' AND version=1), 0, 'Autorisationsnummer', 'autorisationsnummer', 1, 12, NULL),
((SELECT idSKRSViewMapping FROM SKRSViewMapping WHERE register='autorisationsregisteret' AND datatype='autorisation' AND version=1), 0, 'CPR', 'cpr', 2, 12, NULL),
((SELECT idSKRSViewMapping FROM SKRSViewMapping WHERE register='autorisationsregisteret' AND datatype='autorisation' AND version=1), 0, 'Fornavn', 'fornavn', 3, 12, NULL),
((SELECT idSKRSViewMapping FROM SKRSViewMapping WHERE register='autorisationsregisteret' AND datatype='autorisation' AND version=1), 0, 'Efternavn', 'efternavn', 4, 12, NULL),
((SELECT idSKRSViewMapping FROM SKRSViewMapping WHERE register='autorisationsregisteret' AND datatype='autorisation' AND version=1), 0, 'UddannelsesKode', 'uddannelseskode', 5, 4, NULL),
((SELECT idSKRSViewMapping FROM SKRSViewMapping WHERE register='autorisationsregisteret' AND datatype='autorisation' AND version=1), 0, 'ModifiedDate', NULL, 0, 93, NULL),
((SELECT idSKRSViewMapping FROM SKRSViewMapping WHERE register='autorisationsregisteret' AND datatype='autorisation' AND version=1), 0, 'ValidFrom', 'validFrom', 6, 93, NULL),
((SELECT idSKRSViewMapping FROM SKRSViewMapping WHERE register='autorisationsregisteret' AND datatype='autorisation' AND version=1), 0, 'ValidTo', 'validTo', 7, 93, NULL);
Expand Up @@ -65,7 +65,7 @@ public class AutorisationImportTest {
@Test @Test
public void testCanImport() throws IOException, InterruptedException { public void testCanImport() throws IOException, InterruptedException {
File dataset = createTestDataset("data/aut/valid/20090915AutDK.csv"); File dataset = createTestDataset("data/aut/valid/20090915AutDK.csv");
parser.process(dataset); parser.process(dataset, "id");
long cnt = jdbcTemplate.queryForLong("SELECT count(1) FROM Autorisation"); long cnt = jdbcTemplate.queryForLong("SELECT count(1) FROM Autorisation");
assertEquals(4, cnt); assertEquals(4, cnt);
Thread.sleep(1000); Thread.sleep(1000);
Expand All @@ -76,7 +76,7 @@ public void testCanImport() throws IOException, InterruptedException {


// Import another file and check validTo is set correctly and modified date is updated // Import another file and check validTo is set correctly and modified date is updated
dataset = createTestDataset("data/aut/valid/20090918AutDK.csv"); dataset = createTestDataset("data/aut/valid/20090918AutDK.csv");
parser.process(dataset); parser.process(dataset, "id");
cnt = jdbcTemplate.queryForLong("SELECT count(1) FROM Autorisation"); cnt = jdbcTemplate.queryForLong("SELECT count(1) FROM Autorisation");
assertEquals(6, cnt); assertEquals(6, cnt);
cnt = jdbcTemplate.queryForLong("SELECT count(1) FROM Autorisation WHERE ValidTo>=?", new Timestamp(now.getTime())); cnt = jdbcTemplate.queryForLong("SELECT count(1) FROM Autorisation WHERE ValidTo>=?", new Timestamp(now.getTime()));
Expand Down
Expand Up @@ -121,7 +121,7 @@ public void doesNotAllowNumberOfAutorisationerToDecreaseMoreThanThreshold() thro
when(jdbcTemplate.queryForInt(any(String.class))).thenReturn(5); // der er to indgange i den fil vi importer om lidt when(jdbcTemplate.queryForInt(any(String.class))).thenReturn(5); // der er to indgange i den fil vi importer om lidt


try { try {
parser.process(validWith3Removed.getParentFile()); parser.process(validWith3Removed.getParentFile(), "id");
fail("Expected exception from parser because number of autorisationer decreased too much"); fail("Expected exception from parser because number of autorisationer decreased too much");
} catch (ParserException e) { } catch (ParserException e) {
assertThat(e.getMessage(), containsString(validWith3Removed.getName())); assertThat(e.getMessage(), containsString(validWith3Removed.getName()));
Expand All @@ -134,7 +134,7 @@ public void doesNotAllowNumberOfAutorisationerToDecreaseMoreThanThreshold() thro
@Test @Test
public void doesNotAllowMoreThanOneInputFile() throws IOException { public void doesNotAllowMoreThanOneInputFile() throws IOException {
try { try {
parser.process(valid.getParentFile()); // valid indeholder 2 filer parser.process(valid.getParentFile(), "id"); // valid indeholder 2 filer
fail("Expected exception from parser because number of files is not one"); fail("Expected exception from parser because number of files is not one");
} catch (ParserException e) { } catch (ParserException e) {
assertThat(e.getMessage(), containsString("2")); // antal filer assertThat(e.getMessage(), containsString("2")); // antal filer
Expand Down

0 comments on commit 20057d2

Please sign in to comment.