Search in sources :

Example 1 with MXStringType

use of com.ibm.maximo.MXStringType 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 MXStringType

use of com.ibm.maximo.MXStringType 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)

Example 3 with MXStringType

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

the class TsrmMockTest method testSaveWithMock.

@Test
public void testSaveWithMock() throws PluginException {
    CreateSHSIMPINCType createIncidentType = new CreateSHSIMPINCType();
    CreateSHSIMPINCResponseType incidentResponse = new CreateSHSIMPINCResponseType();
    INCIDENTMboKeySetType incidentMboKeyType = new INCIDENTMboKeySetType();
    INCIDENTKeyType incidentKey = new INCIDENTKeyType();
    MXStringType incidentId = new MXStringType();
    incidentId.setValue(INCIDENT_ID);
    incidentKey.setTICKETID(incidentId);
    incidentResponse.setINCIDENTMboKeySet(incidentMboKeyType);
    incidentMboKeyType.getINCIDENT().add(incidentKey);
    when(port.createSHSIMPINC(argThat(new CreateIncidentArg()))).thenReturn(incidentResponse);
    port.createSHSIMPINC(createIncidentType);
    Ticket ticket = new Ticket();
    m_ticketer.saveOrUpdate(ticket);
    verify(port).createSHSIMPINC(createIncidentType);
    assertEquals(ticket.getId(), INCIDENT_ID);
}
Also used : Ticket(org.opennms.api.integration.ticketing.Ticket) CreateSHSIMPINCType(com.ibm.maximo.CreateSHSIMPINCType) INCIDENTMboKeySetType(com.ibm.maximo.INCIDENTMboKeySetType) INCIDENTKeyType(com.ibm.maximo.INCIDENTKeyType) CreateSHSIMPINCResponseType(com.ibm.maximo.CreateSHSIMPINCResponseType) MXStringType(com.ibm.maximo.MXStringType) Test(org.junit.Test)

Example 4 with MXStringType

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

the class TsrmMockTest method testGetWithMock.

@Test
public void testGetWithMock() throws PluginException {
    QuerySHSIMPINCType queryIncident = new QuerySHSIMPINCType();
    QuerySHSIMPINCResponseType queryResponse = new QuerySHSIMPINCResponseType();
    SHSIMPINCSetType queryType = new SHSIMPINCSetType();
    SHSIMPINCINCIDENTType queryIncidentType = new SHSIMPINCINCIDENTType();
    MXStringType incidentId = new MXStringType();
    incidentId.setValue(INCIDENT_ID);
    queryIncidentType.setTICKETID(incidentId);
    queryType.getINCIDENT().add(queryIncidentType);
    queryResponse.setSHSIMPINCSet(queryType);
    when(port.querySHSIMPINC(argThat(new QueryIncidentArg()))).thenReturn(queryResponse);
    port.querySHSIMPINC(queryIncident);
    Ticket ticket = m_ticketer.get(INCIDENT_ID);
    verify(port).querySHSIMPINC(queryIncident);
    assertEquals(ticket.getId(), INCIDENT_ID);
}
Also used : QuerySHSIMPINCResponseType(com.ibm.maximo.QuerySHSIMPINCResponseType) Ticket(org.opennms.api.integration.ticketing.Ticket) SHSIMPINCSetType(com.ibm.maximo.SHSIMPINCSetType) QuerySHSIMPINCType(com.ibm.maximo.QuerySHSIMPINCType) MXStringType(com.ibm.maximo.MXStringType) SHSIMPINCINCIDENTType(com.ibm.maximo.SHSIMPINCINCIDENTType) Test(org.junit.Test)

Aggregations

MXStringType (com.ibm.maximo.MXStringType)4 Ticket (org.opennms.api.integration.ticketing.Ticket)3 MXBooleanType (com.ibm.maximo.MXBooleanType)2 QuerySHSIMPINCResponseType (com.ibm.maximo.QuerySHSIMPINCResponseType)2 QuerySHSIMPINCType (com.ibm.maximo.QuerySHSIMPINCType)2 SHSIMPINCINCIDENTType (com.ibm.maximo.SHSIMPINCINCIDENTType)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 CreateSHSIMPINCResponseType (com.ibm.maximo.CreateSHSIMPINCResponseType)1 CreateSHSIMPINCType (com.ibm.maximo.CreateSHSIMPINCType)1 INCIDENTKeyType (com.ibm.maximo.INCIDENTKeyType)1 INCIDENTMboKeySetType (com.ibm.maximo.INCIDENTMboKeySetType)1 MXDateTimeType (com.ibm.maximo.MXDateTimeType)1 MXStringQueryType (com.ibm.maximo.MXStringQueryType)1 SHSIMPINCQueryType (com.ibm.maximo.SHSIMPINCQueryType)1 SHSIMPINCSetType (com.ibm.maximo.SHSIMPINCSetType)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 JAXBElement (javax.xml.bind.JAXBElement)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1