Micha Kops avatar Micha Kops committed 6278e36

Configuration interface added

Comments (0)

Files changed (9)

 	<parent>
 		<groupId>com.atlassian.confluence.plugin.base</groupId>
 		<artifactId>confluence-plugin-base</artifactId>
-		<version>25</version>
+		<version>26</version>
 	</parent>
 
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>com.hascode.confluence.plugin</groupId>
 	<artifactId>social-comments-plugin</artifactId>
-	<version>0.9.1</version>
+	<version>0.9.5</version>
 	<name>Confluence Social Comments Plugin</name>
 	<description>Allows you to notify Confluence users by typing @username: in a comment</description>
 	<packaging>atlassian-plugin</packaging>
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-api</artifactId>
 			<version>1.6.1</version>
+			<scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-log4j12</artifactId>
 			<version>1.6.1</version>
+			<scope>provided</scope>
 		</dependency>
 		<dependency>
 			<groupId>junit</groupId>

src/main/java/com/hascode/confluence/plugin/socialcomments/action/ConfigureAction.java

 					addActionError(error.getMessage());
 				}
 			}
+		} else {
+			final Set<ConstraintViolation<SocialCommentsConfiguration>> errors = configurationService.validate(config);
+			for (final ConstraintViolation<SocialCommentsConfiguration> error : errors) {
+				addActionError(error.getMessage());
+			}
 		}
 
 		return OK;

src/main/java/com/hascode/confluence/plugin/socialcomments/config/SocialCommentsConfiguration.java

 	private static final long	serialVersionUID	= 1L;
 
 	@NotNull(message = "{com.hascode.socialcomments.validation.from.invalid}")
-	@Pattern(regexp = "^.+@.+\\..+ $", message = "{com.hascode.socialcomments.validation.from.invalid}")
+	@Pattern(regexp = "^.+@.+\\..+$", message = "{com.hascode.socialcomments.validation.from.invalid}")
 	private String				fromEmail;
 
 	@NotNull(message = "{com.hascode.socialcomments.validation.notification.invalid}")

src/main/java/com/hascode/confluence/plugin/socialcomments/event/CommentEventListenerImpl.java

 				socialNotificationService.notifyUser(user, comment);
 			}
 		} catch (final Exception e) {
-			logger.error("handling social comment failed!", e);
+			logger.warn("handling social comment failed!", e);
 		}
 	}
 	/*

src/main/java/com/hascode/confluence/plugin/socialcomments/persistence/SocialCommentsConfigurationServiceImpl.java

 
 import org.hibernate.validator.HibernateValidator;
 
+import com.atlassian.bandana.BandanaManager;
+import com.atlassian.confluence.setup.bandana.ConfluenceBandanaContext;
 import com.hascode.confluence.plugin.socialcomments.config.SocialCommentsConfiguration;
 
 public class SocialCommentsConfigurationServiceImpl implements SocialCommentsConfigurationService {
 	/**
+	 * the key the bandana data is stored at
+	 */
+	private static final String		BANDANA_KEY	= "com.hascode.confluence.plugin.socialcomments.config";
+
+	/**
 	 * the validator instance
 	 */
