RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
Subject overlord = LookupUtil.getSubjectManager().getOverlord();
List<AdvisoryDetails> newDetails = report.getAdvisory();
for (AdvisoryDetails detail : newDetails) {
try {
Advisory newAdv = advManager.getAdvisoryByName(detail.getAdvisory());
if (newAdv == null) {
// Advisory does not exist, create a new one
log.debug("Attempting to create new advisory based off of: " + detail);
newAdv = advManager.createAdvisory(overlord, detail.getAdvisory(), detail.getAdvisory_type(),
detail.getSynopsis());
newAdv.setAdvisory_name(detail.getAdvisory_name());
newAdv.setAdvisory_rel(detail.getAdvisory_rel());
newAdv.setDescription(detail.getDescription());
newAdv.setSolution(detail.getSolution());
newAdv.setIssue_date(detail.getIssue_date());
newAdv.setUpdate_date(detail.getUpdate_date());
newAdv.setTopic(detail.getTopic());
entityManager.flush();
entityManager.persist(newAdv);
}
Repo repo = repoManager.getRepo(overlord, report.getRepoId());
RepoAdvisory repoAdv = new RepoAdvisory(repo, newAdv);
log.debug("Created new mapping of RepoAdvisory repoId = " + repo.getId() + ", distId = "
+ newAdv.getId());
entityManager.flush();
entityManager.persist(repoAdv);
// persist pkgs associated with an errata
List<AdvisoryPackageDetails> pkgs = detail.getPkgs();
Query q = entityManager.createNamedQuery(PackageVersion.QUERY_FIND_PACKAGEVERSION_BY_FILENAME);
for (AdvisoryPackageDetails pkg : pkgs) {
try {
q.setParameter("rpmName", pkg.getRpmFilename());
PackageVersion pExisting = (PackageVersion) q.getSingleResult();
AdvisoryPackage apkg = advManager.findAdvisoryPackage(overlord, newAdv.getId(), pExisting
.getId());
if (apkg == null) {
apkg = new AdvisoryPackage(newAdv, pExisting);
entityManager.persist(apkg);
entityManager.flush();
}
} catch (NoResultException nre) {
log.info("Advisory has package thats not yet in the db [" + pkg.getRpmFilename()
+ "] - Processing rest");
}
}
//persist cves associated with an errata
List<AdvisoryCVEDetails> cves = detail.getCVEs();
log.debug("list of CVEs " + cves);
if (cves != null && cves.size() > 0) {
for (AdvisoryCVEDetails cve : cves) {
AdvisoryCVE acve = new AdvisoryCVE(newAdv, advManager.createCVE(overlord, cve.getName()));
entityManager.persist(acve);
entityManager.flush();
}
}
List<AdvisoryBugDetails> abugs = detail.getBugs();
log.debug("list of Bugs " + abugs);
if (abugs != null && abugs.size() > 0) {
for (AdvisoryBugDetails abug : abugs) {
AdvisoryBuglist abuglist = advManager.getAdvisoryBuglist(overlord, newAdv.getId(), abug
.getBugInfo());
if (abuglist == null) {
abuglist = new AdvisoryBuglist(newAdv, abug.getBugInfo());
entityManager.persist(abuglist);
entityManager.flush();