private void onRCCreationSuccess(BpmNotificationRest notification, BuildConfigurationRest buildConfigurationRest) {
        LOG.debug("Received BPM event RC_CREATION_SUCCESS: " + notification);

        BpmStringMapNotificationRest repositoryCreationTaskResult = (BpmStringMapNotificationRest) notification;

        int repositoryConfigurationId = -1;
        int buildConfigurationSavedId = -1;
        try {
            repositoryConfigurationId = Integer.valueOf(repositoryCreationTaskResult.getData().get("repositoryConfigurationId"));
        } catch (NumberFormatException ex) {
            String errorMessage = "Receive notification about successful BC creation '" + repositoryCreationTaskResult
                    + "' but the ID of the newly created RC '" + repositoryCreationTaskResult.getData()
                    .get("repositoryConfigurationId")
                    + "' is not a number. It should be present under 'repositoryConfigurationId' key.";

            LOG.error(errorMessage, ex);
            sendErrorMessage(repositoryConfigurationId, buildConfigurationSavedId, errorMessage);
            return;
        }

        RepositoryConfiguration repositoryConfiguration = repositoryConfigurationRepository.queryById(repositoryConfigurationId);
        if (repositoryConfiguration == null) {
            String errorMessage = "Repository Configuration was not found in database.";
            LOG.error(errorMessage);
            sendErrorMessage(repositoryConfigurationId, buildConfigurationSavedId, errorMessage);
            return;
        }

        if (buildConfigurationRest != null) { //TODO test me
            BuildConfiguration buildConfiguration = buildConfigurationRest.toDBEntityBuilder()
                    .repositoryConfiguration(repositoryConfiguration)
                    .build();
            BuildConfiguration buildConfigurationSaved = buildConfigurationRepository.save(buildConfiguration);
            buildConfigurationSavedId = buildConfigurationSaved.getId();

            Set<Integer> bcSetIds = buildConfigurationRest.getBuildConfigurationSetIds();
            try {
                if (bcSetIds != null) {
                    addBuildConfigurationToSet(buildConfigurationSaved, bcSetIds);
                }
            } catch (Exception e) {
                LOG.error(e.getMessage());
                sendErrorMessage(repositoryConfigurationId, buildConfigurationSavedId, e.getMessage());
                return;
            }
        }

        RepositoryCreationResultRest repositoryCreationResultRest
                = new RepositoryCreationResultRest(
                        repositoryConfigurationId,
                        buildConfigurationSavedId,
                        RepositoryCreationResultRest.EventType.RC_CREATION_SUCCESS,
                        null);

        wsNotifier.sendMessage(repositoryCreationResultRest); //TODO test me!
    }
private void onRCCreationSuccess(BpmNotificationRest notification, BuildConfigurationRest buildConfigurationRest) {
        LOG.debug("Received BPM event RC_CREATION_SUCCESS: " + notification);

        BpmStringMapNotificationRest repositoryCreationTaskResult = (BpmStringMapNotificationRest) notification;

        int repositoryConfigurationId = -1;
        int buildConfigurationSavedId = -1;
        try {
            repositoryConfigurationId = Integer.valueOf(repositoryCreationTaskResult.getData().get("repositoryConfigurationId"));
        } catch (NumberFormatException ex) {
            String errorMessage = "Receive notification about successful BC creation '" + repositoryCreationTaskResult
                    + "' but the ID of the newly created RC '" + repositoryCreationTaskResult.getData()
                    .get("repositoryConfigurationId")
                    + "' is not a number. It should be present under 'repositoryConfigurationId' key.";

            LOG.error(errorMessage, ex);
            sendErrorMessage(repositoryConfigurationId, buildConfigurationSavedId, errorMessage);
            return;
        }

        RepositoryConfiguration repositoryConfiguration = repositoryConfigurationRepository.queryById(repositoryConfigurationId);
        if (repositoryConfiguration == null) {
            String errorMessage = "Repository Configuration was not found in database.";
            LOG.error(errorMessage);
            sendErrorMessage(repositoryConfigurationId, buildConfigurationSavedId, errorMessage);
            return;
        }

        if (buildConfigurationRest != null) { 
            BuildConfiguration buildConfiguration = buildConfigurationRest.toDBEntityBuilder()
                    .repositoryConfiguration(repositoryConfiguration)
                    .build();
            BuildConfiguration buildConfigurationSaved = buildConfigurationRepository.save(buildConfiguration);
            buildConfigurationSavedId = buildConfigurationSaved.getId();

            Set<Integer> bcSetIds = buildConfigurationRest.getBuildConfigurationSetIds();
            try {
                if (bcSetIds != null) {
                    addBuildConfigurationToSet(buildConfigurationSaved, bcSetIds);
                }
            } catch (Exception e) {
                LOG.error(e.getMessage());
                sendErrorMessage(repositoryConfigurationId, buildConfigurationSavedId, e.getMessage());
                return;
            }
        }

        RepositoryCreationResultRest repositoryCreationResultRest
                = new RepositoryCreationResultRest(
                        repositoryConfigurationId,
                        buildConfigurationSavedId,
                        RepositoryCreationResultRest.EventType.RC_CREATION_SUCCESS,
                        null);

        wsNotifier.sendMessage(repositoryCreationResultRest); 
    }
