use of com.fasterxml.jackson.core.type.TypeReference in project candlepin by candlepin.
the class EntitlementRules method filterPools.
@Override
@SuppressWarnings("checkstyle:indentation")
public List<Pool> filterPools(Consumer consumer, List<Pool> pools, boolean showAll) {
JsonJsContext args = new JsonJsContext(objectMapper);
Map<String, ValidationResult> resultMap = new HashMap<>();
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (!ctype.isType(ConsumerTypeEnum.SHARE)) {
Stream<PoolDTO> poolStream = pools == null ? Stream.empty() : pools.stream().map(this.translator.getStreamMapper(Pool.class, PoolDTO.class));
Stream<EntitlementDTO> entStream = consumer.getEntitlements() == null ? Stream.empty() : consumer.getEntitlements().stream().map(this.translator.getStreamMapper(Entitlement.class, EntitlementDTO.class));
args.put("consumer", this.translator.translate(consumer, ConsumerDTO.class));
args.put("hostConsumer", this.translator.translate(getHost(consumer, pools), ConsumerDTO.class));
args.put("consumerEntitlements", entStream.collect(Collectors.toSet()));
args.put("standalone", config.getBoolean(ConfigProperties.STANDALONE));
args.put("pools", poolStream.collect(Collectors.toSet()));
args.put("caller", CallerType.LIST_POOLS.getLabel());
args.put("log", log, false);
String json = jsRules.runJsFunction(String.class, "validate_pools_list", args);
TypeReference<Map<String, ValidationResult>> typeref = new TypeReference<Map<String, ValidationResult>>() {
};
try {
resultMap = objectMapper.toObject(json, typeref);
} catch (Exception e) {
throw new RuleExecutionException(e);
}
}
List<Pool> filteredPools = new LinkedList<>();
for (Pool pool : pools) {
ValidationResult result;
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
result = new ValidationResult();
resultMap.put(pool.getId(), result);
validatePoolSharingEligibility(result, pool);
} else {
result = resultMap.get(pool.getId());
}
finishValidation(result, pool, 1);
if (result.isSuccessful() && (!result.hasWarnings() || showAll)) {
filteredPools.add(pool);
} else if (log.isDebugEnabled()) {
log.debug("Omitting pool due to failed rules: " + pool.getId());
if (result.hasErrors()) {
log.debug("\tErrors: " + result.getErrors());
}
if (result.hasWarnings()) {
log.debug("\tWarnings: " + result.getWarnings());
}
}
}
return filteredPools;
}
use of com.fasterxml.jackson.core.type.TypeReference in project joynr by bmwcarit.
the class SubscriptionManagerTest method registerSubscriptionWithoutExpiryDate.
@Test
public void registerSubscriptionWithoutExpiryDate() throws JoynrSendBufferFullException, JoynrMessageNotSentException, JsonGenerationException, JsonMappingException, IOException {
class IntegerReference extends TypeReference<Integer> {
}
AttributeSubscribeInvocation request = new AttributeSubscribeInvocation(attributeName, IntegerReference.class, attributeSubscriptionCallback, qosWithoutExpiryDate, future);
subscriptionId = request.getSubscriptionId();
subscriptionManager.registerAttributeSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), request);
verify(attributeSubscriptionDirectory).put(Mockito.anyString(), Mockito.eq(attributeSubscriptionCallback));
verify(subscriptionStates).put(Mockito.anyString(), Mockito.any(PubSubState.class));
verify(cleanupScheduler, never()).schedule(Mockito.any(Runnable.class), Mockito.anyLong(), Mockito.any(TimeUnit.class));
verify(subscriptionEndFutures, never()).put(Mockito.anyString(), Mockito.any(ScheduledFuture.class));
verify(dispatcher).sendSubscriptionRequest(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), any(SubscriptionRequest.class), any(MessagingQos.class));
}
use of com.fasterxml.jackson.core.type.TypeReference in project joynr by bmwcarit.
the class SubscriptionManagerTest method registerSubscription.
@SuppressWarnings("unchecked")
@Test
public void registerSubscription() throws JoynrSendBufferFullException, JoynrMessageNotSentException, JsonGenerationException, JsonMappingException, IOException {
class IntegerReference extends TypeReference<Integer> {
}
Future<String> future = mock(Future.class);
AttributeSubscribeInvocation subscriptionRequest = new AttributeSubscribeInvocation(attributeName, IntegerReference.class, attributeSubscriptionCallback, qos, future);
subscriptionManager.registerAttributeSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), subscriptionRequest);
subscriptionId = subscriptionRequest.getSubscriptionId();
verify(attributeSubscriptionDirectory).put(Mockito.anyString(), Mockito.eq(attributeSubscriptionCallback));
verify(subscriptionStates).put(Mockito.anyString(), Mockito.any(PubSubState.class));
verify(cleanupScheduler).schedule(Mockito.any(Runnable.class), Mockito.eq(qos.getExpiryDateMs()), Mockito.eq(TimeUnit.MILLISECONDS));
verify(subscriptionEndFutures, Mockito.times(1)).put(Mockito.eq(subscriptionId), Mockito.any(ScheduledFuture.class));
verify(dispatcher).sendSubscriptionRequest(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), any(SubscriptionRequest.class), any(MessagingQos.class));
}
use of com.fasterxml.jackson.core.type.TypeReference in project muikku by otavanopisto.
the class EntityCacheEvictor method onWebhookNotificationEvent.
public void onWebhookNotificationEvent(@Observes WebhookNotificationEvent event) {
try {
List<String> evictTypePaths = cacheConfigs.getEvictTypePaths(event.getType());
Map<String, String> data = null;
try {
data = new ObjectMapper().readValue(event.getData(), new TypeReference<Map<String, String>>() {
});
} catch (IOException e) {
logger.log(Level.SEVERE, "Could not parse webhook notification data", e);
return;
}
for (AbstractEntityCache cache : caches) {
try {
Pattern pattern = Pattern.compile("\\{[a-zA-Z]*\\}");
for (String evictTypePath : evictTypePaths) {
String path = evictTypePath;
Matcher matcher = pattern.matcher(path);
while (matcher.find()) {
String variable = StringUtils.substring(matcher.group(0), 1, -1);
String value = data.get(variable);
if (value != null) {
path = matcher.replaceFirst(value);
} else {
logger.log(Level.SEVERE, String.format("Failed to parse path %s", evictTypePath));
break;
}
matcher = pattern.matcher(path);
}
cache.remove(path);
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to evict caches", e);
return;
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Cache evict crashed", e);
}
}
use of com.fasterxml.jackson.core.type.TypeReference in project AJSC by att.
the class RefresheableRESTErrorMap method refresh.
public static void refresh(File file) throws Exception {
try {
System.out.println("Loading error to http status code map...");
ObjectMapper mapper = new ObjectMapper();
TypeReference<HashMap<String, RestError>> typeRef = new TypeReference<HashMap<String, RestError>>() {
};
HashMap<String, RestError> map = mapper.readValue(file, typeRef);
wrapped.set(map);
System.out.println("File " + file.getName() + " is loaded into the error map");
} catch (Exception e) {
System.err.println("File " + file.getName() + " cannot be loaded into the error map " + e.getMessage());
throw new Exception("Error reading REST error map file " + file.getName(), e);
} finally {
System.out.println("Done with load...");
}
}
Aggregations