Search in sources :

Example 16 with StringUtils

use of org.apache.commons.lang3.StringUtils in project data-prep by Talend.

the class PreparationAPITest method testPreparationPreviewOnPreparationWithTrimAction_TDP_5057.

/**
 * Verify a calculate time since preview after a trim step on a preparation
 * see <a href="https://jira.talendforge.org/browse/TDP-5057">TDP-5057</a>
 */
@Test
public void testPreparationPreviewOnPreparationWithTrimAction_TDP_5057() throws IOException {
    // Create a dataset from csv
    final String datasetId = testClient.createDataset("preview/best_sad_songs_of_all_time.csv", "testPreview");
    // Create a preparation
    String preparationId = testClient.createPreparationFromDataset(datasetId, "testPrep", home.getId());
    // apply trim action on the 8nd column to make this column date valid
    Map<String, String> trimParameters = new HashMap<>();
    trimParameters.put("create_new_column", "false");
    trimParameters.put("padding_character", "whitespace");
    trimParameters.put("scope", "column");
    trimParameters.put("column_id", "0008");
    trimParameters.put("column_name", "Added At");
    trimParameters.put("row_id", "null");
    testClient.applyAction(preparationId, Trim.TRIM_ACTION_NAME, trimParameters);
    // check column is date valid after trim action
    InputStream inputStream = testClient.getPreparation(preparationId).asInputStream();
    mapper.getDeserializationConfig().without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    RowMetadata preparationContent = mapper.readValue(inputStream, Data.class).metadata;
    List<PatternFrequency> patternFrequencies = preparationContent.getColumns().get(8).getStatistics().getPatternFrequencies();
    assertTrue(patternFrequencies.stream().map(// 
    PatternFrequency::getPattern).anyMatch("yyyy-MM-dd"::equals));
    // create a preview of calculate time since action
    PreviewAddParameters previewAddParameters = new PreviewAddParameters();
    previewAddParameters.setDatasetId(datasetId);
    previewAddParameters.setPreparationId(preparationId);
    previewAddParameters.setTdpIds(Arrays.asList(1, 2, 3, 4, 5, 6, 7));
    Action calculateTimeUntilAction = new Action();
    calculateTimeUntilAction.setName(ComputeTimeSince.TIME_SINCE_ACTION_NAME);
    MixedContentMap actionParameters = new MixedContentMap();
    actionParameters.put("create_new_column", "true");
    actionParameters.put("time_unit", "HOURS");
    actionParameters.put("since_when", "now_server_side");
    actionParameters.put("scope", "column");
    actionParameters.put("column_id", "0008");
    actionParameters.put("column_name", "Added At");
    calculateTimeUntilAction.setParameters(actionParameters);
    previewAddParameters.setActions(Collections.singletonList(calculateTimeUntilAction));
    JsonPath jsonPath = given().contentType(// 
    ContentType.JSON).body(// 
    previewAddParameters).expect().statusCode(200).log().ifError().when().post(// 
    "/api/preparations/preview/add").jsonPath();
    // check non empty value for the new column
    assertEquals(// 
    "new preview column should contains values according to calculate time since action", // 
    7, jsonPath.getList("records.0009").stream().map(String::valueOf).filter(StringUtils::isBlank).count());
}
Also used : Action(org.talend.dataprep.api.preparation.Action) EntityBuilder.buildAction(org.talend.dataprep.api.service.EntityBuilder.buildAction) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JsonPath(com.jayway.restassured.path.json.JsonPath) PreviewAddParameters(org.talend.dataprep.api.service.api.PreviewAddParameters) PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) StringUtils(org.apache.commons.lang3.StringUtils) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) MixedContentMap(org.talend.dataprep.api.preparation.MixedContentMap) Test(org.junit.Test)

Example 17 with StringUtils

use of org.apache.commons.lang3.StringUtils in project eclipse.jdt.ls by eclipse.

the class Foo3 method localVariable.

public void localVariable() {
    StringUtils util = new StringUtils();
    System.out.println(this.properties);
    System.out.println(util);
}
Also used : StringUtils(org.apache.commons.lang3.StringUtils)

Example 18 with StringUtils

use of org.apache.commons.lang3.StringUtils in project alf.io by alfio-event.

the class CheckInManager method extractStatus.

