List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast
public static String substringAfterLast(final String str, final String separator)
Gets the substring after the last occurrence of a separator.
From source file:com.thinkbiganalytics.feedmgr.rest.controller.FeedRestController.java
@GET @Path("/{feedId}/profile-summary") @Produces(MediaType.APPLICATION_JSON)/*www . ja v a 2s . c om*/ @ApiOperation("Gets a summary of the feed profiles.") @ApiResponses({ @ApiResponse(code = 200, message = "Returns the profile summaries.", response = Map.class, responseContainer = "List"), @ApiResponse(code = 500, message = "The profiles are unavailable.", response = RestResponseStatus.class) }) public Response profileSummary(@PathParam("feedId") String feedId) { FeedMetadata feedMetadata = getMetadataService().getFeedById(feedId); final String profileTable = HiveUtils.quoteIdentifier(feedMetadata.getProfileTableName()); String query = "SELECT * from " + profileTable + " where columnname = '(ALL)'"; List<Map<String, Object>> rows = new ArrayList<>(); try { QueryResult results = hiveService.query(query); rows.addAll(results.getRows()); //add in the archive date time fields if applicipable String ARCHIVE_PROCESSOR_TYPE = "com.thinkbiganalytics.nifi.GetTableData"; if (feedMetadata.getInputProcessorType().equalsIgnoreCase(ARCHIVE_PROCESSOR_TYPE)) { NifiProperty property = NifiPropertyUtil.findPropertyByProcessorType(feedMetadata.getProperties(), ARCHIVE_PROCESSOR_TYPE, "Date Field"); if (property != null && property.getValue() != null) { String field = property.getValue(); if (field.contains(".")) { field = StringUtils.substringAfterLast(field, "."); } query = "SELECT * from " + profileTable + " where metrictype IN('MIN_TIMESTAMP','MAX_TIMESTAMP') AND columnname = " + HiveUtils.quoteString(field); QueryResult dateRows = hiveService.query(query); if (dateRows != null && !dateRows.isEmpty()) { rows.addAll(dateRows.getRows()); } } } } catch (DataAccessException e) { if (e.getCause() instanceof org.apache.hive.service.cli.HiveSQLException && e.getCause().getMessage().contains("Table not found")) { //this exception is ok to swallow since it just means no profile data exists yet } else if (e.getCause().getMessage().contains("HiveAccessControlException Permission denied")) { throw new AccessControlException("You do not have permission to execute this hive query"); } else { throw e; } } return Response.ok(rows).build(); }
From source file:de.jcup.egradle.core.model.groovyantlr.AbstractGroovyModelBuilder.java
/** * Resolves method chain last part after . ("e.g. a "xyz.doLast" will return * "doLast" - a "xyz" returns <code>null</code>) * //from w w w. ja v a 2 s . c o m * @param item * @return last part after dot, otherwise <code>null</code> */ private String resolveLastMethodChainPart(String name) { if (name == null) { return null; } if (name.indexOf('.') == -1) { return null; } String lastCall = StringUtils.substringAfterLast(name, "."); return lastCall; }
From source file:com.zht.common.codegen.util.UIEasyStrUtil.java
public static void handlerProperty_Date(GenEntityProperty prop) { String entitysimplName = prop.getGenEntity().getName(); if (entitysimplName != null && entitysimplName.contains(".")) { entitysimplName = StringUtils.substringAfterLast(entitysimplName, "."); entitysimplName = ZStrUtil.toLowerCaseFirst(entitysimplName); }//from www . jav a 2 s. c o m StringBuffer editStr = new StringBuffer(""); StringBuffer queryStr = new StringBuffer(""); StringBuffer displayStr = new StringBuffer(""); String calzzType = ""; String editType = prop.getEditType(); String data_options = " "; if ("date".equals(editType)) { calzzType = "class=\"easyui-datebox\" "; } else if ("datetime".equals(editType)) { calzzType = "class=\"easyui-datetimebox\" "; } else if ("autoCurrentTime".equals(editType)) { calzzType = "class=\"easyui-datetimebox\""; } editStr.append("<input type=\"text\" name=\"" + prop.getPropertyName() + "\" value=\"${" + entitysimplName + "." + prop.getPropertyName() + "}\"").append(" "); editStr.append(calzzType).append(" "); if (prop.getNullable() != null && prop.getNullable() == false) { data_options += "required:true,"; } editStr.append(" data-options=\"" + data_options + "\""); editStr.append("/>"); queryStr.append(editStr.toString().replace(" data-options=\"" + data_options + "\"", " ") .replace("name=\"" + prop.getPropertyName() + "\"", " name=\"webParams[" + prop.getPropertyName() + "]\" ") .replace("value=\"${" + entitysimplName + "." + prop.getPropertyName() + "}\"", " ")); if (prop.getIsQueryCondtion()) { prop.setGeneratedQueryOfPropertyStr(queryStr.toString()); } if ("autoCurrentTime".equals(editType)) { editStr = new StringBuffer(); } prop.setGeneratedEditOfPropertyStr(editStr.toString()); displayStr.append("{field:'" + prop.getPropertyName() + "',title:'" + prop.getDisplay() + "',width:" + prop.getColumnWidth() + ","); String simpleForamt = prop.getSimpleFormat(); if (simpleForamt != null && simpleForamt.length() > 0) { displayStr.append(simpleForamt); } displayStr.append("},"); prop.setGeneratedListDisplayOfPropertyStr(displayStr.toString()); }
From source file:com.sonicle.webtop.mail.MailManager.java
public void setEmailDomainMailcard(String email, String html) { ensureProfileDomain(true);//from w w w .j ava 2s . co m if (RunContext.isWebTopAdmin() || RunContext.isPermitted(true, getTargetProfileId(), SERVICE_ID, "DOMAIN_MAILCARD_SETTINGS", "CHANGE")) { if (!StringUtils.contains(email, "@")) return; writeMailcard(getTargetProfileId().getDomainId(), "mailcard_" + StringUtils.substringAfterLast(email, "@"), html); } else { throw new AuthException("You have insufficient rights to perform the operation [{}]", "DOMAIN_MAILCARD_SETTINGS:CHANGE"); } }
From source file:de.blizzy.documentr.page.PageStore.java
@Override public void relocatePage(final String projectName, final String branchName, final String path, String newParentPagePath, User user) throws IOException { Assert.hasLength(projectName);/* www . j a va 2 s.c om*/ Assert.hasLength(branchName); Assert.hasLength(path); Assert.hasLength(newParentPagePath); Assert.notNull(user); // check if pages exist by trying to load them getPage(projectName, branchName, path, false); getPage(projectName, branchName, newParentPagePath, false); ILockedRepository repo = null; List<String> oldPagePaths; List<String> deletedPagePaths; List<String> newPagePaths; List<PagePathChangedEvent> pagePathChangedEvents; try { repo = globalRepositoryManager.getProjectBranchRepository(projectName, branchName); String pageName = path.contains("/") ? StringUtils.substringAfterLast(path, "/") : path; //$NON-NLS-1$ //$NON-NLS-2$ final String newPagePath = newParentPagePath + "/" + pageName; //$NON-NLS-1$ File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File oldSubPagesDir = Util.toFile(new File(workingDir, DocumentrConstants.PAGES_DIR_NAME), path); oldPagePaths = listPagePaths(oldSubPagesDir, true); oldPagePaths = Lists.newArrayList(Lists.transform(oldPagePaths, new Function<String, String>() { @Override public String apply(String p) { return path + "/" + p; //$NON-NLS-1$ } })); oldPagePaths.add(path); File deletedPagesSubDir = Util.toFile(new File(workingDir, DocumentrConstants.PAGES_DIR_NAME), newPagePath); deletedPagePaths = listPagePaths(deletedPagesSubDir, true); deletedPagePaths = Lists.newArrayList(Lists.transform(deletedPagePaths, new Function<String, String>() { @Override public String apply(String p) { return newPagePath + "/" + p; //$NON-NLS-1$ } })); deletedPagePaths.add(newPagePath); Git git = Git.wrap(repo.r()); AddCommand addCommand = git.add(); for (String dirName : Sets.newHashSet(DocumentrConstants.PAGES_DIR_NAME, DocumentrConstants.ATTACHMENTS_DIR_NAME)) { File dir = new File(workingDir, dirName); File newSubPagesDir = Util.toFile(dir, newPagePath); if (newSubPagesDir.exists()) { git.rm().addFilepattern(dirName + "/" + newPagePath).call(); //$NON-NLS-1$ } File newPageFile = Util.toFile(dir, newPagePath + DocumentrConstants.PAGE_SUFFIX); if (newPageFile.exists()) { git.rm().addFilepattern(dirName + "/" + newPagePath + DocumentrConstants.PAGE_SUFFIX).call(); //$NON-NLS-1$ } File newMetaFile = Util.toFile(dir, newPagePath + DocumentrConstants.META_SUFFIX); if (newMetaFile.exists()) { git.rm().addFilepattern(dirName + "/" + newPagePath + DocumentrConstants.META_SUFFIX).call(); //$NON-NLS-1$ } File newParentPageDir = Util.toFile(dir, newParentPagePath); File subPagesDir = Util.toFile(dir, path); if (subPagesDir.exists()) { FileUtils.copyDirectoryToDirectory(subPagesDir, newParentPageDir); git.rm().addFilepattern(dirName + "/" + path).call(); //$NON-NLS-1$ addCommand.addFilepattern(dirName + "/" + newParentPagePath + "/" + pageName); //$NON-NLS-1$ //$NON-NLS-2$ } File pageFile = Util.toFile(dir, path + DocumentrConstants.PAGE_SUFFIX); if (pageFile.exists()) { FileUtils.copyFileToDirectory(pageFile, newParentPageDir); git.rm().addFilepattern(dirName + "/" + path + DocumentrConstants.PAGE_SUFFIX).call(); //$NON-NLS-1$ addCommand.addFilepattern( dirName + "/" + newParentPagePath + "/" + pageName + DocumentrConstants.PAGE_SUFFIX); //$NON-NLS-1$ //$NON-NLS-2$ } File metaFile = Util.toFile(dir, path + DocumentrConstants.META_SUFFIX); if (metaFile.exists()) { FileUtils.copyFileToDirectory(metaFile, newParentPageDir); git.rm().addFilepattern(dirName + "/" + path + DocumentrConstants.META_SUFFIX).call(); //$NON-NLS-1$ addCommand.addFilepattern( dirName + "/" + newParentPagePath + "/" + pageName + DocumentrConstants.META_SUFFIX); //$NON-NLS-1$ //$NON-NLS-2$ } } addCommand.call(); PersonIdent ident = new PersonIdent(user.getLoginName(), user.getEmail()); git.commit().setAuthor(ident).setCommitter(ident) .setMessage("move " + path + " to " + newParentPagePath + "/" + pageName) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ .call(); git.push().call(); newPagePaths = Lists.transform(oldPagePaths, new Function<String, String>() { @Override public String apply(String p) { return newPagePath + StringUtils.removeStart(p, path); } }); pagePathChangedEvents = Lists.transform(oldPagePaths, new Function<String, PagePathChangedEvent>() { @Override public PagePathChangedEvent apply(String oldPath) { String newPath = newPagePath + StringUtils.removeStart(oldPath, path); return new PagePathChangedEvent(projectName, branchName, oldPath, newPath); } }); PageUtil.updateProjectEditTime(projectName); } catch (GitAPIException e) { throw new IOException(e); } finally { Closeables.closeQuietly(repo); } Set<String> allDeletedPagePaths = Sets.newHashSet(oldPagePaths); allDeletedPagePaths.addAll(deletedPagePaths); eventBus.post(new PagesDeletedEvent(projectName, branchName, allDeletedPagePaths)); for (String newPath : newPagePaths) { eventBus.post(new PageChangedEvent(projectName, branchName, newPath)); } for (PagePathChangedEvent event : pagePathChangedEvents) { eventBus.post(event); } }
From source file:com.gp.cong.logisoft.bc.fcl.SedFilingBC.java
public void readRespResponseFile(InputStream is, String aesFilesFolder, String aesResponseFileName) throws Exception { List<String> contents = FileUtils.readLines(new File(aesFilesFolder + aesResponseFileName)); // Iterate the result to print each line of the file. String itn = ""; String shipmentNumber = ""; String status = ""; String exception = ""; if (null != contents && contents.size() > 0) { contents.remove(0);//from w ww . ja v a 2 s . c o m } for (String line : contents) { if (null != line && line.length() > 0) { String key = StringUtils.substringBefore(line, " "); shipmentNumber = StringUtils.substringBefore(key, "-") + "-" + (StringUtils.substringAfterLast(key, "-").substring(0, 2)); status += StringUtils.substringAfterLast(line, key).trim() + " "; } } status = StringUtils.removeEnd(status, " "); if (CommonUtils.isNotEmpty(shipmentNumber)) { FclBlDAO fclBlDAO = new FclBlDAO(); String fileNo = shipmentNumber.contains("-") ? shipmentNumber.substring(0, shipmentNumber.indexOf("-")) : shipmentNumber; if (fileNo.length() > 6) { fileNo = fileNo.substring(2); } //String fileNo = shipmentNumber.contains("-") && shipmentNumber.length() > 2 ? shipmentNumber.substring(2, shipmentNumber.indexOf("-")) : shipmentNumber; FclBl fclBl = fclBlDAO.getFileNoObject(fileNo); LclFileNumber lclFileNumber = null; if (null == fclBl) { lclFileNumber = new LclFileNumberDAO().getByProperty("fileNumber", fileNo); } FclAESDetails fclAESDetails = new FclAESDetails(); SedFilingsDAO sedFilingsDAO = new SedFilingsDAO(); boolean hasAes = false; SedFilings sedFilings = sedFilingsDAO.findByTrnref(shipmentNumber.trim()); if (null != sedFilings) { sedFilings.setItn(itn); if (status.contains("SUCCESSFULLY PROCESSED")) { sedFilings.setStatus("P"); } else { sedFilings.setStatus("E"); } AesHistory aesHistory = new AesHistory(); if (null != fclBl) { aesHistory.setBolId(fclBl.getBol()); aesHistory.setFclBlNo(fclBl.getBolId()); for (Object object : fclBl.getFclAesDetails()) { FclAESDetails aes = (FclAESDetails) object; if (null != aes.getAesDetails() && aes.getAesDetails().equalsIgnoreCase(itn)) { hasAes = true; break; } } if (!hasAes && CommonUtils.isNotEmpty(itn)) { fclAESDetails.setAesDetails(itn); fclAESDetails.setFileNo(fileNo); fclAESDetails.setTrailerNoId(fclBl.getBol()); fclBl.getFclAesDetails().add(fclAESDetails); fclBlDAO.update(fclBl); } } else if (null != lclFileNumber) { //aesHistory.setBolId(lclFileNumber.getId()); aesHistory.setFclBlNo(lclFileNumber.getFileNumber()); } aesHistory.setFileNumber(shipmentNumber); aesHistory.setAesException(exception); aesHistory.setFileNo(fileNo); aesHistory.setItn(itn); aesHistory.setStatus(status); aesHistory.setProcessedDate(new Date()); byte[] bs = IOUtils.toByteArray(is); Blob blob = fclBlDAO.getSession().getLobHelper().createBlob(bs); aesHistory.setResponseFile(blob); new AesHistoryDAO().save(aesHistory); sedFilingsDAO.update(sedFilings); } } }
From source file:Interface.FoodCollectionSupervisor.FoodCollectionWorkArea.java
private void btnFindingDriversActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFindingDriversActionPerformed // TODO add your handling code here: int selectedRow = tblNewRequest.getSelectedRow(); int nearestMiles = 0; if (selectedRow < 0) { JOptionPane.showMessageDialog(null, "Please select the row from the table."); return;/*w w w. j a va2s . c o m*/ } btnAssignRequest.setEnabled(false); btnFindingDrivers.setName("Finding closest drivers..."); btnFindingDrivers.setEnabled(false); jScrollPane6.setVisible(true); FoodCollectionWorkRequest request = (FoodCollectionWorkRequest) tblNewRequest.getValueAt(selectedRow, 0); String pickupAddress = request.getSender().getEmployee().getAddress(); DefaultTableModel model = (DefaultTableModel) tblRecommendationDriver.getModel(); model.setRowCount(0); for (UserAccount ua : organization.getUserAccountDirectory().getUserAccountList()) { Employee ee = ua.getEmployee(); if (ee instanceof FoodCollectionDriverEmployee) { try { if (nearestMiles == 3) { break; } String driverCurrentLocation = ((FoodCollectionDriverEmployee) (ee)).getDriverCurrentAddress(); String sourceAddress = pickupAddress; String myKey = "AIzaSyDxQT-LVz0VhlZN_4FZ4NaKoa63zeGIge0"; driverCurrentLocation = driverCurrentLocation.replace(" ", "+"); sourceAddress = sourceAddress.replace(" ", "+"); String url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=#ORIGIN&destinations=#DESTINATION&mode=driving&units=imperial&language=fr-FR&key=#KEY"; url = url.replace("#ORIGIN", driverCurrentLocation); url = url.replace("#DESTINATION", sourceAddress); url = url.replace("#KEY", myKey); // HttpURLConnectionExample http = new HttpURLConnectionExample(); // System.out.println("Testing 1 - Send Http GET request"); String json = sendGet(url); String a = StringUtils.substringBefore(json, "miles"); String b = StringUtils.substringAfterLast(a, "\""); b = b.replace(",", "."); String distance = b + "miles"; //System.out.println("Distance : " + b +" miles."); Double bInMiles = Double.parseDouble(b); if (bInMiles < 2.0) { nearestMiles++; } Object[] row = new Object[3]; row[0] = ua.getEmployee().getName(); row[1] = ((FoodCollectionDriverEmployee) (ee)).getDriverCurrentAddress(); row[2] = distance; model.addRow(row); } catch (Exception e) { System.out.println("Message :" + e.getMessage()); } } } btnAssignRequest.setEnabled(true); btnFindingDrivers.setName("Recommendation for closest driver >>"); btnFindingDrivers.setEnabled(true); }
From source file:com.xpn.xwiki.objects.classes.BaseClass.java
/** * {@inheritDoc}/* w w w .j a v a 2 s. c o m*/ * * @see com.xpn.xwiki.objects.BaseCollection#getDiff(java.lang.Object, com.xpn.xwiki.XWikiContext) */ @Override public List<ObjectDiff> getDiff(Object oldObject, XWikiContext context) { ArrayList<ObjectDiff> difflist = new ArrayList<ObjectDiff>(); BaseClass oldClass = (BaseClass) oldObject; for (PropertyClass newProperty : (Collection<PropertyClass>) getFieldList()) { String propertyName = newProperty.getName(); PropertyClass oldProperty = (PropertyClass) oldClass.get(propertyName); String propertyType = StringUtils.substringAfterLast(newProperty.getClassType(), "."); if (oldProperty == null) { difflist.add(new ObjectDiff(getXClassReference(), getNumber(), "", ObjectDiff.ACTION_PROPERTYADDED, propertyName, propertyType, "", "")); } else if (!oldProperty.equals(newProperty)) { difflist.add(new ObjectDiff(getXClassReference(), getNumber(), "", ObjectDiff.ACTION_PROPERTYCHANGED, propertyName, propertyType, "", "")); } } for (PropertyClass oldProperty : (Collection<PropertyClass>) oldClass.getFieldList()) { String propertyName = oldProperty.getName(); PropertyClass newProperty = (PropertyClass) get(propertyName); String propertyType = StringUtils.substringAfterLast(oldProperty.getClassType(), "."); if (newProperty == null) { difflist.add(new ObjectDiff(getXClassReference(), getNumber(), "", ObjectDiff.ACTION_PROPERTYREMOVED, propertyName, propertyType, "", "")); } } return difflist; }
From source file:org.aliuge.crawler.extractor.selector.action.file.DownLoadFileAction.java
License:asdf
/** * /*from ww w . j a v a 2s .c o m*/ */ @Override public String doAction(Map<String, Object> result, String remoteFile) throws DownLoadException { // String path = getDownDir(result); URL url; try { url = new URL(remoteFile); } catch (MalformedURLException e) { e.printStackTrace(); throw new DownLoadException("" + e.getMessage()); } String fileName = ""; if (md5File) { try { fileName = MD5Utils.createMD5(remoteFile); fileName = fileName + "." + StringUtils.substringAfterLast(url.getPath(), "."); } catch (Exception e) { } } else { fileName = StringUtils.substringAfterLast(url.getPath(), "/"); } MultiThreadDownload download = new MultiThreadDownload(1024 * 1024L); if (asynchronous) { download.downFile(url, path, fileName, false); } else { download.downLoad(url, path, fileName); } // return StringUtils.replace(path + fileName, "\\", "/"); }
From source file:org.aliuge.crawler.extractor.selector.action.file.DownLoadImageResizeAction.java
/** * /* w w w. ja va2 s .com*/ */ @Override public String doAction(Map<String, Object> result, String remoteFile) throws DownLoadException { String path = getDownDir(result); URL url; try { url = new URL(remoteFile); } catch (MalformedURLException e) { e.printStackTrace(); throw new DownLoadException("" + e.getMessage()); } String fileName = ""; if (md5File) { try { fileName = MD5Utils.createMD5(remoteFile); String suffix = StringUtils.substringAfterLast(url.getPath(), "."); if (StringUtils.isBlank(suffix)) { suffix = "jpg"; } fileName = fileName + "." + suffix; } catch (Exception e) { } } else { fileName = StringUtils.substringAfterLast(url.getPath(), "/"); } MultiThreadDownload download = new MultiThreadDownload(1024 * 1024L); if (asynchronous) { download.downImageThenResizeAsyn(url, path, fileName, w, quality); } else { download.downImageThenResizeSyn(url, path, fileName, w, quality); } // return StringUtils.replace(path + fileName, "\\", "/"); }