List of usage examples for java.util Collections EMPTY_MAP
Map EMPTY_MAP
To view the source code for java.util Collections EMPTY_MAP.
Click Source Link
From source file:org.flowable.cmmn.test.runtime.VariablesTest.java
@SuppressWarnings("unchecked") @Test/*from w w w .j a v a 2 s . c o m*/ @CmmnDeployment(resources = "org/flowable/cmmn/test/task/CmmnTaskServiceTest.testOneHumanTaskCase.cmmn") public void setVariablesWithEmptyMap() { CaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceBuilder() .variable("varToUpdate", "initialValue").caseDefinitionKey("oneHumanTaskCase").start(); this.expectedException.expect(FlowableIllegalArgumentException.class); this.expectedException.expectMessage("variables is empty"); cmmnRuntimeService.setVariables(caseInstance.getId(), Collections.EMPTY_MAP); }
From source file:de.innovationgate.wgpublisher.plugins.WGAPluginSet.java
private void init(WGACore core, File pluginsDir, boolean workspaceSet) throws PluginSetInitException { try {/*from w ww .j a v a 2 s. c o m*/ _core = core; _workspaceSet = workspaceSet; _runtimeContexts = new HashMap<PluginID, RuntimeContext>(); _pluginsDir = pluginsDir; createPluginDirectories(); _dbServer = new HsqlPluginsDatabaseServer(this); _dbServer.init(WGAConfiguration.SINGLETON_SERVER_PREFIX + _dbServer.getClass().getName(), "Plugins Database Directory", Collections.EMPTY_MAP); _pluginsByInstallationKey = new HashMap<String, WGAPlugin>(); _activePluginsByUniqueName = new HashMap<String, WGAPlugin>(); Iterator<WGAPlugin> plugins = _plugins.iterator(); while (plugins.hasNext()) { WGAPlugin plugin = (WGAPlugin) plugins.next(); try { plugin.init(); if (plugin.isActive()) { _activePluginsByUniqueName.put(plugin.getPluginID().getUniqueName(), plugin); if (plugin.getInstallationKey() != null) { _pluginsByInstallationKey.put(plugin.getInstallationKey(), plugin); } } } catch (MissingDefaultPluginException e) { // Will be tolerated for now, handled later on default plugin evaluation } catch (InvalidPluginException e) { _core.getLog().error("Error initializing plugin " + plugin.getPluginID().toString(), e); } } } catch (PluginSetInitException e) { throw e; } catch (Exception e) { throw new PluginSetInitException("Exception initializing plugin set", e); } }
From source file:ddf.catalog.source.solr.SolrMetacardClientImpl.java
@Override public Set<ContentType> getContentTypes() { Set<ContentType> finalSet = new HashSet<>(); String contentTypeField = resolver.getField(Metacard.CONTENT_TYPE, AttributeType.AttributeFormat.STRING, true, Collections.EMPTY_MAP); String contentTypeVersionField = resolver.getField(Metacard.CONTENT_TYPE_VERSION, AttributeType.AttributeFormat.STRING, true, Collections.EMPTY_MAP); /*/*from w ww . j a v a2s. c om*/ * If we didn't find the field, it most likely means it does not exist. If it does not * exist, then we can safely say that no content types are in this catalog provider */ if (contentTypeField == null || contentTypeVersionField == null) { return finalSet; } SolrQuery query = new SolrQuery(contentTypeField + ":[* TO *]"); query.setFacet(true); query.addFacetField(contentTypeField); query.addFacetPivotField(contentTypeField + "," + contentTypeVersionField); try { QueryResponse solrResponse = client.query(query, METHOD.POST); List<FacetField> facetFields = solrResponse.getFacetFields(); for (Map.Entry<String, List<PivotField>> entry : solrResponse.getFacetPivot()) { // if no content types have an associated version, the list of pivot fields will be // empty. // however, the content type names can still be obtained via the facet fields. if (CollectionUtils.isEmpty(entry.getValue())) { LOGGER.debug("No content type versions found associated with any available content types."); if (CollectionUtils.isNotEmpty(facetFields)) { // Only one facet field was added. That facet field may contain multiple // values (content type names). for (FacetField.Count currContentType : facetFields.get(0).getValues()) { // unknown version, so setting it to null ContentType contentType = new ContentTypeImpl(currContentType.getName(), null); finalSet.add(contentType); } } } else { for (PivotField pf : entry.getValue()) { String contentTypeName = pf.getValue().toString(); LOGGER.debug("contentTypeName: {}", contentTypeName); if (CollectionUtils.isEmpty(pf.getPivot())) { // if there are no sub-pivots, that means that there are no content type // versions // associated with this content type name LOGGER.debug("Content type does not have associated contentTypeVersion: {}", contentTypeName); ContentType contentType = new ContentTypeImpl(contentTypeName, null); finalSet.add(contentType); } else { for (PivotField innerPf : pf.getPivot()) { LOGGER.debug("contentTypeVersion: {}. For contentTypeName: {}", innerPf.getValue(), contentTypeName); ContentType contentType = new ContentTypeImpl(contentTypeName, innerPf.getValue().toString()); finalSet.add(contentType); } } } } } } catch (SolrServerException | SolrException | IOException e) { LOGGER.info("Solr exception getting content types", e); } return finalSet; }
From source file:org.codehaus.groovy.grails.plugins.web.api.ControllersApi.java
/** * Initializes a command object.//w ww. j av a 2 s . c om * * If type is a domain class and the request body or parameters include an id, the id is used to retrieve * the command object instance from the database, otherwise the no-arg constructor on type is invoke. If * an attempt is made to retrieve the command object instance from the database and no corresponding * record is found, null is returned. * * The command object is then subjected to data binding and dependency injection before being returned. * * * @param controllerInstance The controller instance * @param type The type of the command object * @return the initialized command object or null if the command object is a domain class, the body or * parameters included an id and no corresponding record was found in the database. */ public Object initializeCommandObject(final Object controllerInstance, final Class type) throws Exception { final HttpServletRequest request = getRequest(controllerInstance); final DataBindingSource dataBindingSource = DataBindingUtils .createDataBindingSource(getGrailsApplication(controllerInstance), type, request); final DataBindingSource commandObjectBindingSource = WebMetaUtils.getCommandObjectBindingSource(type, dataBindingSource); final Object commandObjectInstance; Object entityIdentifierValue = null; if (DomainClassArtefactHandler.isDomainClass(type)) { entityIdentifierValue = commandObjectBindingSource.getIdentifierValue(); if (entityIdentifierValue == null) { final GrailsWebRequest webRequest = GrailsWebRequest.lookup(request); entityIdentifierValue = webRequest != null ? webRequest.getParams().getIdentifier() : null; } } if (entityIdentifierValue != null) { commandObjectInstance = InvokerHelper.invokeStaticMethod(type, "get", entityIdentifierValue); } else { commandObjectInstance = type.newInstance(); } if (commandObjectInstance != null) { final boolean shouldDoDataBinding; if (entityIdentifierValue != null) { final HttpMethod requestMethod = HttpMethod.valueOf(request.getMethod()); switch (requestMethod) { case PATCH: case POST: case PUT: shouldDoDataBinding = true; break; default: shouldDoDataBinding = false; } } else { shouldDoDataBinding = true; } if (shouldDoDataBinding) { bindData(controllerInstance, commandObjectInstance, commandObjectBindingSource, Collections.EMPTY_MAP, null); } final ApplicationContext applicationContext = getApplicationContext(controllerInstance); final AutowireCapableBeanFactory autowireCapableBeanFactory = applicationContext .getAutowireCapableBeanFactory(); autowireCapableBeanFactory.autowireBeanProperties(commandObjectInstance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); } return commandObjectInstance; }
From source file:com.thoughtworks.go.server.service.ElasticAgentPluginService.java
public void jobCompleted(JobInstance job) { AgentInstance agentInstance = agentService.findAgent(job.getAgentUuid()); if (!agentInstance.isElastic()) { LOGGER.debug("Agent {} is not elastic. Skipping further execution.", agentInstance.getUuid()); return;/* w ww.j av a 2 s .c o m*/ } if (job.isAssignedToAgent()) { jobCreationTimeMap.remove(job.getId()); } String pluginId = agentInstance.elasticAgentMetadata().elasticPluginId(); String elasticAgentId = agentInstance.elasticAgentMetadata().elasticAgentId(); ElasticProfile elasticProfile = job.getPlan().getElasticProfile(); ClusterProfile clusterProfile = job.getPlan().getClusterProfile(); Map<String, String> elasticProfileConfiguration = elasticProfile.getConfigurationAsMap(true); Map<String, String> clusterProfileConfiguration = clusterProfile != null ? clusterProfile.getConfigurationAsMap(true) : Collections.EMPTY_MAP; elasticAgentPluginRegistry.reportJobCompletion(pluginId, elasticAgentId, job.getIdentifier(), elasticProfileConfiguration, clusterProfileConfiguration); }
From source file:jef.database.DbUtils.java
/** * ????// w ww . j a v a 2 s .co m * * @param <T> * @param queryObj * @return */ @SuppressWarnings("unchecked") public static <T extends IQueryableEntity> JoinElement toReferenceJoinQuery(Query<T> queryObj, List<Reference> excludeRef) { // ?? Map<Reference, List<AbstractRefField>> map = queryObj.isCascadeViaOuterJoin() ? DbUtils.getMergeAsOuterJoinRef(queryObj) : Collections.EMPTY_MAP; Query<?>[] otherQuery = queryObj.getOtherQueryProvider(); if (otherQuery.length == 0 && map.isEmpty()) { return queryObj; } // AbstractJoinImpl j = DbUtils.getJoin(queryObj, map, ArrayUtils.asList(otherQuery), excludeRef); if (j != null) { j.setFetchSize(queryObj.getFetchSize()); j.setMaxResult(queryObj.getMaxResult()); j.setQueryTimeout(queryObj.getQueryTimeout()); if (queryObj.getSelectItems() != null) { List<QueryAlias> qs = j.allElements(); for (int i = 0; i < qs.size(); i++) { qs.get(i).setAlias("T" + (i + 1)); } SelectsImpl select = new jef.database.query.SelectsImpl(qs); select.merge((AbstractEntityMappingProvider) queryObj.getSelectItems()); j.setSelectItems(select); } // TODO cacheable, Transformer, // attributeQuery???????? j.setResultTransformer(queryObj.getResultTransformer()); j.setCacheable(queryObj.isCacheable()); // FilterCondition? if (queryObj.getFilterCondition() != null) { for (QueryAlias qa : j.allElements()) { if (qa.getStaticRef() != null) { List<Condition> con = queryObj.getFilterCondition().get(qa.getStaticRef()); if (con != null) { j.addRefConditions(qa.getQuery(), con); } } } } return j; } else { return queryObj; } }
From source file:fr.duminy.jbackup.core.ConfigurationManagerTest.java
private static Map describe(BackupConfiguration config) { Map properties;/* w ww.ja va2 s . c o m*/ try { properties = PropertyUtils.describe(config); } catch (Exception e) { LOG.error("unable to extract properties from configuration", e); properties = Collections.EMPTY_MAP; } properties.remove("class"); properties.put("archiveFactory", config.getArchiveFactory().getClass().getName()); List<BackupConfiguration.Source> sources = (List<BackupConfiguration.Source>) properties.remove("sources"); properties.put("sources.size", sources.size()); for (int i = 0; i < sources.size(); i++) { Map sourceProperties = null; try { sourceProperties = PropertyUtils.describe(sources.get(i)); } catch (Exception e) { LOG.error("unable to extract source #" + i, e); } sourceProperties.remove("class"); properties.put("sources[" + i + "]", sourceProperties); } return properties; }
From source file:org.activiti.engine.impl.persistence.entity.TaskEntity.java
@SuppressWarnings("unchecked") public Map<String, Object> getActivityInstanceVariables() { if (execution != null) { return execution.getVariables(); }/*from w ww . j a va 2 s . c o m*/ return Collections.EMPTY_MAP; }
From source file:com.ms.commons.summer.web.util.json.JsonBeanUtils.java
/** * Creates a bean from a JSONObject, with the specific configuration. *//* w w w . ja v a 2 s .com*/ public static Object toBean(JSONObject jsonObject, Object root, JsonConfig jsonConfig) { if (jsonObject == null || jsonObject.isNullObject() || root == null) { return root; } Class rootClass = root.getClass(); if (rootClass.isInterface()) { throw new JSONException("Root bean is an interface. " + rootClass); } Map classMap = jsonConfig.getClassMap(); if (classMap == null) { classMap = Collections.EMPTY_MAP; } Map props = JSONUtils.getProperties(jsonObject); PropertyFilter javaPropertyFilter = jsonConfig.getJavaPropertyFilter(); for (Iterator entries = jsonObject.names().iterator(); entries.hasNext();) { String name = (String) entries.next(); Class type = (Class) props.get(name); Object value = jsonObject.get(name); if (javaPropertyFilter != null && javaPropertyFilter.apply(root, name, value)) { continue; } String key = JSONUtils.convertToJavaIdentifier(name, jsonConfig); try { PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(root, key); if (pd != null && pd.getWriteMethod() == null) { log.warn("Property '" + key + "' has no write method. SKIPPED."); continue; } if (!JSONUtils.isNull(value)) { if (value instanceof JSONArray) { if (pd == null || List.class.isAssignableFrom(pd.getPropertyType())) { Class targetClass = findTargetClass(key, classMap); targetClass = targetClass == null ? findTargetClass(name, classMap) : targetClass; Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(targetClass, null); List list = JSONArray.toList((JSONArray) value, newRoot, jsonConfig); setProperty(root, key, list, jsonConfig); } else { Class innerType = JSONUtils.getInnerComponentType(pd.getPropertyType()); Class targetInnerType = findTargetClass(key, classMap); if (innerType.equals(Object.class) && targetInnerType != null && !targetInnerType.equals(Object.class)) { innerType = targetInnerType; } Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(innerType, null); Object array = JSONArray.toArray((JSONArray) value, newRoot, jsonConfig); if (innerType.isPrimitive() || JSONUtils.isNumber(innerType) || Boolean.class.isAssignableFrom(innerType) || JSONUtils.isString(innerType)) { array = JSONUtils.getMorpherRegistry() .morph(Array.newInstance(innerType, 0).getClass(), array); } else if (!array.getClass().equals(pd.getPropertyType())) { if (!pd.getPropertyType().equals(Object.class)) { Morpher morpher = JSONUtils.getMorpherRegistry() .getMorpherFor(Array.newInstance(innerType, 0).getClass()); if (IdentityObjectMorpher.getInstance().equals(morpher)) { ObjectArrayMorpher beanMorpher = new ObjectArrayMorpher( new BeanMorpher(innerType, JSONUtils.getMorpherRegistry())); JSONUtils.getMorpherRegistry().registerMorpher(beanMorpher); } array = JSONUtils.getMorpherRegistry() .morph(Array.newInstance(innerType, 0).getClass(), array); } } setProperty(root, key, array, jsonConfig); } } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type) || JSONUtils.isNumber(type) || JSONUtils.isString(type) || JSONFunction.class.isAssignableFrom(type)) { if (pd != null) { if (jsonConfig.isHandleJettisonEmptyElement() && "".equals(value)) { setProperty(root, key, null, jsonConfig); } else if (!pd.getPropertyType().isInstance(value)) { Morpher morpher = JSONUtils.getMorpherRegistry() .getMorpherFor(pd.getPropertyType()); if (IdentityObjectMorpher.getInstance().equals(morpher)) { log.warn("Can't transform property '" + key + "' from " + type.getName() + " into " + pd.getPropertyType().getName() + ". Will register a default BeanMorpher"); JSONUtils.getMorpherRegistry().registerMorpher( new BeanMorpher(pd.getPropertyType(), JSONUtils.getMorpherRegistry())); } setProperty(root, key, JSONUtils.getMorpherRegistry().morph(pd.getPropertyType(), value), jsonConfig); } else { setProperty(root, key, value, jsonConfig); } } else if (root instanceof Map) { setProperty(root, key, value, jsonConfig); } else { log.warn("Tried to assign property " + key + ":" + type.getName() + " to bean of class " + root.getClass().getName()); } } else { if (pd != null) { Class targetClass = pd.getPropertyType(); if (jsonConfig.isHandleJettisonSingleElementArray()) { JSONArray array = new JSONArray().element(value, jsonConfig); Class newTargetClass = findTargetClass(key, classMap); newTargetClass = newTargetClass == null ? findTargetClass(name, classMap) : newTargetClass; Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(newTargetClass, null); if (targetClass.isArray()) { setProperty(root, key, JSONArray.toArray(array, newRoot, jsonConfig), jsonConfig); } else if (Collection.class.isAssignableFrom(targetClass)) { setProperty(root, key, JSONArray.toList(array, newRoot, jsonConfig), jsonConfig); } else if (JSONArray.class.isAssignableFrom(targetClass)) { setProperty(root, key, array, jsonConfig); } else { setProperty(root, key, toBean((JSONObject) value, newRoot, jsonConfig), jsonConfig); } } else { if (targetClass == Object.class) { targetClass = findTargetClass(key, classMap); targetClass = targetClass == null ? findTargetClass(name, classMap) : targetClass; } Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(targetClass, null); setProperty(root, key, toBean((JSONObject) value, newRoot, jsonConfig), jsonConfig); } } else if (root instanceof Map) { Class targetClass = findTargetClass(key, classMap); targetClass = targetClass == null ? findTargetClass(name, classMap) : targetClass; Object newRoot = jsonConfig.getNewBeanInstanceStrategy().newInstance(targetClass, null); setProperty(root, key, toBean((JSONObject) value, newRoot, jsonConfig), jsonConfig); } else { log.warn("Tried to assign property " + key + ":" + type.getName() + " to bean of class " + rootClass.getName()); } } } else { if (type.isPrimitive()) { // assume assigned default value log.warn("Tried to assign null value to " + key + ":" + type.getName()); setProperty(root, key, JSONUtils.getMorpherRegistry().morph(type, null), jsonConfig); } else { setProperty(root, key, null, jsonConfig); } } } catch (JSONException jsone) { throw jsone; } catch (Exception e) { throw new JSONException("Error while setting property=" + name + " type " + type, e); } } return root; }
From source file:org.apache.sling.servlets.post.impl.operations.StreamingUploadOperationTest.java
@Test public void testPartsContentRange() throws RepositoryException, UnsupportedEncodingException { List<Modification> changes = new ArrayList<Modification>(); PostResponse response = new AbstractPostResponse() { @Override//from ww w .j ava2s .c o m protected void doSend(HttpServletResponse response) throws IOException { } @Override public void onChange(String type, String... arguments) { } @Override public String getPath() { return "/test/upload/location"; } }; List<Part> partsList = new ArrayList<Part>(); partsList.add(new MockPart("formfield1", null, null, 0, new ByteArrayInputStream("testformfield1".getBytes("UTF-8")), Collections.EMPTY_MAP)); partsList.add(new MockPart("formfield2", null, null, 0, new ByteArrayInputStream("testformfield2".getBytes("UTF-8")), Collections.EMPTY_MAP)); partsList.add(new MockPart("test1.txt", "text/plain", "test1bad.txt", 4, new ByteArrayInputStream("test".getBytes("UTF-8")), mapOf("Content-Range", "bytes 0-3/8", "Content-Length", "4"))); partsList.add(new MockPart("test1.txt", "text/plain", "test1bad.txt", 4, new ByteArrayInputStream("part".getBytes("UTF-8")), mapOf("Content-Range", "bytes 4-7/8", "Content-Length", "4"))); partsList.add(new MockPart("*", "text/plain2", "test2.txt", 8, new ByteArrayInputStream("test1234".getBytes("UTF-8")), Collections.EMPTY_MAP)); partsList.add(new MockPart("badformfield2", null, null, 0, new ByteArrayInputStream("testbadformfield2".getBytes("UTF-8")), Collections.EMPTY_MAP)); final Iterator<Part> partsIterator = partsList.iterator(); final Map<String, Resource> repository = new HashMap<String, Resource>(); final ResourceResolver resourceResolver = new MockResourceResolver() { @Override public Resource getResource(String path) { Resource resource = repository.get(path); if (resource == null) { if ("/test/upload/location".equals(path)) { resource = new MockRealResource(this, path, "sling:Folder"); repository.put(path, resource); LOG.debug("Created {} ", path); } } LOG.debug("Resource {} is {} {}", path, resource, ResourceUtil.isSyntheticResource(resource)); return resource; } @Override public Iterable<Resource> getChildren(Resource resource) { List<Resource> children = new ArrayList<Resource>(); for (Map.Entry<String, Resource> e : repository.entrySet()) { if (isChild(resource.getPath(), e.getKey())) { children.add(e.getValue()); } } return children; } private boolean isChild(String path, String key) { if (key.length() > path.length() && key.startsWith(path)) { return !key.substring(path.length() + 1).contains("/"); } return false; } @Override public Iterator<Resource> listChildren(Resource parent) { return getChildren(parent).iterator(); } @Override public void delete(Resource resource) throws PersistenceException { } @Override public Resource create(Resource resource, String s, Map<String, Object> map) throws PersistenceException { Resource childResource = resource.getChild(s); if (childResource != null) { throw new IllegalArgumentException("Child " + s + " already exists "); } String resourceType = (String) map.get("sling:resourceType"); if (resourceType == null) { resourceType = (String) map.get("jcr:primaryType"); } if (resourceType == null) { LOG.warn("Resource type null for {} {} ", resource, resource.getPath() + "/" + s); } Resource newResource = new MockRealResource(this, resource.getPath() + "/" + s, resourceType, map); repository.put(newResource.getPath(), newResource); LOG.debug("Created Resource {} ", newResource.getPath()); return newResource; } @Override public void revert() { } @Override public void commit() throws PersistenceException { LOG.debug("Committing"); for (Map.Entry<String, Resource> e : repository.entrySet()) { LOG.debug("Committing {} ", e.getKey()); Resource r = e.getValue(); ModifiableValueMap vm = r.adaptTo(ModifiableValueMap.class); for (Map.Entry<String, Object> me : vm.entrySet()) { if (me.getValue() instanceof InputStream) { try { String value = IOUtils.toString((InputStream) me.getValue()); LOG.debug("Converted {} {} ", me.getKey(), value); vm.put(me.getKey(), value); } catch (IOException e1) { throw new PersistenceException("Failed to commit input stream", e1); } } } LOG.debug("Converted {} ", vm); } LOG.debug("Comittted {} ", repository); } @Override public boolean hasChanges() { return false; } }; SlingHttpServletRequest request = new MockSlingHttpServlet3Request(null, null, null, null, null) { @Override public Object getAttribute(String name) { if ("request-parts-iterator".equals(name)) { return partsIterator; } return super.getAttribute(name); } @Override public ResourceResolver getResourceResolver() { return resourceResolver; } }; streamedUplodOperation.doRun(request, response, changes); { Resource r = repository.get("/test/upload/location/test1.txt"); Assert.assertNotNull(r); ValueMap m = r.adaptTo(ValueMap.class); Assert.assertNotNull(m); Assert.assertEquals("nt:file", m.get("jcr:primaryType")); } { Resource r = repository.get("/test/upload/location/test1.txt/jcr:content"); Assert.assertNotNull(r); ValueMap m = r.adaptTo(ValueMap.class); Assert.assertNotNull(m); Assert.assertEquals("nt:resource", m.get("jcr:primaryType")); Assert.assertTrue(m.get("jcr:lastModified") instanceof Calendar); Assert.assertEquals("text/plain", m.get("jcr:mimeType")); Assert.assertEquals("testpart", m.get("jcr:data")); } { Resource r = repository.get("/test/upload/location/test2.txt"); Assert.assertNotNull(r); ValueMap m = r.adaptTo(ValueMap.class); Assert.assertNotNull(m); Assert.assertEquals("nt:file", m.get("jcr:primaryType")); } { Resource r = repository.get("/test/upload/location/test2.txt/jcr:content"); Assert.assertNotNull(r); ValueMap m = r.adaptTo(ValueMap.class); Assert.assertNotNull(m); Assert.assertEquals("nt:resource", m.get("jcr:primaryType")); Assert.assertTrue(m.get("jcr:lastModified") instanceof Calendar); Assert.assertEquals("text/plain2", m.get("jcr:mimeType")); Assert.assertEquals("test1234", m.get("jcr:data")); } }