repoId = FacesContextUtility.getRequiredRequestParameter("id");
}
}
try {
PackageVersion packageVersion = null;
try {
log.debug("Streaming new package bits from uploaded file: " + fileItem.getFile());
// Grab a stream for the file being uploaded
InputStream packageStream = new FileInputStream(fileItem.getFile());
try {
// Ask the bean to create the package
/* Currently, this is just used in the workflow for deploying a new package. This will probably get
refactored in the future for a general way of adding packages to the repo as its own operation. For
now, don't worry about that. The rest of this will be written assuming it's part of the deploy
workflow and we'll deal with the refactoring later.
jdobies, Feb 27, 2008
*/
try {
ContentManagerLocal contentManager = LookupUtil.getContentManager();
//store information about uploaded file for packageDetails as most of it is already available
Map<String, String> packageUploadDetails = new HashMap<String, String>();
packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_SIZE,
String.valueOf(fileItem.getFileSize()));
packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_INSTALL_DATE,
String.valueOf(System.currentTimeMillis()));
packageUploadDetails.put(ContentManagerLocal.UPLOAD_OWNER, subject.getName());
packageUploadDetails.put(ContentManagerLocal.UPLOAD_FILE_NAME, fileItem.getFileName());
String sha = null;
String md5 = null;
try {//Easier to implement here than in server side bean. Shouldn't affect performance too much.
md5 = new MessageDigestGenerator(MessageDigestGenerator.MD5).calcDigestString(fileItem
.getFile());
sha = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(fileItem
.getFile());
} catch (IOException e1) {
log.warn("Error calculating file digest(s)", e1);
}
packageUploadDetails.put(ContentManagerLocal.UPLOAD_MD5, md5);
packageUploadDetails.put(ContentManagerLocal.UPLOAD_SHA256, sha);
packageUploadDetails.put(ContentManagerLocal.UPLOAD_DISPLAY_VERSION, displayVersion);
//For package types that handle their own versioning, etc. let's use what the user passed in
//as a version. For the standard, i.e. agent-plugin defined, package types use what we want
//to use for them - sha-based versions to deal with improper versions discovered/declared by
//the packages (i.e. versions in MANIFEST.MF not properly updated)
//
//Did I say I can't wait for all this to disappear with the new provisioning? :)
boolean nonStandardPackageType = ContentManagerHelper.getPackageTypePluginContainer().getPluginManager().getBehavior(packageTypeId) != null;
String versionToUse = nonStandardPackageType ? displayVersion : formatVersion(sha);
Integer iRepoId = usingARepo ? Integer.parseInt(repoId) : null;
packageVersion = contentManager.getUploadedPackageVersion(subject, packageName, packageTypeId,
versionToUse, architectureId, packageStream, packageUploadDetails, iRepoId);
} catch (NoResultException nre) {
//eat the exception. Some of the queries return no results if no package yet exists which is fine.
} catch (Exception e) {
String errorMessages = ThrowableUtil.getAllMessages(e);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR, "Failed to create package ["
+ packageName + "] in repository. Cause: " + errorMessages);
return "failure";
}
} finally {
packageStream.close();
}
} catch (IOException e) {
String errorMessages = ThrowableUtil.getAllMessages(e);
FacesContextUtility.addMessage(FacesMessage.SEVERITY_ERROR,
"Failed to retrieve the input stream. Cause: " + errorMessages);
return "failure";
}
int[] packageVersionList = new int[] { packageVersion.getId() };
// Put the package ID in the session so it can fit into the deploy existing package workflow
HttpSession session = request.getSession();
session.setAttribute("selectedPackages", packageVersionList);
} finally {