}
// now finally create the new package version - this cascade-persists down several levels
// note that other content sources might already be previously defined this, so only
// persist it if it does not yet exist
PackageVersion pv = new PackageVersion(pkg, newDetails.getVersion(), arch);
pv.setDisplayName(newDetails.getDisplayName());
pv.setDisplayVersion(newDetails.getDisplayVersion());
pv.setExtraProperties(newDetails.getExtraProperties());
pv.setFileCreatedDate(newDetails.getFileCreatedDate());
pv.setFileName(newDetails.getFileName());
pv.setFileSize(newDetails.getFileSize());
pv.setLicenseName(newDetails.getLicenseName());
pv.setLicenseVersion(newDetails.getLicenseVersion());
pv.setLongDescription(newDetails.getLongDescription());
pv.setMD5(newDetails.getMD5());
pv.setMetadata(newDetails.getMetadata());
pv.setSHA256(newDetails.getSHA256());
pv.setShortDescription(newDetails.getShortDescription());
q = entityManager.createNamedQuery(PackageVersion.QUERY_FIND_BY_PACKAGE_DETAILS_KEY);
q.setParameter("packageName", newDetails.getName());
q.setParameter("packageTypeName", pt.getName());
q.setParameter("resourceType", rt);
q.setParameter("architectureName", arch.getName());
q.setParameter("version", newDetails.getVersion());
try {
PackageVersion pvExisting = (PackageVersion) q.getSingleResult();
// the PackageVersion already exists, which is OK, another content source already defined it
// but, let's make sure the important pieces of data are the same, otherwise, two content
// sources SAY they have the same PackageVersion, but they really don't. We warn in the log
// but the new data will overwrite the old.
packageVersionAttributeCheck(pvExisting, pvExisting.getExtraProperties(), pv, pv.getExtraProperties(),
"ExtraProps");
packageVersionAttributeCheck(pvExisting, pvExisting.getFileSize(), pv, pv.getFileSize(), "FileSize");
packageVersionAttributeCheck(pvExisting, pvExisting.getFileName(), pv, pv.getFileName(), "FileName");
packageVersionAttributeCheck(pvExisting, pvExisting.getMD5(), pv, pv.getMD5(), "MD5");
packageVersionAttributeCheck(pvExisting, pvExisting.getSHA256(), pv, pv.getSHA256(), "SHA256");
// what about metadata? test that for length only? string comparision check?
pv = pvExisting;
} catch (NoResultException nre) {
// this is fine, its the first time we've seen this PV, let merge just create a new one