Search in sources :

Example 96 with Duration

use of javax.xml.datatype.Duration in project msgraph-sdk-java by microsoftgraph.

the class GsonFactory method getGsonInstance.

/**
 * Creates an instance of GSON
 *
 * @param logger the logger
 * @return the new instance
 */
public static Gson getGsonInstance(final ILogger logger) {
    final JsonSerializer<Calendar> calendarJsonSerializer = new JsonSerializer<Calendar>() {

        @Override
        public JsonElement serialize(final Calendar src, final Type typeOfSrc, final JsonSerializationContext context) {
            if (src == null) {
                return null;
            }
            try {
                return new JsonPrimitive(CalendarSerializer.serialize(src));
            } catch (final Exception e) {
                logger.logError(PARSING_MESSAGE + src, e);
                return null;
            }
        }
    };
    final JsonDeserializer<Calendar> calendarJsonDeserializer = new JsonDeserializer<Calendar>() {

        @Override
        public Calendar deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
            if (json == null) {
                return null;
            }
            try {
                return CalendarSerializer.deserialize(json.getAsString());
            } catch (final ParseException e) {
                logger.logError(PARSING_MESSAGE + json.getAsString(), e);
                return null;
            }
        }
    };
    final JsonSerializer<byte[]> byteArrayJsonSerializer = new JsonSerializer<byte[]>() {

        @Override
        public JsonElement serialize(final byte[] src, final Type typeOfSrc, final JsonSerializationContext context) {
            if (src == null) {
                return null;
            }
            try {
                return new JsonPrimitive(ByteArraySerializer.serialize(src));
            } catch (final Exception e) {
                logger.logError(PARSING_MESSAGE + src, e);
                return null;
            }
        }
    };
    final JsonDeserializer<byte[]> byteArrayJsonDeserializer = new JsonDeserializer<byte[]>() {

        @Override
        public byte[] deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
            if (json == null) {
                return null;
            }
            try {
                return ByteArraySerializer.deserialize(json.getAsString());
            } catch (final ParseException e) {
                logger.logError(PARSING_MESSAGE + json.getAsString(), e);
                return null;
            }
        }
    };
    final JsonSerializer<DateOnly> dateJsonSerializer = new JsonSerializer<DateOnly>() {

        @Override
        public JsonElement serialize(final DateOnly src, final Type typeOfSrc, final JsonSerializationContext context) {
            if (src == null) {
                return null;
            }
            return new JsonPrimitive(src.toString());
        }
    };
    final JsonDeserializer<DateOnly> dateJsonDeserializer = new JsonDeserializer<DateOnly>() {

        @Override
        public DateOnly deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
            if (json == null) {
                return null;
            }
            try {
                return DateOnly.parse(json.getAsString());
            } catch (final ParseException e) {
                logger.logError(PARSING_MESSAGE + json.getAsString(), e);
                return null;
            }
        }
    };
    final JsonSerializer<EnumSet<?>> enumSetJsonSerializer = new JsonSerializer<EnumSet<?>>() {

        @Override
        public JsonElement serialize(final EnumSet<?> src, final Type typeOfSrc, final JsonSerializationContext context) {
            if (src == null || src.isEmpty()) {
                return null;
            }
            return EnumSetSerializer.serialize(src);
        }
    };
    final JsonDeserializer<EnumSet<?>> enumSetJsonDeserializer = new JsonDeserializer<EnumSet<?>>() {

        @Override
        public EnumSet<?> deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
            if (json == null) {
                return null;
            }
            return EnumSetSerializer.deserialize(typeOfT, json.getAsString());
        }
    };
    final JsonSerializer<Duration> durationJsonSerializer = new JsonSerializer<Duration>() {

        @Override
        public JsonElement serialize(final Duration src, final Type typeOfSrc, final JsonSerializationContext context) {
            return new JsonPrimitive(src.toString());
        }
    };
    final JsonDeserializer<Duration> durationJsonDeserializer = new JsonDeserializer<Duration>() {

        @Override
        public Duration deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
            try {
                return DatatypeFactory.newInstance().newDuration(json.toString());
            } catch (Exception e) {
                return null;
            }
        }
    };
    return new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Calendar.class, calendarJsonSerializer).registerTypeAdapter(Calendar.class, calendarJsonDeserializer).registerTypeAdapter(GregorianCalendar.class, calendarJsonSerializer).registerTypeAdapter(GregorianCalendar.class, calendarJsonDeserializer).registerTypeAdapter(byte[].class, byteArrayJsonDeserializer).registerTypeAdapter(byte[].class, byteArrayJsonSerializer).registerTypeAdapter(DateOnly.class, dateJsonSerializer).registerTypeAdapter(DateOnly.class, dateJsonDeserializer).registerTypeAdapter(EnumSet.class, enumSetJsonSerializer).registerTypeAdapter(EnumSet.class, enumSetJsonDeserializer).registerTypeAdapter(Duration.class, durationJsonSerializer).registerTypeAdapter(Duration.class, durationJsonDeserializer).registerTypeAdapterFactory(new FallBackEnumTypeAdapter()).create();
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonSerializer(com.google.gson.JsonSerializer) JsonDeserializer(com.google.gson.JsonDeserializer) JsonDeserializationContext(com.google.gson.JsonDeserializationContext) GsonBuilder(com.google.gson.GsonBuilder) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) EnumSet(java.util.EnumSet) GregorianCalendar(java.util.GregorianCalendar) DateOnly(com.microsoft.graph.models.extensions.DateOnly) Duration(javax.xml.datatype.Duration) JsonParseException(com.google.gson.JsonParseException) ParseException(java.text.ParseException) Type(java.lang.reflect.Type) JsonElement(com.google.gson.JsonElement) JsonSerializationContext(com.google.gson.JsonSerializationContext) JsonParseException(com.google.gson.JsonParseException) ParseException(java.text.ParseException)

