-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from companieshouse/feature/add-put-endpoint
Add put endpoints to save disqualified officers
- Loading branch information
Showing
22 changed files
with
947 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...main/java/uk/gov/companieshouse/disqualifiedofficersdataapi/config/ApplicationConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/uk/gov/companieshouse/disqualifiedofficersdataapi/config/LoggingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...k/gov/companieshouse/disqualifiedofficersdataapi/config/MongoDisqualificationsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
.../companieshouse/disqualifiedofficersdataapi/controller/DisqualifiedOfficerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...a/uk/gov/companieshouse/disqualifiedofficersdataapi/controller/HealthCheckController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...v/companieshouse/disqualifiedofficersdataapi/model/CorporateDisqualificationDocument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/uk/gov/companieshouse/disqualifiedofficersdataapi/model/Created.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
Oops, something went wrong.