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:com.smartmarmot.orabbix.Configurator.java
public DBConn[] rebuildDBList(DBConn[] _dbc) { try {/*from w ww . j a v a2 s. co m*/ verifyConfig(); String[] localdblist = this.getDBList(); String[] remotedblist = new String[_dbc.length]; for (int i = 0; i < _dbc.length; i++) { remotedblist[i] = _dbc[i].getName(); } Collection<DBConn> connections = new ArrayList<DBConn>(); for (int j = 0; j < localdblist.length; j++) { if (ArrayUtils.contains(remotedblist, localdblist[j])) { DBConn tmpDBConn; tmpDBConn = _dbc[ArrayUtils.indexOf(remotedblist, localdblist[j])]; connections.add(tmpDBConn); } if (!ArrayUtils.contains(remotedblist, localdblist[j])) { /* * adding database */ SmartLogger.logThis(Level.INFO, "New database founded! " + localdblist[j]); DBConn tmpDBConn = this.getConnection(localdblist[j]); if (tmpDBConn != null) { connections.add(tmpDBConn); } } } for (int x = 0; x < _dbc.length; x++) { if (!ArrayUtils.contains(localdblist, _dbc[x].getName())) { SmartLogger.logThis(Level.WARN, "Database " + _dbc[x].getName() + " removed from configuration file"); /** * removing database */ // _dbc[x].closeAll(); _dbc[x].getSPDS().close(); SmartLogger.logThis(Level.WARN, "Database " + _dbc[x].getName() + " conections closed"); _dbc[x] = null; } } DBConn[] connArray = (DBConn[]) connections.toArray(new DBConn[0]); return connArray; } catch (Exception ex) { SmartLogger.logThis(Level.ERROR, "Error on Configurator while retriving the databases list " + Constants.DATABASES_LIST + " error:" + ex); return _dbc; } }
From source file:net.sf.json.xml.XMLSerializer.java
private Element processJSONObject(JSONObject jsonObject, Element root, String[] expandableProperties, boolean isRoot) { if (jsonObject.isNullObject()) { root.addAttribute(new Attribute(addJsonPrefix("null"), "true")); return root; } else if (jsonObject.isEmpty()) { return root; }//w w w .j a v a2s. c o m if (isRoot) { if (!rootNamespace.isEmpty()) { setNamespaceLenient(true); for (Iterator entries = rootNamespace.entrySet().iterator(); entries.hasNext();) { Map.Entry entry = (Map.Entry) entries.next(); String prefix = (String) entry.getKey(); String uri = (String) entry.getValue(); if (StringUtils.isBlank(prefix)) { root.setNamespaceURI(uri); } else { root.addNamespaceDeclaration(prefix, uri); } } } } addNameSpaceToElement(root); Object[] names = jsonObject.names().toArray(); List unprocessed = new ArrayList(); for (int i = 0; i < names.length; i++) { String name = (String) names[i]; Object value = jsonObject.get(name); if (name.startsWith("@xmlns")) { setNamespaceLenient(true); int colon = name.indexOf(':'); if (colon == -1) { // do not override if already defined by nameSpaceMaps if (StringUtils.isBlank(root.getNamespaceURI())) { root.setNamespaceURI(String.valueOf(value)); } } else { String prefix = name.substring(colon + 1); if (StringUtils.isBlank(root.getNamespaceURI(prefix))) { root.addNamespaceDeclaration(prefix, String.valueOf(value)); } } } else { unprocessed.add(name); } } Element element = null; for (int i = 0; i < unprocessed.size(); i++) { String name = (String) unprocessed.get(i); Object value = jsonObject.get(name); if (name.startsWith("@")) { int colon = name.indexOf(':'); if (colon == -1) { root.addAttribute(new Attribute(name.substring(1), String.valueOf(value))); } else { String prefix = name.substring(1, colon); final String namespaceURI = root.getNamespaceURI(prefix); root.addAttribute(new Attribute(name.substring(1), namespaceURI, String.valueOf(value))); } } else if (name.equals("#text")) { if (value instanceof JSONArray) { root.appendChild(((JSONArray) value).join("", true)); } else { root.appendChild(String.valueOf(value)); } } else if (value instanceof JSONArray && (((JSONArray) value).isExpandElements() || ArrayUtils.contains(expandableProperties, name) || (isPerformAutoExpansion && canAutoExpand((JSONArray) value)))) { JSONArray array = (JSONArray) value; int l = array.size(); for (int j = 0; j < l; j++) { Object item = array.get(j); element = newElement(name); root.appendChild(element); if (item instanceof JSONObject) { element = processJSONValue((JSONObject) item, root, element, expandableProperties); } else if (item instanceof JSONArray) { element = processJSONValue((JSONArray) item, root, element, expandableProperties); } else { element = processJSONValue(item, root, element, expandableProperties); } addNameSpaceToElement(element); } } else { element = newElement(name); root.appendChild(element); element = processJSONValue(value, root, element, expandableProperties); addNameSpaceToElement(element); } } return root; }
From source file:gov.nih.nci.cabig.caaers.rules.business.service.CaaersRulesEngineService.java
/** * Will clean the ruleset retrieved from authoring service, by removing elements like * a. StudySDO/*from ww w. j ava2 s .c om*/ * b. OrganizationSDO * c. FactResolver * d. EvaluationResult. * @param ruleSet */ public void cleanRuleSet(RuleSet ruleSet) { if (ruleSet == null || ruleSet.getRule() == null || ruleSet.getRule().size() <= 0) return; for (Rule rule : ruleSet.getRule()) { List<Column> toRemove = new ArrayList<Column>(); for (Column c : rule.getCondition().getColumn()) { if (ArrayUtils.contains(columnsToTrash, c.getIdentifier())) toRemove.add(c); } rule.getCondition().getColumn().removeAll(toRemove); } }
From source file:net.firejack.platform.core.cache.CacheProcessor.java
@Override public void deleteUserRole(Long userId, Long roleId) { if (userId != null && roleId != null) { UserSessionManager userSessionManager = UserSessionManager.getInstance(); boolean deleted = false; CacheManager cacheManager = CacheManager.getInstance(); //check whether role is contextual and if yes then update contextual roles cache data Map<Long, SecuredRecordPermissions> userContextRolePermissions = cacheManager .getAllSecuredRecordPermissions(); for (SecuredRecordPermissions securedRecordPermissions : userContextRolePermissions.values()) { UserContextPermissions userRolePermissions = securedRecordPermissions.getUserContextPermissions() .get(userId);// ww w. j a v a2 s . c o m if (userRolePermissions != null) { ContextPermissions removedContextPermissions = userRolePermissions.removeContextRole(roleId); if (removedContextPermissions != null) { Map<String, IdFilter> userIdFilters = cacheManager.getIdFiltersForUser(userId); if (userIdFilters != null) { boolean updated = false; for (UserPermission permission : removedContextPermissions.userPermissionsSnapshot()) { if (ActionDetectorFactory.isReadPermission(permission)) { String entityType = ActionDetectorFactory.getReadPermissionType(permission); IdFilter idFilter = userIdFilters.get(entityType); if (idFilter != null) { Long entityId = Long.valueOf(permission.getEntityId()); if (ArrayUtils.contains(idFilter.getGrantedIdList(), entityId)) { List<Long> grantedIdList = new ArrayList<Long>( Arrays.asList(idFilter.getGrantedIdList())); grantedIdList.remove(entityId); idFilter.setGrantedIdList( grantedIdList.toArray(new Long[grantedIdList.size()])); updated = true; } } } } if (updated) { cacheManager.setIdFiltersForUser(userId, userIdFilters); } } userSessionManager.refreshUserContextRolePermissions(userId, getUserPermissionsBySecuredRecords(userId)); deleted = true; } } } if (!deleted) {//if role was not found among contextual roles then remove usual role userSessionManager.removeUsualUserRole(userId, roleId, this); Map<Long, List<Long>> rolesByUser = cacheManager.getUserRoles(); List<Long> userRoles = rolesByUser.get(userId); if (userRoles != null) { userRoles.remove(roleId); cacheManager.setUserRoles(rolesByUser); } } } }
From source file:jef.tools.StringUtils.java
/** * ???/*ww w. j a v a 2 s . com*/ * * @return */ public static Substring subLeftWithChar(String ss, char[] chars) { int n = ss.length(); for (int i = 0; i < ss.length(); i++) { char c = ss.charAt(i); if (!ArrayUtils.contains(chars, c)) { n = i; break; } } return new Substring(ss, 0, n); }
From source file:jef.tools.StringUtils.java
/** * ?????//from w ww . ja va 2 s .c o m * * @return */ public static Substring subRightWithChar(String ss, char[] chars) { int n = 0; for (int i = ss.length() - 1; i >= 0; i--) { char c = ss.charAt(i); if (!ArrayUtils.contains(chars, c)) { n = i + 1; break; } } return new Substring(ss, n, ss.length()); }
From source file:net.firejack.platform.core.cache.CacheProcessor.java
@Override public void deleteContextUserRoles(Map<Long, Collection<ContextPermissions>> userRoles) { if (userRoles != null && !userRoles.isEmpty()) { UserSessionManager userSessionManager = UserSessionManager.getInstance(); CacheManager cacheManager = CacheManager.getInstance(); //check whether role is contextual and if yes then update contextual roles cache data Map<Long, SecuredRecordPermissions> userContextRolePermissions = cacheManager .getAllSecuredRecordPermissions(); for (Map.Entry<Long, Collection<ContextPermissions>> userRoleEntry : userRoles.entrySet()) { Long userId = userRoleEntry.getKey(); for (SecuredRecordPermissions securedRecordPermissions : userContextRolePermissions.values()) { UserContextPermissions userRolePermissions = securedRecordPermissions .getUserContextPermissions().get(userId); if (userRolePermissions != null) { Collection<ContextPermissions> roles = userRoleEntry.getValue(); if (roles != null) { for (ContextPermissions role : roles) { ContextPermissions removedContextPermissions = userRolePermissions .removeContextRole(role); if (removedContextPermissions != null) { Map<String, IdFilter> userIdFilters = cacheManager.getIdFiltersForUser(userId); if (userIdFilters != null) { boolean updated = false; for (UserPermission permission : removedContextPermissions .userPermissionsSnapshot()) { if (ActionDetectorFactory.isReadPermission(permission)) { String entityType = ActionDetectorFactory .getReadPermissionType(permission); IdFilter idFilter = userIdFilters.get(entityType); if (idFilter != null) { Long entityId = Long.valueOf(permission.getEntityId()); if (ArrayUtils.contains(idFilter.getGrantedIdList(), entityId)) { List<Long> grantedIdList = new ArrayList<Long>( Arrays.asList(idFilter.getGrantedIdList())); grantedIdList.remove(entityId); idFilter.setGrantedIdList(grantedIdList .toArray(new Long[grantedIdList.size()])); updated = true; } } } }/*from w ww . j ava 2 s .c om*/ if (updated) { cacheManager.setIdFiltersForUser(userId, userIdFilters); } } userSessionManager.refreshUserContextRolePermissions(userId, getUserPermissionsBySecuredRecords(userId)); } } } } } } } }
From source file:com.flexive.ejb.beans.AccountEngineBean.java
/** * {@inheritDoc}//from w ww . jav a 2 s . co m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void setRoles(long accountId, long... roles) throws FxApplicationException { if (roles == null) roles = new long[0]; final Account account = load(accountId); if (!_checkPermissions(account)[MAY_SET_ROLES]) throw new FxNoAccessException("ex.account.roles.noAssignPermission", accountId); // Write roles to database Connection con = null; PreparedStatement ps = null; StringBuilder sbHistory = new StringBuilder(1000); try { roles = FxArrayUtils.removeDuplicates(roles); con = Database.getDbConnection(); UserTicket ticket = FxContext.getUserTicket(); List<Role> orgRoles = getRoles(accountId, RoleLoadMode.FROM_USER_ONLY); sbHistory.append("<original>\n"); for (Role org : orgRoles) sbHistory.append(" <role id=\"").append(org.getId()).append("\">").append(org.getName()) .append("</role>\n"); sbHistory.append("</original>\n"); //only allow to assign roles which the calling user is a member of (unless it is a global supervisor) if (!ticket.isGlobalSupervisor() && !(ticket.isMandatorSupervisor() && account.getMandatorId() == ticket.getMandatorId())) { final List<Long> orgRoleIds = FxSharedUtils.getSelectableObjectIdList(orgRoles); //check removed roles for (long check : orgRoleIds) { if (!ArrayUtils.contains(roles, check)) { if (!ticket.isInRole(Role.getById(check))) { EJBUtils.rollback(ctx); throw new FxNoAccessException("ex.account.roles.assign.noMember.remove", Role.getById(check).getName()); } } } //check added roles for (long check : roles) { if (!orgRoleIds.contains(check)) { if (!ticket.isInRole(Role.getById(check))) { EJBUtils.rollback(ctx); throw new FxNoAccessException("ex.account.roles.assign.noMember.add", Role.getById(check).getName()); } } } } // Delete the old assignments of the user ps = con.prepareStatement("DELETE FROM " + TBL_ROLE_MAPPING + " WHERE ACCOUNT=?"); ps.setLong(1, accountId); ps.executeUpdate(); if (roles.length > 0) { ps.close(); ps = con.prepareStatement( "INSERT INTO " + TBL_ROLE_MAPPING + " (ACCOUNT,USERGROUP,ROLE) VALUES (?,?,?)"); } sbHistory.append("<new>\n"); // Store the new assignments of the account for (long role : roles) { if (Role.isUndefined(role)) continue; ps.setLong(1, accountId); ps.setLong(2, UserGroup.GROUP_NULL); ps.setLong(3, role); ps.executeUpdate(); sbHistory.append(" <role id=\"").append(role).append("\">").append(Role.getById(role).getName()) .append("</role>\n"); } sbHistory.append("</new>\n"); LifeCycleInfoImpl.updateLifeCycleInfo(TBL_ACCOUNTS, "ID", accountId); // Ensure any active ticket of the updated account are refreshed UserTicketStore.flagDirtyHavingUserId(accountId); EJBLookup.getHistoryTrackerEngine().trackData(sbHistory.toString(), "history.account.setRoles", account.getLoginName()); } catch (SQLException exc) { EJBUtils.rollback(ctx); throw new FxUpdateException(LOG, exc, "ex.account.roles.updateFailed.sql", accountId, exc.getMessage()); } finally { Database.closeObjects(AccountEngineBean.class, con, ps); } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.visio.informationflow.VisioInformationFlowExport.java
/** * @param edgeProps// ww w .j ava2 s. co m * @param noDirectionBOs * @param secondToFirstBOs * @param firstToSecondBOs * @param bidirectionalBOs * @param iface * * @return the edge count */ private int calculateEdgeCount(Map<String, String> edgeProps, InformationSystemInterface iface, List<String> bidirectionalBOs, List<String> firstToSecondBOs, List<String> secondToFirstBOs, List<String> noDirectionBOs) { List<Direction> directions = Lists.newArrayList(); List<String> transportsLabels = Lists.newArrayList(); if (ArrayUtils.contains(lineCaptionSelected, InformationFlowOptionsBean.LINE_DESCR_BUSINESS_OBJECTS)) { addTransportLabelAndDirection(transportsLabels, directions, bidirectionalBOs, Direction.BOTH_DIRECTIONS); addTransportLabelAndDirection(transportsLabels, directions, noDirectionBOs, Direction.NO_DIRECTION); addTransportLabelAndDirection(transportsLabels, directions, firstToSecondBOs, Direction.FIRST_TO_SECOND); addTransportLabelAndDirection(transportsLabels, directions, secondToFirstBOs, Direction.SECOND_TO_FIRST); if (transportsLabels.isEmpty() && directions.isEmpty()) { transportsLabels.add(""); directions.add(Direction.NO_DIRECTION); } } else { transportsLabels.add(""); directions.add(iface.getInterfaceDirection()); } int edgeCount = transportsLabels.size(); List<String> commonTransportLabels = determineCommonLabels(iface); // add edges for (int i = 0; i < edgeCount; i++) { List<String> allEdgeLabels = Lists.newArrayList(commonTransportLabels); allEdgeLabels.add(transportsLabels.get(i)); allEdgeLabels.removeAll(Lists.newArrayList("")); edgeProps.put(PROP_FLOW_INFORMATION_OBJECTS, StringUtils.join(allEdgeLabels, "; ")); addEdgeWithDirection(iface, directions.get(i), edgeProps); } return edgeCount; }
From source file:gtu._work.ui.DirectoryCompareUI.java
private JTextField getSearchText() { if (searchText == null) { searchText = new JTextField(); ToolTipManager.sharedInstance().setInitialDelay(0); searchText.setToolTipText(// w w w. j a v a 2 s. c o m ": date >= 20140829, ?: size < 1mb, ??: name *= action, path *= WEB-INF [:" + SEARCHTEXTPATTERN.pattern() + "]"); searchText.setPreferredSize(new java.awt.Dimension(222, 24)); searchText.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { System.out.println("KeyEvent.getKeyCode = " + evt.getKeyCode()); int[] keyCodeIgnore = new int[] { 38, 40, 37, 39, 8, 17, 18, 16 }; if (!ArrayUtils.contains(keyCodeIgnore, evt.getKeyCode())) { totalScanFiles(evt); } } }); } return searchText; }