* OPERATION TO ADD THE DB PK ID AS THE PARENT
*
* - DB WRITE: SECTION PLUS ALL CONTENT (FULL AND PARTS)
*/
private void sectionEnd() {
Section currentSection = this.model.getSection();
String itempath = currentSection.getSourceReference();
// get the primary key for the "parent" section
String[] pathelements = getItemPathElements(itempath);
if (pathelements != null && pathelements.length > 0 && !pathelements[0].equals(itempath)) {
pathelements = Arrays.copyOf(pathelements, pathelements.length - 1);
// String parentItempath = "/"
// + StringUtils.arrayToDelimitedString(pathelements, "/");
String parentItempath = getParentItemPath(itempath);
Integer parentPrimaryKey = this.model.findPrimaryKey(parentItempath);
if (parentPrimaryKey == null && pathelements.length > 0) {
// BUILD THE MISSING PARENT!!!
this.buildMissingParentSection(parentItempath);
parentPrimaryKey = this.model.findPrimaryKey(parentItempath);
}
String parentLevelPosition = this.model.findLevelPosition(parentItempath);
Integer currentSequence = this.sectionSequenceTracker.get(parentItempath);
Integer nextSequence = 1;
if (currentSequence != null) {
nextSequence = currentSequence + 1;
}
log.debug("looking for parent primary key: used itempath [" + itempath
+ "], converted to parent item path [" + parentItempath + "] found pk [" + parentPrimaryKey + "]");
// add parent's primary key
currentSection.setParentSectionId(parentPrimaryKey);
currentSection.setSectionSequence(nextSequence);
currentSection.setParentLevelPosition(parentLevelPosition);
this.sectionSequenceTracker.put(parentItempath, nextSequence);
}
// SAVE SECTION
persistence.storeSection(currentSection);
// CONFIRM: ADD PK TO MODEL TRACKER
assert currentSection.getId() != null : "Attempting to add a section's primary key, but it is null after a save";
log.debug("Adding Primary Key for itempath->sectionId: " + itempath + "," + currentSection.getId());
this.model.addPrimaryKeyMapping(itempath, currentSection.getId());
this.model.addLevelPositionMapping(itempath, currentSection.getLevelPosition());
this.sectionSequenceTracker.put(itempath, 0); // this is for any
// children
// SAVE CONTENTS
ContentFull contentFull = this.convertUscFieldsToContentFull(currentSection);
List<ContentPart> contentPartList = this.convertUscFieldsToContentPartList(currentSection);
// RULE: If content is ONLY NOTES, it almost always
// (I have not seen an exception yet)
// is all DIVS and TABLES...
// VERY difficult to chop up into content parts... only store full for
// now.
persistence.storeContentFull(contentFull, (!currentSection.getIsNewRecord() == Boolean.TRUE));
if (!contentFull.isNotes()) {
persistence.storeContentParts(currentSection.getId(), contentFull.getId(), contentPartList,
(!currentSection.getIsNewRecord() == Boolean.TRUE));
}
this.workingUscFieldList = null;
this.currentUscField = null;