public void run(String[] arg0) throws ActionException { try { boolean brokerActive = PrefsPropsUtil.getBoolean( PortletPropsKeys.MQTT_AUTO_CONNECT, PortletPropsValues.MQTT_AUTO_CONNECT); if (brokerActive) { MqttLocalServiceUtil.connect(); } } catch (SystemException | MqttException e) { _log.error(e); throw new ActionException(e); } }
@Override public void applySubscriptionsList() throws MqttException, SystemException { String[] subscriptions = PrefsPropsUtil.getStringArray( PortletPropsKeys.MQTT_SUBSCRIPTIONS_LIST, StringPool.NEW_LINE, PortletPropsValues.MQTT_SUBSCRIPTIONS_ARRAY); if (_getInstance().isConnected()) { String[] topics = ConfigUtil.properties2topic(subscriptions); int[] qos = ConfigUtil.properties2qos(subscriptions); for (int i = 0; i<topics.length; i++) { subscribe(topics[i], qos[i]); } } }
private void _noRetry() { try { PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(); portletPreferences.setValue( PortletPropsKeys.MQTT_ERRORS_RETRY_CONNECT, String.valueOf(false)); portletPreferences.store(); } catch (Exception e1) { _log.error(e1); } }
private void _setupRetry(Throwable e) { try { PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(); portletPreferences.setValue( PortletPropsKeys.MQTT_ERRORS_RETRY_CONNECT, String.valueOf(true)); portletPreferences.store(); } catch (Exception e1) { _log.error(e); } }
public String getNameInNamespace(long companyId, Binding binding) throws Exception { String baseDN = PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_BASE_DN); if (Validator.isNull(baseDN)) { return binding.getName(); } else { StringBuilder sb = new StringBuilder(); sb.append(binding.getName()); sb.append(StringPool.COMMA); sb.append(baseDN); return sb.toString(); } }
public static void sendInternal(String subject, String body, boolean isHtml) throws SystemException, AddressException, PortalException { Company cmp = null; try { cmp = CompanyServiceUtil.getCompanyByVirtualHost(AppConstants.COMPANY_VIRTUAL_HOST); } catch (Throwable t) { } if (cmp != null) { long cmpId = cmp.getCompanyId(); String toStr = PrefsPropsUtil.getString(cmpId, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS); send(toStr, subject, body, isHtml); } }
public static void send(String toStr, String subject, String body, boolean isHtml) throws SystemException, AddressException, PortalException { Company cmp = null; try { cmp = CompanyServiceUtil.getCompanyByVirtualHost(AppConstants.COMPANY_VIRTUAL_HOST); } catch (Throwable t) { } if (cmp != null) { long cmpId = cmp.getCompanyId(); String fromStr = PrefsPropsUtil.getString(cmpId, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS); InternetAddress from = new InternetAddress(fromStr); InternetAddress to = new InternetAddress(toStr); if (from != null && to != null && subject != null && body != null) { MailMessage message = new MailMessage(from, to, subject, body, isHtml); MailServiceUtil.sendEmail(message); } } }
private synchronized MqttClient _getInstance() throws MqttException, SystemException { if (_mqttClient == null) { String serverURI = PrefsPropsUtil.getString( PortletPropsKeys.MQTT_BROKER_URL, PortletPropsValues.MQTT_BROKER_URL); String clientID = PrefsPropsUtil.getString( PortletPropsKeys.MQTT_BROKER_CLIENTID, PortletPropsValues.MQTT_BROKER_CLIENTID); MemoryPersistence persistence = new MemoryPersistence(); _mqttClient = new MqttClient(serverURI, clientID, persistence); _mqttClient.setCallback(this); } return _mqttClient; }
/** * Gets the value for a given configuration key (or the default setting if not found) * This method may either access the portlet data-source for local settings or the portal properties for global configuration settings * * @param key the configuration key * @return the configuration value */ public static String getConfigValue(final E_ConfigKey key) { String value = null; if (key.isSystemProperty()) { try { value = PrefsPropsUtil.getString( PortalUtil.getDefaultCompanyId(), key.getSystemProperty()); // m_objLog.debug("Got portal property "+key.getSystemProperty()+" = "+value); } catch (final SystemException e) { value = key.getDefaultValue(); m_objLog.error(e); } } else { value = AHConfigLocalServiceUtil.getConfig(key.toString(), key.getDefaultValue()); m_objLog.info("Got portlet property "+key.toString()+" = "+value); } return value; }
/** * Send news update mail. * * @param sub the sub * @param offers the offers */ public void sendNewsUpdateMail(final AHSubscription sub, final List<AHOffer> offers) { try { final String addr = PrefsPropsUtil.getString( PortalUtil.getDefaultCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS); final InternetAddress from = new InternetAddress(addr); final InternetAddress to = new InternetAddress(sub.getEmail()); final String subj = CustomPortalServiceHandler .getConfigValue(E_ConfigKey.NEWS_UPDATE_SUBJ); final String body = CustomPortalServiceHandler .getConfigValue(E_ConfigKey.NEWS_UPDATE_BODY); this.sendNewsMail(from, to, subj, body, sub, offers); } catch (final Throwable t) { m_objLog.error(t); } }
@SuppressWarnings("unchecked") private static Map<String, Object> readConfiguration( String configurationFile) throws IOException, SystemException { ClassLoader classLoader = ConfigurationUtil.class.getClassLoader(); InputStream inputStream = classLoader.getResourceAsStream( configurationFile); String configuration = StringUtil.read(inputStream); String journalArticleIndexPrimaryKeyAttribute; if (PrefsPropsUtil.getBoolean("journal.articles.index.all.versions")) { journalArticleIndexPrimaryKeyAttribute = "pk"; } else { journalArticleIndexPrimaryKeyAttribute = "resourcePrimKey"; } configuration = configuration.replace( "$$JOURNAL_ARTICLE_INDEX_PRIMARY_KEY_ATTRIBUTE$$", journalArticleIndexPrimaryKeyAttribute); Yaml yaml = new Yaml(); return (Map<String, Object>)yaml.load(configuration); }
@Override public void messageArrived(String topic, MqttMessage message) throws Exception { Message mb = new Message(); mb.put("topic", topic); mb.put("qos", message.getQos()); mb.put("retained", message.isRetained()); String payload = new String(message.getPayload()); mb.setPayload(payload); MessageBusUtil.sendMessage( PortletPropsValues.MQTT_MESSAGES_DESTINATION, mb); boolean logInfo = PrefsPropsUtil.getBoolean( PortletPropsKeys.MQTT_EVENTS_LOGINFO, PortletPropsValues.MQTT_EVENTS_LOGINFO); if (logInfo) { _log.info(String.format("arrived [%s,%s,%s] %s", topic, message.getQos(), message.isRetained()?"R":"", payload)); } }
@Override public void publish(String topic, byte[] payload, int qos) throws MqttException, SystemException { _getInstance().publish(topic, payload, qos, false); boolean logInfo = PrefsPropsUtil.getBoolean( PortletPropsKeys.MQTT_EVENTS_LOGINFO, PortletPropsValues.MQTT_EVENTS_LOGINFO); if (logInfo) { _log.info(String.format("send [%s,%s] %s", topic, qos, payload)); } }
@Override public void resetSubscriptionsList() throws MqttException, SystemException { String[] subscriptions = PrefsPropsUtil.getStringArray( PortletPropsKeys.MQTT_SUBSCRIPTIONS_LIST, StringPool.NEW_LINE, PortletPropsValues.MQTT_SUBSCRIPTIONS_ARRAY); if (_getInstance().isConnected()) { String[] topics = ConfigUtil.properties2topic(subscriptions); _getInstance().unsubscribe(topics); } }
@Override public void subscribe(String topic, int qos) throws MqttException, SystemException { _getInstance().subscribe(topic, qos); boolean logInfo = PrefsPropsUtil.getBoolean( PortletPropsKeys.MQTT_EVENTS_LOGINFO, PortletPropsValues.MQTT_EVENTS_LOGINFO); if (logInfo) { _log.info("subscribe " + topic); } }
private void _notityMail(String context, Throwable e) { try { String errorMailTo = PrefsPropsUtil.getString( PortletPropsKeys.MQTT_ERRORS_SEND_MAIL_TO, PortletPropsValues.MQTT_ERRORS_SEND_MAIL_TO); if (Validator.isNotNull(errorMailTo)) { MailMessage mailMessage = new MailMessage(); long companyId = PortalUtil.getDefaultCompanyId(); String fromAddress = PrefsPropsUtil.getString( companyId, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS); mailMessage.setHTMLFormat(false); mailMessage.setTo(new InternetAddress(errorMailTo)); mailMessage.setSubject(String.format( "%s Mqtt connector error", PortalUtil.getComputerName())); mailMessage.setFrom(new InternetAddress(fromAddress)); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); mailMessage.setBody(String.format( "context: %s\nerror: %s\n stacktrace:%s\n", context, e.getMessage(), sw.toString())); MailServiceUtil.sendEmail(mailMessage); } } catch (Exception e1) { _log.error(e1); } }
public Binding getUser(long companyId, String screenName) throws Exception { LdapContext ctx = getContext(companyId); if (ctx == null) { return null; } String baseDN = PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_BASE_DN); Properties userMappings = getUserMappings(companyId); StringBuilder filter = new StringBuilder(); filter.append(StringPool.OPEN_PARENTHESIS); filter.append(userMappings.getProperty("screenName")); filter.append(StringPool.EQUAL); filter.append(screenName); filter.append(StringPool.CLOSE_PARENTHESIS); SearchControls cons = new SearchControls(SearchControls.SUBTREE_SCOPE, 1, 0, null, false, false); NamingEnumeration<SearchResult> enu = ctx.search(baseDN, filter.toString(), cons); //System.out.println("TTTTTTTTT " + baseDN + " --------- " + filter.toString() + " ==== " + cons + ""); ctx.close(); if (enu.hasMoreElements()) { Binding binding = enu.nextElement(); // System.out.println("TTTTTTTTT " + binding); return binding; } else { return null; } }
public boolean getIsZimbraLdap(long companyId){ boolean isZimbraLdap = false; try { isZimbraLdap = PrefsPropsUtil.getBoolean(LADAP_ZIMBRA); // System.out.println("hello dung " + isZimbraLdap); } catch (Exception e) { // System.out.println("hello sai "); isZimbraLdap = false; } return isZimbraLdap; }
public LdapContext getContext(long companyId) throws Exception { String baseProviderURL = PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_BASE_PROVIDER_URL); String pricipal = PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_SECURITY_PRINCIPAL); String credentials = PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_SECURITY_CREDENTIALS); return getContext(companyId, baseProviderURL, pricipal, credentials); }
public Binding getUser(LdapContext ctx, long companyId, String screenName) throws Exception { if (ctx == null) { return null; } String baseDN = PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_BASE_DN); Properties userMappings = getUserMappings(companyId); StringBuilder filter = new StringBuilder(); filter.append(StringPool.OPEN_PARENTHESIS); filter.append(userMappings.getProperty("screenName")); filter.append(StringPool.EQUAL); filter.append(screenName); filter.append(StringPool.CLOSE_PARENTHESIS); SearchControls cons = new SearchControls(SearchControls.SUBTREE_SCOPE, 1, 0, null, false, false); NamingEnumeration<SearchResult> enu = ctx.search(baseDN, filter.toString(), cons); ///System.out.println("TTTTTTTTT " + baseDN + " --------- " + filter.toString() + " ==== " + cons + ""); ctx.close(); if (enu.hasMoreElements()) { Binding binding = enu.nextElement(); // System.out.println("TTTTTTTTT " + binding); return binding; } else { return null; } }
public static void sendMail(String emailTo, String nameTo, String content[], long companyId, Locale userLocale) { try{ InternetAddress to = new InternetAddress(emailTo, nameTo); String portal = LanguageUtil.get(userLocale, "p2ptaskactivity.mail.portal"); String subject= LanguageUtil.get(userLocale, "p2ptaskactivity.mail.subject"); String bodyTitle = LanguageUtil.format(userLocale, "p2ptaskactivity.mail.body.title", nameTo); String bodyMessage = LanguageUtil.format(userLocale, "p2ptaskactivity.mail.body.message", content); String bodyEnd = LanguageUtil.get(userLocale, "p2ptaskactivity.mail.body.end"); String body = bodyTitle +"\n\n"+ bodyMessage +"\n\n"+ bodyEnd +"\n\n"+ portal+"\n"; log.debug("MESSAGE: "+bodyMessage); String fromName=PrefsPropsUtil.getString(companyId,PropsKeys.ADMIN_EMAIL_FROM_NAME,""); String fromAddress=PrefsPropsUtil.getString(companyId,PropsKeys.ADMIN_EMAIL_FROM_ADDRESS,""); InternetAddress from = new InternetAddress(fromAddress, fromName); MailMessage mailm = new MailMessage(from, to, subject, body, true); MailServiceUtil.sendEmail(mailm); } catch(Exception ex) { } }
@Override public String getSuffix(long groupId) { try { long cerotonvalue = PrefsPropsUtil.getLong(groupId, "ceroton-value",-1); if(cerotonvalue>0){ return "/" + cerotonvalue; } } catch (SystemException e) { e.printStackTrace(); } return ""; }
@Override public String translate(Locale locale, CourseResult result) { long cerotonvalue = -1; try { cerotonvalue = PrefsPropsUtil.getLong(CourseLocalServiceUtil.fetchCourse(result.getCourseId()).getGroupCreatedId() , "ceroton-value",-1); } catch (SystemException e) { e.printStackTrace(); } return translate(locale, (double)result.getResult(), cerotonvalue); }
@Override public String translate(Locale locale, ModuleResult result) { long cerotonvalue = -1; try { cerotonvalue = PrefsPropsUtil.getLong(ModuleLocalServiceUtil.fetchModule(result.getModuleId()).getGroupId() , "ceroton-value",-1); } catch (SystemException e) { e.printStackTrace(); } return translate(locale, (double)result.getResult(), cerotonvalue); }
@Override public String translate(Locale locale, LearningActivityResult result) { long cerotonvalue = -1; try { cerotonvalue = PrefsPropsUtil.getLong(LearningActivityLocalServiceUtil.fetchLearningActivity(result.getActId()).getGroupId() , "ceroton-value",-1); } catch (SystemException e) { e.printStackTrace(); } return translate(locale, (double)result.getResult(), cerotonvalue); }
@Override public String translate(Locale locale, long groupId, double result) { long cerotonvalue = -1; try { cerotonvalue = PrefsPropsUtil.getLong(groupId, "ceroton-value",-1); } catch (SystemException e) { e.printStackTrace(); } return translate(locale, result, cerotonvalue); }
@Override public long toBase100(long groupId,double result) { try { long cerotonvalue = PrefsPropsUtil.getLong(groupId, "ceroton-value",-1); if(cerotonvalue>0){ return (long) (result * 100 /cerotonvalue); } } catch (SystemException e) { e.printStackTrace(); } return (long) (result); }
@Override public long getMaxValue(long groupId) { try { return PrefsPropsUtil.getLong(groupId, "ceroton-value",0); } catch (SystemException e) { e.printStackTrace(); } return 0; }
private void sendEmail(String email, String subject, String body, boolean sendHtml) throws Exception { InternetAddress rcpt = new InternetAddress(email); InternetAddress from = new InternetAddress(PrefsPropsUtil.getString(LiferayUtil.getThemeDisplay().getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS)); MailMessage mailMessage = new MailMessage(); mailMessage.setBody(body); mailMessage.setHTMLFormat(sendHtml); mailMessage.setFrom(from); mailMessage.setTo(rcpt); mailMessage.setSubject(subject); MailServiceUtil.sendEmail(mailMessage); }
public static void sendEmailNotification(JSONObject payLoad, ServiceContext serviceContext) throws SystemException { if(Validator.isNotNull(payLoad)){ // String fromName = PrefsPropsUtil.getString(payLoad.getLong("companyId"), PropsKeys.ADMIN_EMAIL_FROM_NAME); String fromName = "MOBILINK Mail System"; String fromAddress = PrefsPropsUtil.getString(payLoad.getLong("companyId"), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS); String toName = payLoad.getString("toName"); String toAddress = payLoad.getString("toAddress"); String subject = payLoad.getString("subject"); String body = payLoad.getString("body"); SubscriptionSender subscriptionSender = new SubscriptionSender(); subscriptionSender.setBody(body); subscriptionSender.setCompanyId(serviceContext.getCompanyId()); subscriptionSender.setFrom(fromAddress, fromName); subscriptionSender.setHtmlFormat(true); subscriptionSender.setServiceContext(serviceContext); subscriptionSender.setSubject(subject); subscriptionSender.setUserId(payLoad.getLong("userId")); subscriptionSender.setMailId("user", payLoad.getLong("userId")); subscriptionSender.addRuntimeSubscribers(toAddress, toName); subscriptionSender.flushNotificationsAsync(); //SendUserNotification try { long toUserId = payLoad.getLong("toUserId"); long activityId = payLoad.getLong("activityId"); JSONObject payloadJSON = JSONFactoryUtil.createJSONObject(); payloadJSON.put("userId", payLoad.getLong("userId")); payloadJSON.put("toUserId", toUserId); payloadJSON.put("activityId", activityId); payloadJSON.put("contentNotification", payLoad.getString("contentNotification")); payloadJSON.put("subject", payLoad.getString("subject")); // if(toUserId == 0){ // List<Participant> listMParticipants = ParticipantLocalServiceUtil.findByF_activityId(activityId); // for (MParticipant mParticipant : listMParticipants) { // UserNotificationEventLocalServiceUtil.addUserNotificationEvent(mParticipant.getUserMappingId(), // ActivitiesConstants.MEETUP_MGT_CENTER, // (new Date()).getTime(), // mParticipant.getUserId(), // payloadJSON.toString(), // false, serviceContext); // } // }else{ // UserNotificationEventLocalServiceUtil.addUserNotificationEvent(toUserId, // ActivitiesConstants.MEETUP_MGT_CENTER, // (new Date()).getTime(), // payLoad.getLong("userId"), // payloadJSON.toString(), // false, serviceContext); // } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }