Example usage for org.apache.commons.lang3 StringUtils substringAfter

List of usage examples for org.apache.commons.lang3 StringUtils substringAfter

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringAfter.

Prototype

public static String substringAfter(final String str, final String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:org.igov.service.business.action.task.core.ActionTaskService.java

private String addCalculatedFields(String saFieldsCalc, TaskInfo curTask, String currentRow) {
    HistoricTaskInstance details = oHistoryService.createHistoricTaskInstanceQuery().includeProcessVariables()
            .taskId(curTask.getId()).singleResult();
    LOG.info("Process variables of the task {}:{}: {}", curTask.getId(), saFieldsCalc,
            details.getProcessVariables());
    if (details != null && details.getProcessVariables() != null) {
        Set<String> headersExtra = new HashSet<>();
        for (String key : details.getProcessVariables().keySet()) {
            if (!key.startsWith("sBody")) {
                headersExtra.add(key);//from ww  w .  ja  va  2  s. c om
            }
        }
        saFieldsCalc = StringUtils.substringAfter(saFieldsCalc, "\"");
        saFieldsCalc = StringUtils.substringBeforeLast(saFieldsCalc, "\"");
        for (String expression : saFieldsCalc.split(";")) {
            LOG.info("Processing expression: {}", expression);
            String variableName = StringUtils.substringBefore(expression, "=");
            String condition = StringUtils.substringAfter(expression, "=");
            LOG.info("Checking variable with (name={}, condition={}, expression={}) ", variableName, condition,
                    expression);
            try {
                Object conditionResult = getObjectResultofCondition(headersExtra, details, details, condition);
                currentRow = currentRow + ";" + conditionResult;
                LOG.info("Adding calculated field {} with the value {}", variableName, conditionResult);
            } catch (Exception oException) {
                LOG.error("Error: {}, occured while processing (variable={}) ", oException.getMessage(),
                        variableName);
                LOG.debug("FAIL:", oException);
            }
        }
    }
    return currentRow;
}

From source file:org.igov.service.business.action.task.core.ActionTaskService.java

protected void processExtractFieldsParameter(Set<String> headersExtra, HistoricTaskInstance currTask,
        String saFields, Map<String, Object> line) {
    HistoricTaskInstance details = oHistoryService.createHistoricTaskInstanceQuery().includeProcessVariables()
            .taskId(currTask.getId()).singleResult();
    LOG.info("Process variables of the task {}:{}", currTask.getId(), details.getProcessVariables());
    if (details.getProcessVariables() != null) {
        LOG.info("(Cleaned saFields={})", saFields);
        String[] expressions = saFields.split(";");
        if (expressions != null) {
            for (String expression : expressions) {
                String variableName = StringUtils.substringBefore(expression, "=");
                String condition = StringUtils.substringAfter(expression, "=");
                LOG.info("Checking variable with (name={}, condition={}, expression={})", variableName,
                        condition, expression);
                try {
                    Object conditionResult = getObjectResultofCondition(headersExtra, currTask, details,
                            condition);//  www  .  j a v a 2  s. c o m
                    line.put(variableName, conditionResult);
                } catch (Exception oException) {
                    LOG.error("Error: {}, occured while processing variable {}", oException.getMessage(),
                            variableName);
                    LOG.debug("FAIL:", oException);
                }
            }
        }
    }
}

From source file:org.igov.service.business.action.task.core.ActionTaskService.java

public String formHeader(String saFields, List<HistoricTaskInstance> foundHistoricResults,
        String saFieldsCalc) {// w  w  w .  j  a v a  2  s.co  m
    String res = null;
    if (saFields != null && !"".equals(saFields.trim())) {
        LOG.info("Fields have custom header names");
        StringBuilder sb = new StringBuilder();
        String[] fields = saFields.split(";");
        LOG.info("fields: " + fields);
        for (int i = 0; i < fields.length; i++) {
            if (fields[i].contains("\\=")) {
                sb.append(StringUtils.substringBefore(fields[i], "\\="));
                LOG.info("if (fields[i].contains(\"\\\\=\"))_sb: " + sb);
            } else {
                sb.append(fields[i]);
                LOG.info("else_sb: " + sb);
            }
            if (i < fields.length - 1) {
                sb.append(";");
                LOG.info("(i < fields.length - 1)_sb: " + sb);
            }
        }
        res = sb.toString();
        res = res.replaceAll("\\$\\{", "");
        res = res.replaceAll("\\}", "");
        LOG.info("Formed header from list of fields: {}", res);
    } else {
        if (foundHistoricResults != null && !foundHistoricResults.isEmpty()) {
            HistoricTaskInstance historicTask = foundHistoricResults.get(0);
            Set<String> keys = historicTask.getProcessVariables().keySet();
            StringBuilder sb = new StringBuilder();
            Iterator<String> iter = keys.iterator();
            while (iter.hasNext()) {
                sb.append(iter.next());
                if (iter.hasNext()) {
                    sb.append(";");
                }
            }
            res = sb.toString();
            LOG.info("res: " + res);
        }
        LOG.info("Formed header from all the fields of a task: {}", res);
    }
    if (saFieldsCalc != null) {
        saFieldsCalc = StringUtils.substringAfter(saFieldsCalc, "\"");
        saFieldsCalc = StringUtils.substringBeforeLast(saFieldsCalc, "\"");
        String[] params = saFieldsCalc.split(";");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < params.length; i++) {
            String currParam = params[i];
            String cutHeader = StringUtils.substringBefore(currParam, "=");
            LOG.info("Adding header to the csv file from saFieldsCalc: {}", cutHeader);
            sb.append(cutHeader);
            if (i < params.length - 1) {
                sb.append(";");
            }
        }
        res = res + ";" + sb.toString();
        LOG.info("Header with calculated fields: {}", res);
    }
    return res;
}

