Search in sources :

Example 11 with ToString

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);
    }
}
Also used : ToString(lombok.ToString) PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) ChainedMapper(org.talend.sdk.component.runtime.manager.chain.ChainedMapper) Mapper(org.talend.sdk.component.runtime.input.Mapper) Input(org.talend.sdk.component.runtime.input.Input) Jsonb(javax.json.bind.Jsonb) ChainedMapper(org.talend.sdk.component.runtime.manager.chain.ChainedMapper) JsonObject(javax.json.JsonObject)

Example 12 with ToString

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;
    });
}
Also used : lombok.val(lombok.val) X509Certificate(java.security.cert.X509Certificate) PersonDirectoryPrincipalResolver(org.apereo.cas.authentication.principal.resolvers.PersonDirectoryPrincipalResolver) Setter(lombok.Setter) lombok.val(lombok.val) StringUtils(org.apache.commons.lang3.StringUtils) LinkedHashMap(java.util.LinkedHashMap) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) ToString(lombok.ToString) Optional(java.util.Optional) Principal(org.apereo.cas.authentication.principal.Principal) PrincipalResolutionContext(org.apereo.cas.authentication.principal.resolvers.PrincipalResolutionContext) Credential(org.apereo.cas.authentication.Credential) StringUtils(org.apache.commons.lang3.StringUtils)

Example 13 with ToString

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;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) Getter(lombok.Getter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) LoggingUtils(org.apereo.cas.util.LoggingUtils) Operation(io.swagger.v3.oas.annotations.Operation) ObjectProvider(org.springframework.beans.factory.ObjectProvider) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) ToString(lombok.ToString) GetMapping(org.springframework.web.bind.annotation.GetMapping) Nullable(org.springframework.lang.Nullable) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) SingleLogoutRequestExecutor(org.apereo.cas.logout.slo.SingleLogoutRequestExecutor) DateTimeUtils(org.apereo.cas.util.DateTimeUtils) MediaType(org.springframework.http.MediaType) Collection(java.util.Collection) lombok.val(lombok.val) HttpServletResponse(javax.servlet.http.HttpServletResponse) Collectors(java.util.stream.Collectors) BaseCasActuatorEndpoint(org.apereo.cas.web.BaseCasActuatorEndpoint) ISOStandardDateFormat(org.apereo.cas.util.ISOStandardDateFormat) RestControllerEndpoint(org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint) AtomicLong(java.util.concurrent.atomic.AtomicLong) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Optional(java.util.Optional) CoreAuthenticationUtils(org.apereo.cas.authentication.CoreAuthenticationUtils) Ticket(org.apereo.cas.ticket.Ticket) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 14 with ToString

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);
    }
}
Also used : lombok.val(lombok.val) ToString(lombok.ToString) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 15 with ToString

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;
    }
}
Also used : StringWriter(java.io.StringWriter) TypeNameValuesStringBuilder(com.googlecode.jmxtrans.model.naming.typename.TypeNameValuesStringBuilder) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ToString(lombok.ToString) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Result(com.googlecode.jmxtrans.model.Result)

Aggregations

ToString (lombok.ToString)28 Map (java.util.Map)6 HashMap (java.util.HashMap)5 List (java.util.List)4 HashSet (java.util.HashSet)3 EclipseNode (lombok.eclipse.EclipseNode)3 Slf4j (lombok.extern.slf4j.Slf4j)3 lombok.val (lombok.val)3 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)2 Github (com.jcabi.github.Github)2 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 LinkedHashMap (java.util.LinkedHashMap)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2 Collectors.toMap (java.util.stream.Collectors.toMap)2 Getter (lombok.Getter)2