private void onRCCreationSuccess ( BpmNotificationRest notification , BuildConfigurationRest buildConfigurationRest ) { LOG . debug ( "Received BPM event RC_CREATION_SUCCESS: " + notification ) ; BpmStringMapNotificationRest repositoryCreationTaskResult = ( BpmStringMapNotificationRest ) notification ; int repositoryConfigurationId = - 1 ; int buildConfigurationSavedId = - 1 ; try { repositoryConfigurationId = Integer . valueOf ( repositoryCreationTaskResult . getData ( ) . get ( "repositoryConfigurationId" ) ) ; } catch ( NumberFormatException ex ) { String errorMessage = "Receive notification about successful BC creation '" + repositoryCreationTaskResult + "' but the ID of the newly created RC '" + repositoryCreationTaskResult . getData ( ) . get ( "repositoryConfigurationId" ) + "' is not a number. It should be present under 'repositoryConfigurationId' key." ; LOG . error ( errorMessage , ex ) ; sendErrorMessage ( repositoryConfigurationId , buildConfigurationSavedId , errorMessage ) ; return ; } RepositoryConfiguration repositoryConfiguration = repositoryConfigurationRepository . queryById ( repositoryConfigurationId ) ; if ( repositoryConfiguration == null ) { String errorMessage = "Repository Configuration was not found in database." ; LOG . error ( errorMessage ) ; sendErrorMessage ( repositoryConfigurationId , buildConfigurationSavedId , errorMessage ) ; return ; } if ( buildConfigurationRest != null ) { //TODO test me BuildConfiguration buildConfiguration = buildConfigurationRest . toDBEntityBuilder ( ) . repositoryConfiguration ( repositoryConfiguration ) . build ( ) ; BuildConfiguration buildConfigurationSaved = buildConfigurationRepository . save ( buildConfiguration ) ; buildConfigurationSavedId = buildConfigurationSaved . getId ( ) ; Set < Integer > bcSetIds = buildConfigurationRest . getBuildConfigurationSetIds ( ) ; try { if ( bcSetIds != null ) { addBuildConfigurationToSet ( buildConfigurationSaved , bcSetIds ) ; } } catch ( Exception e ) { LOG . error ( e . getMessage ( ) ) ; sendErrorMessage ( repositoryConfigurationId , buildConfigurationSavedId , e . getMessage ( ) ) ; return ; } } RepositoryCreationResultRest repositoryCreationResultRest = new RepositoryCreationResultRest ( repositoryConfigurationId , buildConfigurationSavedId , RepositoryCreationResultRest . EventType . RC_CREATION_SUCCESS , null ) ; wsNotifier . sendMessage ( repositoryCreationResultRest ) ; //TODO test me! }
Given the successful BC creation, add the BC into the BC sets. This solution has been
selected because if this was done in BPM process there would have to be a foreach cycle and
at least two REST requests for each BC Set ID. The process would become too complicated.
Notification listeners are ideal for these kind of operations.
Given the successful BC creation add the BC into the BC sets . This solution has been selected because if this was done in BPM process there would have to be a foreach cycle and at least two REST requests for each BC Set ID . The process would become too complicated . Notification listeners are ideal for these kind of operations .