From source file:org.igov.service.business.action.task.core.ActionTaskService.java

/**
 * saFeilds paramter may contain name of headers or can be empty. Before
 * forming the result - we need to cut header names
 *
 //     * @param saFields/*from   ww  w  .  ja v  a2 s  .c  o m*/
 //     * @param foundHistoricResults
 //     * @return
 */
public String processSaFields(String saFields, List<HistoricTaskInstance> foundHistoricResults) {
    String res = null;

    if (saFields != null) {
        LOG.info("saFields has custom header names");
        StringBuilder sb = new StringBuilder();
        String[] fields = saFields.split(";");
        for (int i = 0; i < fields.length; i++) {
            if (fields[i].contains("=")) {
                sb.append(StringUtils.substringAfter(fields[i], "="));
            } else {
                sb.append(fields[i]);
            }
            if (i < fields.length - 1) {
                sb.append(";");
            }
        }
        res = sb.toString();
    } else {
        if (foundHistoricResults != null && !foundHistoricResults.isEmpty()) {
            HistoricTaskInstance historicTask = foundHistoricResults.get(0);
            Set<String> keys = historicTask.getProcessVariables().keySet();
            StringBuilder sb = new StringBuilder();
            Iterator<String> iter = keys.iterator();
            while (iter.hasNext()) {
                sb.append("${").append(iter.next()).append("}");
                if (iter.hasNext()) {
                    sb.append(";");
                }
            }
            res = sb.toString();
        }
        LOG.info("Formed header from all the fields of a task: {}", res);
    }
    return res;
}

From source file:org.imsglobal.lti.toolProvider.mediaType.SecurityContract.java

/**
 * Class constructor./*from   w  w  w  .  j ava  2 s  . c o m*/
 *
 * @param ToolProvider toolProvider  Tool Provider instance
 * @param string secret Shared secret
 */
public SecurityContract(ToolProvider toolProvider, String secret) {

    tcContexts = new HashMap<String, String>(); //toolConsumer contexts from JSON-LD spec
    for (JSONContext context : toolProvider.getConsumer().getProfile().getContexts()) {
        tcContexts.putAll(context.getTerms());
        //PHP: $tcContexts = array_merge(get_object_vars($context), $tcContexts);
        //context here is a JSON-LD Context, it contains rewrite rules and ontology refs for a JSON schema
    }

    this.setSharedSecret(secret);

    toolServices = new HashMap<String, ToolService>();
    for (ToolService requiredService : toolProvider.getRequiredServices()) {
        for (String format : requiredService.getFormats()) {
            ServiceDefinition service = toolProvider.findService(format, requiredService.getActions());
            if ((service != null) && toolServices.containsKey(service.getId())) {
                String id = service.getId();
                String part1 = StringUtils.substringBefore(id, ":");
                String part2 = StringUtils.substringAfter(id, ":");
                if (StringUtils.isNotEmpty(part2)) {
                    if (tcContexts.containsKey(part1)) {
                        id = tcContexts.get(part1) + part2;
                    }
                }
                ToolService toolService = new ToolService();
                toolService.setType("RestServiceProfile");
                toolService.setService(id);
                toolService.setActions(requiredService.getActions());
                toolServices.put(service.getId(), toolService);
            }
        }
    }
    for (ToolService optionalService : toolProvider.getOptionalServices()) {
        for (String format : optionalService.getFormats()) {
            ServiceDefinition service = toolProvider.findService(format, optionalService.getActions());
            if ((service != null) && toolServices.containsKey(service.getId())) {
                String id = service.getId();
                String part1 = StringUtils.substringBefore(id, ":");
                String part2 = StringUtils.substringAfter(id, ":");
                if (StringUtils.isNotEmpty(part2)) {
                    if (tcContexts.containsKey(part1)) {
                        id = tcContexts.get(part1) + part2;
                    }
                }
                ToolService toolService = new ToolService();
                toolService.setType("RestServiceProfile");
                toolService.setService(id);
                toolService.setActions(optionalService.getActions());
                toolServices.put(service.getId(), toolService);
            }
        }
    }
}

