Search in sources :

Example 6 with StringUtils

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"));
}
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 7 with StringUtils

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;
}
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 8 with StringUtils

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;
}
Also used : StringUtils(org.apache.commons.lang3.StringUtils) QueryRule(org.molgenis.data.QueryRule)

Example 9 with StringUtils

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"));
}
Also used : NumberTool(org.apache.velocity.tools.generic.NumberTool) QueryManagerScriptService(org.xwiki.query.script.QueryManagerScriptService) StringUtils(org.apache.commons.lang3.StringUtils) XWikiContext(com.xpn.xwiki.XWikiContext) TagPluginApi(com.xpn.xwiki.plugin.tag.TagPluginApi) MathTool(org.apache.velocity.tools.generic.MathTool) ModelScriptService(org.xwiki.model.script.ModelScriptService) DocumentReference(org.xwiki.model.reference.DocumentReference) RegexTool(org.xwiki.velocity.tools.RegexTool) Before(org.junit.Before)

Example 10 with StringUtils

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;
}
Also used : HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)10 ColumnSpec (com.thinkbiganalytics.util.ColumnSpec)3 HashMap (java.util.HashMap)3 FlowFile (org.apache.nifi.flowfile.FlowFile)3 ThriftService (com.thinkbiganalytics.nifi.v2.thrift.ThriftService)2 Connection (java.sql.Connection)2 ComponentLog (org.apache.nifi.logging.ComponentLog)2 ProcessException (org.apache.nifi.processor.exception.ProcessException)2 QueryRule (org.molgenis.data.QueryRule)2 DefaultCheckInResult (alfio.manager.support.DefaultCheckInResult)1 OnSitePaymentResult (alfio.manager.support.OnSitePaymentResult)1 TicketAndCheckInResult (alfio.manager.support.TicketAndCheckInResult)1 TicketStatus (alfio.model.Ticket.TicketStatus)1 Sets (com.google.common.collect.Sets)1 StackRepoDetails (com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 TableMergeSyncSupport (com.thinkbiganalytics.ingest.TableMergeSyncSupport)1 TableRegisterSupport (com.thinkbiganalytics.ingest.TableRegisterSupport)1 PartitionSpec (com.thinkbiganalytics.util.PartitionSpec)1 TableRegisterConfiguration (com.thinkbiganalytics.util.TableRegisterConfiguration)1