List of usage examples for java.util Properties putIfAbsent
@Override public synchronized Object putIfAbsent(Object key, Object value)
From source file:org.apache.samza.system.kafka.KafkaSystemAdmin.java
/** * Fetch stream properties for all intermediate streams. * * @param config kafka system config// www . j av a 2s.co m * @return a {@link Map} from {@code streamId} to stream {@link Properties} */ @VisibleForTesting static Map<String, Properties> getIntermediateStreamProperties(Config config) { Map<String, Properties> intermedidateStreamProperties = Collections.emptyMap(); ApplicationConfig appConfig = new ApplicationConfig(config); if (appConfig.getAppMode() == ApplicationConfig.ApplicationMode.BATCH) { StreamConfig streamConfig = new StreamConfig(config); intermedidateStreamProperties = JavaConverters.asJavaCollectionConverter(streamConfig.getStreamIds()) .asJavaCollection().stream().filter(streamConfig::getIsIntermediateStream) .collect(Collectors.toMap(Function.identity(), streamId -> { Properties properties = new Properties(); properties.putAll(streamConfig.getStreamProperties(streamId)); properties.putIfAbsent(TopicConfig.RETENTION_MS_CONFIG, String.valueOf(KafkaConfig.DEFAULT_RETENTION_MS_FOR_BATCH())); return properties; })); } return intermedidateStreamProperties; }
From source file:uk.ac.cam.cl.dtg.segue.comm.EmailManager.java
/** * Send an email to a user based on a content template. * * @param userDTO - the user to email// w w w . j a v a2 s.c om * @param emailContentTemplate - the content template to send to the user. * @param tokenToValueMapping - a Map of tokens to values that will be replaced in the email template. * @param emailType - the type of email that this is so that it is filtered appropriately based on user email prefs. * @throws ContentManagerException if we can't parse the content * @throws SegueDatabaseException if we cannot contact the database for logging. */ public void sendTemplatedEmailToUser(final RegisteredUserDTO userDTO, final EmailTemplateDTO emailContentTemplate, final Map<String, Object> tokenToValueMapping, final EmailType emailType) throws ContentManagerException, SegueDatabaseException { // generate properties from hashMap for token replacement process Properties propertiesToReplace = new Properties(); propertiesToReplace.putAll(this.flattenTokenMap(tokenToValueMapping, Maps.newHashMap(), "")); // Add all properties in the user DTO (preserving types) so they are available to email templates. Map userPropertiesMap = new org.apache.commons.beanutils.BeanMap(userDTO); propertiesToReplace.putAll(this.flattenTokenMap(userPropertiesMap, Maps.newHashMap(), "")); // default properties //TODO: We should find and replace this in templates as the case is wrong. propertiesToReplace.putIfAbsent("givenname", userDTO.getGivenName() == null ? "" : userDTO.getGivenName()); propertiesToReplace.putIfAbsent("sig", SIGNATURE); EmailCommunicationMessage emailCommunicationMessage = constructMultiPartEmail(userDTO.getId(), userDTO.getEmail(), emailContentTemplate, propertiesToReplace, emailType); if (emailType.equals(EmailType.SYSTEM)) { addSystemEmailToQueue(emailCommunicationMessage); } else { this.filterByPreferencesAndAddToQueue(userDTO, emailCommunicationMessage); } }
From source file:uk.ac.cam.cl.dtg.segue.comm.EmailManager.java
/** * This method loads the HTML and plain text templates and returns the resulting EmailCommunicationMessage. * //from ww w .ja v a2 s. c o m * @param userId * - (nullable) the id of the user the email should be sent to * @param userEmail * - the email of the user * @param emailType * - the type of e-mail being created * @return * - a multi-part EmailCommunicationMessage * @throws ContentManagerException * - if there has been an error accessing content * @throws ResourceNotFoundException * - if the resource has not been found * */ public EmailCommunicationMessage constructMultiPartEmail(@Nullable final Long userId, final String userEmail, EmailTemplateDTO emailContent, Properties contentProperties, final EmailType emailType) throws ContentManagerException, ResourceNotFoundException { Validate.notNull(userEmail); Validate.notEmpty(userEmail); contentProperties.putIfAbsent("sig", SIGNATURE); String plainTextContent = completeTemplateWithProperties(emailContent.getPlainTextContent(), contentProperties); String HTMLContent = completeTemplateWithProperties(emailContent.getHtmlContent(), contentProperties, true); String replyToAddress = emailContent.getReplyToEmailAddress(); String replyToName = emailContent.getReplyToName(); if (replyToAddress == null || replyToAddress.isEmpty()) { replyToAddress = globalProperties.getProperty(Constants.REPLY_TO_ADDRESS); replyToName = globalProperties.getProperty(Constants.MAIL_NAME); } ContentDTO htmlTemplate = getContentDTO("email-template-html"); ContentDTO plainTextTemplate = getContentDTO("email-template-ascii"); Properties htmlTemplateProperties = new Properties(); htmlTemplateProperties.put("content", HTMLContent); htmlTemplateProperties.put("email", userEmail); String htmlMessage = completeTemplateWithProperties(htmlTemplate.getValue(), htmlTemplateProperties, true); Properties plainTextTemplateProperties = new Properties(); plainTextTemplateProperties.put("content", plainTextContent); plainTextTemplateProperties.put("email", userEmail); String plainTextMessage = completeTemplateWithProperties(plainTextTemplate.getValue(), plainTextTemplateProperties); return new EmailCommunicationMessage(userId, userEmail, emailContent.getSubject(), plainTextMessage, htmlMessage, emailType, replyToAddress, replyToName); }