Skip to content

Commit

Permalink
Merge pull request #12 from companieshouse/feature/add-put-endpoint
Browse files Browse the repository at this point in the history
Add put endpoints to save disqualified officers
  • Loading branch information
amartin7663 authored Apr 6, 2022
2 parents 89b9e75 + 77199c9 commit 03b5d25
Show file tree
Hide file tree
Showing 22 changed files with 947 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
*.zip
*.tar.gz
*.rar
*.iml

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/target/

#Intellij
.idea
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ test-unit Run unit tests
## Endpoints
| URL | Description |
| --- | ----------- |
| /disqualified-officers-data-api/healthcheck | Health check URL returns 200 if service is running |
| /disqualified-officers/healthcheck | Health check URL returns 200 if service is running |
| --- | ----------- |
| /disqualified-officers/natural/{officerId}/internal | Save or update a natural disqualified officer record |
| --- | ----------- |
| /disqualified-officers/corporate/{officerId}/internal | Save or update a corporate disqualified officer record |
68 changes: 60 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>uk.gov.companieshouse</groupId>
<artifactId>companies-house-parent</artifactId>
<version>1.3.0</version>
<artifactId>companies-house-spring-boot-parent</artifactId>
<version>1.5.0-rc1</version>
<relativePath />
</parent>
<artifactId>disqualified-officers-data-api</artifactId>
Expand All @@ -23,6 +23,13 @@
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<jib-maven-plugin.version>3.1.1</jib-maven-plugin.version>
<io-cucumber.version>7.2.3</io-cucumber.version>

<!-- Internal -->
<structured-logging.version>1.9.12</structured-logging.version>
<private-api-sdk-java.version>2.0.141</private-api-sdk-java.version>
<api-sdk-manager-java-library.version>1.0.4</api-sdk-manager-java-library.version>
<api-helper-java-library.version>1.4.5</api-helper-java-library.version>

