1 37 package net.sourceforge.cruisecontrol.publishers.sfee; 38 39 import com.vasoftware.sf.soap42.webservices.ClientSoapStubFactory; 40 import com.vasoftware.sf.soap42.webservices.filestorage.IFileStorageAppSoap; 41 import com.vasoftware.sf.soap42.webservices.frs.FrsFileSoapList; 42 import com.vasoftware.sf.soap42.webservices.frs.FrsFileSoapRow; 43 import com.vasoftware.sf.soap42.webservices.frs.IFrsAppSoap; 44 import com.vasoftware.sf.soap42.webservices.sfmain.ISourceForgeSoap; 45 import net.sourceforge.cruisecontrol.CruiseControlException; 46 import net.sourceforge.cruisecontrol.util.ValidationHelper; 47 import org.jdom.Element; 48 49 import javax.activation.DataHandler ; 50 import java.io.File ; 51 import java.net.MalformedURLException ; 52 import java.rmi.RemoteException ; 53 import java.util.ArrayList ; 54 import java.util.Collection ; 55 import java.util.Iterator ; 56 57 63 public class SfeeFrsPublisher extends SfeePublisher { 64 private File file; 65 private String releaseID; 66 private String uploadName; 67 68 public void setFile(String filename) { 69 this.file = new File (filename); 70 } 71 72 public void setReleaseID(String releaseID) { 73 this.releaseID = releaseID; 74 } 75 76 public void setUploadname(String uploadname) { 77 uploadName = uploadname; 78 } 79 80 public void publish(Element cruisecontrolLog) throws CruiseControlException { 81 ValidationHelper.assertExists(getFile(), "file", this.getClass()); 82 ValidationHelper.assertIsNotDirectory(getFile(), "file", this.getClass()); 83 ValidationHelper.assertIsReadable(getFile(), "file", this.getClass()); 84 85 if (uploadName == null) { 86 uploadName = getFile().getName(); 87 } 88 89 ISourceForgeSoap soap = (ISourceForgeSoap) ClientSoapStubFactory 90 .getSoapStub(ISourceForgeSoap.class, getServerURL()); 91 try { 92 String sessionID = soap.login(getUsername(), getPassword()); 93 94 IFrsAppSoap frsApp = (IFrsAppSoap) ClientSoapStubFactory.getSoapStub(IFrsAppSoap.class, getServerURL()); 95 96 FrsFileSoapList fileList = frsApp.getFrsFileList(sessionID, releaseID); 97 Collection existingFiles = findExistingFiles(fileList, uploadName); 98 for (Iterator i = existingFiles.iterator(); i.hasNext();) { 99 String id = (String ) i.next(); 100 frsApp.deleteFrsFile(sessionID, id); 101 } 102 103 DataHandler dataHandler = new DataHandler (getFile().toURL()); 104 IFileStorageAppSoap fileStorageApp = 105 (IFileStorageAppSoap) ClientSoapStubFactory.getSoapStub(IFileStorageAppSoap.class, getServerURL()); 106 String storedFileId = fileStorageApp.uploadFile(sessionID, dataHandler); 107 frsApp.createFrsFile(sessionID, releaseID, uploadName, dataHandler.getContentType(), storedFileId); 108 } catch (RemoteException e) { 109 throw new CruiseControlException(e); 110 } catch (MalformedURLException e) { 111 throw new CruiseControlException(e); 112 } 113 114 115 } 116 117 protected File getFile() { 118 return file; 119 } 120 121 private static Collection findExistingFiles(FrsFileSoapList fileList, String filename) { 122 FrsFileSoapRow[] files = fileList.getDataRows(); 123 ArrayList duplicates = new ArrayList (); 124 for (int i = 0; i < files.length; i++) { 125 FrsFileSoapRow nextFile = files[i]; 126 if (nextFile.getFilename().equals(filename)) { 127 duplicates.add(nextFile.getId()); 128 } 129 } 130 return duplicates; 131 } 132 133 public void subValidate() throws CruiseControlException { 134 ValidationHelper.assertIsSet(releaseID, "releaseid", this.getClass()); 135 ValidationHelper.assertIsSet(getFile(), "file", this.getClass()); 136 } 137 } 138 | Popular Tags |