Search in sources :

Example 51 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar 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 52 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project tdi-studio-se by Talend.

the class NetsuiteManagement_CXF method search.

public void search(String searchentity, String searchFieldName, String searchOperator, List<String> searchValue, String forcedType) throws DatatypeConfigurationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if ((searchValue.get(0) != null) && (searchFieldName != null)) {
        this.criteriaSetter = findMethod(this.searchBasicClass, "set" + searchFieldName);
        if (this.criteriaSetter == null) {
            SearchCustomField customCriteria = null;
            if (forcedType.equals("String")) {
                SearchStringCustomField searchArgumentType = new SearchStringCustomField();
                searchArgumentType.setInternalId(searchFieldName);
                if (searchValue != null && searchValue.size() != 0) {
                    searchArgumentType.setSearchValue(searchValue.get(0));
                }
                searchArgumentType.setOperator(SearchStringFieldOperator.fromValue(searchOperator));
                customCriteria = searchArgumentType;
            } else if (forcedType.equals("Long")) {
                SearchLongCustomField searchArgumentType = new SearchLongCustomField();
                searchArgumentType.setInternalId(searchFieldName);
                if (searchValue != null && searchValue.size() != 0) {
                    searchArgumentType.setSearchValue(Long.valueOf(Long.parseLong(searchValue.get(0))));
                    if (searchValue.size() > 1) {
                        searchArgumentType.setSearchValue2(Long.valueOf(Long.parseLong(searchValue.get(1))));
                    }
                }
                searchArgumentType.setOperator(SearchLongFieldOperator.fromValue(searchOperator));
                customCriteria = searchArgumentType;
            } else if (forcedType.equals("Date")) {
                SearchDateCustomField searchArgumentType = new SearchDateCustomField();
                if (searchValue != null && searchValue.size() != 0) {
                    Calendar calValue = Calendar.getInstance();
                    Calendar calValue2 = Calendar.getInstance();
                    String dateFormat = "yyyy-MM-dd";
                    String timeFormat = "HH:mm:ss";
                    String format = dateFormat + " " + timeFormat;
                    if (searchValue.get(0).length() == dateFormat.length()) {
                        format = dateFormat;
                    }
                    if (searchValue.get(0).length() == timeFormat.length()) {
                        searchValue.set(0, new SimpleDateFormat(dateFormat).format(calValue.getTime()) + " " + searchValue.get(0));
                        if (searchValue.size() > 1) {
                            searchValue.set(1, new SimpleDateFormat(dateFormat).format(calValue.getTime()) + " " + searchValue.get(1));
                        }
                    }
                    DateFormat df = new SimpleDateFormat(format);
                    try {
                        calValue.setTime(df.parse(searchValue.get(0)));
                        if (searchValue.size() > 1) {
                            calValue2.setTime(df.parse(searchValue.get(1)));
                        }
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    XMLGregorianCalendar xts = DatatypeFactory.newInstance().newXMLGregorianCalendar();
                    xts.setYear(calValue.get(Calendar.YEAR));
                    xts.setMonth(calValue.get(Calendar.MONTH) + 1);
                    xts.setDay(calValue.get(Calendar.DAY_OF_MONTH));
                    xts.setHour(calValue.get(Calendar.HOUR_OF_DAY));
                    xts.setMinute(calValue.get(Calendar.MINUTE));
                    xts.setSecond(calValue.get(Calendar.SECOND));
                    xts.setMillisecond(calValue.get(Calendar.MILLISECOND));
                    xts.setTimezone(calValue.get(Calendar.ZONE_OFFSET) / 60000);
                    searchArgumentType.setSearchValue(xts);
                    if (searchValue.size() > 1) {
                        XMLGregorianCalendar xts2 = DatatypeFactory.newInstance().newXMLGregorianCalendar();
                        xts2.setYear(calValue.get(Calendar.YEAR));
                        xts2.setMonth(calValue.get(Calendar.MONTH) + 1);
                        xts2.setDay(calValue.get(Calendar.DAY_OF_MONTH));
                        xts2.setHour(calValue.get(Calendar.HOUR_OF_DAY));
                        xts2.setMinute(calValue.get(Calendar.MINUTE));
                        xts2.setSecond(calValue.get(Calendar.SECOND));
                        xts2.setMillisecond(calValue.get(Calendar.MILLISECOND));
                        xts2.setTimezone(calValue.get(Calendar.ZONE_OFFSET) / 60000);
                        searchArgumentType.setSearchValue2(xts2);
                    }
                }
                searchArgumentType.setOperator(SearchDateFieldOperator.fromValue(searchOperator));
                customCriteria = searchArgumentType;
            } else if (forcedType.equals("Boolean")) {
                SearchBooleanCustomField searchArgumentType = new SearchBooleanCustomField();
                searchArgumentType.setInternalId(searchFieldName);
                searchArgumentType.setSearchValue(Boolean.valueOf(Boolean.parseBoolean(searchValue.get(0))));
                customCriteria = searchArgumentType;
            } else if (forcedType.equals("Double")) {
                SearchDoubleCustomField searchArgumentType = new SearchDoubleCustomField();
                searchArgumentType.setInternalId(searchFieldName);
                if (searchValue != null && searchValue.size() != 0) {
                    searchArgumentType.setSearchValue(Double.valueOf(Double.parseDouble(searchValue.get(0))));
                    if (searchValue.size() > 1) {
                        searchArgumentType.setSearchValue2(Double.valueOf(Double.parseDouble(searchValue.get(1))));
                    }
                }
                searchArgumentType.setOperator(SearchDoubleFieldOperator.fromValue(searchOperator));
                customCriteria = searchArgumentType;
            } else if (forcedType.equals("List")) {
                SearchMultiSelectCustomField searchArgumentType = new SearchMultiSelectCustomField();
                int len = searchValue.size();
                List<ListOrRecordRef> lr = searchArgumentType.getSearchValue();
                for (int i = 0; i < len; i++) {
                    ListOrRecordRef lRecordRef = new ListOrRecordRef();
                    lRecordRef.setName(searchValue.get(i));
                    lr.add(lRecordRef);
                }
                searchArgumentType.setOperator(SearchMultiSelectFieldOperator.fromValue(searchOperator));
                customCriteria = searchArgumentType;
            } else {
                throw new IllegalArgumentException("Unsupported search field type: " + forcedType);
            }
            push(customCriteria);
            this.hasCustomCriteria = true;
        } else {
            this.criteriaSetter.invoke(this.searchBasic, new Object[] { getSearchField(this.searchBasicClass, searchValue, searchFieldName, searchOperator) });
        }
    }
}
Also used : SearchBooleanCustomField(com.netsuite.webservices.platform.core.SearchBooleanCustomField) SearchStringCustomField(com.netsuite.webservices.platform.core.SearchStringCustomField) SearchMultiSelectCustomField(com.netsuite.webservices.platform.core.SearchMultiSelectCustomField) ListOrRecordRef(com.netsuite.webservices.platform.core.ListOrRecordRef) Calendar(java.util.Calendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SearchLongCustomField(com.netsuite.webservices.platform.core.SearchLongCustomField) SearchCustomField(com.netsuite.webservices.platform.core.SearchCustomField) SearchDoubleCustomField(com.netsuite.webservices.platform.core.SearchDoubleCustomField) SearchDateCustomField(com.netsuite.webservices.platform.core.SearchDateCustomField) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) List(java.util.List) SearchCustomFieldList(com.netsuite.webservices.platform.core.SearchCustomFieldList) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 53 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project jena by apache.