<!--sonar configuration-->
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml,
Expand Down Expand Up @@ -54,12 +61,57 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>uk.gov.companieshouse</groupId>
<artifactId>structured-logging</artifactId>
<version>${structured-logging.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.companieshouse</groupId>
<artifactId>private-api-sdk-java</artifactId>
<version>${private-api-sdk-java.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.companieshouse</groupId>
<artifactId>api-sdk-manager-java-library</artifactId>
<version>${api-sdk-manager-java-library.version}</version>
</dependency>
<dependency>
<groupId>uk.gov.companieshouse</groupId>
<artifactId>api-helper-java</artifactId>
<version>${api-helper-java-library.version}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${io-cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 3 additions & 1 deletion routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ app_name: disqualified-officers-data-api
group: api
weight: 905
routes:
1: ^/disqualified-officers-data-api/healthcheck
1: ^/disqualified-officers/healthcheck
2: ^/disqualified-officers/natural/(.*)/internal
3: ^/disqualified-officers/corporate/(.*)/internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package uk.gov.companieshouse.disqualifiedofficersdataapi.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import uk.gov.companieshouse.environment.EnvironmentReader;
import uk.gov.companieshouse.environment.impl.EnvironmentReaderImpl;

import javax.annotation.PostConstruct;

@Configuration
public class ApplicationConfig {

@Autowired
private MappingMongoConverter mappingMongoConverter;

@Bean
EnvironmentReader environmentReader() {
return new EnvironmentReaderImpl();
}


/**
* Converter to remove _class from the mongo record during saving
*/
@PostConstruct
public void createConverterToRemoveClassName() {
mappingMongoConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package uk.gov.companieshouse.disqualifiedofficersdataapi.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import uk.gov.companieshouse.logging.Logger;
import uk.gov.companieshouse.logging.LoggerFactory;

/**
* Configuration class for logging.
*/
@Configuration
public class LoggingConfig {

@Value("${logger.namespace}")
private String loggerNamespace;

/**
* Creates a logger with specified namespace.
*
* @return the {@link LoggerFactory} for the specified namespace
*/
@Bean
public Logger logger() {
return LoggerFactory.getLogger(loggerNamespace);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package uk.gov.companieshouse.disqualifiedofficersdataapi.config;

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.MongoTransactionManager;
import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@ConditionalOnProperty(name = "mongodb.disqualifications.disqualifications", havingValue = "true")
@Configuration
@EnableTransactionManagement
public class MongoDisqualificationsConfig extends AbstractMongoClientConfiguration {

@Value("${spring.data.mongodb.name}")
private String databaseName;

@Value("${spring.data.mongodb.uri}")
private String databaseUri;

@Bean
MongoTransactionManager transactionManager(MongoDatabaseFactory dbFactory) {
return new MongoTransactionManager(dbFactory);
}

@Override
protected String getDatabaseName() {
return this.databaseName;
}

protected String getDatabaseUri() {
return this.databaseUri;
}

@Override
public MongoClient mongoClient() {
final ConnectionString connectionString =
new ConnectionString(getDatabaseUri());
final MongoClientSettings mongoClientSettings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.build();
return MongoClients.create(mongoClientSettings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package uk.gov.companieshouse.disqualifiedofficersdataapi.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import uk.gov.companieshouse.api.disqualification.InternalCorporateDisqualificationApi;
import uk.gov.companieshouse.api.disqualification.InternalNaturalDisqualificationApi;
import uk.gov.companieshouse.disqualifiedofficersdataapi.service.DisqualifiedOfficerService;

import uk.gov.companieshouse.logging.Logger;

@RestController
public class DisqualifiedOfficerController {

@Autowired
private Logger logger;
@Autowired
private DisqualifiedOfficerService service;


/**
* PUT request to save or update a Natural Disqualified Officer.
*
* @param officerId the id for the disqualified officer
* @param requestBody the request body containing disqualified officer data
* @return no response
*/
@PutMapping("/disqualified-officers/natural/{officer_id}/internal")
public ResponseEntity<Void> naturalDisqualifiedOfficer(
@RequestHeader("x-request-id") String contextId,
@PathVariable("officer_id") String officerId,
@RequestBody InternalNaturalDisqualificationApi requestBody
) throws JsonProcessingException {
logger.info(String.format(
"Processing disqualified officer information for officer id %s",
officerId));

service.processNaturalDisqualification(contextId, officerId, requestBody);

return ResponseEntity.status(HttpStatus.OK).build();
}



/**
* PUT request to save or update a Corporate Disqualified Officers.
*
* @param officerId the id for the disqualified officer
* @param requestBody the request body containing disqualified officer data
* @return no response
*/
@PutMapping("/disqualified-officers/corporate/{officer_id}/internal")
public ResponseEntity<Void> corporateDisqualifiedOfficer(
@RequestHeader("x-request-id") String contextId,
@PathVariable("officer_id") String officerId,
@RequestBody InternalCorporateDisqualificationApi requestBody
) throws JsonProcessingException {
logger.info(String.format(
"Processing disqualified officer information for officer id %s",
officerId));

service.processCorporateDisqualification(contextId, officerId, requestBody);

return ResponseEntity.status(HttpStatus.OK).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package uk.gov.companieshouse.disqualifiedofficersdataapi.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HealthCheckController {

@GetMapping("/healthcheck")
public ResponseEntity<Void> healthcheck() {
return ResponseEntity.status(HttpStatus.OK).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package uk.gov.companieshouse.disqualifiedofficersdataapi.model;

import uk.gov.companieshouse.api.disqualification.CorporateDisqualificationApi;

public class CorporateDisqualificationDocument extends DisqualificationDocument {

private CorporateDisqualificationApi data;

public CorporateDisqualificationApi getData() {
return data;
}

public CorporateDisqualificationDocument setData(CorporateDisqualificationApi data) {
this.data = data;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package uk.gov.companieshouse.disqualifiedofficersdataapi.model;

import java.time.LocalDateTime;

public class Created {

private LocalDateTime at;

public LocalDateTime getAt() {
return at;
}

public Created setAt(LocalDateTime at) {
this.at = at;
return this;
}
}

Loading

0 comments on commit 03b5d25

Please sign in to comment.