-	private static Validator	validator;
+	private static Validator		validator;
 	static {
 		final Configuration<?> config = Validation.byDefaultProvider().providerResolver(new ValidationProviderResolver() {
 			@Override
 		validator = factory.getValidator();
 	}
 
+	/**
+	 * the bandana manager
+	 */
+	private final BandanaManager	bandanaManager;
+
+	public SocialCommentsConfigurationServiceImpl(final BandanaManager bandanaManager) {
+		this.bandanaManager = bandanaManager;
+	}
+
 	/*
 	 * (non-Javadoc)
 	 * 
 	 */
 	@Override
 	public void saveOrUpdate(final SocialCommentsConfiguration config) {
-		// TODO Auto-generated method stub
+		bandanaManager.setValue(new ConfluenceBandanaContext(), BANDANA_KEY, config);
 
 	}
 
 	 */
 	@Override
 	public SocialCommentsConfiguration load() {
-		return new SocialCommentsConfiguration();
+		SocialCommentsConfiguration config = (SocialCommentsConfiguration) bandanaManager.getValue(new ConfluenceBandanaContext(), BANDANA_KEY);
+		if (config == null) {
+			config = new SocialCommentsConfiguration();
+		}
+		return config;
 	}
 
 }

src/main/java/com/hascode/confluence/plugin/socialcomments/service/SocialNotificationServiceImpl.java

 import com.atlassian.confluence.setup.settings.SettingsManager;
 import com.atlassian.mail.MailException;
 import com.atlassian.user.User;
+import com.hascode.confluence.plugin.socialcomments.config.SocialCommentsConfiguration;
+import com.hascode.confluence.plugin.socialcomments.persistence.SocialCommentsConfigurationService;
 
 public class SocialNotificationServiceImpl implements SocialNotificationService {
 	/**
+	 * the email's mime type
+	 */
+	private static final String							MIME_TYPE	= "text/plain";
+
+	/**
 	 * the logger instance
 	 */
-	private final Logger			logger	= Logger.getLogger(SocialNotificationService.class);
+	private final Logger								logger		= Logger.getLogger(SocialNotificationService.class);
 
 	/**
 	 * the settings manager
 	 */
-	private final SettingsManager	settingsManager;
+	private final SettingsManager						settingsManager;
 
-	public SocialNotificationServiceImpl(final SettingsManager settingsManager) {
+	/**
+	 * the config dao
+	 */
+	private final SocialCommentsConfigurationService	configService;
+
+	public SocialNotificationServiceImpl(final SettingsManager settingsManager, final SocialCommentsConfigurationService configService) {
 		this.settingsManager = settingsManager;
+		this.configService = configService;
 	}
 
 	/*
 	 */
 	@Override
 	public void notifyUser(final User user, final Comment comment) {
-		final String subject = "Social Comment Notification";
+		final SocialCommentsConfiguration config = configService.load();
+		if (!configService.validate(config).isEmpty()) {
+			logger.warn("social comments configuration is not validated. please adjust your settings in the admin area!");
+			return;
+		}
+
 		final String body = generateMailBody(user, comment);
-		final String mimeType = "text/plain";
-		final String fromName = "test@test.com";
-
-		final ConfluenceMailQueueItem mailItem = new ConfluenceMailQueueItem(user.getEmail(), subject, body, mimeType);
-		mailItem.setFromName(fromName);
+		final ConfluenceMailQueueItem mailItem = new ConfluenceMailQueueItem(user.getEmail(), config.getEmailSubject(), body, MIME_TYPE);
+		mailItem.setFromName(config.getFromEmail());
 		logger.debug("trying to send mail: " + mailItem.toString());
 
 		try {
 		}
 
 	}
-
 	/**
 	 * generates the mail body
 	 * 
 	 * @return the generated mail body
 	 */
 	private String generateMailBody(final User user, final Comment comment) {
+		final SocialCommentsConfiguration config = configService.load();
 		final String url = settingsManager.getGlobalSettings().getBaseUrl() + comment.getUrlPath();
-		return String.format("Dear %s,\nsomeone wanted to notify you about the following wiki comment: \n\n%s", user.getFullName(), url);
+		final String userName = user.getFullName();
+
+		String body = config.getNotificationText();
+		body = body.replaceAll("#name#", userName);
+		body = body.replaceAll("#url#", url);
+		return body;
 	}
 
 }

src/main/resources/atlassian-plugin.xml

 		<description>${project.description}</description>
 		<version>${project.version}</version>
 		<vendor name="${project.organization.name}" url="${project.organization.url}" />
-		<param name="configure.url">$req.getContextPath()/plugins/socialcomments/configure.action</param>
+		<param name="configure.url">/plugins/socialcomments/configure.action</param>
 	</plugin-info>
 
 	<!-- COMPONENTS -->

src/main/resources/plugins/socialcomments/configuration.vm

 			    -moz-border-radius: 15px 15px 15px 15px;
 			    padding: 20px;
 			}
+			#socialcomments-notification {
+				height:150px;
+				width:400px;
+			}
 			</style>
         
                 <h1>$action.getText("socialcomments.msg.configuration")</h1>
 	                				<tr>
 	                					<th>$action.getText("socialcomments.msg.notification")</th>
 	                					<td>
-	                						<textarea name="notification">$!socialCommentConfig.getNotificationText()</textarea><br/>
+	                						<textarea name="notification" id="socialcomments-notification">$!socialCommentConfig.getNotificationText()</textarea><br/>
 	                						<small>$action.getText("socialcomments.msg.notification.hint")</small><br/>
 	                						<small>$action.getText("socialcomments.msg.notification.example")</small>
 	                					</td>

src/test/java/com/hascode/confluence/plugin/socialcomments/service/SocialNotificationServiceTest.java

 import com.atlassian.confluence.setup.settings.Settings;
 import com.atlassian.confluence.setup.settings.SettingsManager;
 import com.atlassian.user.User;
+import com.hascode.confluence.plugin.socialcomments.persistence.SocialCommentsConfigurationService;
 
 @RunWith(PowerMockRunner.class)
 @PrepareForTest(ConfluenceMailQueueItem.class)
 public class SocialNotificationServiceTest {
 	@Mock
-	private SettingsManager	settingsManager;
+	private SettingsManager						settingsManager;
 
 	@Mock
-	private User			user;
+	private User								user;
 
 	@Mock
-	private Comment			comment;
+	private Comment								comment;
 
 	@Mock
-	private Settings		settings;
+	private Settings							settings;
+
+	@Mock
+	private SocialCommentsConfigurationService	configService;
 
 	@Before
 	public void setUp() {
 		PowerMockito.mock(ConfluenceMailQueueItem.class);
 
 		// init
-		final SocialNotificationService service = new SocialNotificationServiceImpl(settingsManager);
+		final SocialNotificationService service = new SocialNotificationServiceImpl(settingsManager, configService);
 
 		// test
 		service.notifyUser(user, comment);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.