use of dlshade.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 dlshade.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 dlshade.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;
}
use of dlshade.org.apache.commons.lang3.StringUtils in project xwiki-platform by xwiki.
the class LiveTableResultsTest method setUp.
@Before
@SuppressWarnings("deprecation")
public void setUp() throws Exception {
setOutputSyntax(Syntax.PLAIN_1_0);
request.put("outputSyntax", "plain");
request.put("xpage", "plain");
oldcore.getXWikiContext().setAction("get");
queryService = mock(QueryManagerScriptService.class);
oldcore.getMocker().registerComponent(ScriptService.class, "query", queryService);
modelService = mock(ModelScriptService.class);
oldcore.getMocker().registerComponent(ScriptService.class, "model", modelService);
TagPluginApi tagPluginApi = mock(TagPluginApi.class);
doReturn(tagPluginApi).when(oldcore.getSpyXWiki()).getPluginApi(eq("tag"), any(XWikiContext.class));
registerVelocityTool("stringtool", new StringUtils());
registerVelocityTool("mathtool", new MathTool());
registerVelocityTool("regextool", new RegexTool());
registerVelocityTool("numbertool", new NumberTool());
loadPage(new DocumentReference("xwiki", "XWiki", "LiveTableResultsMacros"));
}
use of dlshade.org.apache.commons.lang3.StringUtils in project yorc-a4c-plugin by ystia.
the class ToscaComponentExporter method getVelocityContext.
static Map<String, Object> getVelocityContext() {
Map<String, Object> velocityCtx = new HashMap<>();
velocityCtx.put("vtPath", "org/ystia/yorc/alien4cloud/plugin/tosca");
velocityCtx.put("yorcUtils", new ToscaComponentUtils());
velocityCtx.put("stringsUtils", new StringUtils());
return velocityCtx;
}
Aggregations