public ProjectNotifier addNotifier( int projectId, ProjectNotifier notifier ) throws ContinuumException { ProjectNotifier notif = new ProjectNotifier(); notif.setSendOnSuccess( notifier.isSendOnSuccess() ); notif.setSendOnFailure( notifier.isSendOnFailure() ); notif.setSendOnError( notifier.isSendOnError() ); notif.setSendOnWarning( notifier.isSendOnWarning() ); notif.setConfiguration( notifier.getConfiguration() ); notif.setType( notifier.getType() ); notif.setFrom( ProjectNotifier.FROM_USER ); Project project = getProjectWithAllDetails( projectId ); project.addNotifier( notif ); updateProject( project ); return notif; }
private List<ProjectNotifier> getProjectNotifiers( Map<String, Object> context ) { List<ProjectNotifier> projectNotifiers = new ArrayList<ProjectNotifier>(); List<Map<String, Object>> notifiers = ContinuumBuildConstant.getProjectNotifiers( context ); if ( notifiers != null ) { for ( Map<String, Object> map : notifiers ) { ProjectNotifier notifier = new ProjectNotifier(); notifier.setConfiguration( ContinuumBuildConstant.getNotifierConfiguration( map ) ); notifier.setEnabled( ContinuumBuildConstant.isNotifierEnabled( map ) ); notifier.setFrom( ContinuumBuildConstant.getNotifierFrom( map ) ); notifier.setRecipientType( ContinuumBuildConstant.getNotifierRecipientType( map ) ); notifier.setSendOnError( ContinuumBuildConstant.isNotifierSendOnError( map ) ); notifier.setSendOnFailure( ContinuumBuildConstant.isNotifierSendOnFailure( map ) ); notifier.setSendOnScmFailure( ContinuumBuildConstant.isNotifierSendOnScmFailure( map ) ); notifier.setSendOnSuccess( ContinuumBuildConstant.isNotifierSendOnSuccess( map ) ); notifier.setSendOnWarning( ContinuumBuildConstant.isNotifierSendOnWarning( map ) ); notifier.setType( ContinuumBuildConstant.getNotifierType( map ) ); projectNotifiers.add( notifier ); } } return projectNotifiers; }
protected static List<ProjectNotifier> createMailNotifierList( String emailAddress ) { if ( emailAddress == null ) { return null; } ProjectNotifier notifier = new ProjectNotifier(); notifier.setType( "mail" ); Properties props = new Properties(); props.put( "address", emailAddress ); notifier.setConfiguration( props ); List<ProjectNotifier> notifiers = new ArrayList<ProjectNotifier>(); notifiers.add( notifier ); return notifiers; }
private void getProjectGroupNotifiers( ProjectGroup projectGroup, Map<String, List<ProjectNotifier>> notifiersMap ) { // perform the project group level notifications if ( projectGroup.getNotifiers() != null ) { for ( ProjectNotifier projectNotifier : (List<ProjectNotifier>) projectGroup.getNotifiers() ) { List<ProjectNotifier> projectNotifiers = notifiersMap.get( projectNotifier.getType() ); if ( projectNotifiers == null ) { projectNotifiers = new ArrayList<ProjectNotifier>(); } if ( !projectNotifier.isEnabled() ) { log.info( projectNotifier.getType() + " projectNotifier (id=" + projectNotifier.getId() + ") is disabled." ); continue; } projectNotifiers.add( projectNotifier ); notifiersMap.put( projectNotifier.getType(), projectNotifiers ); } } } }
if ( notifier.isFromUser() ) ProjectNotifier userNotifier = new ProjectNotifier(); userNotifier.setType( notifier.getType() ); userNotifier.setEnabled( notifier.isEnabled() ); userNotifier.setConfiguration( notifier.getConfiguration() ); userNotifier.setFrom( notifier.getFrom() ); userNotifier.setRecipientType( notifier.getRecipientType() ); userNotifier.setSendOnError( notifier.isSendOnError() ); userNotifier.setSendOnFailure( notifier.isSendOnFailure() ); userNotifier.setSendOnSuccess( notifier.isSendOnSuccess() ); userNotifier.setSendOnWarning( notifier.isSendOnWarning() ); userNotifier.setSendOnScmFailure( notifier.isSendOnScmFailure() );
if ( notifier.getConfiguration() != null ) map.put( ContinuumBuildAgentUtil.KEY_NOTIFIER_CONFIGURATION, notifier.getConfiguration() ); if ( StringUtils.isNotBlank( notifier.getType() ) ) map.put( ContinuumBuildAgentUtil.KEY_NOTIFIER_TYPE, notifier.getType() ); map.put( ContinuumBuildAgentUtil.KEY_NOTIFIER_FROM, notifier.getFrom() ); map.put( ContinuumBuildAgentUtil.KEY_NOTIFIER_RECIPIENT_TYPE, notifier.getRecipientType() ); map.put( ContinuumBuildAgentUtil.KEY_NOTIFIER_ENABLED, notifier.isEnabled() ); map.put( ContinuumBuildAgentUtil.KEY_NOTIFIER_SEND_ON_ERROR, notifier.isSendOnError() ); map.put( ContinuumBuildAgentUtil.KEY_NOTIFIER_SEND_ON_SUCCESS, notifier.isSendOnSuccess() ); map.put( ContinuumBuildAgentUtil.KEY_NOTIFIER_SEND_ON_FAILURE, notifier.isSendOnFailure() ); map.put( ContinuumBuildAgentUtil.KEY_NOTIFIER_SEND_ON_SCMFAILURE, notifier.isSendOnScmFailure() ); map.put( ContinuumBuildAgentUtil.KEY_NOTIFIER_SEND_ON_WARNING, notifier.isSendOnWarning() ); pNotifiers.add( map );
throws IOException, XMLStreamException ProjectNotifier projectNotifier = new ProjectNotifier(); projectNotifier.setModelEncoding( encoding ); java.util.Set parsed = new java.util.HashSet(); while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT ) projectNotifier.setId( getIntegerValue( getTrimmedValue( xmlStreamReader.getElementText()), "id", xmlStreamReader, strict ) ); projectNotifier.setType( getTrimmedValue( xmlStreamReader.getElementText()) ); projectNotifier.setFrom( getIntegerValue( getTrimmedValue( xmlStreamReader.getElementText()), "from", xmlStreamReader, strict ) ); projectNotifier.setEnabled( getBooleanValue( getTrimmedValue( xmlStreamReader.getElementText()), "enabled", xmlStreamReader ) ); projectNotifier.setRecipientType( getIntegerValue( getTrimmedValue( xmlStreamReader.getElementText()), "recipientType", xmlStreamReader, strict ) ); projectNotifier.setSendOnSuccess( getBooleanValue( getTrimmedValue( xmlStreamReader.getElementText()), "sendOnSuccess", xmlStreamReader ) ); projectNotifier.setSendOnFailure( getBooleanValue( getTrimmedValue( xmlStreamReader.getElementText()), "sendOnFailure", xmlStreamReader ) ); projectNotifier.setSendOnError( getBooleanValue( getTrimmedValue( xmlStreamReader.getElementText()), "sendOnError", xmlStreamReader ) ); projectNotifier.setSendOnWarning( getBooleanValue( getTrimmedValue( xmlStreamReader.getElementText()), "sendOnWarning", xmlStreamReader ) ); .trim() projectNotifier.addConfiguration( key, value );
projectNotifier = new ProjectNotifier(); if ( build.getState() == ContinuumProjectState.FAILED && projectNotifier.isSendOnFailure() ) if ( build.getState() == ContinuumProjectState.ERROR && projectNotifier.isSendOnError() ) return projectNotifier.isSendOnError(); return projectNotifier.isSendOnFailure(); return projectNotifier.isSendOnSuccess(); return build.getState() != ContinuumProjectState.WARNING || projectNotifier.isSendOnWarning(); return projectNotifier.isSendOnError(); return projectNotifier.isSendOnFailure(); return projectNotifier.isSendOnSuccess(); return build.getState() != ContinuumProjectState.WARNING || projectNotifier.isSendOnWarning();
ProjectNotifier notifier = new ProjectNotifier(); notifier.setConfiguration( props ); notifier.setFrom( ProjectNotifier.FROM_PROJECT ); if ( notif.isFromUser() )
private void sendNotification( String messageId, ProjectNotifier projectNotifier, Map context ) { String notifierType = projectNotifier.getType(); if ( !projectNotifier.isEnabled() ) { getLogger().info( notifierType + " notifier (id=" + projectNotifier.getId() + ") is disabled." ); return; } Map configuration = projectNotifier.getConfiguration(); try { context.put( CONTEXT_PROJECT_NOTIFIER, projectNotifier ); Notifier notifier = notifierManager.getNotifier( notifierType ); Set recipients = recipientSource.getRecipients( String.valueOf( projectNotifier.getId() ), messageId, configuration, context ); notifier.sendNotification( messageId, recipients, configuration, context ); } catch ( NotificationException e ) { getLogger().error( "Error while trying to use the " + notifierType + " notifier.", e ); } } }
/** * Method addConfiguration * * @param key * @param value */ public void addConfiguration(Object key, String value) { getConfiguration().put( key, value ); } //-- void addConfiguration(Object, String)
public void assertProjectEquals( String name, List notifiers, String version, Project actual ) { assertEquals( "project.name", name, actual.getName() ); // assertEquals( "project.scmUrl", scmUrl, actual.getScmUrl() ); if ( notifiers != null ) { assertNotNull( "project.notifiers", actual.getNotifiers() ); assertEquals( "project.notifiers.size", notifiers.size(), actual.getNotifiers().size() ); for ( int i = 0; i < notifiers.size(); i++ ) { ProjectNotifier notifier = (ProjectNotifier) notifiers.get( i ); ProjectNotifier actualNotifier = (ProjectNotifier) actual.getNotifiers().get( i ); assertEquals( "project.notifiers.notifier.type", notifier.getType(), actualNotifier.getType() ); assertEquals( "project.notifiers.notifier.configuration.address", notifier.getConfiguration().get( "address" ), actualNotifier.getConfiguration().get( "address" ) ); } } assertEquals( "project.version", version, actual.getVersion() ); }
public boolean shouldNotify( ProjectScmRoot projectScmRoot, ProjectNotifier projectNotifier ) { if ( projectNotifier == null ) { projectNotifier = new ProjectNotifier(); } return projectScmRoot != null && ( alwaysSend || projectScmRoot.getState() == ContinuumProjectState.ERROR && projectNotifier.isSendOnScmFailure() && projectScmRoot.getOldState() != projectScmRoot.getState() ); }
if ( notifier.getId() == Integer.parseInt( notifierId ) && notifier.getConfiguration().containsKey( ADDRESS_FIELD ) )
public void removeNotifier( int projectId, int notifierId ) throws ContinuumException { Project project = getProjectWithAllDetails( projectId ); ProjectNotifier n = getNotifier( projectId, notifierId ); if ( n != null ) { if ( n.isFromProject() ) { n.setEnabled( false ); storeNotifier( n ); } else { project.removeNotifier( n ); updateProject( project ); } } }
private void sendNotification( String messageId, MessageContext context ) { String notifierType = context.getNotifiers().get( 0 ).getType(); try { Notifier notifier = notifierManager.getNotifier( notifierType ); notifier.sendMessage( messageId, context ); } catch ( NotificationException e ) { log.error( "Error while trying to use the " + notifierType + " notifier.", e ); } }
if ( notifier.isFromUser() ) ProjectNotifier userNotifier = new ProjectNotifier(); userNotifier.setType( notifier.getType() ); userNotifier.setEnabled( notifier.isEnabled() ); userNotifier.setConfiguration( notifier.getConfiguration() ); userNotifier.setFrom( notifier.getFrom() ); userNotifier.setRecipientType( notifier.getRecipientType() ); userNotifier.setSendOnError( notifier.isSendOnError() ); userNotifier.setSendOnFailure( notifier.isSendOnFailure() ); userNotifier.setSendOnSuccess( notifier.isSendOnSuccess() ); userNotifier.setSendOnWarning( notifier.isSendOnWarning() );
if ( projectNotifier.getId() != 0 ) serializer.writeCharacters( String.valueOf( projectNotifier.getId() ) ); serializer.writeEndElement(); if ( projectNotifier.getType() != null && !projectNotifier.getType().equals( "mail" ) ) serializer.writeCharacters( projectNotifier.getType() ); serializer.writeEndElement(); if ( projectNotifier.getFrom() != 0 ) serializer.writeCharacters( String.valueOf( projectNotifier.getFrom() ) ); serializer.writeEndElement(); if ( projectNotifier.isEnabled() != true ) serializer.writeCharacters( String.valueOf( projectNotifier.isEnabled() ) ); serializer.writeEndElement(); if ( projectNotifier.getRecipientType() != 0 ) serializer.writeCharacters( String.valueOf( projectNotifier.getRecipientType() ) ); serializer.writeEndElement(); if ( projectNotifier.isSendOnSuccess() != true ) serializer.writeCharacters( String.valueOf( projectNotifier.isSendOnSuccess() ) ); serializer.writeEndElement();
throws IOException, XMLStreamException ProjectNotifier projectNotifier = new ProjectNotifier(); java.util.Set parsed = new java.util.HashSet(); while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT ) projectNotifier.setId( getIntegerValue( getTrimmedValue( getDefaultValue( xmlStreamReader.getElementText(), "0" ) ), "id", xmlStreamReader, strict ) ); projectNotifier.setType( getTrimmedValue( getDefaultValue( xmlStreamReader.getElementText(), "mail" ) ) ); projectNotifier.setFrom( getIntegerValue( getTrimmedValue( getDefaultValue( xmlStreamReader.getElementText(), "0" ) ), "from", xmlStreamReader, strict ) ); projectNotifier.setEnabled( getBooleanValue( getTrimmedValue( getDefaultValue( xmlStreamReader.getElementText(), "true" ) ), "enabled", xmlStreamReader ) ); projectNotifier.setRecipientType( getIntegerValue( getTrimmedValue( getDefaultValue( xmlStreamReader.getElementText(), "0" ) ), "recipientType", xmlStreamReader, strict ) ); projectNotifier.setSendOnSuccess( getBooleanValue( getTrimmedValue( getDefaultValue( xmlStreamReader.getElementText(), "true" ) ), "sendOnSuccess", xmlStreamReader ) ); projectNotifier.setSendOnFailure( getBooleanValue( getTrimmedValue( getDefaultValue( xmlStreamReader.getElementText(), "true" ) ), "sendOnFailure", xmlStreamReader ) ); projectNotifier.setSendOnError( getBooleanValue( getTrimmedValue( getDefaultValue( xmlStreamReader.getElementText(), "true" ) ), "sendOnError", xmlStreamReader ) ); projectNotifier.setSendOnWarning( getBooleanValue( getTrimmedValue( getDefaultValue( xmlStreamReader.getElementText(), "true" ) ), "sendOnWarning", xmlStreamReader ) ); projectNotifier.addConfiguration( key, value ); projectNotifier.setSendOnScmFailure( getBooleanValue( getTrimmedValue( getDefaultValue( xmlStreamReader.getElementText(), "false" ) ), "sendOnScmFailure", xmlStreamReader ) );