| Total Complexity | 5 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package com.hltech.pact.gen.domain.pact; |
||
| 13 | @Slf4j |
||
| 14 | public class PactJsonGenerator { |
||
| 15 | |||
| 16 | private ObjectMapper objectMapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); |
||
| 17 | |||
| 18 | public void writePactFiles(File destinationDir, Collection<Pact> pacts) { |
||
| 19 | pacts.forEach(pact -> writePactFile(destinationDir, pact)); |
||
| 20 | } |
||
| 21 | |||
| 22 | private void writePactFile(File destinationDir, Pact pact) { |
||
| 23 | if (destinationDir != null && !destinationDir.exists()) { |
||
| 24 | destinationDir.mkdirs(); |
||
| 25 | } |
||
| 26 | |||
| 27 | final String pactFileName = pact.getConsumer().getName() + "-" + pact.getProvider().getName() + ".json"; |
||
| 28 | try { |
||
| 29 | objectMapper.writeValue(new File(destinationDir, pactFileName), pact); |
||
| 30 | } catch (IOException ex) { |
||
| 31 | log.error("Unable to write {} to json file", pact); |
||
| 32 | throw new PactGenerationException("Unable to write pact to json file", ex); |
||
| 33 | } |
||
| 36 |