public class FamilyMapper {
private static final Logger logger = LoggerFactory.getLogger(CommonMapper.class);
public void toRelationship(Family dqFamily, Gedcom dqGedcom, GedcomxConversionResult result) throws IOException {
String familyId = dqFamily.getId();
Marker familyContext = ConversionContext.getDetachedMarker(String.format("@%s@ FAM", familyId));
ConversionContext.addReference(familyContext);
List<SpouseRef> husbands = dqFamily.getHusbandRefs();
String husbandId = husbands.size() > 0 ? husbands.get(0).getRef() : null;
List<SpouseRef> wives = dqFamily.getWifeRefs();
String wifeId = wives.size() > 0 ? wives.get(0).getRef() : null;
Relationship coupleRelationship = null;
Date lastModified = CommonMapper.toDate(dqFamily.getChange()); //todo: set the timestamp on the attribution?
if ( husbandId != null && wifeId != null) {
coupleRelationship = CommonMapper.toRelationship(familyId, husbandId, wifeId, RelationshipType.Couple);
result.addRelationship(coupleRelationship);
}
for (ChildRef child : dqFamily.getChildRefs()) {
String childId = child.getRef();
Person dqChild = (dqGedcom == null) ? null : dqGedcom.getPerson(childId);
List<ParentFamilyRef> childToFamilyLinks;
if (dqChild != null) {
childToFamilyLinks = dqChild.getParentFamilyRefs();
} else {
logger.warn(ConversionContext.getContext(), "Could not find referenced child (@{}@ INDI).", childId);
childToFamilyLinks = Collections.<ParentFamilyRef>emptyList();
}
if (husbandId != null) {
Relationship gedxRelationship = CommonMapper.toRelationship(familyId, husbandId, childId, RelationshipType.ParentChild);
addFacts(gedxRelationship, familyId, childToFamilyLinks);
result.addRelationship(gedxRelationship);
}
if (wifeId != null) {
Relationship gedxRelationship = CommonMapper.toRelationship(familyId, wifeId, childId, RelationshipType.ParentChild);
addFacts(gedxRelationship, familyId, childToFamilyLinks);
result.addRelationship(gedxRelationship);
}
}
int index = 0;
for (EventFact eventFact : dqFamily.getEventsFacts()) {
Marker factContext = ConversionContext.getDetachedMarker(eventFact.getTag() + '.' + (++index));
ConversionContext.addReference(factContext);
if (coupleRelationship != null) {
Fact fact = FactMapper.toFact(eventFact, result);
coupleRelationship.addFact(fact);
} else {
logger.warn(ConversionContext.getContext(), "The GEDCOM X converter only supports the {} fact in the presence of a couple relationship.", eventFact.getTag());
}
ConversionContext.removeReference(factContext);
}
if (coupleRelationship != null) {
coupleRelationship.setSources(CommonMapper.toSourcesAndSourceReferences(dqFamily.getSourceCitations(), result));
} else {
int size = dqFamily.getSourceCitations().size();
if (size > 0) {
logger.warn(ConversionContext.getContext(), "The GEDCOM X converter only supports a source citation(s) in the presence of a couple relationship; {} source citation(s) ignored.", size);
}
}
int cntLdsOrdinances = dqFamily.getLdsOrdinances().size();
if (cntLdsOrdinances > 0) {
logger.warn(ConversionContext.getContext(), "Did not convert information for {} LDS ordinances.", cntLdsOrdinances);
}
int cntNotes = dqFamily.getNotes().size() + dqFamily.getNoteRefs().size();
if (cntNotes > 0) {
logger.warn(ConversionContext.getContext(), "Did not process {} notes or references to notes.", cntNotes);
}
int cntMedia = dqFamily.getMedia().size() + dqFamily.getMediaRefs().size();
if (cntMedia > 0) {
logger.warn(ConversionContext.getContext(), "Did not process {} media items or references to media items.", cntMedia);
}
for (String refNum : dqFamily.getReferenceNumbers()) {
Marker refnContext = ConversionContext.getDetachedMarker("REFN");
ConversionContext.addReference(refnContext);
logger.warn(ConversionContext.getContext(), "User reference number ({}) was ignored.", refNum);
ConversionContext.removeReference(refnContext);
}
if (dqFamily.getRin() != null) {
logger.warn(ConversionContext.getContext(), "RIN ({}) was ignored.", dqFamily.getRin());
}
if (dqFamily.getUid() != null) {
Marker uidContext = ConversionContext.getDetachedMarker(dqFamily.getUidTag());
ConversionContext.addReference(uidContext);
logger.warn(ConversionContext.getContext(), "UID ({}) was ignored.", dqFamily.getUid());
ConversionContext.removeReference(uidContext);
}