12.07.2015 Views

Database.com Metadata API Developer's Guide - Salesforce.com

Database.com Metadata API Developer's Guide - Salesforce.com

Database.com Metadata API Developer's Guide - Salesforce.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

File-Based Callsdeploy()if (!deployResult.isSuccess() && deployResult.getErrorStatusCode() != null) {throw new Exception(deployResult.getErrorStatusCode() + " msg: " +deployResult.getErrorMessage());}if (!fetchDetails) {// Get the final result with details if we didn't do it in the last attempt.deployResult = metadataConnection.checkDeployStatus(asyncResultId, true);}if (!deployResult.isSuccess()) {printErrors(deployResult, "Final list of failures:\n");throw new Exception("The files were not successfully deployed");}}System.out.println("The file " + ZIP_FILE + " was successfully deployed");/*** Read the zip file contents into a byte array.* @return byte[]* @throws Exception - if cannot find the zip file to deploy*/private byte[] readZipFile()throws Exception{// We assume here that you have a deploy.zip file.// See the retrieve sample for how to retrieve a zip file.File deployZip = new File(ZIP_FILE);if (!deployZip.exists() || !deployZip.isFile())throw new Exception("Cannot find the zip file to deploy. Looking for " +deployZip.getAbsolutePath());}FileInputStream fos = new FileInputStream(deployZip);ByteArrayOutputStream bos = new ByteArrayOutputStream();int readbyte = -1;while ((readbyte = fos.read()) != -1) {bos.write(readbyte);}fos.close();bos.close();return bos.toByteArray();/*** Print out any errors, if any, related to the deploy.* @param result - DeployResult*/private void printErrors(DeployResult result, String messageHeader){DeployDetails deployDetails = result.getDetails();StringBuilder errorMessageBuilder = new StringBuilder();if (deployDetails != null) {DeployMessage[] <strong>com</strong>ponentFailures = deployDetails.getComponentFailures();for (DeployMessage message : <strong>com</strong>ponentFailures) {String loc = (message.getLineNumber() == 0 ? "" :("(" + message.getLineNumber() + "," +message.getColumnNumber() + ")"));if (loc.length() == 0&& !message.getFileName().equals(message.getFullName())) {loc = "(" + message.getFullName() + ")";}errorMessageBuilder.append(message.getFileName() + loc + ":" +message.getProblem()).append('\n');}RunTestsResult rtr = deployDetails.getRunTestResult();if (rtr.getFailures() != null) {for (RunTestFailure failure : rtr.getFailures()) {30

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!