private TicketAndCheckInResult extractStatus(Optional<Event> maybeEvent, Optional<Ticket> maybeTicket, String ticketIdentifier, Optional<String> ticketCode) {
    if (!maybeEvent.isPresent()) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(EVENT_NOT_FOUND, "Event not found"));
    }
    if (!maybeTicket.isPresent()) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(TICKET_NOT_FOUND, "Ticket with uuid " + ticketIdentifier + " not found"));
    }
    if (!ticketCode.filter(StringUtils::isNotEmpty).isPresent()) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(EMPTY_TICKET_CODE, "Missing ticket code"));
    }
    Ticket ticket = maybeTicket.get();
    Event event = maybeEvent.get();
    String code = ticketCode.get();
    TicketCategory tc = ticketCategoryRepository.getById(ticket.getCategoryId());
    ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
    if (!tc.hasValidCheckIn(now, event.getZoneId())) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy - hh:mm");
        String from = tc.getValidCheckInFrom() == null ? ".." : formatter.format(tc.getValidCheckInFrom(event.getZoneId()));
        String to = tc.getValidCheckInTo() == null ? ".." : formatter.format(tc.getValidCheckInTo(event.getZoneId()));
        String formattedNow = formatter.format(now);
        return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(INVALID_TICKET_CATEGORY_CHECK_IN_DATE, String.format("Invalid check-in date: valid range for category %s is from %s to %s, current time is: %s", tc.getName(), from, to, formattedNow)));
    }
    log.trace("scanned code is {}", code);
    log.trace("true code    is {}", ticket.ticketCode(event.getPrivateKey()));
    if (!code.equals(ticket.ticketCode(event.getPrivateKey()))) {
        return new TicketAndCheckInResult(null, new DefaultCheckInResult(INVALID_TICKET_CODE, "Ticket qr code does not match"));
    }
    final TicketStatus ticketStatus = ticket.getStatus();
    if (ticketStatus == TicketStatus.TO_BE_PAID) {
        return new TicketAndCheckInResult(ticket, new OnSitePaymentResult(MUST_PAY, "Must pay for ticket", MonetaryUtil.centsToUnit(ticket.getFinalPriceCts()), event.getCurrency()));
    }
    if (ticketStatus == TicketStatus.CHECKED_IN) {
        return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(ALREADY_CHECK_IN, "Error: already checked in"));
    }
    if (ticket.getStatus() != TicketStatus.ACQUIRED) {
        return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(INVALID_TICKET_STATE, "Invalid ticket state, expected ACQUIRED state, received " + ticket.getStatus()));
    }
    return new TicketAndCheckInResult(ticket, new DefaultCheckInResult(OK_READY_TO_BE_CHECKED_IN, "Ready to be checked in"));
}
Also used : OnSitePaymentResult(alfio.manager.support.OnSitePaymentResult) TicketAndCheckInResult(alfio.manager.support.TicketAndCheckInResult) ZonedDateTime(java.time.ZonedDateTime) StringUtils(org.apache.commons.lang3.StringUtils) TicketStatus(alfio.model.Ticket.TicketStatus) DefaultCheckInResult(alfio.manager.support.DefaultCheckInResult) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 19 with StringUtils

use of org.apache.commons.lang3.StringUtils in project nifi by apache.

the class LivySessionController method openSession.

private JSONObject openSession() throws IOException, JSONException, InterruptedException {
    ComponentLog log = getLogger();
    JSONObject newSessionInfo;
    final ObjectMapper mapper = new ObjectMapper();
    String sessionsUrl = livyUrl + "/sessions";
    StringBuilder payload = new StringBuilder("{\"kind\":\"" + controllerKind + "\"");
    if (jars != null) {
        List<String> jarsArray = Arrays.stream(jars.split(",")).filter(StringUtils::isNotBlank).map(String::trim).collect(Collectors.toList());
        String jarsJsonArray = mapper.writeValueAsString(jarsArray);
        payload.append(",\"jars\":");
        payload.append(jarsJsonArray);
    }
    if (files != null) {
        List<String> filesArray = Arrays.stream(files.split(",")).filter(StringUtils::isNotBlank).map(String::trim).collect(Collectors.toList());
        String filesJsonArray = mapper.writeValueAsString(filesArray);
        payload.append(",\"files\":");
        payload.append(filesJsonArray);
    }
    payload.append("}");
    log.debug("openSession() Session Payload: " + payload.toString());
    Map<String, String> headers = new HashMap<>();
    headers.put("Content-Type", APPLICATION_JSON);
    headers.put("X-Requested-By", USER);
    newSessionInfo = readJSONObjectFromUrlPOST(sessionsUrl, headers, payload.toString());
    Thread.sleep(1000);
    while (newSessionInfo.getString("state").equalsIgnoreCase("starting")) {
        log.debug("openSession() Waiting for session to start...");
        newSessionInfo = getSessionInfo(newSessionInfo.getInt("id"));
        log.debug("openSession() newSessionInfo: " + newSessionInfo);
        Thread.sleep(1000);
    }
    return newSessionInfo;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ComponentLog(org.apache.nifi.logging.ComponentLog) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 20 with StringUtils

use of org.apache.commons.lang3.StringUtils in project molgenis by molgenis.

the class SemanticSearchServiceHelper method createDisMaxQueryRuleForTerms.

/**
 * Create disMaxJunc query rule based a list of queryTerm. All queryTerms are lower cased and stop words are removed
 *
 * @return disMaxJunc queryRule
 */
public QueryRule createDisMaxQueryRuleForTerms(List<String> queryTerms) {
    List<QueryRule> rules = new ArrayList<>();
    queryTerms.stream().filter(StringUtils::isNotEmpty).map(this::escapeCharsExcludingCaretChar).forEach(query -> {
        rules.add(new QueryRule(AttributeMetadata.LABEL, Operator.FUZZY_MATCH, query));
        rules.add(new QueryRule(AttributeMetadata.DESCRIPTION, Operator.FUZZY_MATCH, query));
    });
    QueryRule finalDisMaxQuery = new QueryRule(rules);
    finalDisMaxQuery.setOperator(Operator.DIS_MAX);
    return finalDisMaxQuery;
}
Also used : StringUtils(org.apache.commons.lang3.StringUtils) QueryRule(org.molgenis.data.QueryRule)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)29 HashMap (java.util.HashMap)10 List (java.util.List)10 Optional (java.util.Optional)10 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)8 Set (java.util.Set)7 lombok.val (lombok.val)7 ArrayList (java.util.ArrayList)6 Arrays (java.util.Arrays)5 Stream (java.util.stream.Stream)5 ColumnSpec (com.thinkbiganalytics.util.ColumnSpec)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 Slf4j (lombok.extern.slf4j.Slf4j)3 FlowFile (org.apache.nifi.flowfile.FlowFile)3 CollectionUtils (org.apereo.cas.util.CollectionUtils)3 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 ThriftService (com.thinkbiganalytics.nifi.v2.thrift.ThriftService)2 IOException (java.io.IOException)2