Search in sources :

Example 1 with MXBooleanType

use of com.ibm.maximo.MXBooleanType in project opennms by OpenNMS.

the class TsrmTicketerPlugin method updateIncidentWithTicket.

private void updateIncidentWithTicket(SHSIMPINCINCIDENTType incident, Ticket ticket) {
    if (!StringUtils.isEmpty(ticket.getAttribute(AFFECTED_PERSON))) {
        MXStringType affectedPerson = new MXStringType();
        affectedPerson.setValue(ticket.getAttribute(AFFECTED_PERSON));
        incident.setAFFECTEDPERSON(affectedPerson);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(ASSET_NUM))) {
        MXStringType assetNum = new MXStringType();
        assetNum.setValue(ticket.getAttribute(ASSET_NUM));
        incident.setASSETNUM(assetNum);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(CLASS_ID))) {
        MXStringType classId = new MXStringType();
        classId.setValue(ticket.getAttribute(CLASS_ID));
        incident.setCLASS(classId);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(CLASS_STRUCTURE_ID))) {
        MXStringType classStructureId = new MXStringType();
        classStructureId.setValue(ticket.getAttribute(CLASS_STRUCTURE_ID));
        incident.setCLASSSTRUCTUREID(classStructureId);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(COMMODITY))) {
        MXStringType commodity = new MXStringType();
        commodity.setValue(ticket.getAttribute(COMMODITY));
        incident.setCOMMODITY(commodity);
    }
    if (!StringUtils.isEmpty(ticket.getSummary())) {
        MXStringType description = new MXStringType();
        description.setValue(ticket.getSummary());
        incident.setDESCRIPTION(description);
    }
    if (!StringUtils.isEmpty(ticket.getDetails())) {
        MXStringType longDescription = new MXStringType();
        longDescription.setValue(ticket.getDetails());
        incident.setDESCRIPTIONLONGDESCRIPTION(longDescription);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(LOCATION))) {
        MXStringType location = new MXStringType();
        location.setValue(ticket.getAttribute(LOCATION));
        incident.setLOCATION(location);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(OWNER_GROUP))) {
        MXStringType ownerGroup = new MXStringType();
        ownerGroup.setValue(ticket.getAttribute(OWNER_GROUP));
        incident.setOWNERGROUP(ownerGroup);
    }
    if (!StringUtils.isEmpty(ticket.getUser())) {
        if (StringUtils.isEmpty(ticket.getId())) {
            MXStringType reportedBy = new MXStringType();
            reportedBy.setValue(ticket.getUser());
            incident.setREPORTEDBY(reportedBy);
        } else {
            MXDateTimeType date = new MXDateTimeType();
            GregorianCalendar calendarTime = new GregorianCalendar();
            calendarTime.setTime(new Date());
            XMLGregorianCalendar value;
            @SuppressWarnings({ "unchecked", "rawtypes" }) JAXBElement<MXDateTimeType> jaxbElement = new JAXBElement(new QName(MXDateTimeType.class.getName()), MXDateTimeType.class, date);
            try {
                value = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendarTime);
                date.setValue(value);
                incident.setCHANGEDATE(jaxbElement);
            } catch (DatatypeConfigurationException e) {
                LOG.error("Unable to create changedDate", e);
            }
        }
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SHS_CALLER_TYPE))) {
        MXStringType shsCallerType = new MXStringType();
        shsCallerType.setValue(ticket.getAttribute(SHS_CALLER_TYPE));
        incident.setSHSCALLERTYPE(shsCallerType);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SHS_REASON_FOR_OUTAGE))) {
        MXStringType shsReasonForOutage = new MXStringType();
        shsReasonForOutage.setValue(ticket.getAttribute(SHS_REASON_FOR_OUTAGE));
        incident.setSHSREASONFOROUTAGE(shsReasonForOutage);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SHS_RESOLUTION))) {
        MXStringType shsResolution = new MXStringType();
        shsResolution.setValue(ticket.getAttribute(SHS_RESOLUTION));
        incident.setSHSRESOLUTION(shsResolution);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SHS_ROOM_NUMBER))) {
        MXStringType shsRoomNumber = new MXStringType();
        shsRoomNumber.setValue(ticket.getAttribute(SHS_ROOM_NUMBER));
        incident.setSHSROOMNUMBER(shsRoomNumber);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SITE_ID))) {
        MXStringType siteId = new MXStringType();
        siteId.setValue(ticket.getAttribute(SITE_ID));
        incident.setSITEID(siteId);
    }
    if (!StringUtils.isEmpty(ticket.getAttribute(SOURCE))) {
        MXStringType source = new MXStringType();
        source.setValue(ticket.getAttribute(SOURCE));
        incident.setSOURCE(source);
    }
    MXStringType status = new MXStringType();
    try {
        if (ticket.getState().equals(Ticket.State.OPEN)) {
            status.setValue(getProperties().getProperty("tsrm.status.open"));
        } else if (ticket.getState().equals(Ticket.State.CLOSED)) {
            status.setValue(getProperties().getProperty("tsrm.status.close"));
        }
    } catch (IOException e) {
        LOG.error("Unable to load tsrm.status from properties ", e);
    }
    incident.setSTATUS(status);
    if (!StringUtils.isEmpty(ticket.getAttribute(STATUS_IFACE))) {
        MXBooleanType statusIface = new MXBooleanType();
        statusIface.setValue(Boolean.parseBoolean(ticket.getAttribute(STATUS_IFACE)));
        incident.setSTATUSIFACE(statusIface);
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) MXBooleanType(com.ibm.maximo.MXBooleanType) QName(javax.xml.namespace.QName) MXDateTimeType(com.ibm.maximo.MXDateTimeType) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) JAXBElement(javax.xml.bind.JAXBElement) IOException(java.io.IOException) MXStringType(com.ibm.maximo.MXStringType) Date(java.util.Date)