the class XSDFuncOp method dateTimeCast.

/** Cast a NodeValue to a date/time type (xsd dateTime, date, time, g*) according to F&O
     *  <a href="http://www.w3.org/TR/xpath-functions/#casting-to-datetimes">17.1.5 Casting to date and time types</a>
     *  Throws an exception on incorrect case.
     *   
     *  @throws ExprEvalTypeException  
     */
public static NodeValue dateTimeCast(NodeValue nv, XSDDatatype xsd) {
    if (nv.isString()) {
        String s = nv.getString();
        if (!xsd.isValid(s))
            throw new ExprEvalTypeException("Invalid lexical form: '" + s + "' for " + xsd.getURI());
        return NodeValue.makeNode(s, xsd);
    }
    if (!nv.hasDateTime())
        throw new ExprEvalTypeException("Not a date/time type: " + nv);
    XMLGregorianCalendar xsdDT = nv.getDateTime();
    if (XSDDatatype.XSDdateTime.equals(xsd)) {
        // ==> DateTime
        if (nv.isDateTime())
            return nv;
        if (!nv.isDate())
            throw new ExprEvalTypeException("Can't cast to XSD:dateTime: " + nv);
        // DateTime with time 00:00:00 ... and timezone, if any
        String tzStr = tzStrFromNV(nv);
        String x = String.format("%04d-%02d-%02dT00:00:00%s", xsdDT.getYear(), xsdDT.getMonth(), xsdDT.getDay(), tzStr);
        return NodeValue.makeNode(x, xsd);
    }
    if (XSDDatatype.XSDdate.equals(xsd)) {
        // ==> Date
        if (nv.isDate())
            return nv;
        if (!nv.isDateTime())
            throw new ExprEvalTypeException("Can't cast to XSD:date: " + nv);
        // Timezone
        String tzStr = tzStrFromNV(nv);
        String x = String.format("%04d-%02d-%02d%s", xsdDT.getYear(), xsdDT.getMonth(), xsdDT.getDay(), tzStr);
        return NodeValue.makeNode(x, xsd);
    }
    if (XSDDatatype.XSDtime.equals(xsd)) {
        // ==> time
        if (nv.isTime())
            return nv;
        if (!nv.isDateTime())
            throw new ExprEvalTypeException("Can't cast to XSD:time: " + nv);
        // Careful formatting
        DateTimeStruct dts = parseAnyDT(nv);
        if (dts.timezone == null)
            dts.timezone = "";
        String x = String.format("%s:%s:%s%s", dts.hour, dts.minute, dts.second, dts.timezone);
        return NodeValue.makeNode(x, xsd);
    }
    if (XSDDatatype.XSDgYear.equals(xsd)) {
        // ==> Year
        if (nv.isGYear())
            return nv;
        if (!nv.isDateTime() && !nv.isDate())
            throw new ExprEvalTypeException("Can't cast to XSD:gYear: " + nv);
        String x = String.format("%04d", xsdDT.getYear());
        return NodeValue.makeNode(x, xsd);
    }
    if (XSDDatatype.XSDgYearMonth.equals(xsd)) {
        // ==> YearMonth
        if (nv.isGYearMonth())
            return nv;
        if (!nv.isDateTime() && !nv.isDate())
            throw new ExprEvalTypeException("Can't cast to XSD:gYearMonth: " + nv);
        String x = String.format("%04d-%02d", xsdDT.getYear(), xsdDT.getMonth());
        return NodeValue.makeNode(x, xsd);
    }
    if (XSDDatatype.XSDgMonth.equals(xsd)) {
        // ==> Month
        if (nv.isGMonth())
            return nv;
        if (!nv.isDateTime() && !nv.isDate())
            throw new ExprEvalTypeException("Can't cast to XSD:gMonth: " + nv);
        String x = String.format("--%02d", xsdDT.getMonth());
        return NodeValue.makeNode(x, xsd);
    }
    if (XSDDatatype.XSDgMonthDay.equals(xsd)) {
        // ==> MonthDay
        if (nv.isGMonthDay())
            return nv;
        if (!nv.isDateTime() && !nv.isDate())
            throw new ExprEvalTypeException("Can't cast to XSD:gMonthDay: " + nv);
        String x = String.format("--%02d-%02d", xsdDT.getMonth(), xsdDT.getDay());
        return NodeValue.makeNode(x, xsd);
    }
    if (XSDDatatype.XSDgDay.equals(xsd)) {
        // Day
        if (nv.isGDay())
            return nv;
        if (!nv.isDateTime() && !nv.isDate())
            throw new ExprEvalTypeException("Can't cast to XSD:gDay: " + nv);
        String x = String.format("---%02d", xsdDT.getDay());
        return NodeValue.makeNode(x, xsd);
    }
    throw new ExprEvalTypeException("Can't case to <" + xsd.getURI() + ">: " + nv);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DateTimeStruct(org.apache.jena.sparql.util.DateTimeStruct)

Example 54 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project jena by apache.

the class XSDFuncOp method compareDateTimeFO.

/** Strict F&O handling of compare date(times).
     * But that means applying the "local" timezone if there is no TZ.
     * The data may have come from different timezones to the query. 
     */
private static int compareDateTimeFO(NodeValue nv1, NodeValue nv2) {
    XMLGregorianCalendar dt1 = nv1.getDateTime();
    XMLGregorianCalendar dt2 = nv2.getDateTime();
    int x = compareXSDDateTime(dt1, dt2);
    if (x == XSDDateTime.INDETERMINATE) {
        NodeValue nv3 = (nv1.isDate()) ? fixupDate(nv1) : fixupDateTime(nv1);
        if (nv3 != null) {
            XMLGregorianCalendar dt3 = nv3.getDateTime();
            x = compareXSDDateTime(dt3, dt2);
            if (x == XSDDateTime.INDETERMINATE)
                throw new ARQInternalErrorException("Still get indeterminate comparison");
            return x;
        }
        nv3 = (nv2.isDate()) ? fixupDate(nv2) : fixupDateTime(nv2);
        if (nv3 != null) {
            XMLGregorianCalendar dt3 = nv3.getDateTime();
            x = compareXSDDateTime(dt1, dt3);
            if (x == XSDDateTime.INDETERMINATE)
                throw new ARQInternalErrorException("Still get indeterminate comparison");
            return x;
        }
        throw new ARQInternalErrorException("Failed to fixup dateTimes");
    }
    return x;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Example 55 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project jena by apache.

the class NodeValueOps method xsd_add.

private static XMLGregorianCalendar xsd_add(XMLGregorianCalendar cal, Duration duration) {
    //if ( ! isYearMonth(duration) && ! isDayTime(duration) )
    XMLGregorianCalendar result = (XMLGregorianCalendar) cal.clone();
    result.add(duration);
    return result;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Aggregations

XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)336 Test (org.testng.annotations.Test)159 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)130 Task (com.evolveum.midpoint.task.api.Task)104 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)72 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)52 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)44 Date (java.util.Date)36 TestValidityRecomputeTask (com.evolveum.midpoint.model.intest.sync.TestValidityRecomputeTask)32 ArrayList (java.util.ArrayList)32 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)31 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)31 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)30 AbstractSynchronizationStoryTest (com.evolveum.midpoint.model.intest.sync.AbstractSynchronizationStoryTest)23 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)21 GregorianCalendar (java.util.GregorianCalendar)18 QName (javax.xml.namespace.QName)18 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)15 Duration (javax.xml.datatype.Duration)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)14