From source file:org.ingini.mongodb.jongo.example.util.ImportQuotes.java

public static void main(String[] args) throws IOException, URISyntaxException {
    Jongo jongo = new Jongo(new MongoClient("127.0.0.1", 27017).getDB("movie_db"));
    MongoCollection quoteCollection = jongo.getCollection("quotes");

    URI uri = ImportQuotes.class.getClassLoader().getResource("raw/quotes.list").toURI();
    Stream<String> lines = Files.lines(Paths.get(uri), forName("windows-1252"));

    List<List<String>> quotesList = new ArrayList<>();

    lines.skip(14).forEach(s -> {// w  ww.  j a  va  2  s.  c  om
        List<String> quotes = new ArrayList<>();
        if (quotesList.size() == 0) {
            quotesList.add(quotes);
        }
        quotes = quotesList.get(quotesList.size() - 1);

        if (s.isEmpty() && quotes.get(quotes.size() - 1).isEmpty()) {
            quotesList.add(new ArrayList<>());
        }

        quotes.add(s);
    });

    System.out.println("Quotes lists: " + quotesList.size());

    List<FilmQuote> filmQuotes = new ArrayList<>();
    for (List<String> quotes : quotesList) {
        Set<ActorQuote> actorQuotes = new LinkedHashSet<>();
        Iterator<String> iterator = quotes.subList(1, quotes.size()).iterator();

        String actorName = null;
        String quote = null;
        while (iterator.hasNext()) {
            String s = iterator.next();
            if (s.contains(":")) {
                if (actorName != null && quote != null) {
                    actorQuotes.add(new ActorQuote(actorName, quote));
                }
                actorName = StringUtils.substringBefore(s, ":");
                quote = StringUtils.substringAfter(s, ":");
            } else if (s.isEmpty()) {
                actorQuotes.add(new ActorQuote(actorName, quote));
            } else {
                quote += StringUtils.substringAfter(s, " ");
            }

        }
        FilmQuote filmQuote = new FilmQuote("english", quotes.get(0), actorQuotes);
        filmQuotes.add(filmQuote);
        quoteCollection.insert(filmQuote);
    }

    System.out.println("Film Quotes lists: " + filmQuotes.size());

}

From source file:org.jasig.cas.support.oauth.web.OAuth20AccessTokenControllerTests.java