Example 2 with MXBooleanType

use of com.ibm.maximo.MXBooleanType in project opennms by OpenNMS.

the class TsrmTicketerPlugin method get.

@Override
public Ticket get(String ticketId) throws PluginException {
    SHSIMPINCQueryType queryType = new SHSIMPINCQueryType();
    SHSIMPINCQueryType.INCIDENT incidentQuery = new SHSIMPINCQueryType.INCIDENT();
    List<MXStringQueryType> ticketList = incidentQuery.getTICKETID();
    MXStringQueryType ticketQuery = new MXStringQueryType();
    ticketQuery.setValue(ticketId);
    ticketList.add(ticketQuery);
    queryType.setINCIDENT(incidentQuery);
    QuerySHSIMPINCType queryIncident = new QuerySHSIMPINCType();
    queryIncident.setSHSIMPINCQuery(queryType);
    QuerySHSIMPINCResponseType response = port.querySHSIMPINC(queryIncident);
    if (!CollectionUtils.isEmpty(response.getSHSIMPINCSet().getINCIDENT())) {
        // Response will only have one element in the list
        SHSIMPINCINCIDENTType incident = response.getSHSIMPINCSet().getINCIDENT().get(0);
        if (incident != null) {
            Ticket ticket = new Ticket();
            MXStringType affectedPerson = new MXStringType();
            affectedPerson = incident.getAFFECTEDPERSON();
            MXStringType assetNum = new MXStringType();
            assetNum = incident.getASSETNUM();
            MXStringType classId = new MXStringType();
            classId = incident.getCLASS();
            MXStringType classStructureId = new MXStringType();
            classStructureId = incident.getCLASSSTRUCTUREID();
            MXStringType description = new MXStringType();
            description = incident.getDESCRIPTION();
            MXStringType longDescription = new MXStringType();
            longDescription = incident.getDESCRIPTIONLONGDESCRIPTION();
            MXStringType location = new MXStringType();
            location = incident.getLOCATION();
            MXStringType ownerGroup = new MXStringType();
            ownerGroup = incident.getOWNERGROUP();
            MXStringType reportedBy = new MXStringType();
            reportedBy = incident.getREPORTEDBY();
            MXStringType shsCallerType = new MXStringType();
            shsCallerType = incident.getSHSCALLERTYPE();
            MXStringType shsReasonForOutage = new MXStringType();
            shsReasonForOutage = incident.getSHSREASONFOROUTAGE();
            MXStringType shsResolution = new MXStringType();
            shsResolution = incident.getSHSRESOLUTION();
            MXStringType shsRoomNumber = new MXStringType();
            shsRoomNumber = incident.getSHSROOMNUMBER();
            MXStringType siteId = new MXStringType();
            siteId = incident.getSITEID();
            MXStringType source = new MXStringType();
            source = incident.getSOURCE();
            MXBooleanType statusIface = new MXBooleanType();
            statusIface = incident.getSTATUSIFACE();
            MXStringType ticketIdFromIncident = new MXStringType();
            ticketIdFromIncident = incident.getTICKETID();
            if (ticketIdFromIncident == null) {
                return null;
            }
            ticket.setId(ticketIdFromIncident.getValue());
            if (affectedPerson != null) {
                ticket.addAttribute(AFFECTED_PERSON, affectedPerson.getValue());
            }
            if (assetNum != null) {
                ticket.addAttribute(ASSET_NUM, assetNum.getValue());
            }
            if (classId != null) {
                ticket.addAttribute(CLASS_ID, classId.getValue());
            }
            if (classStructureId != null) {
                ticket.addAttribute(CLASS_STRUCTURE_ID, classStructureId.getValue());
            }
            if (description != null) {
                ticket.setSummary(description.getValue());
            }
            if (longDescription != null) {
                ticket.setDetails(longDescription.getValue());
            }
            if (location != null) {
                ticket.addAttribute(LOCATION, location.getValue());
            }
            if (ownerGroup != null) {
                ticket.addAttribute(OWNER_GROUP, ownerGroup.getValue());
            }
            if (reportedBy != null) {
                ticket.setUser(reportedBy.getValue());
            }
            if (shsCallerType != null) {
                ticket.addAttribute(SHS_CALLER_TYPE, shsCallerType.getValue());
            }
            if (shsReasonForOutage != null) {
                ticket.addAttribute(SHS_REASON_FOR_OUTAGE, shsReasonForOutage.getValue());
            }
            if (shsResolution != null) {
                ticket.addAttribute(SHS_RESOLUTION, shsResolution.getValue());
            }
            if (shsRoomNumber != null) {
                ticket.addAttribute(SHS_ROOM_NUMBER, shsRoomNumber.getValue());
            }
            if (siteId != null) {
                ticket.addAttribute(SITE_ID, siteId.getValue());
            }
            if (source != null) {
                ticket.addAttribute(SOURCE, source.getValue());
            }
            MXStringType status = new MXStringType();
            status = incident.getSTATUS();
            try {
                if ((status != null) && (status.getValue() != null) && (status.getValue().equals(getProperties().getProperty("tsrm.status.open")))) {
                    ticket.setState(Ticket.State.OPEN);
                } else if ((status != null) && (status.getValue() != null) && (status.getValue().equals(getProperties().getProperty("tsrm.status.close")))) {
                    ticket.setState(Ticket.State.CLOSED);
                }
            } catch (IOException e) {
                LOG.error("Unable to load tsrm.status from properties ", e);
            }
            if (statusIface != null) {
                ticket.addAttribute(STATUS_IFACE, statusIface.isValue().toString());
            }
            return ticket;
        }
        return null;
    } else {
        return null;
    }
}
Also used : QuerySHSIMPINCResponseType(com.ibm.maximo.QuerySHSIMPINCResponseType) Ticket(org.opennms.api.integration.ticketing.Ticket) MXStringQueryType(com.ibm.maximo.MXStringQueryType) MXBooleanType(com.ibm.maximo.MXBooleanType) QuerySHSIMPINCType(com.ibm.maximo.QuerySHSIMPINCType) SHSIMPINCQueryType(com.ibm.maximo.SHSIMPINCQueryType) IOException(java.io.IOException) MXStringType(com.ibm.maximo.MXStringType) SHSIMPINCINCIDENTType(com.ibm.maximo.SHSIMPINCINCIDENTType)

Aggregations

MXBooleanType (com.ibm.maximo.MXBooleanType)2 MXStringType (com.ibm.maximo.MXStringType)2 IOException (java.io.IOException)2 MXDateTimeType (com.ibm.maximo.MXDateTimeType)1 MXStringQueryType (com.ibm.maximo.MXStringQueryType)1 QuerySHSIMPINCResponseType (com.ibm.maximo.QuerySHSIMPINCResponseType)1 QuerySHSIMPINCType (com.ibm.maximo.QuerySHSIMPINCType)1 SHSIMPINCINCIDENTType (com.ibm.maximo.SHSIMPINCINCIDENTType)1 SHSIMPINCQueryType (com.ibm.maximo.SHSIMPINCQueryType)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 JAXBElement (javax.xml.bind.JAXBElement)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 QName (javax.xml.namespace.QName)1 Ticket (org.opennms.api.integration.ticketing.Ticket)1