// persistDefinitionChangeSet where the definition is passed as an argument to
// the latter. As it stands right now, each plugin implementation will have
// duplicate logic for determining whether this is a template or definition change
// set. That logic could be pulled up into DriftManagerBean.
MongoDBChangeSet newChangeSet = new MongoDBChangeSet();
newChangeSet.setResourceId(changeSet.getResourceId());
newChangeSet.setDriftDefinitionId(changeSet.getDriftDefinitionId());
newChangeSet.setDriftHandlingMode(changeSet.getDriftHandlingMode());
newChangeSet.setCategory(changeSet.getCategory());
newChangeSet.setDriftDefinitionId(changeSet.getDriftDefinitionId());
if (!isTemplateChangeSet(changeSet)) {
DriftDefinition driftDef = getDriftDef(subject, changeSet.getDriftDefinitionId());
if (driftDef == null) {
throw new IllegalArgumentException("Cannot persist change set. " +
DriftDefinition.class.getSimpleName() + " with id " + changeSet.getDriftDefinitionId() +
" cannot be found.");
}
newChangeSet.setDriftDefinitionName(driftDef.getName());
}
for (Drift drift : changeSet.getDrifts()) {
MongoDBChangeSetEntry entry = new MongoDBChangeSetEntry();
entry.setPath(drift.getPath());
entry.setCategory(drift.getCategory());
// we only need to initialize the newFileHash property here since each drift
// is going to be a FILE_ADDED entry.
entry.setNewFileHash(drift.getNewDriftFile().getHashId());
newChangeSet.add(entry);
}
changeSetDAO.save(newChangeSet);
return newChangeSet.getId();
}