List of usage examples for org.apache.commons.collections CollectionUtils collect
public static Collection collect(Iterator inputIterator, Transformer transformer)
From source file:com.topsec.tsm.sim.report.model.ReportModel.java
@SuppressWarnings("unchecked") public static List<String> getDeviceTypeList(DataSourceService dataSourceService, SID sid) { if (GlobalUtil.isNullOrEmpty(sid)) { return null; }/* w w w . j av a2s .c om*/ Set<?> devices = GlobalUtil.isNullOrEmpty(sid.getUserDevice()) ? Collections.emptySet() : sid.getUserDevice(); List<String> dvcTypes = null; if (sid.isOperator()) { dvcTypes = dataSourceService.getDistinctDvcType(DataSourceService.CMD_ALL); } else { List<SimDatasource> simDatasources = dataSourceService.getDataSource(DataSourceService.CMD_ALL); dvcTypes = new ArrayList<String>(); BeanToPropertyValueTransformer trans = new BeanToPropertyValueTransformer("ip"); Collection<String> userDeviceIPs = (Collection<String>) CollectionUtils.collect(devices, trans); for (SimDatasource simDatasource : simDatasources) { Device device = AssetFacade.getInstance().getAssetByIp(simDatasource.getDeviceIp()); if (device != null && userDeviceIPs.contains(simDatasource.getDeviceIp())) { if (!dvcTypes.contains(simDatasource.getSecurityObjectType())) { dvcTypes.add(simDatasource.getSecurityObjectType()); } } } } if (!sid.hasAuditorRole() && dvcTypes.contains(LogKeyInfo.LOG_SYSTEM_TYPE)) { dvcTypes.remove(LogKeyInfo.LOG_SYSTEM_TYPE); } return dvcTypes; }
From source file:com.topsec.tsm.sim.report.model.ReportModel.java
@SuppressWarnings("unchecked") public static List<String> getDeviceIpList(DataSourceService dataSourceService, SID sid) { List<String> deviceIpList = null; if (sid == null) { return deviceIpList; }//from w w w . j av a 2s . co m Set<?> devices = GlobalUtil.isNullOrEmpty(sid.getUserDevice()) ? Collections.emptySet() : sid.getUserDevice(); List<SimDatasource> simDatasources = dataSourceService.getDataSource(DataSourceService.CMD_ALL); if (sid.hasOperatorRole()) { deviceIpList = new ArrayList<String>(); BeanToPropertyValueTransformer trans = new BeanToPropertyValueTransformer("ip"); Collection<String> userDeviceIPs = (Collection<String>) CollectionUtils.collect(devices, trans); for (SimDatasource simDatasource : simDatasources) { Device device = AssetFacade.getInstance().getAssetByIp(simDatasource.getDeviceIp()); if (device != null && userDeviceIPs.contains(simDatasource.getDeviceIp())) { if (!deviceIpList.contains(simDatasource.getDeviceIp())) { deviceIpList.add(simDatasource.getDeviceIp()); } } } } return deviceIpList; }
From source file:nl.strohalm.cyclos.controls.admins.mailPreferences.MailPreferencesAction.java
@Override protected void prepareForm(final ActionContext context) throws Exception { final HttpServletRequest request = context.getRequest(); final MailPreferencesForm form = context.getForm(); final Administrator admin = context.getElement(); AdminGroup group = admin.getAdminGroup(); group = getFetchService().fetch(group, AdminGroup.Relationships.VIEW_INFORMATION_OF, Group.Relationships.MESSAGE_CATEGORIES); // Find the initial groups this admin manages final List<MemberGroup> initialGroups = new ArrayList<MemberGroup>(); for (final MemberGroup memberGroup : getFetchService().fetch(group, AdminGroup.Relationships.MANAGES_GROUPS) .getManagesGroups()) {//ww w. j av a 2 s. c o m if (memberGroup.isInitialGroup()) { initialGroups.add(memberGroup); } } final TransferTypeQuery transferTypeQuery = new TransferTypeQuery(); transferTypeQuery.setFromOrToAccountTypes(group.getViewInformationOf()); final List<TransferType> transferTypes = transferTypeService.search(transferTypeQuery); for (final Iterator<TransferType> iterator = transferTypes.iterator(); iterator.hasNext();) { // Remove those transfer types which does not allow direct payment or self payment final TransferType tt = iterator.next(); final Context ttContext = tt.getContext(); if (!ttContext.isPayment() && !ttContext.isSelfPayment()) { iterator.remove(); } } final TransferTypeQuery newPendingPaymentsQuery = new TransferTypeQuery(); newPendingPaymentsQuery.setAuthorizable(true); final List<TransferType> newPendingPayments = transferTypeService.search(newPendingPaymentsQuery); List<GuaranteeType> guaranteeTypes = Collections.emptyList(); if (getPermissionService().checkPermission("systemGuaranteeTypes", "view")) { final GuaranteeTypeQuery guaranteeTypeQuery = new GuaranteeTypeQuery(); guaranteeTypeQuery.setEnabled(true); guaranteeTypes = guaranteeTypeService.search(guaranteeTypeQuery); } final List<MessageCategory> messageCategories = new ArrayList<MessageCategory>( group.getMessageCategories()); Collections.sort(messageCategories); AdminNotificationPreference notificationPreference = null; try { notificationPreference = preferenceService.load(admin, AdminNotificationPreference.Relationships.TRANSFER_TYPES, AdminNotificationPreference.Relationships.MESSAGE_CATEGORIES, AdminNotificationPreference.Relationships.MEMBER_ALERTS, AdminNotificationPreference.Relationships.SYSTEM_ALERTS); form.setAdminNotificationPreference("applicationErrors", notificationPreference.isApplicationErrors()); form.setAdminNotificationPreference("systemInvoices", notificationPreference.isSystemInvoices()); request.setAttribute("selectedTransferTypes", notificationPreference.getTransferTypes()); request.setAttribute("selectedNewPendingPayments", notificationPreference.getNewPendingPayments()); request.setAttribute("selectedGuaranteeTypes", notificationPreference.getGuaranteeTypes()); request.setAttribute("selectedMessageCategories", notificationPreference.getMessageCategories()); request.setAttribute("selectedNewMembers", notificationPreference.getNewMembers()); request.setAttribute("selectedSystemAlerts", CollectionUtils .collect(notificationPreference.getSystemAlerts(), AlertTypeTransformer.INSTANCE)); request.setAttribute("selectedMemberAlerts", CollectionUtils .collect(notificationPreference.getMemberAlerts(), AlertTypeTransformer.INSTANCE)); } catch (final EntityNotFoundException e) { // Ignore - no current preference } RequestHelper.storeEnum(request, MemberAlert.Alerts.class, "memberAlerts"); RequestHelper.storeEnum(request, SystemAlert.Alerts.class, "systemAlerts"); request.setAttribute("transferTypes", transferTypes); request.setAttribute("newPendingPayments", newPendingPayments); request.setAttribute("guaranteeTypes", guaranteeTypes); request.setAttribute("messageCategories", messageCategories); request.setAttribute("initialGroups", initialGroups); request.setAttribute("notificationPreference", notificationPreference); }
From source file:nl.surfnet.coin.api.ApiController.java
@SuppressWarnings("unchecked") private Group20Entry addLinkedSurfTeamGroupsForExternalGroups(String userId, Group20Entry group20Entry, List<Group20> listOfAllExternalGroups, List<GroupProvider> allGroupProviders) { List<String> grouperTeamIds = new ArrayList<String>(); Collection<String> identifiers = CollectionUtils.collect(listOfAllExternalGroups, new Transformer() { @Override/*from w w w .j av a 2 s .c o m*/ public Object transform(Object input) { return ((Group20) input).getId(); } }); List<TeamExternalGroup> externalGroupIdentifiers = teamExternalGroupDao .getByExternalGroupIdentifiers(identifiers); for (TeamExternalGroup teamExternalGroup : externalGroupIdentifiers) { grouperTeamIds.add(teamExternalGroup.getGrouperTeamId()); } if (!grouperTeamIds.isEmpty()) { Group20Entry linkedTeams = groupService.getGroups20ByIds(userId, grouperTeamIds.toArray(new String[grouperTeamIds.size()]), 0, 0); linkedTeams = groupProviderConfiguration.addUrnPartForGrouper(allGroupProviders, linkedTeams); group20Entry.getEntry().addAll(linkedTeams.getEntry()); // remove duplicates: convert to set and back. group20Entry.setEntry(new ArrayList<Group20>(new HashSet<Group20>(group20Entry.getEntry()))); } return group20Entry; }
From source file:nl.surfnet.coin.api.service.PersonServiceImpl.java
@SuppressWarnings("unchecked") @Override/*from w ww .j a v a 2 s . c o m*/ public GroupMembersEntry getGroupMembers(String groupId, String onBehalfOf, String spEntityId, Integer count, Integer startIndex, String sortBy) { /* * first get all members from grouper. Note that we don't support sortBy but * we do support count and startIndex. See * https://jira.surfconext.nl/jira/browse/BACKLOG-438 */ GroupMembersEntry entry = apiGrouperDao.findAllMembers(groupId, startIndex, count); List<Person> persons = entry.getEntry(); if (!CollectionUtils.isEmpty(persons)) { Collection<String> identifiers = CollectionUtils.collect(persons, new Transformer() { @Override public Object transform(Object input) { return ((Person) input).getId(); } }); // Now enrich the information List<Person> enrichedPersons = ldapClient.findPersons(identifiers); for (Person person : enrichedPersons) { person.setVoot_membership_role(getVootMembersShip(person.getId(), persons)); } // Apply ARP ARP arp = clientDetailsService.getArp(spEntityId); LOG.debug("ARP for SP {} is: {}", spEntityId, arp); List<Person> arpEnforcedPersons = enforceArp(spEntityId, enrichedPersons); entry.setEntry(arpEnforcedPersons); } return entry; }
From source file:nl.surfnet.coin.janus.JanusRestClient.java
/** * {@inheritDoc}/* ww w. j a v a 2 s .c o m*/ */ @Override public EntityMetadata getMetadataByEntityId(String entityId) { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("entityid", entityId); final Collection metadataAsStrings = CollectionUtils.collect(Arrays.asList(Metadata.values()), new Transformer() { @Override public Object transform(Object input) { return ((Metadata) input).val(); } }); parameters.put("keys", StringUtils.join(metadataAsStrings, ',')); URI signedUri; try { signedUri = sign("getMetadata", parameters); if (LOG.isTraceEnabled()) { LOG.trace("Signed Janus-request is: {}", signedUri); } @SuppressWarnings("unchecked") final Map<String, Object> restResponse = restTemplate.getForObject(signedUri, Map.class); Assert.notNull(restResponse, "Rest response from Janus should not be null"); if (LOG.isTraceEnabled()) { LOG.trace("Janus-request returned: {}", restResponse.toString()); } final EntityMetadata entityMetadata = EntityMetadata.fromMetadataMap(restResponse); entityMetadata.setAppEntityId(entityId); return entityMetadata; } catch (IOException e) { LOG.error("While doing Janus-request", e); } return null; }
From source file:nl.surfnet.coin.janus.JanusRestClient.java
@Override public List<EntityMetadata> getSpList() { Map<String, String> parameters = new HashMap<String, String>(); final Collection metadataAsStrings = CollectionUtils.collect(Arrays.asList(Metadata.values()), new Transformer() { @Override//from www . j a va 2 s. c o m public Object transform(Object input) { return ((Metadata) input).val(); } }); parameters.put("keys", StringUtils.join(metadataAsStrings, ',')); URI signedUri; try { signedUri = sign("getSpList", parameters); if (LOG.isTraceEnabled()) { LOG.trace("Signed Janus-request is: {}", signedUri); } @SuppressWarnings("unchecked") final Map<String, Map<String, Object>> restResponse = restTemplate.getForObject(signedUri, Map.class); if (LOG.isTraceEnabled()) { LOG.trace("Janus-request returned: {}", restResponse.toString()); } List<EntityMetadata> entities = new ArrayList<EntityMetadata>(); for (Map.Entry<String, Map<String, Object>> entry : restResponse.entrySet()) { String entityId = entry.getKey(); final EntityMetadata e = EntityMetadata.fromMetadataMap(entry.getValue()); e.setAppEntityId(entityId); entities.add(e); } return entities; } catch (IOException e) { LOG.error("While doing Janus-request", e); } return null; }
From source file:nl.surfnet.coin.janus.JanusRestClient.java
@Override public List<EntityMetadata> getIdpList() { Map<String, String> parameters = new HashMap<String, String>(); final Collection metadataAsStrings = CollectionUtils.collect(Arrays.asList(Metadata.values()), new Transformer() { @Override/* w w w . jav a 2s . c om*/ public Object transform(Object input) { return ((Metadata) input).val(); } }); parameters.put("keys", StringUtils.join(metadataAsStrings, ',')); URI signedUri; try { signedUri = sign("getIdpList", parameters); if (LOG.isTraceEnabled()) { LOG.trace("Signed Janus-request is: {}", signedUri); } @SuppressWarnings("unchecked") final Map<String, Map<String, Object>> restResponse = restTemplate.getForObject(signedUri, Map.class); if (LOG.isTraceEnabled()) { LOG.trace("Janus-request returned: {}", restResponse.toString()); } List<EntityMetadata> entities = new ArrayList<EntityMetadata>(); for (Map.Entry<String, Map<String, Object>> entry : restResponse.entrySet()) { String entityId = entry.getKey(); final EntityMetadata e = EntityMetadata.fromMetadataMap(entry.getValue()); e.setAppEntityId(entityId); entities.add(e); } return entities; } catch (IOException e) { LOG.error("While doing Janus-request", e); } return null; }
From source file:nl.surfnet.coin.teams.service.impl.ApiGrouperDaoImpl.java
@SuppressWarnings("unchecked") private void addPersonRolesToGroup(Collection<Person> persons, String groupId) { try {//w w w . java 2 s .co m RolesMembersRowCallbackHandler handler = new RolesMembersRowCallbackHandler(); Collection<String> personIds = CollectionUtils.collect(persons, new Transformer() { @Override public Object transform(Object input) { return ((Person) input).getId(); } }); Map<String, Object> params = new HashMap<String, Object>(); params.put("groupId", groupId); params.put("identifiers", personIds); namedParameterJdbcTemplate.query(SQL_ROLES_BY_TEAM_AND_MEMBERS, params, handler); for (Person person : persons) { Role role = handler.roles.get(person.getId()); role = (role == null ? Role.Member : role); person.setVoot_membership_role(role.name().toLowerCase()); } } catch (EmptyResultDataAccessException e) { // this we can ignore } }
From source file:org.andromda.cartridges.gui.metafacades.GuiUseCaseLogicImpl.java
/** * @return navigationChildren// w ww . j av a 2 s .c o m * @see org.andromda.cartridges.gui.metafacades.GuiUseCase#getNavigationChildren() */ @Override protected Collection<UseCaseFacade> handleGetNavigationChildren() { return CollectionUtils.collect(this.getIncludes(), new Transformer() { @Override public Object transform(final Object object) { final IncludeFacade include = (IncludeFacade) object; return include.getAddition(); } }); }