List of usage examples for org.apache.commons.collections KeyValue getKey
Object getKey();
From source file:gsn.beans.VSensorConfig.java
/** * Note that the key and value both are trimmed before being inserted into * the data strcture./*from www. j a va 2 s .c o m*/ * * @return */ public TreeMap<String, String> getMainClassInitialParams() { if (!this.isGetMainClassInitParamsInitialized) { this.isGetMainClassInitParamsInitialized = true; for (final KeyValue param : this.mainClassInitialParams) { this.mainClassInitParams.put(param.getKey().toString().toLowerCase(), param.getValue().toString()); } } return this.mainClassInitParams; }
From source file:gsn.beans.VSensorConfig.java
public String toString() { final StringBuilder builder = new StringBuilder("Input Stream ["); for (final InputStream inputStream : this.getInputStreams()) { builder.append("Input-Stream-Name").append(inputStream.getInputStreamName()); builder.append("Input-Stream-Query").append(inputStream.getQuery()); builder.append(" Stream-Sources ( "); if (inputStream.getSources() == null) builder.append("null"); else/*from w w w . j ava 2 s . c om*/ for (final StreamSource ss : inputStream.getSources()) { builder.append("Stream-Source Alias : ").append(ss.getAlias()); for (final AddressBean addressing : ss.getAddressing()) { builder.append("Stream-Source-wrapper >").append(addressing.getWrapper()) .append("< with addressign predicates : "); for (final KeyValue keyValue : addressing.getPredicates()) builder.append("Key=").append(keyValue.getKey()).append("Value=") .append(keyValue.getValue()); } builder.append(" , "); } builder.append(")"); } builder.append("]"); return "VSensorConfig{" + "name='" + this.name + '\'' + ", priority=" + this.priority + ", mainClass='" + this.mainClass + '\'' + ", description='" + this.description + '\'' + ", outputStreamRate=" + this.outputStreamRate + ", addressing=" + this.addressing + ", outputStructure=" + this.outputStructure + ", storageHistorySize='" + this.storageHistorySize + '\'' + builder.toString() + ", mainClassInitialParams=" + this.mainClassInitialParams + ", lastModified=" + this.lastModified + ", fileName='" + this.fileName + '\'' + ", logger=" + this.logger + ", nameInitialized=" + this.nameInitialized + ", isStorageCountBased=" + this.isStorageCountBased + ", parsedStorageSize=" + this.parsedStorageSize + '}'; }
From source file:gsn.http.restapi.RequestHandler.java
private Map<String, String> createHeaderMap(VSensorConfig vsconf) { Map<String, String> metadata = new LinkedHashMap<String, String>(); //vs name/*from w ww.j av a 2 s. c om*/ metadata.put(stringConstantsProperties.getProperty("VS_NAME"), vsconf.getName()); //is_public String is_public_res = "IS_PUBLIC_TRUE"; if (Main.getContainerConfig().isAcEnabled() && DataSource.isVSManaged(vsconf.getName())) is_public_res = "IS_PUBLIC_FALSE"; metadata.put(stringConstantsProperties.getProperty("IS_PUBLIC"), stringConstantsProperties.getProperty(is_public_res)); //predicates for (KeyValue df : vsconf.getAddressing()) { metadata.put(df.getKey().toString().toLowerCase().trim(), df.getValue().toString().trim()); } //description metadata.put(stringConstantsProperties.getProperty("DESCRIPTION"), vsconf.getDescription()); return metadata; }
From source file:gsn.webservice.standard.GSNWebServiceSkeleton.java
/** * Auto generated method signature// w w w. j a v a 2s.c om * * @param getVirtualSensorsDetails */ public gsn.webservice.standard.GetVirtualSensorsDetailsResponse getVirtualSensorsDetails( gsn.webservice.standard.GetVirtualSensorsDetails getVirtualSensorsDetails) { //throw new java.lang.UnsupportedOperationException("Please implement " + this.getClass().getName() + "#getVirtualSensorsDetails"); // User user = getUserForAC(getVirtualSensorsDetails.getAcDetails()); // GetVirtualSensorsDetailsResponse response = new GetVirtualSensorsDetailsResponse(); // // HashMap<String, ArrayList<String>> vsAndFields = buildSelection( getVirtualSensorsDetails.getFieldSelector()); for (Map.Entry<String, ArrayList<String>> selection : vsAndFields.entrySet()) { if (!Main.getContainerConfig().isAcEnabled() || (user != null && (user.hasReadAccessRight(selection.getKey()) || user.isAdmin()))) { VSensorConfig config = Mappings.getConfig(selection.getKey()); if (config != null) { GSNWebService_VirtualSensorDetails details = new GSNWebService_VirtualSensorDetails(); details.setVsname(selection.getKey()); for (GSNWebService_DetailsType detail : getVirtualSensorsDetails.getDetailsType()) { if ("INFO".equals(detail.getValue())) { GSNWebService_ConfInfo info = new GSNWebService_ConfInfo(); info.setDescription(config.getDescription()); details.setInfo(info); } else if ("PROCESSOR".equals(detail.getValue())) { GSNWebService_ConfProcessor processor = new GSNWebService_ConfProcessor(); processor.setClassName(config.getProcessingClass()); for (Map.Entry<String, String> entry : config.getMainClassInitialParams().entrySet()) { GSNWebService_ConfPredicate predicate = new GSNWebService_ConfPredicate(); predicate.setName(entry.getKey().toString()); predicate.setString(entry.getValue().toString()); processor.addInitParams(predicate); } details.setProcessor(processor); } else if ("ADDRESSING".equals(detail.getValue())) { GSNWebService_ConfAddressing addressing = new GSNWebService_ConfAddressing(); for (KeyValue kv : config.getAddressing()) { GSNWebService_ConfPredicate predicate = new GSNWebService_ConfPredicate(); predicate.setName(kv.getKey().toString()); predicate.setString(kv.getValue().toString()); addressing.addPredicates(predicate); } details.setAddressing(addressing); } else if ("OUTPUTSTRUCTURE".equals(detail.getValue())) { GSNWebService_ConfOutputStructure outputstructure = new GSNWebService_ConfOutputStructure(); for (DataField df : config.getOutputStructure()) { GSNWebService_DataField dataField = new GSNWebService_DataField(); if (df.getDescription() != null) dataField.setDescription(df.getDescription()); if (df.getName() != null) dataField.setName(df.getName()); if (df.getType() != null) dataField.setType(df.getType()); dataField.setString(""); outputstructure.addFields(dataField); } details.setOutputStructure(outputstructure); } else if ("WRAPPER".equals(detail.getValue())) { GSNWebService_ConfWrapper wrapperConf = new GSNWebService_ConfWrapper(); for (gsn.beans.InputStream inputStream : config.getInputStreams()) { for (gsn.beans.StreamSource source : inputStream.getSources()) { AddressBean ab = source.getActiveAddressBean(); // GSNWebService_WrapperDetails wd = new GSNWebService_WrapperDetails(); // GSNWebService_WrapperURL wrapperURL = new GSNWebService_WrapperURL(); wrapperURL.setVirtualSensor(config.getName()); wrapperURL.setStream(inputStream.getInputStreamName()); wrapperURL.setSource(source.getAlias().toString()); wrapperURL.setWrapper(source.getActiveAddressBean().getWrapper()); wd.setWrapperURLs(wrapperURL); // for (KeyValue kv : ab.getPredicates()) { GSNWebService_ConfPredicate predicate = new GSNWebService_ConfPredicate(); predicate.setName(kv.getKey().toString()); predicate.setString(kv.getValue().toString()); wd.addPredicates(predicate); } // for (DataField df : source.getWrapper().getOutputFormat()) { GSNWebService_DataField dataField = new GSNWebService_DataField(); if (df.getDescription() != null) dataField.setDescription(df.getDescription()); if (df.getName() != null) dataField.setName(df.getName()); if (df.getType() != null) dataField.setType(df.getType()); dataField.setString(""); wd.addOutputFormat(dataField); } wrapperConf.addWrapperDetails(wd); } } details.setWrapper(wrapperConf); } } response.addVirtualSensorDetails(details); } } } // // return response; }
From source file:org.jahia.modules.tagcloud.taglibs.TagCloudTag.java
/** * Generates the tag cloud associated with the specified bound component, including only tags with a cardinality above the specified minimum cardinality for inclusion, up to * the specified maximum number of tags. * * @param boundComponent the component for which we want to generate a tag cloud. * @param minimumCardinalityForInclusion minimum cardinality (i.e. number of tagged elements) for a tag to be included in the tag cloud * @param maxNumberOfTags maximum number of tags included in the cloud, keeping most numerous tags first (i.e. tags with lower cardinality will be excluded from * the cloud first) * @param currentQuery the currently applied facet query * @param renderContext the {@link org.jahia.services.render.RenderContext} in which this tag cloud is being generated * @throws RepositoryException if something went wrong accessing the JCR repository while processing the bound component's tags *//* w w w.j a v a 2 s . c o m*/ public void generateTagCloud(JCRNodeWrapper boundComponent, int minimumCardinalityForInclusion, int maxNumberOfTags, String currentQuery, RenderContext renderContext) throws RepositoryException { // applied facets final Map<String, List<KeyValue>> appliedFacets = Functions.getAppliedFacetFilters(currentQuery); // query QueryResultWrapper filteredTags = getNodesWithFacets(boundComponent, minimumCardinalityForInclusion, maxNumberOfTags, appliedFacets); if (!filteredTags.isFacetResultsEmpty()) { // map recording which unapplied tags have which cardinality, sorted in reverse cardinality order (most numerous tags first, being more important) final NavigableMap<Integer, Set<Tag>> tagCounts = new TreeMap<Integer, Set<Tag>>(); // applied tags facets final List<KeyValue> appliedTagsValues = appliedFacets.get(Constants.TAGS); // list of applied tags List<Tag> appliedTagsList = Collections.emptyList(); if (appliedTagsValues != null) { appliedTagsList = new ArrayList<Tag>(appliedTagsValues.size()); } // action URL start final String facetURLParameterName = getFacetURLParameterName(boundComponent.getName()); final String url = renderContext.getURLGenerator().getMainResource(); final String actionURLStart = url + "?" + facetURLParameterName + "="; // process the query results final FacetField tags = filteredTags.getFacetField(Constants.TAGS); final List<FacetField.Count> values = tags.getValues(); int totalCardinality = 0; for (FacetField.Count value : values) { // facet query should only return tags with a cardinality greater than the one we specified final int count = (int) value.getCount(); // facets return value of the j:tags property which is a weak reference to a node so we need to load it to get its name final String tagUUID = value.getName(); final JCRNodeWrapper tagNode = boundComponent.getSession().getNodeByUUID(tagUUID); final String name = tagNode.getDisplayableName(); // create tag final Tag tag = new Tag(name, count, tagUUID, value); if (!Functions.isFacetValueApplied(value, appliedFacets)) { // only add tag to cloud if it's not applied // increase totalCardinality with the current tag's count, this is used to compute the tag's weight in the cloud totalCardinality += count; // add tag to tag counts Set<Tag> associatedTags = tagCounts.get(count); if (associatedTags == null) { associatedTags = new HashSet<Tag>(); tagCounts.put(count, associatedTags); } associatedTags.add(tag); } else { // get KeyValue for current tag KeyValue current = null; for (KeyValue tagsValue : appliedTagsValues) { if (tagUUID.equals(tagsValue.getKey())) { current = tagsValue; break; } } tag.setDeleteActionURL( getActionURL(actionURLStart, Functions.getDeleteFacetUrl(current, currentQuery))); appliedTagsList.add(tag); } } Tag.setTotalCardinality(totalCardinality); // extract only the maxNumberOfTags most numerous tags final Map<String, Tag> tagCloud = new LinkedHashMap<String, Tag>(maxNumberOfTags); boolean stop = false; for (Set<Tag> tags1 : tagCounts.descendingMap().values()) { if (stop) { break; } for (Tag tag : tags1) { if (tagCloud.size() < maxNumberOfTags) { String result = getActionURL(actionURLStart, Functions.getFacetDrillDownUrl(tag.getFacetValue(), currentQuery)); tag.setActionURL(result); tagCloud.put(tag.getName(), tag); } else { stop = true; break; } } } // put cloud and applied tags in their respective page context variables pageContext.setAttribute(cloudVar, tagCloud, PageContext.REQUEST_SCOPE); pageContext.setAttribute(appliedTags, appliedTagsList, PageContext.REQUEST_SCOPE); } }
From source file:org.jahia.taglibs.facet.Functions.java
/** * Check whether a facet value is currently applied to the query * * @param facetValueObj the facet value object to check (either FacetField.Count or Map.Entry<String, Long>) * @param appliedFacets variable retrieved from {@link Functions#getAppliedFacetFilters(String)} * @return true if facet value is applied otherwise false *//*from w ww . ja v a 2 s. co m*/ public static boolean isFacetValueApplied(Object facetValueObj, Map<String, List<KeyValue>> appliedFacets) { boolean facetValueApplied = false; if (facetValueObj != null) { String facetKey = null; String facetValue = null; try { if (facetValueObj instanceof FacetField.Count) { FacetField.Count facetCount = (FacetField.Count) facetValueObj; facetKey = facetCount.getFacetField().getName(); facetValue = facetCount.getName(); } else if (facetValueObj instanceof RangeFacet.Count) { RangeFacet.Count facetCount = (RangeFacet.Count) facetValueObj; facetKey = facetCount.getRangeFacet().getName(); facetValue = facetCount.getValue().toString(); } else if (facetValueObj instanceof Map.Entry<?, ?>) { @SuppressWarnings("unchecked") Map.Entry<String, Long> facetCount = (Map.Entry<String, Long>) facetValueObj; facetKey = facetCount.getKey(); facetValue = facetCount.getValue().toString(); } else { throw new IllegalArgumentException("Passed parameter is not of a valid facet value type"); } } catch (ClassCastException e) { throw new IllegalArgumentException("Passed parameter is not of a valid facet value type", e); } if (appliedFacets != null && appliedFacets.containsKey(facetKey)) { for (KeyValue facet : appliedFacets.get(facetKey)) { if (facet.getKey().equals(facetValue)) { facetValueApplied = true; break; } } } } return facetValueApplied; }
From source file:org.obiba.onyx.quartz.editor.locale.LocaleProperties.java
public KeyValue getKeyValue(IQuestionnaireElement element, Locale locale, final String key) { ListMultimap<Locale, KeyValue> labels = getElementLabels(element); if (labels != null) { List<KeyValue> keyValueList = labels.get(locale); if (keyValueList != null) { try { return Iterables.find(keyValueList, new Predicate<KeyValue>() { @Override/*from ww w . ja va 2 s. c o m*/ public boolean apply(@Nullable KeyValue keyValue) { return keyValue != null && StringUtils.equals(keyValue.getKey(), key); } }); } catch (NoSuchElementException e) { // do nothing } } } return null; }
From source file:org.obiba.onyx.quartz.editor.locale.LocaleProperties.java
public void removeValue(IQuestionnaireElement element, final String key) { for (Locale locale : getLocales()) { ListMultimap<Locale, KeyValue> labels = getElementLabels(element); if (labels != null) { List<KeyValue> keyValueList = labels.get(locale); if (keyValueList != null && !keyValueList.isEmpty()) { Iterables.removeIf(keyValueList, new Predicate<KeyValue>() { @Override/*ww w . j a v a 2 s . co m*/ public boolean apply(@Nullable KeyValue keyValue) { return keyValue != null && StringUtils.equals(keyValue.getKey(), key); } }); } } } }
From source file:org.obiba.onyx.quartz.editor.locale.LocaleProperties.java
public void removeValue(IQuestionnaireElement element, Locale locale, final String key) { ListMultimap<Locale, KeyValue> labels = getElementLabels(element); if (labels != null) { List<KeyValue> keyValueList = labels.get(locale); if (keyValueList != null && !keyValueList.isEmpty()) { Iterables.removeIf(keyValueList, new Predicate<KeyValue>() { @Override/*w w w . ja v a 2s . com*/ public boolean apply(@Nullable KeyValue keyValue) { return keyValue != null && StringUtils.equals(keyValue.getKey(), key); } }); } } }
From source file:org.obiba.onyx.quartz.editor.locale.LocaleProperties.java
private Map<Locale, Properties> toLocalePropertiesMap(Questionnaire questionnaire) { Map<Locale, Properties> mapLocaleProperties = new HashMap<Locale, Properties>(); for (Locale locale : getLocales()) { Properties properties = new Properties(); for (Map.Entry<IQuestionnaireElement, ListMultimap<Locale, KeyValue>> entry : getElementLabels() .entrySet()) {//www. j a va 2 s .c o m IQuestionnaireElement element = entry.getKey(); List<KeyValue> keyValueList = entry.getValue().get(locale); for (KeyValue keyValue : keyValueList) { String fullKey = questionnaire.getPropertyKeyProvider().getPropertyKey(element, keyValue.getKey()); String value = keyValue.getValue(); properties.setProperty(fullKey, value != null ? value.replaceAll("\n", "<br/>") : ""); } } mapLocaleProperties.put(locale, properties); } return mapLocaleProperties; }