Skip to content

Commit

Permalink
should check whole list for active exemptions
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrewCH committed Aug 9, 2024
1 parent d957acb commit 666b0e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,8 @@ private PscList createPscDocumentList(List<PscDocument> pscDocuments,
pscList.setStartIndex(startIndex);
pscList.setItems(documents);

if (hasPscExemptions(companyNumber)) {
if(hasExemptFrom(companyNumber) && !hasExemptTo(companyNumber)) {
links.setExemptions(String.format("/company/%s/exemptions", companyNumber));
}
if (hasActivePscExemptions(companyNumber)) {
links.setExemptions(String.format("/company/%s/exemptions", companyNumber));
}

companyMetrics.ifPresentOrElse(metricsApi -> {
Expand Down Expand Up @@ -645,49 +643,23 @@ private PscList createPscDocumentList(List<PscDocument> pscDocuments,
return pscList;
}

private boolean hasPscExemptions(String companyNumber) {
private boolean hasActivePscExemptions(String companyNumber) {
Optional<CompanyExemptions> companyExemptions = companyExemptionsApiService.getCompanyExemptions(companyNumber);

return companyExemptions.filter(x ->
x.getExemptions() != null &&
(x.getExemptions().getPscExemptAsSharesAdmittedOnMarket()!= null ||
x.getExemptions().getPscExemptAsTradingOnEuRegulatedMarket() != null ||
x.getExemptions().getPscExemptAsTradingOnRegulatedMarket() != null ||
x.getExemptions().getPscExemptAsTradingOnUkRegulatedMarket() != null)).isPresent();
}

private boolean hasExemptFrom(String companyNumber) {
Optional<CompanyExemptions> companyExemptions = companyExemptionsApiService.getCompanyExemptions(companyNumber);

return companyExemptions
.map(exemptions -> exemptions.getExemptions())
.filter(exemptions -> exemptions != null)
.map(exemptions -> exemptions.getPscExemptAsSharesAdmittedOnMarket() != null
&& exemptions.getPscExemptAsSharesAdmittedOnMarket().getItems().get(0).getExemptFrom() != null ||
exemptions.getPscExemptAsTradingOnEuRegulatedMarket() != null
&& exemptions.getPscExemptAsTradingOnEuRegulatedMarket().getItems().get(0).getExemptFrom() != null ||
exemptions.getPscExemptAsTradingOnRegulatedMarket() != null
&& exemptions.getPscExemptAsTradingOnRegulatedMarket().getItems().get(0).getExemptFrom() != null ||
exemptions.getPscExemptAsTradingOnUkRegulatedMarket() != null
&& exemptions.getPscExemptAsTradingOnUkRegulatedMarket().getItems().get(0).getExemptFrom() != null)
.orElse(false);
}

private boolean hasExemptTo(String companyNumber) {
Optional<CompanyExemptions> companyExemptions = companyExemptionsApiService.getCompanyExemptions(companyNumber);

return companyExemptions
.map(exemptions -> exemptions.getExemptions())
.filter(exemptions -> exemptions != null)
.map(exemptions -> exemptions.getPscExemptAsSharesAdmittedOnMarket() != null
&& exemptions.getPscExemptAsSharesAdmittedOnMarket().getItems().get(0).getExemptTo() != null ||
exemptions.getPscExemptAsTradingOnEuRegulatedMarket() != null
&& exemptions.getPscExemptAsTradingOnEuRegulatedMarket().getItems().get(0).getExemptTo() != null ||
exemptions.getPscExemptAsTradingOnRegulatedMarket() != null
&& exemptions.getPscExemptAsTradingOnRegulatedMarket().getItems().get(0).getExemptTo() != null ||
exemptions.getPscExemptAsTradingOnUkRegulatedMarket() != null
&& exemptions.getPscExemptAsTradingOnUkRegulatedMarket().getItems().get(0).getExemptTo() != null)
.orElse(false);
((x.getExemptions().getPscExemptAsSharesAdmittedOnMarket()!= null &&
x.getExemptions().getPscExemptAsSharesAdmittedOnMarket().getItems().stream()
.anyMatch(e -> e.getExemptTo()==null)) ||
(x.getExemptions().getPscExemptAsTradingOnEuRegulatedMarket() != null &&
x.getExemptions().getPscExemptAsTradingOnEuRegulatedMarket().getItems().stream()
.anyMatch(e -> e.getExemptTo()==null)) ||
(x.getExemptions().getPscExemptAsTradingOnRegulatedMarket() != null &&
x.getExemptions().getPscExemptAsTradingOnRegulatedMarket().getItems().stream()
.anyMatch(e -> e.getExemptTo()==null)) ||
(x.getExemptions().getPscExemptAsTradingOnUkRegulatedMarket() != null &&
x.getExemptions().getPscExemptAsTradingOnRegulatedMarket().getItems().stream()
.anyMatch(e -> e.getExemptTo()==null)))).isPresent();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.springframework.util.FileCopyUtils;
Expand Down Expand Up @@ -475,7 +476,11 @@ private Exemptions getExemptions() {
exemptionItem.exemptFrom(EXEMPTION_DATE);
exemptionItem.exemptTo(null);

List<ExemptionItem> exemptionItems = Collections.singletonList(exemptionItem);
ExemptionItem ceasedExemptionItem = new ExemptionItem();
exemptionItem.exemptFrom(EXEMPTION_DATE);
exemptionItem.exemptTo(EXEMPTION_DATE);

List<ExemptionItem> exemptionItems = Arrays.asList(exemptionItem, ceasedExemptionItem);


PscExemptAsTradingOnRegulatedMarketItem nonUkEeaStateMarket = new PscExemptAsTradingOnRegulatedMarketItem();
Expand Down

0 comments on commit 666b0e8

Please sign in to comment.