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.
* 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 com.ca.www.UnicenterServicePlus.ServiceDesk.ArrayOfString;
import com.ca.www.UnicenterServicePlus.ServiceDesk.USDWebServiceSoap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.util.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import se.vgregion.usdservice.domain.Issue;
import se.vgregion.util.Attachment;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.util.ByteArrayDataSource;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.ws.Holder;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
/**
* @author David Rosell - Redpill-Linpro
*/
public class USDServiceImpl implements USDService {
private URL endPoint;
private String wsUser;
private String wsPassword;
private String wsAttachmentRepHandle;
private USDWebServiceSoap ws;
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 List ATTRIBUTE_NAMES = Arrays.asList("description", "summary", "status.sym",
"ref_num", "web_url", "type");
private static final List ATTRIBUTE_NAMES_CHG = Arrays.asList("description", "summary", "status.sym",
"chg_ref_num", "web_url");
private static final String TYPE_CHANGE_ORDER = "C";
public USDServiceImpl(Properties p) {
String sEndPoint = p.getProperty("endpoint");
try {
this.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;
}
/*
* (non-Javadoc)
*
* @see se.vgregion.usdservice.USDService#lookupIssues(java.lang.String, java.lang.Integer)
*/
@Override
public List lookupIssues(String userId, int maxRows, boolean includeGroups) {
int sessionID = 0;
try {
sessionID = getUSDWebService().login(wsUser, wsPassword);
String contactHandle = lookupContactHandle(userId, sessionID);
if (contactHandle == null) {
// User not registered in USD, return null
return null;
}
List records = new ArrayList();
// Change Orders - Assignee
records.addAll(getChangeOrdersForAssignee(sessionID, contactHandle, maxRows));
// Incidents, Problems, Requests - Assignee
records.addAll(getRequestForAssignee(sessionID, contactHandle, maxRows));
// Change Orders - Affected
records.addAll(getChangeOrdersForContact(sessionID, contactHandle, maxRows));
// Incidents, Problems, Requests - Affected
records.addAll(getRequestForContact(sessionID, contactHandle, maxRows));
// Group issues - not assigen to user
if (includeGroups) {
String groups = lookupUserGroups(sessionID, contactHandle);
if (groups.length() > 0) {
records.addAll(getChangeOrdersForContactByGroup(sessionID, contactHandle, groups, maxRows));
records.addAll(getRequestForContactByGroup(sessionID, contactHandle, groups, maxRows));
}
}
List listWithoutDuplicates = new ArrayList();
for (Issue record : records) {
if (!listWithoutDuplicates.contains(record)) {
listWithoutDuplicates.add(record);
}
}
return listWithoutDuplicates;
} catch (RemoteException e) {
log.error("Failed to get issue list from USD Service for user=" + userId, e);
throw new RuntimeException(e);
} finally {
getUSDWebService().logout(sessionID);
}
}
/* TODO: Cannot upload attachments */
@Override
public String createRequest(Properties requestParameters, String userId, Collection attachments) {
int sessionID = 0;
try {
sessionID = getUSDWebService().login(wsUser, wsPassword);
String contactHandle = lookupContactHandle(userId, sessionID);
if (contactHandle == null) {
// Use the wsUser as fallback if the user is unknown
contactHandle = lookupContactHandle(wsUser, sessionID);
}
requestParameters.setProperty("customer", contactHandle);
List lAttributes = new ArrayList();
List lAttributeValues = new ArrayList();
for (Enumeration