use of lombok.ToString in project component-runtime by Talend.
the class DIBatchSimulationTest method doRun.
private void doRun(final ComponentManager manager, final Collection<Object> sourceData, final Collection<Object> processorData, final Map<String, Object> globalMap, final AutoChunkProcessor processorProcessor, final InputsHandler inputsHandlerProcessor, final OutputsHandler outputHandlerProcessor, final InputFactory inputsProcessor, final OutputFactory outputsProcessor, final Mapper tempMapperMapper) {
row1Struct row1 = new row1Struct();
tempMapperMapper.start();
final ChainedMapper mapperMapper;
try {
final List<Mapper> splitMappersMapper = tempMapperMapper.split(tempMapperMapper.assess());
mapperMapper = new ChainedMapper(tempMapperMapper, splitMappersMapper.iterator());
mapperMapper.start();
globalMap.put("mapperMapper", mapperMapper);
} finally {
try {
tempMapperMapper.stop();
} catch (final RuntimeException re) {
re.printStackTrace();
}
}
final Input inputMapper = mapperMapper.create();
inputMapper.start();
globalMap.put("inputMapper", inputMapper);
final Jsonb jsonbMapper = Jsonb.class.cast(manager.findPlugin(mapperMapper.plugin()).get().get(ComponentManager.AllServices.class).getServices().get(Jsonb.class));
Object dataMapper;
while ((dataMapper = inputMapper.next()) != null) {
final String jsonValueMapper = javax.json.JsonValue.class.isInstance(dataMapper) ? javax.json.JsonValue.class.cast(dataMapper).toString() : jsonbMapper.toJson(dataMapper);
row1 = jsonbMapper.fromJson(jsonValueMapper, row1.getClass());
sourceData.add(row1);
inputsHandlerProcessor.reset();
inputsHandlerProcessor.setInputValue("FLOW", row1);
outputHandlerProcessor.reset();
processorProcessor.onElement(name -> {
assertEquals(Branches.DEFAULT_BRANCH, name);
final Object read = inputsProcessor.read(name);
processorData.add(read);
return read;
}, outputsProcessor);
}
}
use of lombok.ToString in project cas by apereo.
the class AbstractX509PrincipalResolver method getAlternatePrincipal.
/**
* Get alternate principal if alternate attribute configured.
*
* @param certificate X509 Certificate of user
* @return principal using alternate attribute or null if none configured
*/
protected String getAlternatePrincipal(final X509Certificate certificate) {
if (StringUtils.isBlank(alternatePrincipalAttribute)) {
return null;
}
val attributes = extractPersonAttributes(certificate);
val attribute = attributes.get(alternatePrincipalAttribute);
if (attribute == null) {
LOGGER.debug("Attempt to get alternate principal with attribute [{}] was unsuccessful.", alternatePrincipalAttribute);
return null;
}
val optionalAttribute = CollectionUtils.firstElement(attribute);
return optionalAttribute.map(Object::toString).filter(StringUtils::isNotEmpty).map(alternatePrincipal -> {
LOGGER.debug("Using alternate principal attribute [{}]", alternatePrincipal);
return alternatePrincipal;
}).orElseGet(() -> {
LOGGER.trace("Returning null principal id...");
return null;
});
}
use of lombok.ToString in project cas by apereo.
the class SingleSignOnSessionsEndpoint method destroySsoSessions.
/**
* Destroy sso sessions map.
*
* @param type the type
* @param username the username
* @param from the from
* @param count the count
* @param request the request
* @param response the response
* @return the map
*/
@Operation(summary = "Remove single sign-on session for type and user")
@DeleteMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, Object> destroySsoSessions(@Nullable @RequestParam(name = "type", required = false) final String type, @Nullable @RequestParam(name = "username", required = false) final String username, @RequestParam(name = "from", required = false, defaultValue = "0") final long from, @RequestParam(name = "count", required = false, defaultValue = "1000") final long count, final HttpServletRequest request, final HttpServletResponse response) {
if (StringUtils.isBlank(username) && StringUtils.isBlank(type)) {
return Map.of(STATUS, HttpServletResponse.SC_BAD_REQUEST);
}
if (StringUtils.isNotBlank(username)) {
val sessionsMap = new HashMap<String, Object>(1);
val tickets = centralAuthenticationService.getObject().getTickets(ticket -> ticket instanceof TicketGrantingTicket && ((TicketGrantingTicket) ticket).getAuthentication().getPrincipal().getId().equalsIgnoreCase(username));
tickets.forEach(ticket -> sessionsMap.put(ticket.getId(), destroySsoSession(ticket.getId(), request, response)));
return sessionsMap;
}
val sessionsMap = new HashMap<String, Object>();
val option = SsoSessionReportOptions.valueOf(type);
val collection = getActiveSsoSessions(option, username, from, count);
collection.stream().map(sso -> sso.get(SsoSessionAttributeKeys.TICKET_GRANTING_TICKET.getAttributeKey()).toString()).forEach(ticketGrantingTicket -> destroySsoSession(ticketGrantingTicket, request, response));
sessionsMap.put(STATUS, HttpServletResponse.SC_OK);
return sessionsMap;
}
use of lombok.ToString in project cas by apereo.
the class DefaultAttributeDefinitionStore method loadAttributeDefinitionsFromInputStream.
private void loadAttributeDefinitionsFromInputStream(final Resource resource) {
try {
LOGGER.trace("Loading attribute definitions from [{}]", resource);
val json = new String(resource.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
LOGGER.trace("Loaded attribute definitions [{}] from [{}]", json, resource);
val map = MAPPER.readValue(JsonValue.readHjson(json).toString(), new TypeReference<Map<String, AttributeDefinition>>() {
});
map.forEach(this::registerAttributeDefinition);
} catch (final Exception e) {
LoggingUtils.warn(LOGGER, e);
}
}
use of lombok.ToString in project jmxtrans by jmxtrans.
the class StackdriverWriter method getGatewayMessage.
/**
* Take query results, make a JSON String
*
* @param results List of Result objects
* @return a String containing a JSON message, or null if there are no values to report
*
* @throws IOException if there is some problem generating the JSON, should be uncommon
*/
private String getGatewayMessage(final List<Result> results) throws IOException {
int valueCount = 0;
Writer writer = new StringWriter();
JsonGenerator g = jsonFactory.createGenerator(writer);
g.writeStartObject();
g.writeNumberField("timestamp", System.currentTimeMillis() / 1000);
g.writeNumberField("proto_version", STACKDRIVER_PROTOCOL_VERSION);
g.writeArrayFieldStart("data");
List<String> typeNames = this.getTypeNames();
for (Result metric : results) {
if (isNumeric(metric.getValue())) {
// we have a numeric value, write a value into the message
StringBuilder nameBuilder = new StringBuilder();
// put the prefix if set
if (this.prefix != null) {
nameBuilder.append(prefix);
nameBuilder.append(".");
}
// put the class name or its alias if available
if (!metric.getKeyAlias().isEmpty()) {
nameBuilder.append(metric.getKeyAlias());
} else {
nameBuilder.append(metric.getClassName());
}
// Wildcard "typeNames" substitution
String typeName = com.googlecode.jmxtrans.model.naming.StringUtils.cleanupStr(TypeNameValuesStringBuilder.getDefaultBuilder().build(typeNames, metric.getTypeName()));
if (typeName != null && typeName.length() > 0) {
nameBuilder.append(".");
nameBuilder.append(typeName);
}
// add the attribute name
nameBuilder.append(".");
nameBuilder.append(KeyUtils.getValueKey(metric));
// check for Float/Double NaN since these will cause the message validation to fail
if (metric.getValue() instanceof Float && ((Float) metric.getValue()).isNaN()) {
logger.info("Metric value for " + nameBuilder.toString() + " is NaN, skipping");
continue;
}
if (metric.getValue() instanceof Double && ((Double) metric.getValue()).isNaN()) {
logger.info("Metric value for " + nameBuilder.toString() + " is NaN, skipping");
continue;
}
valueCount++;
g.writeStartObject();
g.writeStringField("name", nameBuilder.toString());
g.writeNumberField("value", Double.valueOf(metric.getValue().toString()));
// if the metric is attached to an instance, include that in the message
if (instanceId != null && !instanceId.isEmpty()) {
g.writeStringField("instance", instanceId);
}
g.writeNumberField("collected_at", metric.getEpoch() / 1000);
g.writeEndObject();
}
}
g.writeEndArray();
g.writeEndObject();
g.flush();
g.close();
// return the message if there are any values to report
if (valueCount > 0) {
return writer.toString();
} else {
return null;
}
}
Aggregations