Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright 2010 Västra Götalandsregionen
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
*/
package se.vgregion.usdservice;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.rpc.holders.StringHolder;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.utils.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import se.vgregion.usdservice.domain.Issue;
import com.ca.www.UnicenterServicePlus.ServiceDesk.USD_WebServiceSoap;
import com.ca.www.UnicenterServicePlus.ServiceDesk.USD_WebServiceSoapSoapBindingStub;
/**
* @author Andrew Culbert
* @author Ulf Carlsson
*
*/
public class USDServiceImpl implements USDService {
private URL endPoint;
private String wsUser;
private String wsPassword;
private String wsAttachmentRepHandle;
private USD_WebServiceSoapSoapBindingStub webService;
private static final Log log = LogFactory.getLog(USDServiceImpl.class);
private Properties usdAppToGroupMappings;
// Define which attributes to fetch when retrieving contact's issue list
private static final String[] attributeNamesMultiTypeList = new String[] { "description", "summary",
"status.sym", "ref_num", "web_url", "type" };
private static final String[] attributeNamesChangeOrderList = new String[] { "description", "summary",
"status.sym", "chg_ref_num", "web_url" };
private static final String TYPE_ISSUE = "IS";
private static final String TYPE_CHANGE_ORDER = "C";
public USDServiceImpl(Properties p) {
String sEndPoint = p.getProperty("endpoint");
try {
endPoint = new URL(sEndPoint);
} catch (MalformedURLException e) {
throw new RuntimeException("URL not found:" + sEndPoint, e);
}
this.wsUser = p.getProperty("user");
this.wsPassword = p.getProperty("password");
this.wsAttachmentRepHandle = p.getProperty("repositoryHandle");
}
public Properties getUsdAppToGroupMappings() {
return usdAppToGroupMappings;
}
public void setUsdAppToGroupMappings(Properties appToGroupMappings) {
this.usdAppToGroupMappings = appToGroupMappings;
// System.out.println("USDMappings:" + usdAppToGroupMappings);
}
private void createAttachment(USD_WebServiceSoap service, int sid, String repHandle, String objectHandle,
String description, String fileName) throws Exception {
FileDataSource fds = new FileDataSource(fileName);
DataHandler dhandler = new DataHandler(fds);
// Affix DIME type header to attachment before sending
((javax.xml.rpc.Stub) service)._setProperty(org.apache.axis.client.Call.ATTACHMENT_ENCAPSULATION_FORMAT,
Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
((org.apache.axis.client.Stub) service).addAttachment(dhandler);
// Create attachment
service.createAttachment(sid, repHandle, objectHandle, description, fileName);
//System.out.println("Creating attachment...SUCCESS");
}
protected String getHandleFromResponse(InputStream xml) throws Exception {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(xml);
NodeList handles = doc.getElementsByTagName("Handle");
int i = handles.getLength();
for (int s = 0; s < handles.getLength(); s++) {
Node handleNode = handles.item(s);
return handleNode.getFirstChild().getNodeValue();
}
return "";
}
private String getGroupHandle(String groupName) {
int sessionID = 0;
String sql = "type = 2308 and delete_flag = 0 and last_name = '" + groupName + "'";
try {
sessionID = getWebService().login(wsUser, wsPassword);
String result = getWebService().doSelect(sessionID, "cnt", sql, -1, new String[] { "last_name" });
ByteArrayInputStream s = new ByteArrayInputStream(result.getBytes());
return getHandleFromResponse(s);
} catch (RemoteException e) {
throw new RuntimeException("Error when getting group handle", e);
} catch (Exception e) {
throw new RuntimeException("Error when parsing xml response when searching for a group", e);
}
}
public String createRequest(Properties requestParameters, String userId, List files,
List filenames) {
String result = null;
int sessionID = 0;
try {
String contactHandle;
sessionID = getWebService().login(wsUser, wsPassword);
try {
contactHandle = getHandleForUserid(sessionID, userId);
} catch (Throwable e) {
log.debug("Trying default contactHandle:" + e.getMessage());
// Use the wsUser if the user is unknown
contactHandle = getHandleForUserid(sessionID, wsUser);
// contactHandle = wsUser;
}
requestParameters.setProperty("customer", contactHandle);
List lAttributes = new ArrayList();
List lAttributeValues = new ArrayList();
for (Enumeration