@Test
public void verifyOK() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET",
            CONTEXT + OAuthConstants.ACCESS_TOKEN_URL);
    mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
    mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
    mockRequest.setParameter(OAuthConstants.CODE, CODE);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final ServicesManager servicesManager = mock(ServicesManager.class);
    final List<RegisteredService> services = new ArrayList<>();
    services.add(getRegisteredService(REDIRECT_URI, CLIENT_SECRET));
    when(servicesManager.getAllServices()).thenReturn(services);
    final TicketRegistry ticketRegistry = mock(TicketRegistry.class);
    final ServiceTicket serviceTicket = mock(ServiceTicket.class);
    final TicketGrantingTicket ticketGrantingTicket = mock(TicketGrantingTicket.class);
    // 10 seconds
    final int timeBefore = 10;
    when(ticketGrantingTicket.getCreationTime()).thenReturn(System.currentTimeMillis() - timeBefore * 1000);
    when(ticketGrantingTicket.getId()).thenReturn(TGT_ID);
    when(serviceTicket.isExpired()).thenReturn(false);
    when(serviceTicket.getId()).thenReturn(CODE);
    when(serviceTicket.getGrantingTicket()).thenReturn(ticketGrantingTicket);
    when(ticketRegistry.getTicket(CODE)).thenReturn(serviceTicket);
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setServicesManager(servicesManager);
    oauth20WrapperController.setTicketRegistry(ticketRegistry);
    oauth20WrapperController.setTimeout(TIMEOUT);
    oauth20WrapperController.afterPropertiesSet();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    verify(ticketRegistry).deleteTicket(CODE);
    assertEquals("text/plain", mockResponse.getContentType());
    assertEquals(200, mockResponse.getStatus());
    final String body = mockResponse.getContentAsString();
    assertTrue(//from w w  w  . j  a  v  a  2s. c o  m
            body.startsWith(OAuthConstants.ACCESS_TOKEN + "=" + TGT_ID + "&" + OAuthConstants.EXPIRES + "="));
    // delta = 2 seconds
    final int delta = 2;
    final int timeLeft = Integer.parseInt(StringUtils.substringAfter(body, "&" + OAuthConstants.EXPIRES + "="));
    assertTrue(timeLeft >= TIMEOUT - timeBefore - delta);
    assertTrue(timeLeft <= TIMEOUT - timeBefore + delta);
}

From source file:org.jasig.cas.web.flow.FrontChannelLogoutActionTests.java

@Test
public void verifyLogoutOneLogoutRequestNotAttempted() throws Exception {
    final String fakeUrl = "http://url";
    final LogoutRequest logoutRequest = new LogoutRequest(TICKET_ID,
            new SimpleWebApplicationServiceImpl(fakeUrl));
    WebUtils.putLogoutRequests(this.requestContext, Arrays.asList(logoutRequest));
    this.requestContext.getFlowScope().put(FrontChannelLogoutAction.LOGOUT_INDEX, 0);
    final Event event = this.frontChannelLogoutAction.doExecute(this.requestContext);
    assertEquals(FrontChannelLogoutAction.REDIRECT_APP_EVENT, event.getId());
    final List<LogoutRequest> list = WebUtils.getLogoutRequests(this.requestContext);
    assertEquals(1, list.size());/*from   w ww.  j  av a 2s .  c  o m*/
    final String url = (String) event.getAttributes().get("logoutUrl");
    assertTrue(url.startsWith(fakeUrl + "?SAMLRequest="));
    final byte[] samlMessage = CompressionUtils.decodeBase64ToByteArray(
            URLDecoder.decode(StringUtils.substringAfter(url, "?SAMLRequest="), "UTF-8"));
    final Inflater decompresser = new Inflater();
    decompresser.setInput(samlMessage);
    final byte[] result = new byte[1000];
    decompresser.inflate(result);
    decompresser.end();
    final String message = new String(result);
    assertTrue(message
            .startsWith("<samlp:LogoutRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" ID=\""));
    assertTrue(message.indexOf("<samlp:SessionIndex>" + TICKET_ID + "</samlp:SessionIndex>") >= 0);
}

From source file:org.jbb.permissions.impl.acl.PermissionTranslator.java

public Permission toApiModel(AclPermissionEntity permissionEntity, PermissionValue value) {
    String code = permissionEntity.getCode();

    PermissionDefinition definition = null;
    if (code.startsWith(AdministratorPermissions.ADMIN_ROLE_PREFIX)) {
        definition = EnumUtils.getEnum(AdministratorPermissions.class,
                StringUtils.substringAfter(code, AdministratorPermissions.ADMIN_ROLE_PREFIX));
    } else if (code.startsWith(MemberPermissions.MEMBER_ROLE_PREFIX)) {
        definition = EnumUtils.getEnum(MemberPermissions.class,
                StringUtils.substringAfter(code, MemberPermissions.MEMBER_ROLE_PREFIX));
    }/*  ww w .j a  va  2s. c o m*/

    return Permission.builder().definition(definition).value(value).build();
}

From source file:org.kalypso.gml.ui.internal.shape.PathShapeExistsValidator.java

private void checkFileExists(final IWorkspaceRoot root, final IPath basePath, final String extension)
        throws CoreException {
    final String ext = StringUtils.substringAfter(extension, "."); //$NON-NLS-1$

    final IPath path = basePath.addFileExtension(ext);

    final IFile file = root.getFile(path);
    if (file.exists())
        fail();// ww  w .j a va2s  . co  m
}