Search in sources :

Example 1 with MicroblogProfile

use of org.opennms.netmgt.config.microblog.MicroblogProfile in project opennms by OpenNMS.

the class DefaultMicroblogConfigurationDao method saveProfile.

public void saveProfile(final MicroblogProfile profile) throws IOException {
    reloadConfiguration();
    final MicroblogConfiguration config = getContainer().getObject();
    boolean found = false;
    final ListIterator<MicroblogProfile> it = config.getMicroblogProfiles().listIterator();
    while (it.hasNext()) {
        final MicroblogProfile existing = it.next();
        if (existing.getName().equals(profile.getName())) {
            found = true;
            it.set(profile);
            break;
        }
    }
    if (!found)
        config.addMicroblogProfile(profile);
    final File file = getContainer().getFile();
    if (file == null) {
        LOG.warn("No file associated with this config.  Skipping marshal.");
        return;
    }
    FileWriter writer = null;
    try {
        writer = new FileWriter(file);
        JaxbUtils.marshal(config, writer);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
Also used : MicroblogProfile(org.opennms.netmgt.config.microblog.MicroblogProfile) FileWriter(java.io.FileWriter) File(java.io.File) MicroblogConfiguration(org.opennms.netmgt.config.microblog.MicroblogConfiguration)

Example 2 with MicroblogProfile

use of org.opennms.netmgt.config.microblog.MicroblogProfile in project opennms by OpenNMS.

the class MicroblogClient method saveAccessToken.

private void saveAccessToken(final String profile, final AccessToken token) throws IOException {
    final MicroblogProfile mp = getProfile(profile);
    mp.setOauthAccessToken(token.getToken());
    mp.setOauthAccessTokenSecret(token.getTokenSecret());
    m_configDao.saveProfile(mp);
}
Also used : MicroblogProfile(org.opennms.netmgt.config.microblog.MicroblogProfile)

Example 3 with MicroblogProfile

use of org.opennms.netmgt.config.microblog.MicroblogProfile in project opennms by OpenNMS.

the class MicroblogClient method getTwitter.

public Twitter getTwitter(final String profile) {
    final MicroblogProfile mp = getProfile(profile);
    final ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setClientURL(mp.getServiceUrl());
    if (!isEmpty(mp.getOauthConsumerKey()))
        builder.setOAuthConsumerKey(mp.getOauthConsumerKey().orElse(null));
    if (!isEmpty(mp.getOauthConsumerSecret()))
        builder.setOAuthConsumerSecret(mp.getOauthConsumerSecret().orElse(null));
    if (!isEmpty(mp.getOauthAccessToken()))
        builder.setOAuthAccessToken(mp.getOauthAccessToken().orElse(null));
    if (!isEmpty(mp.getOauthAccessTokenSecret()))
        builder.setOAuthAccessTokenSecret(mp.getOauthAccessTokenSecret().orElse(null));
    if (!isEmpty(mp.getAuthenUsername()))
        builder.setUser(mp.getAuthenUsername().orElse(null));
    if (!isEmpty(mp.getAuthenPassword()))
        builder.setPassword(mp.getAuthenPassword().orElse(null));
    return new TwitterFactory(builder.build()).getInstance();
}
Also used : ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) MicroblogProfile(org.opennms.netmgt.config.microblog.MicroblogProfile) TwitterFactory(twitter4j.TwitterFactory)

Aggregations

MicroblogProfile (org.opennms.netmgt.config.microblog.MicroblogProfile)3 File (java.io.File)1 FileWriter (java.io.FileWriter)1 MicroblogConfiguration (org.opennms.netmgt.config.microblog.MicroblogConfiguration)1 TwitterFactory (twitter4j.TwitterFactory)1 ConfigurationBuilder (twitter4j.conf.ConfigurationBuilder)1