List of usage examples for org.apache.commons.lang3 StringUtils substringAfter
public static String substringAfter(final String str, final String separator)
Gets the substring after the first occurrence of a separator.
From source file:org.pepstock.jem.springbatch.tasks.ChunkDataSourcesManager.java
/** * Replaces inside of property value system variables or properties loaded by Spring * @param value property value to change * @return value changed//from ww w . j a v a 2 s . co m */ private static String replaceProperties(String value) { String changed = null; // if property starts with jem.data // I need to ask to DataPaths Container in which data path I can put the file if (value.startsWith("${" + ConfigKeys.JEM_DATA_PATH_NAME + "}")) { // takes the rest of file name String fileName = StringUtils.substringAfter(value, "${" + ConfigKeys.JEM_DATA_PATH_NAME + "}"); // checks all paths try { // gets datapaths PathsContainer paths = DataPathsContainer.getInstance().getPaths(fileName); // is relative! // creates a file with dataPath as parent, plus file name File file = new File(paths.getCurrent().getContent(), fileName); // the absolute name of the file is property value changed = file.getAbsolutePath(); } catch (InvalidDatasetNameException e) { throw new BuildException(e); } } else { // uses SB utilities to changed all properties changed = JobsProperties.getInstance().replacePlaceHolders(value); } return changed; }
From source file:org.pepstock.jem.springbatch.tasks.DataSetManager.java
/** * /*from w w w .jav a2 s . c o m*/ * @param ddImpl * @param ds * @return * @throws BuildException */ private static FileWrapper getFile(DataSet ds, String disposition) throws SpringBatchException { // gets the data path and checks // if dataset name starts String dataPath = DataPathsContainer.getInstance().getAbsoluteDataPath(ds.getName()); //checks if the Dsname is a absolute file name // if absolute path is equals return the file // otherwise checks datapath File file = null; String fileName = null; //checks if the Dsname is a absolute file name // if absolute path is equals return the file // otherwise checks datapath if (dataPath != null) { // if name is absolute // creates a new FILE object with full pathname file = new File(ds.getName()); // normalizes using UNIX rules fileName = FilenameUtils.normalize(file.getAbsolutePath(), true); // extract the short name, taking the string after dataPath fileName = StringUtils.substringAfter(fileName, dataPath); // removes the first / of the filename fileName = fileName.substring(1); // we must check if full is correct in disposition NEW (only for new allocation) if (Disposition.NEW.equalsIgnoreCase(disposition)) { try { // checks all paths PathsContainer paths = DataPathsContainer.getInstance().getPaths(fileName); // creates a file with dataPath as parent, plus file name file = new File(paths.getCurrent().getContent(), fileName); } catch (InvalidDatasetNameException e) { throw new SpringBatchException(e.getMessageInterface(), e, e.getObjects()); } } } else { // should be relative file = new File(ds.getName()); // normalizes the full path and checks again with the name // if equals means that is absolute because the previuos checks only if it's using the // data paths if (FilenameUtils.normalize(file.getAbsolutePath(), true).equalsIgnoreCase(ds.getName())) { // normalizes using UNIX rules fileName = FilenameUtils.normalize(file.getAbsolutePath(), true); } else { try { // checks all paths PathsContainer paths = DataPathsContainer.getInstance().getPaths(ds.getName()); // is relative! // creates a file with dataPath as parent, plus file name file = new File(paths.getCurrent().getContent(), ds.getName()); // if disposition is not in new allocation and the file with current path doesn't exists, // try to use the old path is exist if (!Disposition.NEW.equalsIgnoreCase(disposition) && !file.exists() && paths.getOld() != null) { file = new File(paths.getOld().getContent(), ds.getName()); } // normalizes using UNIX rules fileName = FilenameUtils.normalize(ds.getName(), true); } catch (InvalidDatasetNameException e) { throw new SpringBatchException(e.getMessageInterface(), e, e.getObjects()); } } } return new FileWrapper(file, fileName); }
From source file:org.pepstock.jem.springbatch.tasks.DataSource.java
/** * Replaces inside of property value system variables or properties loaded by Spring * @param value property value to change * @return value changed/*w w w.ja v a 2 s . c o m*/ */ private String replaceProperties(String value) { String changed = null; // if property starts with jem.data // I need to ask to DataPaths Container in which data path I can put the file if (value.startsWith("${" + ConfigKeys.JEM_DATA_PATH_NAME + "}")) { // takes the rest of file name String fileName = StringUtils.substringAfter(value, "${" + ConfigKeys.JEM_DATA_PATH_NAME + "}"); // checks all paths try { // gets datapaths PathsContainer paths = DataPathsContainer.getInstance().getPaths(fileName); // is relative! // creates a file with dataPath as parent, plus file name File file = new File(paths.getCurrent().getContent(), fileName); // the absolute name of the file is property value changed = file.getAbsolutePath(); } catch (InvalidDatasetNameException e) { throw new BuildException(e); } } else { // uses SB utilities to changed all properties changed = JobsProperties.getInstance().replacePlaceHolders(value); } return changed; }
From source file:org.pepstock.jem.springbatch.tasks.SpringBatchSecurityManager.java
@Override public void checkPermission(Permission perm) { // checks if someone add a security manager if (perm instanceof RuntimePermission && "setSecurityManager".equalsIgnoreCase(perm.getName())) { LogAppl.getInstance().emit(NodeMessage.JEMC274E); throw new SecurityException(NodeMessage.JEMC274E.toMessage().getMessage()); }/*from w w w . j a v a2 s .c o m*/ // this check is necessary to avoid that someone // set jem properties, accessing outside of GFS if (perm instanceof PropertyPermission && "write".equalsIgnoreCase(perm.getActions()) && perm.getName().startsWith("jem")) { LogAppl.getInstance().emit(NodeMessage.JEMC127E); throw new SecurityException(NodeMessage.JEMC127E.toMessage().getMessage()); } // checks is administrator. if true return. if (isAdministrator() || isInternalAction()) { return; } // checks the file access // calling the right method, in according // with the action of permission if (perm instanceof FilePermission) { if ("read".equalsIgnoreCase(perm.getActions())) { checkRead(perm.getName()); } else if ("write".equalsIgnoreCase(perm.getActions())) { checkWrite(perm.getName()); } else if ("delete".equalsIgnoreCase(perm.getActions())) { checkDelete(perm.getName()); } else { checkRead(perm.getName()); } } else if (perm instanceof SocketPermission) { // checks the RMI access. // checks to RMI is not allowed if you're not a admin SocketPermission sperm = (SocketPermission) perm; int port = Parser.parseInt(StringUtils.substringAfter(sperm.getName(), ":"), Integer.MAX_VALUE); int portRmi = Parser.parseInt(System.getProperty(RmiKeys.JEM_RMI_PORT), Integer.MIN_VALUE); // if is going to RMI port and // is not executing JEM code and is not grantor if (port == portRmi && !isInternalAction() && !isGrantor()) { // extracts host name String hostname = StringUtils.substringBefore(sperm.getName(), ":"); try { // gets hostname and localhost String resolved = InetAddress.getByName(hostname).getHostAddress(); String localhost = InetAddress.getLocalHost().getHostAddress(); // if they are equals and the user // desn't have the internal service permission // EXCEPTION!! if (resolved.equalsIgnoreCase(localhost) && !checkBatchPermission(Permissions.INTERNAL_SERVICES)) { LogAppl.getInstance().emit(NodeMessage.JEMC128E); throw new SecurityException(NodeMessage.JEMC128E.toMessage().getMessage()); } } catch (UnknownHostException e) { // if there is an error on resolving the hostname LogAppl.getInstance().emit(NodeMessage.JEMC128E); throw new SecurityException(NodeMessage.JEMC128E.toMessage().getMessage(), e); } } } }
From source file:org.phenotips.integration.lims247.internal.LimsSynchronizationEventListener.java
/** * Prepare a JSON payload to send to the registered LIMS servers to notify of the change. The JSON looks like: * * <pre>// w ww . ja va2s. co m * { * "eid": "ExternalId123", * "event": "update", // or "create" or "delete" * "pn": "wiki name", * "username": "uname", * "auth_token": "strtoken" * } * </pre> * * The username and authentication token is taken either from the cached LIMS authentication, or from the XWiki user * logged in. * * @param event the original event that notified of the change * @param doc the modified document, a patient sheet document * @param context the current request context * @return a JSON object */ private JSONObject getPayload(Event event, XWikiDocument doc, XWikiContext context) { JSONObject result = new JSONObject(); String eid = doc.getXObject(PATIENT_CLASS).getStringValue(EXTERNAL_ID_PROPERTY_NAME); result.put(IDENTIFIER_KEY, eid); if (event instanceof DocumentCreatedEvent) { result.put(EVENT_KEY, "create"); } else if (event instanceof DocumentUpdatedEvent) { result.put(EVENT_KEY, "update"); } else if (event instanceof DocumentDeletedEvent) { result.put(EVENT_KEY, "delete"); } LimsAuthentication auth = (LimsAuthentication) context.getRequest().getSession() .getAttribute(Lims247AuthServiceImpl.SESSION_KEY); if (auth != null) { // FIXME Reuse this authentication only if the authentication server is the same as the target server result.put(LimsServer.INSTANCE_IDENTIFIER_KEY, context.getDatabase()); result.put(LimsServer.USERNAME_KEY, StringUtils.substringAfter(auth.getUser().getUser(), ".")); result.put(LimsServer.TOKEN_KEY, auth.getToken()); } else if (context.getUserReference() != null) { result.put(LimsServer.INSTANCE_IDENTIFIER_KEY, context.getUserReference().getWikiReference().getName()); result.put(LimsServer.USERNAME_KEY, context.getUserReference().getName()); result.put(LimsServer.TOKEN_KEY, this.token.getToken()); } else { result.put(LimsServer.INSTANCE_IDENTIFIER_KEY, context.getDatabase()); result.put(LimsServer.USERNAME_KEY, ""); result.put(LimsServer.TOKEN_KEY, ""); } return result; }
From source file:org.phenotips.integration.lims247.script.PhenoTipsTokenAuthenticatorScriptService.java
/** * Check if the specified token is valid for the specified user. * * @param username the username whose authentication to check * @param token the token to check/*from www.j a v a 2 s . c o m*/ * @return {@code true} if the token is valid for the user, {@code false} otherwise */ public boolean isTokenValid(String username, String token) { XWikiContext context = (XWikiContext) this.execution.getContext() .getProperty(XWikiContext.EXECUTIONCONTEXT_KEY); // First check if the token is valid on LIMS LimsAuthentication limsAuth = (LimsAuthentication) context.getRequest().getSession() .getAttribute(Lims247AuthServiceImpl.SESSION_KEY); if (limsAuth != null && StringUtils.equals(limsAuth.getToken(), token) && StringUtils.equals(StringUtils.substringAfter(limsAuth.getUser().getUser(), "."), username)) { return true; } DocumentReference previousUserReference = context.getUserReference(); // Check if the token is valid in PhenoTips boolean result = false; try { DocumentReference ref = new DocumentReference(context.getDatabase(), "XWiki", username); context.setUserReference(ref); result = this.token.isTokenValid(token); if (!result) { ref = ref.replaceParent(ref.getWikiReference(), new WikiReference("xwiki")); context.setUserReference(ref); result = this.token.isTokenValid(token); } } finally { context.setUserReference(previousUserReference); } return result; }
From source file:org.phenotips.ontology.internal.solr.MendelianInheritanceInMan.java
@Override public OntologyTerm getTerm(String id) { OntologyTerm result = super.getTerm(id); if (result == null) { String optionalPrefix = STANDARD_NAME + ":"; if (StringUtils.startsWith(id, optionalPrefix)) { result = getTerm(StringUtils.substringAfter(id, optionalPrefix)); }//from w ww .jav a 2 s.c o m } return result; }
From source file:org.phenotips.oo.OmimSourceParser.java
private void loadField(String name, String value) { if (StringUtils.isAnyBlank(name, value)) { return;//from w w w . j av a2 s .c o m } switch (name) { case FIELD_MIM_NUMBER: this.crtTerm.addField(ID_FIELD, value); break; case FIELD_TITLE: String title = StringUtils.substringBefore(value, TITLE_SEPARATOR).trim(); String[] synonyms = StringUtils.split(StringUtils.substringAfter(value, TITLE_SEPARATOR), TITLE_SEPARATOR); this.crtTerm.addField(NAME_FIELD, title); for (String synonym : synonyms) { this.crtTerm.addField(SYNONYM_FIELD, synonym.trim()); } break; case FIELD_TEXT: this.crtTerm.addField("def", value); break; default: return; } }
From source file:org.phenotips.vocabulary.internal.GeneNomenclature.java
@Override public VocabularyTerm getTerm(String symbol) { if (StringUtils.isBlank(symbol)) { return null; }//w ww . j a v a 2 s. c om String escapedSymbol = ClientUtils.escapeQueryChars( StringUtils.contains(symbol, ":") ? StringUtils.substringAfter(symbol, ":") : symbol); VocabularyTerm result = getTermById(escapedSymbol); if (result != null) { return result; } result = getTermBySymbolOrAlias(escapedSymbol); if (result != null) { return result; } result = getTermByAlternativeId(escapedSymbol); return result; }
From source file:org.phenotips.vocabulary.internal.solr.AbstractOWLSolrVocabulary.java
/** * If the {@code id} stats with the optional prefix, removes the prefix and performs the search again. * * @param id the ID of the term of interest * @return the {@link VocabularyTerm} corresponding with the given ID, null if no such {@link VocabularyTerm} exists */// ww w .j ava 2s . co m private VocabularyTerm searchTermWithoutPrefix(@Nonnull final String id) { final String optPrefix = this.getTermPrefix() + SEPARATOR; return StringUtils.startsWith(id.toUpperCase(), optPrefix.toUpperCase()) ? getTerm(StringUtils.substringAfter(id, SEPARATOR)) : null; }