List of usage examples for org.apache.commons.lang ArrayUtils contains
public static boolean contains(boolean[] array, boolean valueToFind)
Checks if the value is in the given array.
From source file:ips1ap101.lib.core.web.app.GestorPaginaBasica.java
public void descartarFormulariosVirtuales() { track("descartarFormulariosVirtuales"); String virtualFormName;//from www .ja v a 2 s . com VirtualFormDescriptor descriptor; VirtualFormDescriptor[] descriptors; if (isRetruque()) { try { descriptors = getPaginaBasica().getForm1().getVirtualForms(); if (descriptors != null) { for (int i = 0; i < descriptors.length; i++) { descriptor = descriptors[i]; if (descriptor != null) { virtualFormName = descriptor.getName(); if (virtualFormName != null) { boolean contains = ArrayUtils.contains(discardableVirtualForms, virtualFormName); if (contains) { getPaginaBasica().getForm1().discardSubmittedValues(virtualFormName); } } } } } } catch (Exception ex) { handle(ex); } } }
From source file:com.flexive.shared.FxSharedUtils.java
/** * Splits the given text using separator. String literals are supported, e.g. * abc,def yields two elements, but 'abc,def' yields one (stringDelims = ['\''], separator = ','). * * @param text the text to be splitted * @param stringDelims delimiters for literal string values, usually ' and " * @param separator separator between tokens * @return split string/*from www . j av a2 s . co m*/ */ public static String[] splitLiterals(String text, char[] stringDelims, char separator) { if (text == null) { return new String[0]; } List<String> result = new ArrayList<String>(); Character currentStringDelim = null; int startIndex = 0; for (int i = 0; i < text.length(); i++) { char character = text.charAt(i); if (character == separator && currentStringDelim == null) { // not in string if (startIndex != -1) { result.add(text.substring(startIndex, i).trim()); } startIndex = i + 1; } else if (currentStringDelim != null && currentStringDelim == character) { // end string result.add(text.substring(startIndex, i).trim()); currentStringDelim = null; startIndex = -1; } else if (currentStringDelim != null) { // continue in string literal } else if (ArrayUtils.contains(stringDelims, character)) { // begin string literal currentStringDelim = character; // skip string delim startIndex = i + 1; } } if (startIndex != -1 && startIndex <= text.length()) { // add last parameter result.add(text.substring(startIndex, text.length()).trim()); } return result.toArray(new String[result.size()]); }
From source file:com.evolveum.polygon.connector.ldap.AbstractLdapConnector.java
protected void addAttributeModification(Dn dn, List<Modification> modifications, org.apache.directory.api.ldap.model.schema.ObjectClass ldapStructuralObjectClass, ObjectClass icfObjectClass, Attribute icfAttr, ModificationOperation modOp) { AbstractSchemaTranslator<C> schemaTranslator = getSchemaTranslator(); AttributeType attributeType = schemaTranslator.toLdapAttribute(ldapStructuralObjectClass, icfAttr.getName());/*from w ww .j ava2s. co m*/ if (attributeType == null && !configuration.isAllowUnknownAttributes() && !ArrayUtils.contains(configuration.getOperationalAttributes(), icfAttr.getName())) { throw new InvalidAttributeValueException( "Unknown attribute " + icfAttr.getName() + " in object class " + icfObjectClass); } List<Value<Object>> ldapValues = schemaTranslator.toLdapValues(attributeType, icfAttr.getValue()); if (ldapValues == null || ldapValues.isEmpty()) { // Do NOT set AttributeType here modifications.add(new DefaultModification(modOp, attributeType.getName())); } else { // Do NOT set AttributeType here modifications.add(new DefaultModification(modOp, attributeType.getName(), ldapValues.toArray(new Value[ldapValues.size()]))); } }
From source file:com.novartis.opensource.yada.test.ServiceTest.java
/** * Tests many aspects of {@code harmonyMap} or {@code h} YADA parameter results including * for CSV: column counts, header values, row counts, row/column content; and for JSON: * singular result set, correct mapped/unmapped keys and values, record count. * @param query the query to execute//from w w w .j a v a2s. c o m * @throws YADAQueryConfigurationException when request creation fails * @throws YADAResponseException when the test result is invalid */ @Test(enabled = true, dataProvider = "QueryTests", groups = { "options" }) @QueryFile(list = {}) public void testHarmonizer(String query) throws YADAQueryConfigurationException, YADAResponseException { String[] allKeys = { COL_INTEGER, COL_INTEGER_LC, COL_HM_INT, COL_NUMBER, COL_NUMBER_LC, COL_HM_FLOAT, COL_DATE, COL_DATE_LC, COL_HM_DATE, COL_TIME, COL_TIME_LC, COL_HM_TIME }; String[] intKeys = { COL_INTEGER, COL_INTEGER_LC, COL_HM_INT }; String[] floatKeys = { COL_NUMBER, COL_NUMBER_LC, COL_HM_FLOAT }; String[] dateKeys = { COL_DATE, COL_DATE_LC, COL_HM_DATE }; String[] timeKeys = { COL_TIME, COL_TIME_LC, COL_HM_TIME }; Service svc = prepareTest(query); YADARequest req = svc.getYADARequest(); req.setPageSize(new String[] { "-1" }); JSONArray spec = req.getHarmonyMap(); String result = svc.execute(); int qCount = StringUtils.countMatches(query, "qname") + StringUtils.countMatches(query, "q="); String line = null; int lineCount = 0; if (req.getFormat().equals(YADARequest.FORMAT_CSV)) { logStringResult(result); Pattern rx = Pattern.compile( "^(\"([A-Z,]+)\"),(\"([0-9]+)\")?,(\"([0-9.]+)\")?,?(\"(201[3-5]-0[0-9]-[0-9]{2}(\\s00:00:00)?|1362373200|1396584000)\")?,?(\"(201[3-5]-0[0-9]-[0-9]{2} ([0-9]{2}:){2}[0-9]{2}|1441500273000)(\\.0)?\")?$"); // count columns // check for correct values in mapped columns try (BufferedReader br = new BufferedReader(new StringReader(result))) { while ((line = br.readLine()) != null) { if (lineCount > 0) { Matcher m = rx.matcher(line); Assert.assertTrue(m.matches()); // first query only returns three columns if (lineCount < 9) { Assert.assertTrue(validateInteger(m.group(4))); // col 2 Assert.assertTrue(validateNumber(m.group(6))); // col 3 Assert.assertNull(m.group(8)); // col 4 Assert.assertNull(m.group(11)); // col 5 } else if (lineCount > 8 && lineCount < 17) // 2nd query { Assert.assertNull(m.group(4)); // col 2 Assert.assertNull(m.group(6)); // col 3 Assert.assertTrue(validateDate(m.group(8))); // col4 Assert.assertTrue(validateTime(m.group(11))); // col5 } else // 3rd query { Assert.assertNull(m.group(4)); // col 2 Assert.assertNull(m.group(6)); // col 3 Assert.assertNull(m.group(8)); // col 4 Assert.assertTrue(validateTime(m.group(11))); // col5 } } lineCount++; } } catch (IOException e) { throw new YADAResponseException("Result was unreadable.", e); } catch (ParseException e) { throw new YADAResponseException("Result was unparsable.", e); } //TODO confirm correct mapped/unmapped column headers // count rows Assert.assertEquals(lineCount - 1, qCount * 8); //TODO check for "empty values" in unmapped columns } else if (req.getFormat().equals(YADARequest.FORMAT_XML)) { //TODO harmony map xml validation logMarkupResult(result); } else if (req.getFormat().equals(YADARequest.FORMAT_HTML)) { logMarkupResult(result); Pattern rx = Pattern.compile( "^<tr>(<td>([A-Z,]+)</td>)(<td>([0-9]+)?</td>)(<td>([0-9.]+)?</td>)(<td>(201[3-5]-0[0-9]-[0-9]{2}(\\s00:00:00)?|1362373200|1396584000)?</td>)?(<td>((201[3-5]-0[0-9]-[0-9]{2} ([0-9]{2}:){2}[0-9]{2}|1441500273000)(\\.0)?)?</td>)?</tr>$"); Pattern end = Pattern.compile("^</tbody>|</table>|</body>|</html>$"); try (BufferedReader br = new BufferedReader(new StringReader(result))) { while ((line = br.readLine()) != null) { Matcher mEnd = end.matcher(line); if (lineCount > 9 && !mEnd.matches()) { Matcher m = rx.matcher(line); Assert.assertTrue(m.matches()); // first query only returns three columns if (lineCount < 18) { Assert.assertTrue(validateInteger(m.group(4))); // col 2 Assert.assertTrue(validateNumber(m.group(6))); // col 3 Assert.assertNull(m.group(8)); // col 4 Assert.assertNull(m.group(11)); // col 5 } else if (lineCount > 17 && lineCount < 26) // 2nd query { Assert.assertNull(m.group(4)); // col 2 Assert.assertNull(m.group(6)); // col 3 Assert.assertTrue(validateDate(m.group(8))); // col4 Assert.assertTrue(validateTime(m.group(11))); // col5 } else // 3rd query { Assert.assertNull(m.group(4)); // col 2 Assert.assertNull(m.group(6)); // col 3 Assert.assertNull(m.group(8)); // col 4 Assert.assertTrue(validateTime(m.group(11))); // col5 } } else { //TODO confirm correct mapped/unmapped column headers } lineCount++; } } catch (IOException e) { throw new YADAResponseException("Result was unreadable.", e); } catch (ParseException e) { throw new YADAResponseException("Result was unparsable.", e); } // count rows Assert.assertEquals(lineCount - 1, (qCount * 8) + 13); // adding 13 for non-data row html tags } else // JSON { JSONParamsEntry q; YADAParam p; qCount = 1; int resultCount = 8; if (YADAUtils.useJSONParams(req)) { JSONParams jp = req.getJsonParams(); String[] qnameKeys = jp.getKeys(); qCount = qnameKeys.length; for (String qname : qnameKeys) { q = jp.get(qname); p = q.getParam(YADARequest.PS_HARMONYMAP); if (null == spec) spec = new JSONArray(); if (null != p) spec.put(new JSONObject(p.getValue())); } } JSONObject jo = new JSONObject(result); logJSONResult(jo); // confirm singular result set Assert.assertNull(jo.optJSONObject(RESULTSETS)); Assert.assertTrue(jo.has(RESULTSET)); // // check record count int actualRecCount = jo.getJSONObject(RESULTSET).getInt(RECORDS); int expectRecCount = qCount * resultCount; Assert.assertEquals(actualRecCount, expectRecCount, "Result count invalid for query: " + query); // confirm correct mapped/unmapped keys JSONArray rows = jo.getJSONObject(RESULTSET).getJSONArray(ROWS); // For each query, find the hmap // test 8 records corresponding to query index // NOTE: This does not test for presence of unmapped keys, but does test all values for (int i = 0; i < rows.length() / 8; i++) // 1-3 sets of 8 { JSONObject currentSpec = new JSONObject(); // the hmap spec if (spec.length() == 1) currentSpec = spec.getJSONObject(0); // it's a global request param else { for (int j = spec.length() - 1; j >= 0; j--) { currentSpec = spec.getJSONObject(j); // it's an embedded param, and JSONArray returns in reverse order } } // Deconstruct spec into keys and vals String[] currentSpecKeys = new String[currentSpec.length()]; String[] currentSpecVals = new String[currentSpec.length()]; int j = 0; if (currentSpec.length() > 0) { for (String key : JSONObject.getNames(currentSpec)) { currentSpecKeys[j] = key; currentSpecVals[j] = currentSpec.getString(key); j++; } } // check results for (j = 0; j < resultCount; j++) // for each set of results { JSONObject row = rows.getJSONObject(j); // the "row" String[] rowKeys = JSONObject.getNames(row); for (String key : rowKeys) // iterate over the row keys { if (key.matches("[A-Z]+")) // upper case are spec vals Assert.assertTrue(ArrayUtils.contains(currentSpecVals, key)); // row key is in current spec vals else { Assert.assertFalse(ArrayUtils.contains(currentSpecVals, key)); // row key is not current spec vals Assert.assertFalse(ArrayUtils.contains(currentSpecKeys, key)); // row key is in current spec keys } } for (String col : allKeys) // confirm datatype of values { if (row.has(col)) { try { if (ArrayUtils.contains(intKeys, col)) Assert.assertTrue(validateInteger(row.getString(col))); else if (ArrayUtils.contains(floatKeys, col)) Assert.assertTrue(validateNumber(row.getString(col))); else if (ArrayUtils.contains(dateKeys, col)) Assert.assertTrue(validateDate(row.getString(col))); else if (ArrayUtils.contains(timeKeys, col)) Assert.assertTrue(validateTime(row.getString(col))); } catch (ParseException e) { String msg = "Unable to validate result."; throw new YADAResponseException(msg, e); } } } } } } }
From source file:com.flexive.shared.scripting.groovy.GroovyScriptExporterTools.java
/** * Checks if a given input String represents a Java or Groovy keyword * * @param input the input String// w ww.j a v a 2s . c om * @param doubleQuotes true = double quotes, false = single quotes * @return returns a quoted version of the same String if input == keyword */ private static String keyWordNameCheck(String input, boolean doubleQuotes) { if (ArrayUtils.contains(JAVA_KEYWORDS, input) || ArrayUtils.contains(GROOVY_KEYWORDS, input)) { if (doubleQuotes) return "\"" + input + "\""; return "'" + input + "'"; } return input; }
From source file:adalid.core.AbstractDataArtifact.java
private TemporalAddend temporalAddendValueOf(String string, char[] validUnits, char defaultUnit) { String chopped;/*from w w w. j a va 2 s .co m*/ String trimmed = StringUtils.trimToNull(string); if (trimmed == null) { return null; } int end = trimmed.length() - 1; char unit = trimmed.charAt(end); if (Character.isDigit(unit)) { chopped = trimmed; unit = defaultUnit; } else if (end > 0 && ArrayUtils.contains(validUnits, unit)) { chopped = trimmed.substring(0, end); } else { return null; } try { Integer number = Integer.valueOf(chopped); return new TemporalAddend(number, unit); } catch (Exception e) { return null; } }
From source file:com.belle.yitiansystem.merchant.service.impl.MerchantsService.java
/** * ?????/*from w ww . j av a2s.c o m*/ * * @author wang.m * @Date 2012-03-26 */ @Transactional public boolean addUserAuthority(String userid, String authority, SystemmgtUser systemmgtUser) throws Exception { boolean bool = false; try { if (StringUtils.isNotBlank(userid)) { String diffSql = "select group_concat(t2.authrity_name separator '?') from tbl_merchant_user_authority t1 inner join tbl_merchant_authority t2 on(t1.authority_id = t2.id) where t1.user_id = ?"; Object ownPermissions = JDBCUtils.getInstance().uniqueResult(diffSql, new Object[] { userid }); // ? deleteUserAuthorityByPramas(userid); if (StringUtils.isNotBlank(authority)) { // String sql = "insert into tbl_merchant_user_authority(id,user_id,authority_id,create_date,remark) values (?,?,?,?,?)"; String[] strAdd = authority.split(";"); if (strAdd.length > 0) { for (String string : strAdd) { Object[] obj = new Object[5]; // ?uuid String uuid = UUIDGenerator.getUUID(); obj[0] = uuid; obj[1] = userid; obj[2] = string; obj[3] = formDate(); obj[4] = ""; sqlService.updateObject(sql, obj); bool = true; } // ???????????? sql = "select t3.id, t3.authority_id from tbl_merchant_user t1 inner join tbl_merchant_user t2 on(t1.merchant_code = t2.merchant_code) inner join tbl_merchant_user_authority t3 on(t2.id = t3.user_id) where t1.id = ? and t2.is_administrator = ?"; List<Map<String, Object>> resultMaps = JDBCUtils.getInstance().listResultMap(sql, new Object[] { userid, NumberUtils.INTEGER_ZERO }); List<Object[]> sqlParams = new ArrayList<Object[]>(); for (Map<String, Object> resultMap : resultMaps) { if (!ArrayUtils.contains(strAdd, MapUtils.getString(resultMap, "authority_id"))) { sqlParams.add(new Object[] { MapUtils.getString(resultMap, "id") }); } } if (CollectionUtils.isNotEmpty(sqlParams)) { JDBCUtils.getInstance().executeBatch(new JDBCUtils.SQLBatch( "delete from tbl_merchant_user_authority where id = ?", sqlParams)); } } } Object finalPermissions = JDBCUtils.getInstance().uniqueResult(diffSql, new Object[] { userid }); if (!ObjectUtils.equals(ownPermissions, finalPermissions)) { MerchantUser merchantUser = merchantUserDaoImpl.getById(userid); /** ? Modifier by yang.mq **/ MerchantOperationLog operationLog = new MerchantOperationLog(); operationLog.setMerchantCode(merchantUser.getMerchantCode()); if (systemmgtUser != null) { operationLog.setOperator(systemmgtUser.getUsername()); } else { operationLog.setOperator("system"); } operationLog.setOperated(new Date()); operationLog.setOperationType(OperationType.ACCOUNT); operationLog.setOperationNotes(MessageFormat.format( "????{0}?{1}", ownPermissions, finalPermissions)); merchantOperationLogService.saveMerchantOperationLog(operationLog); } bool = true; } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); logger.error("?????!", e); bool = false; } return bool; }
From source file:com.vmware.identity.idm.server.IdentityManager.java
/** * A helper method that will check if requested authentication type is supported based on a provider (user belonging to) * @param requestedAuthnType authentication type to check if it is associated with provider * @param requestedProvider Name of identity source * @param tenantInfo tenant information//from w w w . j a v a2s . co m */ private void validateProviderAllowedAuthnTypes(int requestedAuthnType, String requestedProvider, TenantInformation tenantInfo) throws IDMLoginException { boolean authenticationAllowed = false; Collection<IIdentityStoreData> idsStores = tenantInfo.getIdsStores(); // All identity sources on tenant AuthnPolicy tenantAuthnPolicy = tenantInfo.getAuthnPolicy(); // Authentication policy on tenant IIdentityStoreData identitySource = null; // Retrieve information of requested identity source for (IIdentityStoreData identityStore : idsStores) { if (identityStore.getName().equalsIgnoreCase(requestedProvider)) { identitySource = identityStore; if (identitySource != null) { IIdentityStoreDataEx extendedData = identitySource.getExtendedIdentityStoreData(); if (extendedData.getAuthnTypes() != null) { int[] providerAuthnTypes = extendedData.getAuthnTypes(); if (ArrayUtils.contains(providerAuthnTypes, requestedAuthnType)) { authenticationAllowed = true; } if (!authenticationAllowed) { String errMessage = String.format( "Authentication type : '%s' is not allowed for requested identity provider : '%s'", requestedAuthnType, requestedProvider); throw new IDMLoginException(errMessage); } } } break; } } }
From source file:com.ah.ui.actions.home.HmServicesAction.java
public List<EventItem> getEventTypeList() { List<EventItem> eventTypeList = new ArrayList<EventItem>(); for (int i = 0; i < eventTypeArray.length; i++) { if (isFullMode()) { EventItem item = new EventItem(eventTypeArray[i][0], eventTypeArray[i][1]); if (ArrayUtils.contains(enabled_event, String.valueOf(i))) { item.setEnabled_event(true); }//from w w w. j a v a 2s.c o m eventTypeList.add(item); } else { if (!eventTypeArray[i][0].equals("Client Register")) { EventItem item = new EventItem(eventTypeArray[i][0], eventTypeArray[i][1]); if (ArrayUtils.contains(enabled_event, String.valueOf(i))) { item.setEnabled_event(true); } eventTypeList.add(item); } } } return eventTypeList; }
From source file:com.ah.ui.actions.home.HmServicesAction.java
public List<AlertItem> getAlertTypeList() { List<AlertItem> alertTypeList = new ArrayList<AlertItem>(); for (int i = 0; i < alertTypeArray.length; i++) { AlertItem item = new AlertItem(alertTypeArray[i][0], alertTypeArray[i][1]); if (ArrayUtils.contains(enabledCritical, String.valueOf(i))) { item.setEnabledCritical(true); }/* w w w . ja va2 s.c o m*/ if (ArrayUtils.contains(enabledMajor, String.valueOf(i))) { item.setEnabledMajor(true); } if (ArrayUtils.contains(enabledMinor, String.valueOf(i))) { item.setEnabledMinor(true); } if (ArrayUtils.contains(enabledInfo, String.valueOf(i))) { item.setEnabledInfo(true); } if (ArrayUtils.contains(enabledClear, String.valueOf(i))) { item.setEnabledClear(true); } alertTypeList.add(item); } return alertTypeList; }