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