Example 97 with Duration

use of javax.xml.datatype.Duration in project msgraph-sdk-java by microsoftgraph.

the class DurationTests method testDurationDeserializer.

@Test
public void testDurationDeserializer() throws Exception {
    Duration duration = DatatypeFactory.newInstance().newDurationDayTime(true, 0, 1, 30, 45);
    assertEquals(0, duration.getMonths());
    assertEquals(0, duration.getDays());
    assertEquals(1, duration.getHours());
    assertEquals(30, duration.getMinutes());
    assertEquals(45, duration.getSeconds());
}
Also used : Duration(javax.xml.datatype.Duration) Test(org.junit.Test)

Example 98 with Duration

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

the class ShadowUpdater method recordOperationException.

/**
 * Record results of an operation that have thrown exception.
 * This happens after the error handler is processed - and only for those
 * cases when the handler has re-thrown the exception.
 */
void recordOperationException(ProvisioningContext ctx, ProvisioningOperationState<? extends AsynchronousOperationResult> opState, ObjectDelta<ShadowType> delta, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ObjectAlreadyExistsException, ExpressionEvaluationException {
    PrismObject<ShadowType> repoShadow = opState.getRepoShadow();
    if (repoShadow == null) {
        // we not even bother to create a shadow.
        return;
    }
    Collection<ItemDelta<?, ?>> shadowChanges = new ArrayList<>();
    if (opState.hasPendingOperations()) {
        XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
        pendingOperationsHelper.collectPendingOperationUpdates(shadowChanges, opState, OperationResultStatus.FATAL_ERROR, now);
    }
    if (delta.isAdd()) {
        // This means we have failed add operation here. We tried to add object,
        // but we have failed. Which means that this shadow is now dead.
        Duration deadRetentionPeriod = ProvisioningUtil.getDeadShadowRetentionPeriod(ctx);
        if (XmlTypeConverter.isZero(deadRetentionPeriod)) {
            // Do not bother with marking the shadow as dead. It should be gone immediately.
            // Deleting it now saves one modify operation.
            LOGGER.trace("Deleting repository shadow (after error handling)\n{}", debugDumpLazily(shadowChanges, 1));
            deleteShadow(opState.getRepoShadow(), ctx.getTask(), result);
            return;
        }
        shadowChanges.addAll(prismContext.deltaFor(ShadowType.class).item(ShadowType.F_DEAD).replace(true).item(ShadowType.F_PRIMARY_IDENTIFIER_VALUE).replace().asItemDeltas());
    }
    if (shadowChanges.isEmpty()) {
        return;
    }
    LOGGER.trace("Updating repository shadow (after error handling)\n{}", debugDumpLazily(shadowChanges, 1));
    executeShadowModification(ctx, opState.getRepoShadow(), shadowChanges, result);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration)

Example 99 with Duration

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

the class ProvisioningUtil method getDeadShadowRetentionPeriod.

public static Duration getDeadShadowRetentionPeriod(ProvisioningContext ctx) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    Duration period = null;
    ResourceConsistencyType consistency = ctx.getResource().getConsistency();
    if (consistency != null) {
        period = consistency.getDeadShadowRetentionPeriod();
    }
    if (period == null) {
        period = DEFAULT_DEAD_SHADOW_RETENTION_PERIOD_DURATION;
    }
    return period;
}
Also used : Duration(javax.xml.datatype.Duration)

Example 100 with Duration

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

the class ProvisioningUtil method getGracePeriod.

public static Duration getGracePeriod(ProvisioningContext ctx) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    Duration gracePeriod = null;
    ResourceConsistencyType consistency = ctx.getResource().getConsistency();
    if (consistency != null) {
        gracePeriod = consistency.getPendingOperationGracePeriod();
    }
    return gracePeriod;
}
Also used : Duration(javax.xml.datatype.Duration)

Aggregations

Duration (javax.xml.datatype.Duration)131 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)56 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 Date (java.util.Date)10 Calendar (java.util.Calendar)9 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)8 GregorianCalendar (java.util.GregorianCalendar)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 BigDecimal (java.math.BigDecimal)7 CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 IOException (java.io.IOException)5 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)5 FileNotFoundException (java.io.FileNotFoundException)4 Collection (java.util.Collection)4 NodeValue (org.apache.jena.sparql.expr.NodeValue)4 NotNull (org.jetbrains.annotations.NotNull)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3