001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.camel.fixity;
007
008import org.apache.camel.builder.RouteBuilder;
009import org.apache.camel.component.http.HttpComponent;
010import org.fcrepo.camel.common.config.BasePropsConfig;
011import org.fcrepo.camel.common.config.ConditionOnPropertyTrue;
012import org.slf4j.Logger;
013import org.slf4j.LoggerFactory;
014import org.springframework.beans.factory.annotation.Value;
015import org.springframework.context.annotation.Bean;
016import org.springframework.context.annotation.Conditional;
017import org.springframework.context.annotation.Configuration;
018
019/**
020 * A configuration class for the Fixity service
021 *
022 * @author dbernstein
023 */
024@Configuration
025@Conditional({FcrepoFixityConfig.FixityEnabled.class})
026public class FcrepoFixityConfig extends BasePropsConfig {
027
028    private static final Logger LOGGER = LoggerFactory.getLogger(FcrepoFixityConfig.class);
029    static final String FIXITY_ENABLED = "fixity.enabled";
030
031    static class FixityEnabled extends ConditionOnPropertyTrue {
032        FixityEnabled() {
033            super(FcrepoFixityConfig.FIXITY_ENABLED, false);
034        }
035    }
036
037    @Value("${fixity.input.stream:broker:queue:fixity}")
038    private String inputStream;
039
040
041    @Value("${fixity.delay:0}")
042    private long fixityDelay;
043
044    @Value("${fixity.failure:file:/tmp/?fileName=fixityErrors.log&fileExist=Append}")
045    private String fixityFailure;
046
047
048    @Value("${fixity.success:mock:fixity.success}")
049    private String fixitySuccess;
050
051    /**
052     * The jms message stream for the fixity service
053     * @return
054     */
055    public String getInputStream() {
056        return inputStream;
057    }
058
059    /**
060     * Because fixity checking can put a significant load on a server, it can be convenient
061     * to introduce a delay between each fixity check. That delay is measured in milliseconds.
062     */
063    public long getFixityDelay() {
064        return fixityDelay;
065    }
066
067    /**
068     * It is also possible to trigger an action on success (by default, this is a no-op):
069     */
070    public String getFixitySuccess() {
071        return fixitySuccess;
072    }
073
074    /**
075     * Most importantly, it is possible to configure what should happen when a fixity check fails.
076     * In the default example below, the fixity output is written to a file in `/tmp/fixityErrors.log`. But this can
077     * be changed to send a message to an email address (`fixity.failure=smtp:admin@example.org?subject=Fixity`)
078     * or use just about any other camel component.
079     */
080    public String getFixityFailure() {
081        return fixityFailure;
082    }
083
084    @Bean(name = "http")
085    public HttpComponent http() {
086        return new HttpComponent();
087    }
088
089    @Bean(name = "https")
090    public HttpComponent https() {
091        return new HttpComponent();
092    }
093
094    @Bean
095    public RouteBuilder fixityRoute() {
096        return new FixityRouter();
097    }
098}