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();
}
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());
}
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);
}
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;
}
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;
}
Aggregations