List of usage examples for org.apache.commons.lang StringUtils substringAfter
public static String substringAfter(String str, String separator)
Gets the substring after the first occurrence of a separator.
From source file:edu.arizona.kra.kim.impl.identity.PersonServiceImpl.java
/** * @see org.kuali.rice.kim.api.identity.PersonService#resolvePrincipalNamesToPrincipalIds(org.kuali.rice.krad.bo.BusinessObject, java.util.Map) *//*from ww w . j av a 2 s .c om*/ @SuppressWarnings("unchecked") @Override public Map<String, String> resolvePrincipalNamesToPrincipalIds(BusinessObject businessObject, Map<String, String> fieldValues) { if (fieldValues == null) { return null; } if (businessObject == null) { return fieldValues; } StringBuffer resolvedPrincipalIdPropertyName = new StringBuffer(); // save off all criteria which are not references to Person properties // leave person properties out so they can be resolved and replaced by this method Map<String, String> processedFieldValues = getNonPersonSearchCriteria(businessObject, fieldValues); for (String propertyName : fieldValues.keySet()) { if (!StringUtils.isBlank(fieldValues.get(propertyName)) // property has a value && isPersonProperty(businessObject, propertyName) // is a property on a Person object ) { // strip off the prefix on the property String personPropertyName = ObjectUtils.getNestedAttributePrimitive(propertyName); // special case - the user ID if (StringUtils.equals(KIMPropertyConstants.Person.PRINCIPAL_NAME, personPropertyName)) { @SuppressWarnings("rawtypes") Class targetBusinessObjectClass = null; BusinessObject targetBusinessObject = null; resolvedPrincipalIdPropertyName.setLength(0); // clear the buffer without requiring a new object allocation on each iteration // get the property name up until the ".principalName" // this should be a reference to the Person object attached to the BusinessObject String personReferenceObjectPropertyName = ObjectUtils.getNestedAttributePrefix(propertyName); // check if the person was nested within another BO under the master BO. If so, go up one more level // otherwise, use the passed in BO class as the target class if (ObjectUtils.isNestedAttribute(personReferenceObjectPropertyName)) { String targetBusinessObjectPropertyName = ObjectUtils .getNestedAttributePrefix(personReferenceObjectPropertyName); targetBusinessObject = (BusinessObject) ObjectUtils.getPropertyValue(businessObject, targetBusinessObjectPropertyName); if (targetBusinessObject != null) { targetBusinessObjectClass = targetBusinessObject.getClass(); resolvedPrincipalIdPropertyName.append(targetBusinessObjectPropertyName).append("."); } else { LOG.error("Could not find target property '" + propertyName + "' in class " + businessObject.getClass().getName() + ". Property value was null."); } } else { // not a nested Person property targetBusinessObjectClass = businessObject.getClass(); targetBusinessObject = businessObject; } if (targetBusinessObjectClass != null) { // use the relationship metadata in the KNS to determine the property on the // host business object to put back into the map now that the principal ID // (the value stored in application tables) has been resolved String propName = ObjectUtils .getNestedAttributePrimitive(personReferenceObjectPropertyName); DataObjectRelationship rel = getBusinessObjectMetaDataService() .getBusinessObjectRelationship(targetBusinessObject, propName); if (rel != null) { String sourcePrimitivePropertyName = rel .getParentAttributeForChildAttribute(KIMPropertyConstants.Person.PRINCIPAL_ID); resolvedPrincipalIdPropertyName.append(sourcePrimitivePropertyName); // get the principal - for translation of the principalName to principalId String principalName = fieldValues.get(propertyName); Principal principal = getIdentityService().getPrincipalByPrincipalName(principalName); if (principal != null) { processedFieldValues.put(resolvedPrincipalIdPropertyName.toString(), principal.getPrincipalId()); } else { processedFieldValues.put(resolvedPrincipalIdPropertyName.toString(), null); try { // if the principalName is bad, then we need to clear out the Person object // and base principalId property // so that their values are no longer accidentally used or re-populate // the object ObjectUtils.setObjectProperty(targetBusinessObject, resolvedPrincipalIdPropertyName.toString(), null); ObjectUtils.setObjectProperty(targetBusinessObject, propName, null); ObjectUtils.setObjectProperty(targetBusinessObject, propName + ".principalName", principalName); } catch (Exception ex) { LOG.error( "Unable to blank out the person object after finding that the person with the given principalName does not exist.", ex); } } } else { LOG.error("Missing relationship for " + propName + " on " + targetBusinessObjectClass.getName()); } } else { // no target BO class - the code below probably will not work processedFieldValues.put(resolvedPrincipalIdPropertyName.toString(), null); } } // if the property does not seem to match the definition of a Person property but it // does end in principalName then... // this is to handle the case where the user ID is on an ADD line - a case excluded from isPersonProperty() } else if (propertyName.endsWith("." + KIMPropertyConstants.Person.PRINCIPAL_NAME)) { // if we're adding to a collection and we've got the principalName; let's populate universalUser String principalName = fieldValues.get(propertyName); if (StringUtils.isNotEmpty(principalName)) { String containerPropertyName = propertyName; if (containerPropertyName.startsWith(KRADConstants.MAINTENANCE_ADD_PREFIX)) { containerPropertyName = StringUtils.substringAfter(propertyName, KRADConstants.MAINTENANCE_ADD_PREFIX); } // get the class of the object that is referenced by the property name // if this is not true then there's a principalName collection or primitive attribute // directly on the BO on the add line, so we just ignore that since something is wrong here if (ObjectUtils.isNestedAttribute(containerPropertyName)) { // the first part of the property is the collection name String collectionName = StringUtils.substringBefore(containerPropertyName, "."); // what is the class held by that collection? // JHK: I don't like this. This assumes that this method is only used by the maintenance // document service. If that will always be the case, this method should be moved over there. Class<? extends BusinessObject> collectionBusinessObjectClass = getMaintenanceDocumentDictionaryService() .getCollectionBusinessObjectClass(getMaintenanceDocumentDictionaryService() .getDocumentTypeName(businessObject.getClass()), collectionName); if (collectionBusinessObjectClass != null) { // we are adding to a collection; get the relationships for that object; // is there one for personUniversalIdentifier? List<DataObjectRelationship> relationships = getBusinessObjectMetaDataService() .getBusinessObjectRelationships(collectionBusinessObjectClass); // JHK: this seems like a hack - looking at all relationships for a BO does not guarantee that we get the right one // JHK: why not inspect the objects like above? Is it the property path problems because of the .add. portion? for (DataObjectRelationship rel : relationships) { String parentAttribute = rel.getParentAttributeForChildAttribute( KIMPropertyConstants.Person.PRINCIPAL_ID); if (parentAttribute == null) { continue; } // there is a relationship for personUserIdentifier; use that to find the universal user processedFieldValues.remove(propertyName); String fieldPrefix = StringUtils .substringBeforeLast(StringUtils.substringBeforeLast(propertyName, "." + KIMPropertyConstants.Person.PRINCIPAL_NAME), "."); String relatedPrincipalIdPropertyName = fieldPrefix + "." + parentAttribute; // KR-683 Special handling for extension objects if (EXTENSION.equals(StringUtils.substringAfterLast(fieldPrefix, ".")) && EXTENSION.equals(StringUtils.substringBefore(parentAttribute, "."))) { relatedPrincipalIdPropertyName = fieldPrefix + "." + StringUtils.substringAfter(parentAttribute, "."); } String currRelatedPersonPrincipalId = processedFieldValues .get(relatedPrincipalIdPropertyName); if (StringUtils.isBlank(currRelatedPersonPrincipalId)) { Principal principal = getIdentityService() .getPrincipalByPrincipalName(principalName); if (principal != null) { processedFieldValues.put(relatedPrincipalIdPropertyName, principal.getPrincipalId()); } else { processedFieldValues.put(relatedPrincipalIdPropertyName, null); } } } // relationship loop } else { if (LOG.isDebugEnabled()) { LOG.debug( "Unable to determine class for collection referenced as part of property: " + containerPropertyName + " on " + businessObject.getClass().getName()); } } } else { if (LOG.isDebugEnabled()) { LOG.debug("Non-nested property ending with 'principalName': " + containerPropertyName + " on " + businessObject.getClass().getName()); } } } } } return processedFieldValues; }
From source file:com.healthcit.cacure.model.admin.GeneratedModuleDataDetail.java
/** * Static method which returns the specified part of a given questionCombination map key *///from www .j av a2 s . c o m public static String getMapKeyPart(String mapKey, int part) { if (part == MAP_KEY_FIRST_PART) return StringUtils.substringBefore(mapKey, MAP_KEY_SEPARATOR); else if (part == MAP_KEY_SECOND_PART) return StringUtils.substringAfter(mapKey, MAP_KEY_SEPARATOR); else return null; }
From source file:com.hangum.tadpole.importexport.core.dialogs.CsvToRDBImportDialog.java
private boolean loadObjectDiableStatements(String tableName) { try {/*from ww w . j av a 2 s.c o m*/ disableObjectResults.clear(); SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB); if (btnTrigger.getSelection()) { disableObjectResults = sqlClient.queryForList("triggerListInTable", tableName); //$NON-NLS-1$ } if (btnPk.getSelection()) { if (userDB.getDBDefine() == DBDefine.ALTIBASE_DEFAULT) { Map<String, String> parameters = new HashMap<String, String>(2); parameters.put("user_name", StringUtils.substringBefore(tableName, ".")); parameters.put("table_name", StringUtils.substringAfter(tableName, ".")); disableObjectResults = sqlClient.queryForList("primarykeyListInTable", parameters); } else { disableObjectResults = sqlClient.queryForList("primarykeyListInTable", tableName); //$NON-NLS-1$ } } return true; } catch (Exception e) { logger.error("loadObjectDiableStatements", e); //$NON-NLS-1$ //appendPreviewSQL("/* Disable Object not support or select. */"); return false; } }
From source file:com.haulmont.cuba.core.global.MetadataTools.java
/** * Return a collection of properties included into entity's name pattern (see {@link NamePattern}). * * @param metaClass entity metaclass/*from w w w.j a v a2 s . c om*/ * @param useOriginal if true, and if the given metaclass doesn't define a {@link NamePattern} and if it is an * extended entity, this method tries to find a name pattern in an original entity * @return collection of the name pattern properties */ @Nonnull public Collection<MetaProperty> getNamePatternProperties(MetaClass metaClass, boolean useOriginal) { Collection<MetaProperty> properties = new ArrayList<>(); String pattern = (String) getMetaAnnotationAttributes(metaClass.getAnnotations(), NamePattern.class) .get("value"); if (pattern == null && useOriginal) { MetaClass original = metadata.getExtendedEntities().getOriginalMetaClass(metaClass); if (original != null) { pattern = (String) getMetaAnnotationAttributes(original.getAnnotations(), NamePattern.class) .get("value"); } } if (!StringUtils.isBlank(pattern)) { String value = StringUtils.substringAfter(pattern, "|"); String[] fields = StringUtils.splitPreserveAllTokens(value, ","); for (String field : fields) { String fieldName = StringUtils.trim(field); MetaProperty property = metaClass.getProperty(fieldName); if (property != null) { properties.add(metaClass.getProperty(fieldName)); } else { throw new DevelopmentException( String.format("Property '%s' is not found in %s", field, metaClass.toString()), "NamePattern", pattern); } } } return properties; }
From source file:com.hangum.tadpole.importexport.core.dialogs.CsvToRDBImportDialog.java
private HashMap<String, Object> loadPrimaryKeyColumns(String tableName) { List<HashMap> showIndexColumns = null; HashMap<String, Object> result = new HashMap<String, Object>(); String columns = ""; //$NON-NLS-1$ try {//from w w w .j a v a2s . c o m SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB); if (userDB.getDBDefine() == DBDefine.ALTIBASE_DEFAULT) { Map<String, String> parameters = new HashMap<String, String>(2); parameters.put("user_name", StringUtils.substringBefore(tableName, ".")); parameters.put("table_name", StringUtils.substringAfter(tableName, ".")); showIndexColumns = sqlClient.queryForList("primarykeyListInTable", parameters); } else { showIndexColumns = sqlClient.queryForList("primarykeyListInTable", tableName); //$NON-NLS-1$ } for (HashMap dao : showIndexColumns) { if (userDB.getDBDefine() == DBDefine.SQLite_DEFAULT) { /* cid, name, type, notnull, dflt_value, pk */ if ("1".equals(dao.get("pk").toString())) { //$NON-NLS-1$ //$NON-NLS-2$ result.put(dao.get("name").toString(), (Integer) dao.get("cid") + 1); //$NON-NLS-1$ //$NON-NLS-2$ columns += dao.get("name").toString() + ","; //$NON-NLS-1$ //$NON-NLS-2$ } } else { result.put(dao.get("column_name").toString(), //$NON-NLS-1$ Integer.parseInt(dao.get("column_order").toString())); //$NON-NLS-1$ columns += dao.get("column_name").toString() + ","; //$NON-NLS-1$ //$NON-NLS-2$ } } } catch (Exception e) { logger.error("loadObjectDiableStatements", e); //$NON-NLS-1$ appendPreviewSQL("/* Disable Object not support or select. */"); //$NON-NLS-1$ } result.put("all_key_columns", StringUtils.split(columns, ",")); //$NON-NLS-1$ //$NON-NLS-2$ return result; }
From source file:com.abssh.util.GenericDao.java
/** * countHql.hql??select count(*)?//w ww .ja v a2s . c om * * <br/> * ???hql?,??hql?count?. */ protected long countHqlResult(final String hql, final Object... params) { String fromHql = hql; // select??order by???count,?. fromHql = "from " + StringUtils.substringAfter(fromHql, "from"); if (fromHql.indexOf("order by") > 0) { fromHql = StringUtils.substringBefore(fromHql, "order by"); } String countHql = "select count(*) " + fromHql; try { Long count = findUnique(countHql, params); return count; } catch (Exception e) { throw new RuntimeException("can't auto count,hql is:" + countHql, e); } }
From source file:com.abssh.util.GenericDao.java
/** * countHql.hql??select count(*)?//w w w . jav a 2s. co m * * ???hql?,??hql?count?. */ protected long countHqlResult(final String hql, final Map<String, Object> values) { String fromHql = hql; // select??order by???count,?. fromHql = "from " + StringUtils.substringAfter(fromHql, "from"); if (fromHql.indexOf("order by") > 0) { fromHql = StringUtils.substringBefore(fromHql, "order by"); } String countHql = "select count(*) " + fromHql; try { Long count = findUnique(countHql, values); return count; } catch (Exception e) { throw new RuntimeException("can't auto count,hql is:" + countHql, e); } }
From source file:com.abssh.util.GenericDao.java
/** * countSQL.hql??select count(*)?//w ww . ja va 2s.c om * * <br/> * ???sql?,??sql?count?. * * @author zhirong */ protected long countSqlResult(final String sql, final Object... params) { String fromSql = sql; // select??order by???count,?. fromSql = "from " + StringUtils.substringAfter(fromSql, "from"); if (fromSql.indexOf("order by") > 0) { fromSql = StringUtils.substringBefore(fromSql, "order by"); } String countSql = "select count(*) " + fromSql; try { Long count = null; Object obj = findUniqueSQL(countSql, params); if (obj instanceof BigInteger) { count = ((BigInteger) obj).longValue(); } else if (obj instanceof BigDecimal) { count = ((BigDecimal) obj).longValue(); } return count; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("can't auto count,sql is:" + countSql, e); } }
From source file:com.primovision.lutransport.core.util.TollCompanyTagUploadUtil.java
public static ByteArrayOutputStream createTollUploadErrorResponse(InputStream is, List<String> errors) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(is); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFFont font = wb.createFont();//from ww w. java 2s . c o m font.setColor(Font.COLOR_RED); font.setBoldweight(Font.BOLDWEIGHT_BOLD); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setFont(font); HSSFSheet sheet = wb.getSheetAt(0); Row row = sheet.getRow(0); int lastCell = row.getLastCellNum(); Cell cell = createExcelCell(sheet, row, lastCell, 256 * 100); cell.setCellStyle(cellStyle); cell.setCellValue("ERRORS"); for (String anError : errors) { String lineNoStr = StringUtils.substringBefore(anError, ":"); lineNoStr = StringUtils.substringAfter(lineNoStr, "Line "); Integer lineNo = new Integer(lineNoStr) - 1; row = sheet.getRow(lineNo); cell = createExcelCell(sheet, row, lastCell, 256 * 100); cell.setCellStyle(cellStyle); cell.setCellValue(anError); } return createOutputStream(wb); }
From source file:gobblin.util.HadoopUtils.java
/** * A thread safe variation of {@link #renamePath(FileSystem, Path, Path)} which can be used in * multi-threaded/multi-mapper environment. The rename operation always happens at file level hence directories are * not overwritten under the 'to' path.// w w w . j ava 2 s .c om * * <p> * If the contents of destination 'to' path is not expected to be modified concurrently, use * {@link #renamePath(FileSystem, Path, Path)} which is faster and more optimized * </p> * * <b>NOTE: This does not seem to be working for all {@link FileSystem} implementations. Use * {@link #renameRecursively(FileSystem, Path, Path)}</b> * * @param fileSystem on which the data needs to be moved * @param from path of the data to be moved * @param to path of the data to be moved * */ public static void safeRenameRecursively(FileSystem fileSystem, Path from, Path to) throws IOException { for (FileStatus fromFile : FileListUtils.listFilesRecursively(fileSystem, from)) { Path relativeFilePath = new Path( StringUtils.substringAfter(fromFile.getPath().toString(), from.toString() + Path.SEPARATOR)); Path toFilePath = new Path(to, relativeFilePath); if (!fileSystem.exists(toFilePath)) { boolean renamed = false; // underlying file open can fail with file not found error due to some race condition // when the parent directory is created in another thread, so retry a few times for (int i = 0; !renamed && i < MAX_RENAME_TRIES; i++) { try { renamed = fileSystem.rename(fromFile.getPath(), toFilePath); break; } catch (FileNotFoundException e) { if (i + 1 >= MAX_RENAME_TRIES) { throw e; } } } if (!renamed) { throw new IOException( String.format("Failed to rename %s to %s.", fromFile.getPath(), toFilePath)); } log.info(String.format("Renamed %s to %s", fromFile.getPath(), toFilePath)); } else { log.info(String.format("File already exists %s. Will not rewrite", toFilePath)); } } }