update cassandra listener based on the model updates
update cassandra listener based on the model updates

/*
 * Copyright 2014 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.netflix.spinnaker.echo.events

import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.echo.cassandra.HistoryRepository
import com.netflix.spinnaker.echo.model.Event
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

/**
 * Event listener for echo events
 */
@Component
class CassandraEventListener implements EchoEventListener {

    @Autowired
    HistoryRepository repository

    ObjectMapper mapper = new ObjectMapper()

    @Override
    void processEvent(Event event) {
        String key = "${event.details.source}::${event.details.type}::${event.details.created}"
        repository.saveHistory(key, mapper.writeValueAsString(event))
    }

}

/*
 * Copyright 2014 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.netflix.spinnaker.echo.events

import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spinnaker.echo.cassandra.HistoryRepository
import com.netflix.spinnaker.echo.model.Event
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

/**
 * Event listener for echo events
 */
@Component
class CassandraEventListener implements EchoEventListener {

    @Autowired
    HistoryRepository repository

    ObjectMapper mapper = new ObjectMapper()

    @Override
    void processEvent(Event event) {
        String key = "${event.metaData.source}::${event.metaData.type}::${event.metaData.date}"
        repository.saveHistory(key, mapper.writeValueAsString(event))
    }

}
