List of usage examples for java.util HashMap putAll
public void putAll(Map<? extends K, ? extends V> m)
From source file:org.kuali.student.r1.core.personsearch.service.impl.PersonSearch.java
public Map<String, String> convertPersonPropertiesToEntityProperties(Map<String, String> criteria) { LOG.debug("convertPersonPropertiesToEntityProperties: {}", criteria); boolean nameCriteria = false; boolean addressCriteria = false; boolean externalIdentifierCriteria = false; boolean affiliationCriteria = false; boolean affiliationDefaultOnlyCriteria = false; boolean phoneCriteria = false; boolean emailCriteria = false; boolean employeeIdCriteria = false; // add base lookups for all person lookups HashMap<String, String> newCriteria = new HashMap<String, String>(); newCriteria.putAll(baseLookupCriteria); newCriteria.put("entityTypeContactInfos.entityTypeCode", personEntityTypeLookupCriteria); //Code Changed for JIRA-8997 - SONAR Critical issues - Performance - Inefficient use of keySet iterator instead of entrySet iterator if (criteria != null) { for (Map.Entry<String, String> entry : criteria.entrySet()) { //check active radio button String key = entry.getKey(); if (key.equals(KIMPropertyConstants.Person.ACTIVE)) { newCriteria.put(KIMPropertyConstants.Person.ACTIVE, criteria.get(KIMPropertyConstants.Person.ACTIVE)); } else { // The following if statement enables the "both" button to work correctly. if (!(criteria.containsKey(KIMPropertyConstants.Person.ACTIVE))) { newCriteria.remove(KIMPropertyConstants.Person.ACTIVE); }/*w ww .j a v a 2 s . c om*/ } // if no value was passed, skip the entry in the Map if (StringUtils.isEmpty(entry.getValue())) { continue; } // check if the value needs to be encrypted // handle encrypted external identifiers if (key.equals(KIMPropertyConstants.Person.EXTERNAL_ID) && StringUtils.isNotBlank(criteria.get(key))) { // look for a ext ID type property if (criteria.containsKey(KIMPropertyConstants.Person.EXTERNAL_IDENTIFIER_TYPE_CODE)) { String extIdTypeCode = criteria .get(KIMPropertyConstants.Person.EXTERNAL_IDENTIFIER_TYPE_CODE); if (StringUtils.isNotBlank(extIdTypeCode)) { // if found, load that external ID Type via service EntityExternalIdentifierType extIdType = getIdentityService() .getExternalIdentifierType(extIdTypeCode); // if that type needs to be encrypted, encrypt the value in the criteria map if (extIdType != null && extIdType.isEncryptionRequired()) { try { criteria.put(key, CoreApiServiceLocator.getEncryptionService() .encrypt(criteria.get(key))); } catch (GeneralSecurityException ex) { LOG.error(String.format( "Unable to encrypt value for external ID search of type %s", extIdTypeCode), ex); } } } } } // convert the property to the Entity data model String entityProperty = criteriaConversion.get(key); if (entityProperty != null) { newCriteria.put(entityProperty, criteria.get(key)); } else { entityProperty = key; // just pass it through if no translation present newCriteria.put(key, criteria.get(key)); } // check if additional criteria are needed based on the types of properties specified if (isNameEntityCriteria(entityProperty)) { nameCriteria = true; } if (isExternalIdentifierEntityCriteria(entityProperty)) { externalIdentifierCriteria = true; } if (isAffiliationEntityCriteria(entityProperty)) { affiliationCriteria = true; } if (isAddressEntityCriteria(entityProperty)) { addressCriteria = true; } if (isPhoneEntityCriteria(entityProperty)) { phoneCriteria = true; } if (isEmailEntityCriteria(entityProperty)) { emailCriteria = true; } if (isEmployeeIdEntityCriteria(entityProperty)) { employeeIdCriteria = true; } // special handling for the campus code, since that forces the query to look // at the default affiliation record only if (key.equals("campusCode")) { affiliationDefaultOnlyCriteria = true; } } if (nameCriteria) { newCriteria.put(ENTITY_NAME_PROPERTY_PREFIX + "active", "Y"); newCriteria.put(ENTITY_NAME_PROPERTY_PREFIX + "defaultValue", "Y"); //newCriteria.put(ENTITY_NAME_PROPERTY_PREFIX + "nameCode", "PRFR");//so we only display 1 result } if (addressCriteria) { newCriteria.put(ENTITY_ADDRESS_PROPERTY_PREFIX + "active", "Y"); newCriteria.put(ENTITY_ADDRESS_PROPERTY_PREFIX + "defaultValue", "Y"); } if (phoneCriteria) { newCriteria.put(ENTITY_PHONE_PROPERTY_PREFIX + "active", "Y"); newCriteria.put(ENTITY_PHONE_PROPERTY_PREFIX + "defaultValue", "Y"); } if (emailCriteria) { newCriteria.put(ENTITY_EMAIL_PROPERTY_PREFIX + "active", "Y"); newCriteria.put(ENTITY_EMAIL_PROPERTY_PREFIX + "defaultValue", "Y"); } if (employeeIdCriteria) { newCriteria.put(ENTITY_EMPLOYEE_ID_PROPERTY_PREFIX + "active", "Y"); newCriteria.put(ENTITY_EMPLOYEE_ID_PROPERTY_PREFIX + "primary", "Y"); } if (affiliationCriteria) { newCriteria.put(ENTITY_AFFILIATION_PROPERTY_PREFIX + "active", "Y"); } if (affiliationDefaultOnlyCriteria) { newCriteria.put(ENTITY_AFFILIATION_PROPERTY_PREFIX + "defaultValue", "Y"); } } LOG.debug("Converted: {}", newCriteria); return newCriteria; }
From source file:gaffer.store.Store.java
protected void validateSchemas() { boolean valid = validateTwoSetsContainSameElements(getDataSchema().getEdgeGroups(), getStoreSchema().getEdgeGroups(), "edges") && validateTwoSetsContainSameElements(getDataSchema().getEntityGroups(), getStoreSchema().getEntityGroups(), "entities"); if (!valid) { throw new SchemaException( "ERROR: the store schema did not pass validation because the store schema and data schema contain different numbers of elements. Please check the logs for more detailed information"); }/* www . j av a2 s. c o m*/ for (String group : getDataSchema().getEdgeGroups()) { valid &= validateTwoSetsContainSameElements(getDataSchema().getEdge(group).getProperties(), getStoreSchema().getEdge(group).getProperties(), "properties in the edge \"" + group + "\""); } for (String group : getDataSchema().getEntityGroups()) { valid &= validateTwoSetsContainSameElements(getDataSchema().getEntity(group).getProperties(), getStoreSchema().getEntity(group).getProperties(), "properties in the entity \"" + group + "\""); } if (!valid) { throw new SchemaException( "ERROR: the store schema did not pass validation because at least one of the elements in the store schema and data schema contain different numbers of properties. Please check the logs for more detailed information"); } HashMap<String, StoreElementDefinition> storeSchemaElements = new HashMap<>(); storeSchemaElements.putAll(getStoreSchema().getEdges()); storeSchemaElements.putAll(getStoreSchema().getEntities()); for (Map.Entry<String, StoreElementDefinition> storeElementDefinitionEntry : storeSchemaElements .entrySet()) { DataElementDefinition dataElementDefinition = getDataSchema() .getElement(storeElementDefinitionEntry.getKey()); for (String propertyName : storeElementDefinitionEntry.getValue().getProperties()) { Class propertyClass = dataElementDefinition.getPropertyClass(propertyName); Serialisation serialisation = storeElementDefinitionEntry.getValue().getProperty(propertyName) .getSerialiser(); if (!serialisation.canHandle(propertyClass)) { valid = false; LOGGER.error("Store schema serialiser for property '" + propertyName + "' in the group '" + storeElementDefinitionEntry.getKey() + "' cannot handle property found in the data schema"); } } } if (!valid) { throw new SchemaException( "ERROR: Store schema property serialiser cannot handle a property in the data schema"); } }
From source file:org.wandora.piccolo.actions.SendEmail.java
public void doAction(User user, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, Application application) {//ww w .j a v a2 s . c om try { Properties props = new Properties(); props.put("mail.smtp.host", smtpServer); Session session = Session.getDefaultInstance(props, null); MimeMessage message = new MimeMessage(session); if (subject != null) message.setSubject(subject); if (from != null) message.setFrom(new InternetAddress(from)); Vector<String> recipients = new Vector<String>(); if (recipient != null) { String[] rs = recipient.split(","); String r = null; for (int i = 0; i < rs.length; i++) { r = rs[i]; if (r != null) recipients.add(r); } } MimeMultipart multipart = new MimeMultipart(); Template template = application.getTemplate(emailTemplate, user); HashMap context = new HashMap(); context.put("request", request); context.put("message", message); context.put("recipients", recipients); context.put("emailhelper", new MailHelper()); context.put("multipart", multipart); context.putAll(application.getDefaultContext(user)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); template.process(context, baos); MimeBodyPart mimeBody = new MimeBodyPart(); mimeBody.setContent(new String(baos.toByteArray(), template.getEncoding()), template.getMimeType()); // mimeBody.setContent(baos.toByteArray(),template.getMimeType()); multipart.addBodyPart(mimeBody); message.setContent(multipart); Transport transport = session.getTransport("smtp"); transport.connect(smtpServer, smtpUser, smtpPass); Address[] recipientAddresses = new Address[recipients.size()]; for (int i = 0; i < recipientAddresses.length; i++) { recipientAddresses[i] = new InternetAddress(recipients.elementAt(i)); } transport.sendMessage(message, recipientAddresses); } catch (Exception e) { logger.writelog("WRN", e); } }
From source file:net.semanticmetadata.lire.builders.GlobalDocumentBuilder.java
/** * @param image the image to analyze./*from w w w . ja va 2 s. co m*/ * @return array string. */ public HashMap<String, String> createDescriptorFields(BufferedImage image, boolean returnArray) { docsCreated = true; HashMap<String, String> resultList = new HashMap<String, String>(); if (extractorItems.size() > 0) { for (Map.Entry<ExtractorItem, String[]> extractorItemEntry : extractorItems.entrySet()) { resultList.putAll(getGlobalDescriptorFields(image, extractorItemEntry.getKey(), true)); } } return resultList; }
From source file:ai.eve.volley.stack.HurlStack.java
@Override public HttpResponse performRequest(Request<?> request) throws IOException, AuthFailureError { HashMap<String, String> map = new HashMap<String, String>(); if (!TextUtils.isEmpty(mUserAgent)) { map.put(HTTP.USER_AGENT, mUserAgent); }/*from w w w. j a v a 2s .c o m*/ if (!TextUtils.isEmpty(mSignInfo)) { map.put("SIGN", ESecurity.Encrypt(mSignInfo)); } map.putAll(request.getHeaders()); URL parsedUrl = new URL(request.getUrl()); HttpURLConnection connection = openConnection(parsedUrl, request); for (String headerName : map.keySet()) { connection.addRequestProperty(headerName, map.get(headerName)); } if (EApplication.getCookies() != null) { ELog.I("cookie", EApplication.getCookies().toString()); connection.addRequestProperty("Cookie", EApplication.getReqCookies()); } else { ELog.I("cookie", "null"); } setConnectionParametersForRequest(connection, request); int responseCode = connection.getResponseCode(); if (responseCode == -1) { // -1 is returned by getResponseCode() if the response code could not be retrieved. // Signal to the caller that something was wrong with the connection. throw new IOException("Could not retrieve response code from HttpUrlConnection."); } StatusLine responseStatus = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), connection.getResponseCode(), connection.getResponseMessage()); BasicHttpResponse response = new BasicHttpResponse(responseStatus); response.setEntity(entityFromConnection(connection)); for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) { if (header.getKey() != null) { if (header.getKey().equalsIgnoreCase("Set-Cookie")) { List<String> cookies = header.getValue(); HashMap<String, HttpCookie> cookieMap = new HashMap<String, HttpCookie>(); for (String string : cookies) { List<HttpCookie> cookie = HttpCookie.parse(string); for (HttpCookie httpCookie : cookie) { if (httpCookie.getDomain() != null && httpCookie.getPath() != null) { cookieMap.put(httpCookie.getName() + httpCookie.getDomain() + httpCookie.getPath(), httpCookie); } else if (httpCookie.getDomain() == null && httpCookie.getPath() != null) { cookieMap.put(httpCookie.getName() + httpCookie.getPath(), httpCookie); } else if (httpCookie.getDomain() != null && httpCookie.getPath() == null) { cookieMap.put(httpCookie.getName() + httpCookie.getDomain(), httpCookie); } else { cookieMap.put(httpCookie.getName(), httpCookie); } } } EApplication.setCookies(cookieMap); if (EApplication.getCookies() != null) { ELog.I("?cookie", EApplication.getCookies().toString()); } } else { Header h = new BasicHeader(header.getKey(), header.getValue().get(0)); response.addHeader(h); } } } return response; }
From source file:com.nxt.zyl.data.volley.toolbox.HurlStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { String url = request.getUrl(); HashMap<String, String> map = new HashMap<String, String>(); // chenbo add gzip support,new user-agent if (request.isShouldGzip()) { map.put(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); }// w ww. j a v a2 s . c o m map.put(USER_AGENT, mUserAgent); // end map.putAll(request.getHeaders()); map.putAll(additionalHeaders); if (mUrlRewriter != null) { String rewritten = mUrlRewriter.rewriteUrl(url); if (rewritten == null) { throw new IOException("URL blocked by rewriter: " + url); } url = rewritten; } URL parsedUrl = new URL(url); HttpURLConnection connection = openConnection(parsedUrl, request); for (String headerName : map.keySet()) { connection.addRequestProperty(headerName, map.get(headerName)); } // if (request instanceof MultiPartRequest) { // setConnectionParametersForMultipartRequest(connection, request); // } else { // } setConnectionParametersForRequest(connection, request); // Initialize HttpResponse with data from the HttpURLConnection. ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1); int responseCode = connection.getResponseCode(); if (responseCode == -1) { // -1 is returned by getResponseCode() if the response code could not be retrieved. // Signal to the caller that something was wrong with the connection. throw new IOException("Could not retrieve response code from HttpUrlConnection."); } StatusLine responseStatus = new BasicStatusLine(protocolVersion, connection.getResponseCode(), connection.getResponseMessage()); BasicHttpResponse response = new BasicHttpResponse(responseStatus); response.setEntity(entityFromConnection(connection)); for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) { if (header.getKey() != null) { Header h = new BasicHeader(header.getKey(), header.getValue().get(0)); response.addHeader(h); } } if (ENCODING_GZIP.equalsIgnoreCase(connection.getContentEncoding())) { response.setEntity(new InflatingEntity(response.getEntity())); } return response; }
From source file:net.spfbl.whois.Domain.java
private static synchronized HashMap<String, Domain> getDomainMap() { HashMap<String, Domain> map = new HashMap<String, Domain>(); map.putAll(MAP); return map;/* w ww . j a v a 2 s . c o m*/ }
From source file:org.archive.modules.recrawl.BdbContentDigestHistory.java
public void load(CrawlURI curi) { // make this call in all cases so that the value is initialized and // WARCWriterProcessor knows it should put the info in there HashMap<String, Object> contentDigestHistory = curi.getContentDigestHistory(); @SuppressWarnings("unchecked") Map<String, Object> loadedHistory = store.get(persistKeyFor(curi)); if (loadedHistory != null) { if (logger.isLoggable(Level.FINER)) { logger.finer("loaded history by digest " + persistKeyFor(curi) + " for uri " + curi + " - " + loadedHistory);/*from ww w . j a v a 2s . c om*/ } contentDigestHistory.putAll(loadedHistory); } }
From source file:nl.uva.sne.extractors.JtopiaExtractor.java
@Override public Map<String, Double> termXtraction(String inDir) throws IOException { File dir = new File(inDir); TermsExtractor termExtractor = new TermsExtractor(); TermDocument topiaDoc = new TermDocument(); HashMap<String, Double> keywordsDictionaray = new HashMap(); int count = 0; if (dir.isDirectory()) { for (File f : dir.listFiles()) { if (FilenameUtils.getExtension(f.getName()).endsWith("txt")) { count++;/*from ww w . j a va2s . co m*/ Logger.getLogger(JtopiaExtractor.class.getName()).log(Level.INFO, "{0}: {1} of {2}", new Object[] { f.getName(), count, dir.list().length }); keywordsDictionaray.putAll(extractFromFile(f, termExtractor, topiaDoc)); } } } else if (dir.isFile()) { keywordsDictionaray.putAll(extractFromFile(dir, termExtractor, topiaDoc)); } return keywordsDictionaray; }
From source file:de.jwic.base.JWicRuntime.java
/** * Create a new SessionContext instance. * @param appProperties/*w w w. ja v a2 s .com*/ * @param locale * @param timeZone * @param request * @return */ private SessionContext setupSessionContext(IApplicationSetup appSetup, Locale locale, TimeZone timeZone, HttpServletRequest request) { log.debug("creating new SessionContext for application '" + appSetup.getName() + "'."); SessionContext sc = new SessionContext(appSetup, locale, timeZone); String clientID; if (request != null) { clientID = request.getSession().getId(); HashMap<String, String[]> parameters = new HashMap<String, String[]>(); parameters.putAll(Compatibility.getParameterMap(request)); sc.setInitParameters(parameters); } else { clientID = "test"; } sc.setClientId(clientID); IApplication app = appSetup.createApplication(); sc.setApplication(app); SessionContainer container = sessionManager.create(clientID, appSetup.getName()); boolean cleanUp = true; try { container.setSessionContext(sc); sc.setSessionId(container.getId()); sc.setUserAgent(new UserAgentInfo(request)); app.initialize(sc); Control root = app.createRootControl(sc); // push root control only if no control had been push during root creation if (sc.getTopControl() == null) { sc.pushTopControl(root); } sc.fireEvent(new SessionEvent(request == null ? null : Compatibility.getParameterMap(request)), SessionContext.SESSION_STARTED); cleanUp = false; } finally { if (cleanUp) { log.warn("Session was not created successfully!"); sessionManager.remove(container); } } return sc; }