Search in sources :

Example 1 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project OpenAttestation by OpenAttestation.

the class SelectionBuilder method notAfter.

/**
     * If you get NullPointerException make sure you have called selection()
     * before calling this method.
     * 
     * @param date
     * @return 
     */
public SelectionBuilder notAfter(Date date) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    try {
        XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
        currentSelection.setNotAfter(xmlCalendar);
        return this;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 2 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project OpenAttestation by OpenAttestation.

the class SelectionBuilder method notBefore.

/**
     * If you get NullPointerException make sure you have called selection()
     * before calling this method.
     * 
     * @param date
     * @return 
     */
public SelectionBuilder notBefore(Date date) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    try {
        XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
        currentSelection.setNotBefore(xmlCalendar);
        return this;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 3 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project fastjson by alibaba.

the class Issue1023 method test_for_issue.

public void test_for_issue() throws Exception {
    Date now = new Date();
    GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
    gregorianCalendar.setTime(now);
    XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
    String jsonString = JSON.toJSONString(calendar);
    // success
    calendar = JSON.parseObject(jsonString, XMLGregorianCalendar.class);
    // debug看到是 Long 类型
    Object toJSON1 = JSON.toJSON(calendar);
    // 所以这里会报错:
    // error: java.lang.ClassCastException: java.lang.Long cannot be cast to com.alibaba.fastjson.JSONObject
    //JSONObject jsonObject = (JSONObject) JSON.toJSON(calendar);
    // 所以 这里肯定会报错, 因为 jsonObject 不是JSONObject类型
    //calendar = jsonObject.toJavaObject(XMLGregorianCalendar.class);
    List<XMLGregorianCalendar> calendarList = new ArrayList<XMLGregorianCalendar>();
    calendarList.add(calendar);
    calendarList.add(calendar);
    calendarList.add(calendar);
    // debug 看到是 JSONArray 类型
    Object toJSON2 = JSON.toJSON(calendarList);
    // success: 通过 JSONArray.parseArray 方法可以正确转换
    JSONArray jsonArray = (JSONArray) JSON.toJSON(calendarList);
    jsonString = jsonArray.toJSONString();
    List<XMLGregorianCalendar> calendarList1 = JSONArray.parseArray(jsonString, XMLGregorianCalendar.class);
    // 通过 jsonArray.toJavaList 无法转换
    // error: com.alibaba.fastjson.JSONException: can not cast to : javax.xml.datatype.XMLGregorianCalendar
    List<XMLGregorianCalendar> calendarList2 = jsonArray.toJavaList(XMLGregorianCalendar.class);
    assertNotNull(calendarList2);
    assertEquals(3, calendarList2.size());
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) Date(java.util.Date)

Example 4 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project fastjson by alibaba.

the class XMLGregorianCalendarTest method test_for_issue.

public void test_for_issue() throws Exception {
    GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
    XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
    String text = JSON.toJSONString(calendar);
    Assert.assertEquals(Long.toString(gregorianCalendar.getTimeInMillis()), text);
    XMLGregorianCalendar calendar1 = JSON.parseObject(text, XMLGregorianCalendar.class);
    assertEquals(calendar.toGregorianCalendar().getTimeInMillis(), calendar1.toGregorianCalendar().getTimeInMillis());
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("calendar", calendar);
    String json = JSON.toJSONString(jsonObject);
    Model model = JSON.parseObject(json).toJavaObject(Model.class);
    assertEquals(calendar.toGregorianCalendar().getTimeInMillis(), model.calendar.toGregorianCalendar().getTimeInMillis());
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) JSONObject(com.alibaba.fastjson.JSONObject) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Example 5 with XMLGregorianCalendar

use of javax.xml.datatype.XMLGregorianCalendar in project midpoint by Evolveum.

the class CheckTableHeader method createTriggerTooltip.

private String createTriggerTooltip() {
    ObjectWrapper<O> wrapper = getModelObject();
    PrismObject<O> obj = wrapper.getObject();
    PrismContainer<TriggerType> container = obj.findContainer(ObjectType.F_TRIGGER);
    if (container == null || container.isEmpty()) {
        return null;
    }
    List<String> triggers = new ArrayList<>();
    for (PrismContainerValue<TriggerType> val : container.getValues()) {
        XMLGregorianCalendar time = val.getPropertyRealValue(TriggerType.F_TIMESTAMP, XMLGregorianCalendar.class);
        if (time == null) {
            triggers.add(getString("CheckTableHeader.triggerUnknownTime"));
        } else {
            triggers.add(getString("CheckTableHeader.triggerPlanned", WebComponentUtil.formatDate(time)));
        }
    }
    return StringUtils.join(triggers, '\n');
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ArrayList(java.util.ArrayList)

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