packageVersionQuery.setParameter("resourceTypeId", resourceTypeId);
PackageVersion packageVersion = (PackageVersion) packageVersionQuery.getSingleResult();
// Create the history entity
InstalledPackageHistory history = new InstalledPackageHistory();
history.setContentServiceRequest(persistedRequest);
history.setPackageVersion(packageVersion);
history.setResource(resource);
history.setTimestamp(timestamp);
// Link the deployment configuration values that were saved for the initial history entity for this
// package with this entity as well. This will let us show the user the configuration values on the
// last entry in the audit trail (i.e. for a failed package, the configuration values will be accessible).
Query deploymentConfigurationQuery = entityManager
.createNamedQuery(InstalledPackageHistory.QUERY_FIND_CONFIG_BY_PACKAGE_VERSION_AND_REQ);
deploymentConfigurationQuery.setParameter("packageVersion", packageVersion);
deploymentConfigurationQuery.setParameter("contentServiceRequest", persistedRequest);
deploymentConfigurationQuery.setMaxResults(1);
Configuration deploymentConfiguration = null;
List deploymentConfigurationResults = deploymentConfigurationQuery.getResultList();
if (deploymentConfigurationResults.size() > 0) {
deploymentConfiguration = (Configuration) deploymentConfigurationResults.get(0);
deploymentConfiguration = deploymentConfiguration.deepCopy(false);
}
history.setDeploymentConfigurationValues(deploymentConfiguration);
// If the package indicated installation steps, link them to the resulting history entry
List<DeployPackageStep> transferObjectSteps = singleResponse.getDeploymentSteps();
if (transferObjectSteps != null) {
List<PackageInstallationStep> installationSteps = translateInstallationSteps(transferObjectSteps,
history);
history.setInstallationSteps(installationSteps);
}
if (singleResponse.getResult() == ContentResponseResult.SUCCESS) {
history.setStatus(InstalledPackageHistoryStatus.INSTALLED);
} else {
history.setStatus(InstalledPackageHistoryStatus.FAILED);
history.setErrorMessage(singleResponse.getErrorMessage());
}
entityManager.persist(history);
persistedRequest.addInstalledPackageHistory(history);
// We're closing out the package request for this package version, so remove it from the cache of entries
// that need to be closed
inProgressEntries.remove(packageVersion);
}
// For any entries that were not closed, add closing entries
for (InstalledPackageHistory unclosed : inProgressEntries.values()) {
PackageVersion packageVersion = unclosed.getPackageVersion();
// Create the history entity
InstalledPackageHistory history = new InstalledPackageHistory();
history.setContentServiceRequest(persistedRequest);
history.setPackageVersion(packageVersion);
history.setResource(resource);
history.setTimestamp(timestamp);
// One option is to create a new status that indicates unknown. For now, just give them the same result
// as the overall request result
if (response.getOverallRequestResult() == ContentResponseResult.SUCCESS) {
history.setStatus(InstalledPackageHistoryStatus.INSTALLED);
} else {
history.setStatus(InstalledPackageHistoryStatus.FAILED);
history.setErrorMessage(response.getOverallRequestErrorMessage());
}
entityManager.persist(history);
persistedRequest.addInstalledPackageHistory(history);
}