Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contractual party mapping fix #64

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cdm.event.common.processor;

import cdm.base.staticdata.party.metafields.ReferenceWithMetaParty;
import cdm.legaldocumentation.common.*;
import cdm.legaldocumentation.common.metafields.FieldWithMetaContractualDefinitionsEnum;
import cdm.legaldocumentation.contract.processor.PartyMappingHelper;
import cdm.legaldocumentation.master.MasterAgreementTypeEnum;
import cdm.legaldocumentation.master.MasterConfirmationAnnexTypeEnum;
import cdm.legaldocumentation.master.MasterConfirmationTypeEnum;
Expand All @@ -12,24 +14,37 @@
import com.regnosys.rosetta.common.translation.SynonymToEnumMap;
import com.rosetta.model.lib.path.RosettaPath;
import com.rosetta.model.lib.records.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;

import static com.regnosys.rosetta.common.translation.MappingProcessorUtils.filterListMappings;
import static com.regnosys.rosetta.common.translation.MappingProcessorUtils.setValueAndUpdateMappings;

public class DocumentationHelper {

private static final Logger LOGGER = LoggerFactory.getLogger(DocumentationHelper.class);
private final RosettaPath rosettaPath;
private final MappingContext mappingContext;
private final List<Mapping> mappings;
private final SynonymToEnumMap synonymToEnumMap;
private final ExecutorService executor;
private final List<CompletableFuture<?>> invokedTasks;

public DocumentationHelper(RosettaPath rosettaPath, MappingContext context) {
public DocumentationHelper(RosettaPath rosettaPath, MappingContext mappingContext) {
this.rosettaPath = rosettaPath;
this.mappings = context.getMappings();
this.synonymToEnumMap = context.getSynonymToEnumMap();
this.mappingContext = mappingContext;
this.mappings = mappingContext.getMappings();
this.executor = mappingContext.getExecutor();
this.invokedTasks = mappingContext.getInvokedTasks();
this.synonymToEnumMap = mappingContext.getSynonymToEnumMap();
}

public List<LegalAgreement> getDocumentation(Path synonymPath) {
Expand Down Expand Up @@ -75,6 +90,10 @@ private Optional<LegalAgreement> getMasterAgreement(Path synonymPath) {
mappings,
rosettaPath);

if (builder.hasData()) {
setContractualParty(builder);
}

return setAgreementType(builder, LegalAgreementTypeEnum.MASTER_AGREEMENT);
}

Expand Down Expand Up @@ -122,11 +141,20 @@ private Optional<LegalAgreement> getMasterConfirmation(Path synonymPath) {
mappings,
rosettaPath);

if (builder.hasData()) {
setContractualParty(builder);
}

return setAgreementType(builder, LegalAgreementTypeEnum.MASTER_CONFIRMATION);
}

private Optional<LegalAgreement> getBrokerConfirmation(Path synonymPath) {
LegalAgreement.LegalAgreementBuilder builder = LegalAgreement.builder();

if (builder.hasData()) {
setContractualParty(builder);
}

return setAgreementType(builder, LegalAgreementTypeEnum.BROKER_CONFIRMATION);
}

Expand Down Expand Up @@ -157,6 +185,10 @@ private Optional<LegalAgreement> getCreditSupportAgreement(Path synonymPath) {
mappings,
rosettaPath);

if (builder.hasData()) {
setContractualParty(builder);
}

return setAgreementType(builder, LegalAgreementTypeEnum.CREDIT_SUPPORT_AGREEMENT);
}

Expand Down Expand Up @@ -251,6 +283,10 @@ private Optional<LegalAgreement> getConfirmation(Path synonymPath) {
}
});

if (builder.hasData()) {
setContractualParty(builder);
}

return setAgreementType(builder, LegalAgreementTypeEnum.CONFIRMATION);
}

Expand Down Expand Up @@ -279,10 +315,13 @@ private Optional<LegalAgreement> getOtherAgreement(Path synonymPath) {
mappings,
rosettaPath);

if (builder.hasData()) {
setContractualParty(builder);
}

return setAgreementType(builder, LegalAgreementTypeEnum.OTHER);
}


private Optional<LegalAgreement> setAgreementType(LegalAgreement.LegalAgreementBuilder builder, LegalAgreementTypeEnum masterAgreement) {
if (builder.hasData()) {
builder.getOrCreateLegalAgreementIdentification()
Expand All @@ -293,4 +332,22 @@ private Optional<LegalAgreement> setAgreementType(LegalAgreement.LegalAgreementB
return Optional.empty();
}
}

private void setContractualParty(LegalAgreement.LegalAgreementBuilder builder) {
PartyMappingHelper.getInstance(mappingContext).ifPresent(helper -> {
LOGGER.debug("Waiting for counterparties to be collected before updating contractual parties");
// wait until both counterparties have been collected before getting party references.
// also, add task to invokedTasks so the mapping process does not get shutdown prematurely.
invokedTasks.add(helper.getBothCounterpartiesCollectedFuture().thenAcceptAsync(counterpartyMap -> {
Set<String> counterpartyExternalRefs = counterpartyMap.keySet();
LOGGER.info("Setting contractual party references {}", counterpartyExternalRefs);
List<ReferenceWithMetaParty.ReferenceWithMetaPartyBuilder> contractualParties =
counterpartyExternalRefs.stream()
.map(counterpartyRef ->
ReferenceWithMetaParty.builder().setExternalReference(counterpartyRef))
.collect(Collectors.toList());
builder.setContractualParty(contractualParties);
}, executor));
});
}
}
Loading
Loading