List of usage examples for java.util Map containsValue
boolean containsValue(Object value);
From source file:org.kitodo.dataeditor.ruleset.RulesetManagementIT.java
/** * This test verifies that the labels for divisions are translated * correctly. For this purpose, various cases with different language * requirements (existing, nonexistent and overspecified) are performed. *//* w w w . j av a 2 s.c om*/ @Test public void testDivisionsAreCorrectlyTranslated() throws IOException { RulesetManagement underTest = new RulesetManagement(); underTest.load(new File("src/test/resources/testDivisionsAreCorrectlyTranslated.xml")); assertTrue(underTest.getAcquisitionStages().isEmpty()); // Here we test the translation, whether the expected language always // comes. Map<String, String> divisionsNoLanguage = underTest.getStructuralElements(Collections.emptyList()); assertEquals(1, divisionsNoLanguage.entrySet().size()); assertTrue(divisionsNoLanguage.containsKey(BOOK)); assertTrue(divisionsNoLanguage.containsValue(StringUtils.capitalize(BOOK))); Map<String, String> divisionsDe = underTest .getStructuralElements(LanguageRange.parse("de;q=1.0,cn;q=0.75,fr;q=0.5,ru;q=0.25")); assertEquals(1, divisionsDe.entrySet().size()); assertTrue(divisionsDe.containsKey(BOOK)); assertTrue(divisionsDe.containsValue("Buch")); Map<String, String> divisionsDeDe = underTest .getStructuralElements(LanguageRange.parse("de-DE;q=1.0,cn;q=0.75,fr;q=0.5,ru;q=0.25")); assertEquals(1, divisionsDeDe.entrySet().size()); assertTrue(divisionsDeDe.containsKey(BOOK)); assertTrue(divisionsDeDe.containsValue("Buch")); Map<String, String> divisionsEn = underTest .getStructuralElements(LanguageRange.parse("en;q=1.0,fr;q=0.75,de;q=0.5,cn;q=0.25")); assertEquals(1, divisionsEn.entrySet().size()); assertTrue(divisionsEn.containsKey(BOOK)); assertTrue(divisionsEn.containsValue(StringUtils.capitalize(BOOK))); Map<String, String> divisionsEnUs = underTest .getStructuralElements(LanguageRange.parse("en-US;q=1.0,de;q=0.667,fr;q=0.333")); assertEquals(1, divisionsEnUs.entrySet().size()); assertTrue(divisionsEnUs.containsKey(BOOK)); assertTrue(divisionsEnUs.containsValue(StringUtils.capitalize(BOOK))); Map<String, String> divisionsCnRu = underTest .getStructuralElements(LanguageRange.parse("cn;q=1.0,ru;q=0.5")); assertEquals(1, divisionsCnRu.entrySet().size()); assertTrue(divisionsCnRu.containsKey(BOOK)); assertTrue(divisionsCnRu.containsValue(StringUtils.capitalize(BOOK))); // Now a first view on a book StructuralElementViewInterface view = underTest.getStructuralElementView(BOOK, "", ENGL); assertEquals(1, view.getAllowedSubstructuralElements().entrySet().size()); assertEquals(5, view.getAddableMetadata(Collections.emptyMap(), Collections.emptyList()).size()); assertTrue(view.isComplex()); assertFalse(view.isUndefined()); // Now a nonsense view StructuralElementViewInterface nonsenseView = underTest.getStructuralElementView("bosh", "", ENGL); assertEquals(1, nonsenseView.getAllowedSubstructuralElements().entrySet().size()); assertEquals(5, nonsenseView.getAddableMetadata(Collections.emptyMap(), Collections.emptyList()).size()); assertTrue(nonsenseView.isUndefined()); }
From source file:org.apache.solr.core.SolrResourceLoader.java
/** * Register any {@link org.apache.solr.core.SolrInfoMBean}s * @param infoRegistry The Info Registry *//*from w ww . j a v a2 s.c o m*/ public void inform(Map<String, SolrInfoMBean> infoRegistry) { // this can currently happen concurrently with requests starting and lazy components // loading. Make sure infoMBeans doesn't change. SolrInfoMBean[] arr; synchronized (infoMBeans) { arr = infoMBeans.toArray(new SolrInfoMBean[infoMBeans.size()]); waitingForResources.clear(); } for (SolrInfoMBean bean : arr) { // Too slow? I suspect not, but we may need // to start tracking this in a Set. if (!infoRegistry.containsValue(bean)) { try { infoRegistry.put(bean.getName(), bean); } catch (Exception e) { log.warn("could not register MBean '" + bean.getName() + "'.", e); } } } }
From source file:com.google.dart.engine.services.internal.correction.CorrectionUtils.java
/** * @return the {@link ImportElement} used to import given {@link Element} into {@link #library}. * May be {@code null} if was not imported, i.e. declared in the same library. *///from ww w .j a va 2 s .c o m private ImportElement getImportElement(Element element) { for (ImportElement imp : library.getImports()) { Map<String, Element> definedNames = getImportNamespace(imp); if (definedNames.containsValue(element)) { return imp; } } return null; }
From source file:org.apache.airavata.workflow.model.wf.Workflow.java
/** * @return The set of WSDLs//from ww w .java 2 s.co m */ public Map<String, WsdlDefinitions> getWSDLs() { Map<String, WsdlDefinitions> wsdls = new LinkedHashMap<String, WsdlDefinitions>(); Map<WsdlDefinitions, String> ids = new HashMap<WsdlDefinitions, String>(); // Use LinkedHashMap to preserve the order of WSDLs, which is useful for // some unit tests. for (WSNode node : GraphUtil.getNodes(this.graph, WSNode.class)) { WsdlDefinitions wsdl = node.getComponent().getWSDL(); if (wsdls.containsValue(wsdl)) { String id = ids.get(wsdl); node.setWSDLID(id); } else { // Assign unique key String name = WSDLUtil.getWSDLName(wsdl); String id = StringUtil.convertToJavaIdentifier(name); while (wsdls.containsKey(id)) { id = StringUtil.incrementName(id); } wsdls.put(id, wsdl); ids.put(wsdl, id); node.setWSDLID(id); } } return wsdls; }
From source file:com.linkedin.pinot.integration.tests.BaseClusterIntegrationTest.java
protected CountDownLatch setupSegmentCountCountDownLatch(final String tableName, final int expectedSegmentCount) throws Exception { final CountDownLatch latch = new CountDownLatch(1); HelixManager manager = HelixManagerFactory.getZKHelixManager(getHelixClusterName(), "test_instance", InstanceType.SPECTATOR, ZkStarter.DEFAULT_ZK_STR); manager.connect();//from w w w. j av a 2 s. c om manager.addExternalViewChangeListener(new ExternalViewChangeListener() { private boolean _hasBeenTriggered = false; @Override public void onExternalViewChange(List<ExternalView> externalViewList, NotificationContext changeContext) { // Nothing to do? if (_hasBeenTriggered) { return; } for (ExternalView externalView : externalViewList) { if (externalView.getId().contains(tableName)) { Set<String> partitionSet = externalView.getPartitionSet(); if (partitionSet.size() == expectedSegmentCount) { int onlinePartitionCount = 0; for (String partitionId : partitionSet) { Map<String, String> partitionStateMap = externalView.getStateMap(partitionId); if (partitionStateMap.containsValue("ONLINE")) { onlinePartitionCount++; } } if (onlinePartitionCount == expectedSegmentCount) { System.out.println("Got " + expectedSegmentCount + " online tables, unlatching the main thread"); latch.countDown(); _hasBeenTriggered = true; } } } } } }); return latch; }
From source file:org.apereo.portal.portlets.portletadmin.PortletAdministrationHelper.java
/** * Persist a new or edited PortletDefinition from a form, replacing existing values. * * @param publisher {@code IPerson} that requires permission to save this definition * @param form form data to persist * @return new {@code PortletDefinitionForm} for this portlet ID *///from w w w. j a va2 s. c o m public PortletDefinitionForm savePortletRegistration(IPerson publisher, PortletDefinitionForm form) throws Exception { /* TODO: Service-Layer Security Reboot (great need of refactoring with a community-approved plan in place) */ // User must have the selected lifecycle permission over AT LEAST ONE // category in which this portlet resides. (This is the same check that // is made when the user enters the lifecycle-selection step in the wizard.) if (!hasLifecyclePermission(publisher, form.getLifecycleState(), form.getCategories())) { logger.warn("User '" + publisher.getUserName() + "' attempted to save the following portlet without the selected MANAGE permission: " + form); throw new SecurityException("Not Authorized"); } if (!form.isNew()) { // User must have the previous lifecycle permission // in AT LEAST ONE previous category as well IPortletDefinition def = this.portletDefinitionRegistry.getPortletDefinition(form.getId()); Set<PortletCategory> categories = portletCategoryRegistry.getParentCategories(def); SortedSet<JsonEntityBean> categoryBeans = new TreeSet<>(); for (PortletCategory cat : categories) { categoryBeans.add(new JsonEntityBean(cat)); } if (!hasLifecyclePermission(publisher, def.getLifecycleState(), categoryBeans)) { logger.warn("User '" + publisher.getUserName() + "' attempted to save the following portlet without the previous MANAGE permission: " + form); throw new SecurityException("Not Authorized"); } } if (form.isNew() || portletDefinitionRegistry.getPortletDefinition(form.getId()).getType().getId() != form .getTypeId()) { // User must have access to the selected CPD if s/he selected it in this interaction final int selectedTypeId = form.getTypeId(); final PortletPublishingDefinition cpd = portletPublishingDefinitionDao .getChannelPublishingDefinition(selectedTypeId); final Map<IPortletType, PortletPublishingDefinition> allowableCpds = this .getAllowableChannelPublishingDefinitions(publisher); if (!allowableCpds.containsValue(cpd)) { logger.warn("User '" + publisher.getUserName() + "' attempted to administer the following portlet without the selected " + IPermission.PORTLET_MANAGER_SELECT_PORTLET_TYPE + " permission: " + form); throw new SecurityException("Not Authorized"); } } // create the principal array from the form's principal list -- only principals with permissions final Set<IGroupMember> subscribePrincipalSet = new HashSet<>(form.getPrincipals().size()); final Set<IGroupMember> browsePrincipalSet = new HashSet<>(form.getPrincipals().size()); for (JsonEntityBean bean : form.getPrincipals()) { final String subscribePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_SUBSCRIBER_ACTIVITY; final String browsePerm = bean.getTypeAndIdHash() + "_" + IPermission.PORTLET_BROWSE_ACTIVITY; final EntityEnum entityEnum = bean.getEntityType(); final IGroupMember principal = entityEnum.isGroup() ? (GroupService.findGroup(bean.getId())) : (GroupService.getGroupMember(bean.getId(), entityEnum.getClazz())); if (form.getPermissions().contains(subscribePerm)) { subscribePrincipalSet.add(principal); } if (form.getPermissions().contains(browsePerm)) { browsePrincipalSet.add(principal); } } // create the category list from the form's category bean list List<PortletCategory> categories = new ArrayList<>(); for (JsonEntityBean category : form.getCategories()) { String id = category.getId(); String iCatID = id.startsWith("cat") ? id.substring(3) : id; categories.add(portletCategoryRegistry.getPortletCategory(iCatID)); } final IPortletType portletType = portletTypeRegistry.getPortletType(form.getTypeId()); if (portletType == null) { throw new IllegalArgumentException("No IPortletType exists for ID " + form.getTypeId()); } IPortletDefinition portletDef; if (form.getId() == null) { portletDef = new PortletDefinitionImpl(portletType, form.getFname(), form.getName(), form.getTitle(), form.getApplicationId(), form.getPortletName(), form.isFramework()); } else { portletDef = portletDefinitionRegistry.getPortletDefinition(form.getId()); portletDef.setType(portletType); portletDef.setFName(form.getFname()); portletDef.setName(form.getName()); portletDef.setTitle(form.getTitle()); portletDef.getPortletDescriptorKey().setWebAppName(form.getApplicationId()); portletDef.getPortletDescriptorKey().setPortletName(form.getPortletName()); portletDef.getPortletDescriptorKey().setFrameworkPortlet(form.isFramework()); } portletDef.setDescription(form.getDescription()); portletDef.setTimeout(form.getTimeout()); // Make parameters (NB: these are different from preferences) in the // portletDef reflect the state of the form, in case any have changed. for (String key : form.getParameters().keySet()) { String value = form.getParameters().get(key).getValue(); if (!StringUtils.isBlank(value)) { portletDef.addParameter(key, value); } } portletDef.addParameter(IPortletDefinition.EDITABLE_PARAM, Boolean.toString(form.isEditable())); portletDef.addParameter(IPortletDefinition.CONFIGURABLE_PARAM, Boolean.toString(form.isConfigurable())); portletDef.addParameter(IPortletDefinition.HAS_HELP_PARAM, Boolean.toString(form.isHasHelp())); portletDef.addParameter(IPortletDefinition.HAS_ABOUT_PARAM, Boolean.toString(form.isHasAbout())); // Now add portlet preferences List<IPortletPreference> preferenceList = new ArrayList<>(); for (String key : form.getPortletPreferences().keySet()) { List<String> prefValues = form.getPortletPreferences().get(key).getValue(); if (prefValues != null && prefValues.size() > 0) { String[] values = prefValues.toArray(new String[prefValues.size()]); BooleanAttribute readOnly = form.getPortletPreferenceReadOnly().get(key); preferenceList.add(new PortletPreferenceImpl(key, readOnly.getValue(), values)); } } portletDef.setPortletPreferences(preferenceList); // Lastly update the PortletDefinition's lifecycle state & lifecycle-related metadata updateLifecycleState(form, portletDef, publisher); // The final parameter of IGroupMembers is used to set the initial SUBSCRIBE permission set portletPublishingService.savePortletDefinition(portletDef, publisher, categories, new ArrayList<>(subscribePrincipalSet)); //updatePermissions(portletDef, subscribePrincipalSet, IPermission.PORTLET_SUBSCRIBER_ACTIVITY); updatePermissions(portletDef, browsePrincipalSet, IPermission.PORTLET_BROWSE_ACTIVITY); return this.createPortletDefinitionForm(publisher, portletDef.getPortletDefinitionId().getStringId()); }
From source file:org.jbpm.formbuilder.server.form.GuvnorFormDefinitionServiceTest.java
public void testGetFormItemsOK() throws Exception { HttpClient client = EasyMock.createMock(HttpClient.class); Map<String, String> responses = new HashMap<String, String>(); FormItemRepresentation item1 = RESTAbstractTest.createMockForm("form1", "oneParam").getFormItems().get(1); String jsonItem1 = FormEncodingFactory.getEncoder().encode(item1); FormItemRepresentation item2 = RESTAbstractTest.createMockForm("form2", "anotherParam").getFormItems() .get(2);//from w w w . ja v a2 s .com String jsonItem2 = FormEncodingFactory.getEncoder().encode(item2); StringBuilder props = new StringBuilder(); props.append("form1AutoForm.formdef=AAAAA\n"); props.append("formItemDefinition_item1.json=AAAAA\n"); props.append("formItemDefinition_item2.json=AAAAA\n"); responses.put("GET " + helper.getApiSearchUrl("somePackage"), props.toString()); responses.put("GET " + helper.getApiSearchUrl("somePackage") + "formItemDefinition_item1.json", jsonItem1); responses.put("GET " + helper.getApiSearchUrl("somePackage") + "formItemDefinition_item2.json", jsonItem2); EasyMock.expect(client.executeMethod(EasyMock.isA(MockGetMethod.class))) .andAnswer(new MockAnswer(responses, new IllegalArgumentException("Unexpected call"))).times(3); GuvnorFormDefinitionService service = createService(baseUrl, "", ""); service.getHelper().setClient(client); EasyMock.replay(client); Map<String, FormItemRepresentation> items = service.getFormItems("somePackage"); EasyMock.verify(client); assertNotNull("items shouldn't be null", items); assertEquals("items should have 2 elements", 2, items.size()); assertTrue("forms should contain form1", items.containsValue(item1)); assertTrue("forms should contain form2", items.containsValue(item2)); }
From source file:org.aksw.resparql.IMyHandler.java
@Override public boolean handle(HttpExchange x) throws Exception { Map<String, ContentType> accepts = MyHandler.getPreferredFormats(x.getRequestHeaders()); if (accepts.isEmpty()) return false; //Map.Entry<String, ContentType> type = accepts.entrySet().iterator().next(); RegexInvocationContainer ric = accepts.containsValue(new ContentType("text/html")) ? pageRIC : dataRIC; String targetURL = (String) ric.invoke(x.getRequestURI().toString()); if (targetURL == null) { return false; }/*w w w . j a v a2 s. co m*/ MyHandler.sendRedirect(x, targetURL); return true; }
From source file:edu.ucsd.library.xdre.web.StatsCollectionsReportController.java
public static String getRow(DAMSClient damsClient, String colTitle, String colId, String colType, String unit, String visibility, Map<String, String> colMap, List<String> items) throws Exception { boolean isUnit = colType.equalsIgnoreCase(UNIT); String rowVal = null;//from www. ja v a 2 s . c om String solrQuery = ""; long itemsCount = 0; if (isUnit) { itemsCount = items != null ? items.size() : 0; } else itemsCount = damsClient.countObjects(colId); ; String solrBase = "start=0&rows=1&"; String[] views = { "discover_access_group_ssim:public", "discover_access_group_ssim:local", "discover_access_group_ssim:dams-manager-admin AND NOT(discover_access_group_ssim:public OR discover_access_group_ssim:local)" }; if (isUnit) { solrQuery = solrBase + "q=" + URLEncoder.encode("unit_code_tesim:" + unit + " OR unit_json_tesim:\"" + colTitle + "\"", "UTF-8") + "&fq=" + URLEncoder.encode("has_model_ssim:\"info:fedora/afmodel:DamsObject\"", "UTF-8") + "&fq=" + URLEncoder.encode("-collections_tesim:[* TO *]", "UTF-8"); } else solrQuery = solrBase + "q=" + URLEncoder.encode("collections_tesim:" + colId + " OR collection_sim:\"" + colTitle + "\"", "UTF-8") + "&fq=" + URLEncoder.encode("has_model_ssim:\"info:fedora/afmodel:DamsObject\"", "UTF-8"); Document doc = damsClient.solrLookup(solrQuery); String numFound = doc.selectSingleNode("/response/result/@numFound").getStringValue(); long size = getDiskSize(colId); if (size == 0 || itemsCount != Integer.parseInt(numFound)) { //Collection counted if (items == null || items.size() == 0) items = damsClient.listObjects(colId); int recordSize = items.size(); String item = null; itemsCount = 0; for (int i = 0; i < recordSize; i++) { item = items.get(i); if (!colMap.containsValue(item)) { itemsCount++; } } } rowVal = colTitle + "\t" + colType + "\t" + unit + "\t" + numFound + "\t" + itemsCount + "\t" + NUM_FORMATER.format(size / 1000000.0) + "\t" + visibility; for (int j = 0; j < views.length; j++) { if (isUnit) { solrQuery = solrBase + "q=" + URLEncoder.encode("unit_code_tesim:" + unit + " OR unit_json_tesim:\"" + colTitle + "\"", "UTF-8") + "&fq=" + URLEncoder.encode("has_model_ssim:\"info:fedora/afmodel:DamsObject\"", "UTF-8") + "&fq=" + URLEncoder.encode("-collections_tesim:[* TO *]", "UTF-8") + "&fq=" + URLEncoder.encode(views[j], "UTF-8"); } else solrQuery = solrBase + "q=" + URLEncoder.encode( "collections_tesim:" + colId + " OR collection_sim:\"" + colTitle + "\"", "UTF-8") + "&fq=" + URLEncoder.encode("has_model_ssim:\"info:fedora/afmodel:DamsObject\"", "UTF-8") + "&fq=" + URLEncoder.encode(views[j], "UTF-8"); doc = damsClient.solrLookup(solrQuery); ; numFound = doc.selectSingleNode("/response/result/@numFound").getStringValue(); rowVal += "\t" + (numFound.equals("0") ? " " : numFound); } //System.out.println("Embargo: " + tsUtils.getTripleStoreName() + " " + colName); //List<RightsAction> embargos = null; List<String> restrictedItems = null; List<String> sensitiveItems = null; if (!isUnit) { restrictedItems = getRestrictedItems(damsClient, colId); sensitiveItems = getCulturallySensitiveItems(damsClient, colId); } if (restrictedItems != null && restrictedItems.size() > 0) { rowVal += "\t" + restrictedItems.size(); } else rowVal += "\t "; if (sensitiveItems != null && sensitiveItems.size() > 0) { rowVal += "\t" + sensitiveItems.size(); } else rowVal += "\t "; rowVal += "\t "; if (restrictedItems != null && restrictedItems.size() > 0) { String restricted = ""; for (Iterator<String> it1 = restrictedItems.iterator(); it1.hasNext();) { restricted += (restricted.length() > 0 ? ", " : "") + it1.next(); } rowVal += "Restricted items: [" + restricted + "]"; } if (restrictedItems != null && sensitiveItems.size() > 0) { String sensitive = ""; for (Iterator<String> it1 = sensitiveItems.iterator(); it1.hasNext();) { sensitive += (sensitive.length() > 0 ? ", " : "") + it1.next(); } rowVal += " Culturally sensitive items: [" + sensitive + "]"; } if (isUnit && items != null && items.size() > 0) { String itemsStr = ""; for (Iterator<String> it1 = items.iterator(); it1.hasNext();) { String oid = it1.next(); itemsStr += (itemsStr.length() > 0 ? ", " : "") + oid.substring(oid.lastIndexOf("/") + 1); } rowVal += itemsStr; } return rowVal; }
From source file:eu.squadd.testing.objectspopulator.RandomValuePopulator.java
public Object populateAllFields(final Class targetClass, Map exclusions) throws IllegalAccessException, InstantiationException { final Object target; try {/*w w w . j a v a2s. c o m*/ if (isMathNumberType(targetClass)) { target = getMathNumberType(targetClass); } else { target = ConstructorUtils.invokeConstructor(targetClass, null); } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException ex) { System.err.println(ex.getMessage()); return null; } //final Object target = targetClass.newInstance(); //Get all fields present on the target class final Set<Field> allFields = getAllFields(targetClass, Predicates.<Field>alwaysTrue()); if (this.stopOnMxRecusionDepth) this.currentRecursionDepth++; //Iterate through fields if recursion depth is not reached if (!this.stopOnMxRecusionDepth || (this.stopOnMxRecusionDepth && this.currentRecursionDepth <= scannerFactory.getRecursionDepth())) { for (final Field field : allFields) { try { // check if the field is not on exclusion list if (exclusions != null && exclusions.containsValue(field.getName())) continue; //Set fields to be accessible even when private field.setAccessible(true); final Class<?> fieldType = field.getType(); if (fieldType.isEnum() && Enum.class.isAssignableFrom(fieldType)) { //handle any enums here if you have any } else if (isMathNumberType(fieldType)) { //System.out.println("*** Math number found, populating it: "+fieldType); field.set(target, getManufacturedPojo(fieldType)); } //Check if the field is a collection else if (Collection.class.isAssignableFrom(fieldType)) { //Get the generic type class of the collection final Class<?> genericClass = getGenericClass(field); //Check if the generic type of a list is abstract if (Modifier.isAbstract(genericClass.getModifiers())) { System.out.println("Abstract classes are not supported !!!"); // this stuff needs real class extending abstract one to work //final List<Object> list = new ArrayList(); //list.add(populateAllIn(ClassExtendingAbstract.class)); //field.set(target, list); } else { final List<Object> list = new ArrayList(); list.add(populateAllFields(genericClass, exclusions)); field.set(target, list); } } else if ((isSimpleType(fieldType) || isSimplePrimitiveWrapperType(fieldType)) && !fieldType.isEnum()) { field.set(target, getManufacturedPojo(fieldType)); } else if (!fieldType.isEnum()) { field.set(target, populateAllFields(fieldType, exclusions)); } } catch (IllegalAccessException | InstantiationException ex) { System.err.println(ex.getMessage()); } } } return target; }