List of usage examples for org.apache.commons.io FilenameUtils getName
public static String getName(String filename)
From source file:com.opengamma.component.OpenGammaComponentServer.java
/** * Extracts the server name./*w ww . jav a 2 s .co m*/ * <p> * This examines the first part of the file name and the last directory, * merging these with a dash. * * @param fileName the name to extract from, not null * @return the server name, not null */ protected String extractServerName(String fileName) { if (fileName.contains(":")) { fileName = StringUtils.substringAfter(fileName, ":"); } fileName = FilenameUtils.removeExtension(fileName); String first = FilenameUtils.getName(FilenameUtils.getPathNoEndSeparator(fileName)); String second = FilenameUtils.getName(fileName); if (StringUtils.isEmpty(first) || first.equals(second) || second.startsWith(first + "-")) { return second; } return first + "-" + second; }
From source file:fr.insalyon.creatis.vip.application.server.business.WorkflowBusiness.java
/** * * @param user/* www . ja v a 2 s . c o m*/ * @param groups * @param parametersMap * @param applicationName * @param applicationVersion * @param applicationClass * @param simulationName * @return * @throws BusinessException */ public synchronized String launch(User user, List<String> groups, Map<String, String> parametersMap, String applicationName, String applicationVersion, String applicationClass, String simulationName) throws BusinessException { try { long runningWorkflows = workflowDAO.getNumberOfRunning(user.getFullName()); long runningSimulations = workflowDAO.getRunning().size(); if (runningSimulations >= Server.getInstance().getMaxPlatformRunningSimulations()) { logger.warn("Unable to launch execution '" + simulationName + "': max " + "number of running workflows reached in the platform."); throw new fr.insalyon.creatis.vip.core.server.business.BusinessException( "Max number of running executions reached."); } if (runningWorkflows >= user.getMaxRunningSimulations()) { logger.warn("Unable to launch execution '" + simulationName + "': max " + "number of running workflows reached for user '" + user + "'."); throw new fr.insalyon.creatis.vip.core.server.business.BusinessException( "Max number of running executions reached.<br />You already have " + runningWorkflows + " running executions."); } List<ParameterSweep> parameters = new ArrayList<ParameterSweep>(); for (String name : parametersMap.keySet()) { ParameterSweep ps = new ParameterSweep(name); String valuesStr = parametersMap.get(name); if (valuesStr.contains(ApplicationConstants.SEPARATOR_INPUT)) { String[] values = valuesStr.split(ApplicationConstants.SEPARATOR_INPUT); if (values.length != 3) { throw new fr.insalyon.creatis.vip.core.server.business.BusinessException("Error in range."); } Double start = Double.parseDouble(values[0]); Double stop = Double.parseDouble(values[1]); Double step = Double.parseDouble(values[2]); for (double d = start; d <= stop; d += step) { ps.addValue(d + ""); } } else if (valuesStr.contains(ApplicationConstants.SEPARATOR_LIST)) { String[] values = valuesStr.split(ApplicationConstants.SEPARATOR_LIST); for (String v : values) { String parsedPath = DataManagerUtil.parseBaseDir(user, v.trim()); if (!user.isSystemAdministrator()) { checkFolderACL(user, groups, parsedPath); } ps.addValue(parsedPath); } } else { String parsedPath = DataManagerUtil.parseBaseDir(user, valuesStr.trim()); if (!user.isSystemAdministrator()) { checkFolderACL(user, groups, parsedPath); } ps.addValue(parsedPath); } parameters.add(ps); } AppVersion version = applicationDB.getVersion(applicationName, applicationVersion); DataManagerBusiness dmBusiness = new DataManagerBusiness(); String workflowPath = dmBusiness.getRemoteFile(user, version.getLfn(), Server.getInstance().getConfigurationFolder() + "workflows/" + FilenameUtils.getName(version.getLfn())); //selectRandomEngine could also be used; TODO: make this choice configurable Engine engine = selectEngine(applicationClass); WorkflowExecutionBusiness executionBusiness = new WorkflowExecutionBusiness(engine.getEndpoint()); Workflow workflow = null; try { workflow = executionBusiness.launch(applicationName, applicationVersion, applicationClass, user, simulationName, workflowPath, parameters); } catch (BusinessException be) { be.printStackTrace(); logger.error("BusinessException caught on launch workflow, engine " + engine.getName() + " will be disabled"); } finally { if (workflow == null) { engine.setStatus("disabled"); this.engineBusiness.update(engine); for (User u : CoreDAOFactory.getDAOFactory().getUsersGroupsDAO() .getUsersFromGroup(CoreConstants.GROUP_SUPPORT)) { logger.info("Sending warning email to user " + u.toString() + " having email address " + u.getEmail()); CoreUtil.sendEmail("Urgent: VIP engine disabled", "Engine " + engine.getName() + " has just been disabled. Please check that there is at least one active engine left.", new String[] { u.getEmail() }, true, user.getEmail()); } throw new BusinessException( "Workflow is null, engine " + engine.getName() + " has been disabled"); } else { logger.info("Launched workflow " + workflow.toString()); } } workflowDAO.add(workflow); return workflow.getId(); } catch (WorkflowsDBDAOException | DAOException | DataManagerException ex) { logger.error(ex); throw new BusinessException(ex); } }
From source file:com.impetus.ankush.common.utils.LogViewHandler.java
/** * Method to Get the path of log file for Downloading. * //from w w w . j a v a 2s . co m * @param clusterName * Name of the cluster. * @param filePath * Path of the file on remote machine. * @return Path of the log file for Download. * @throws Exception * the exception */ public String downloadFile(String clusterName, String filePath, String agentInstallDir) throws AnkushException, Exception { // Getting the log file content with total read count value. SSHExec conn = SSHUtils.connectToNode(hostname, username, authInfo, privateKey); // String command = "java -cp $HOME/.ankush/agent/libs/*:$HOME/.ankush/agent/libs/agent-0.1.jar" // + " com.impetus.ankush.agent.action.ActionHandler upload " // + filePath; StringBuilder command = new StringBuilder().append(AgentUtils.getActionHandlerCommand(agentInstallDir)); command.append("upload").append(" ").append(filePath); ExecCommand task = new ExecCommand(command.toString()); if (conn != null) { Result rs = conn.exec(task); if (rs.rc != 0) { conn.disconnect(); throw new AnkushException(rs.error_msg); } else { conn.disconnect(); // Getting the file name for file path. String fileName = FilenameUtils.getName(filePath); // Getting the cluster folder path. String downloadPath = "/public/clusters/logs/" + fileName + ".zip"; // return the down-load path return downloadPath; } } // return the down-load path throw new Exception("Unable to connect to node."); }
From source file:mesclasses.view.RootLayoutController.java
@FXML public void onExport() { File archive;/* w w w . j a v a 2 s . c om*/ try { archive = FileSaveUtil.archive(); } catch (IOException e) { notif(e); return; } FileChooser chooser = new FileChooser(); chooser.setTitle("Sauvegardez les donnes"); chooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Archive MesClasses", "*.zip")); LOG.info("archiving in " + archive.getPath()); chooser.setInitialFileName(FilenameUtils.getName(archive.getPath())); File file = chooser.showSaveDialog(primaryStage); if (file != null) { try { FileUtils.moveFile(archive, file); } catch (IOException ex) { notif(ex); } displayNotification(MessageEvent.SUCCESS, "Donnes sauvegardes"); } }
From source file:de.uzk.hki.da.grid.IrodsCommandLineConnector.java
/** * Iquests ICAT for a given field on the DataObject * @author Jens Peters/*from w w w.ja va 2s .co m*/ * @param dao * @param field * @return */ public String iquestDataObjectField(String dao, String field) { String coll_name = FilenameUtils.getFullPath(dao); String data_name = FilenameUtils.getName(dao); coll_name = coll_name.substring(0, coll_name.length() - 1); String commandAsArray[] = new String[] { "iquest", "\"SELECT " + field.toUpperCase() + " where COLL_NAME = \'" + coll_name + "\' and DATA_NAME = \'" + data_name + "\'" }; String iquest = executeIcommand(commandAsArray); try { return parseResultForAVUField(iquest, field); } catch (IOException e) { logger.error("Error in parsing Resultlist searching for " + field, e); } return ""; }
From source file:com.enioka.jqm.tools.JobManagerHandler.java
private Integer addDeliverable(String path, String fileLabel) throws IOException { Deliverable d = null;//www .j a v a 2s .co m EntityManager em = Helpers.getNewEm(); try { this.ji = em.find(JobInstance.class, ji.getId()); String outputRoot = this.ji.getNode().getDlRepo(); String ext = FilenameUtils.getExtension(path); String relDestPath = "" + ji.getJd().getApplicationName() + "/" + ji.getId() + "/" + UUID.randomUUID() + "." + ext; String absDestPath = FilenameUtils.concat(outputRoot, relDestPath); String fileName = FilenameUtils.getName(path); FileUtils.moveFile(new File(path), new File(absDestPath)); jqmlogger.debug("A deliverable is added. Stored as " + absDestPath + ". Initial name: " + fileName); em.getTransaction().begin(); d = Helpers.createDeliverable(relDestPath, fileName, fileLabel, this.ji.getId(), em); em.getTransaction().commit(); } finally { em.close(); } return d.getId(); }
From source file:net.happyonroad.component.container.support.DefaultComponentResolver.java
@Override public Component resolveComponent(final Dependency dependency, Resource resource) throws InvalidComponentNameException, DependencyNotMeetException { logger.debug("Resolving {} from {}", dependency, resource); String originName = resource.getFilename(); if (originName == null) originName = resource.getDescription(); String fileName = FilenameUtils.getName(originName); Dependency basic = Dependency.parse(fileName); if (!dependency.accept(basic)) { throw new InvalidComponentNameException( "The component file name: " + fileName + " does not satisfy the dependency: " + dependency); }/*w w w . j av a 2 s.com*/ DefaultComponent comp; InputStream stream = null; if (fileName.endsWith(".pom")) { try { stream = resource.getInputStream(); comp = (DefaultComponent) resolveComponent(dependency, stream); comp.setUnderlyingResource(resource); if (!comp.isAggregating()) { File jarFile = digJarFilePath(fileName); if (jarFile != null) { ComponentJarResource jarResource = new ComponentJarResource(dependency, jarFile.getName()); comp.setResource(jarResource); } else { logger.warn("Can't find jar file for {}", comp); } } } catch (IOException e) { throw new IllegalArgumentException("The pom file does not exist: " + fileName); } finally { try { if (stream != null) stream.close(); } catch (IOException ex) { /**/} } } else { if (dependency.getVersion() == null) { dependency.setVersion(basic.getVersion()); } ComponentJarResource jarResource = new ComponentJarResource(dependency, fileName); try { stream = jarResource.getPomStream(); comp = (DefaultComponent) resolveComponent(dependency, stream); comp.setUnderlyingResource(resource); comp.setResource(jarResource); } catch (IOException e) { throw new InvalidComponentException(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), "jar", "Can't resolve pom.xml: " + e.getMessage()); } finally { try { if (stream != null) stream.close(); } catch (IOException ex) { /**/} } } if (comp.getType() == null) comp.setType(dependency.getType()); if (!dependency.accept(comp)) throw new InvalidComponentNameException( "The component file name: " + fileName + " conflict with its inner pom: " + comp.toString()); comp.setClassLoader(new ComponentClassLoader(comp)); return comp; }
From source file:de.iai.ilcd.webgui.controller.admin.ImportHandler.java
private UploadedFileInformation analyzeAndCopyOtherFile(UploadedFile file) throws IOException { UploadedFileInformation fileInformation = new UploadedFileInformation(); /*/*from ww w . j a v a 2s. c om*/ * CG / 2012-01-06: don't use only file.getFileName() - which uses FileItem.getName() - * because IE will return the whole path but not just the file name, * see http://commons.apache.org/fileupload/faq.html#whole-path-from-IE */ String fileName = FilenameUtils.getName(file.getFileName()); fileInformation.setFileName(fileName); fileInformation.setFileType(file.getContentType()); fileInformation.setFileSize(file.getSize()); String targetDirectory = this.getUploadDirectory() + "/" + "external_docs"; InputStream in = file.getInputstream(); this.copyFile(file.getInputstream(), targetDirectory, fileName); in.close(); fileInformation.setPathName(targetDirectory + "/" + fileName); return fileInformation; }
From source file:de.uzk.hki.da.model.ObjectPremisXmlWriter.java
/** * Creates the file element./*from w w w . j a v a2 s .com*/ * * @param f the f * @param object the object * @throws XMLStreamException the xML stream exception * @author Daniel M. de Oliveira * @author Thomas Kleinke * @throws FileNotFoundException */ private void createFileElement(DAFile f, Object object, Package pkg) throws XMLStreamException, FileNotFoundException { logger.debug("Start serializing file \"" + f.toString() + "\" as object element to PREMIS"); createOpenElement("object", 1); createAttribute(C.XSI_NS, "type", "file"); createOpenElement("objectIdentifier", 2); createTextElement("objectIdentifierType", "FILE_PATH", 3); createTextElement("objectIdentifierValue", f.getRep_name() + "/" + f.getRelative_path(), 3); createCloseElement(2); createOpenElement("objectCharacteristics", 2); createTextElement("compositionLevel", "0", 3); createOpenElement("fixity", 3); createTextElement("messageDigestAlgorithm", "MD5", 4); createTextElement("messageDigest", f.getChksum(), 4); createTextElement("messageDigestOriginator", "ContentBroker", 4); createCloseElement(3); createTextElement("size", f.getSize(), 3); createOpenElement("format", 3); createOpenElement("formatRegistry", 4); createTextElement("formatRegistryName", "PRONOM", 5); createTextElement("formatRegistryKey", f.getFormatPUID(), 5); createTextElement("formatRegistryRole", "specification", 5); createCloseElement(4); createCloseElement(3); if (f.getRelative_path().toLowerCase().equals("premis.xml") || !f.getRelative_path().toLowerCase().endsWith(".xml")) { createOpenElement("objectCharacteristicsExtension", 3); createOpenElement("mdSec", 4); createAttribute("ID", "_" + jhoveMDSecIdCounter); jhoveMDSecIdCounter++; createOpenElement("mdWrap", 5); createAttribute("MDTYPE", "OTHER"); createAttribute("OTHERMDTYPE", "JHOVE"); createOpenElement("xmlData", 6); integrateJhoveData( Path.make(jhoveDataPath, f.getRep_name(), DigestUtils.md5Hex(f.getRelative_path())).toString(), 7); createCloseElement(6); createCloseElement(5); createCloseElement(4); createCloseElement(3); } createCloseElement(2);// close objectCharacteristics String originalName = null; for (Event e : pkg.getEvents()) { if (e.getType().toUpperCase().equals(C.EVENT_TYPE_CONVERT) && e.getTarget_file().getRelative_path().equals(f.getRelative_path())) originalName = FilenameUtils.getName(e.getSource_file().getRelative_path()); } if (originalName == null) originalName = FilenameUtils.getName(f.getRelative_path()); createTextElement("originalName", originalName, 2); createOpenElement("storage", 2); createOpenElement("contentLocation", 3); createTextElement("contentLocationType", "FILE_PATH", 4); createTextElement("contentLocationValue", f.getRep_name() + "/" + f.getRelative_path(), 4); createCloseElement(3); createCloseElement(2); createOpenElement("relationship", 2); createTextElement("relationshipType", "structural", 3); createTextElement("relationshipSubType", "is included in", 3); createOpenElement("relatedObjectIdentification", 3); createTextElement("relatedObjectIdentifierType", "PACKAGE_NAME", 4); createTextElement("relatedObjectIdentifierValue", object.getIdentifier() + ".pack_" + pkg.getName() + ".tar", 4); createCloseElement(3); createCloseElement(2); createCloseElement(1); }
From source file:com.aliyun.odps.mapred.BridgeJobRunner.java
/** * Register temporary resources.//from w w w. j a v a2s .c om */ private void processTempResources() throws OdpsException { String[] res = job.getResources(); if (res == null) { return; } StringBuilder sb = new StringBuilder(); for (String r : res) { if (r.toLowerCase().startsWith(TEMP_RESOURCE_PREFIX)) { Resource.Type type = r.endsWith(".jar") ? Resource.Type.JAR : Resource.Type.FILE; URL url; try { url = new URL(r); } catch (MalformedURLException e) { throw new OdpsException(e); } aliasToTempResource.put(FilenameUtils.getName(url.getPath()), metaExplorer.addFileResourceWithRetry(url.getPath(), type, "_" + jobId, true)); } else { if (sb.length() > 0) { sb.append(','); } sb.append(r); } } job.setResources(sb.toString()); }