All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.swisscom.cloud.sb.broker.provisioning.lastoperation.LastOperationJobContext.groovy Maven / Gradle / Ivy

There is a newer version: 6.21.6
Show newest version
package com.swisscom.cloud.sb.broker.provisioning.lastoperation

import com.swisscom.cloud.sb.broker.model.*
import com.swisscom.cloud.sb.broker.model.repository.LastOperationRepository
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Component

@CompileStatic
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
class LastOperationJobContext {

    @Autowired
    private LastOperationRepository lastOperationRepository

    LastOperation lastOperation
    ServiceInstance serviceInstance
    Plan plan
    ProvisionRequest provisionRequest
    DeprovisionRequest deprovisionRequest

    void notifySuccess(String message = null) {
        notifyResult(true, message)
    }

    void notifyFailure(String message = null) {
        notifyResult(false, message)
    }

    void notifyResult(boolean success, String message = null) {
        updateJob(success ? LastOperation.Status.SUCCESS : LastOperation.Status.FAILED, message)
    }

    void notifyProgress(String message = null, String internalState = null) {
        updateJob(LastOperation.Status.IN_PROGRESS, message, internalState)
    }

    private void updateJob(LastOperation.Status status, String message = null, String internalState = null) {
        lastOperation = lastOperationRepository.merge(lastOperation)
        lastOperation.status = status
        lastOperation.description = message
        lastOperation.internalState = internalState
        lastOperationRepository.save(lastOperation)
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy