Search in sources :

Example 1 with ConfigFileFinder

use of org.alfresco.util.ConfigFileFinder in project alfresco-repository by Alfresco.

the class RenditionDefinitionRegistry2Impl method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    PropertyCheck.mandatory(this, "transformServiceRegistry", transformServiceRegistry);
    PropertyCheck.mandatory(this, "timeoutDefault", timeoutDefault);
    PropertyCheck.mandatory(this, "jsonObjectMapper", jsonObjectMapper);
    // If we have a cronExpression it indicates that we will schedule reading.
    if (cronExpression != null) {
        PropertyCheck.mandatory(this, "initialAndOnErrorCronExpression", initialAndOnErrorCronExpression);
    }
    configFileFinder = new ConfigFileFinder(jsonObjectMapper) {

        @Override
        protected void readJson(JsonNode jsonNode, String readFromMessage, String baseUrl) throws IOException {
            try {
                JsonNode renditions = jsonNode.get("renditions");
                if (renditions != null && renditions.isArray()) {
                    for (JsonNode rendition : renditions) {
                        RenditionDef def = jsonObjectMapper.convertValue(rendition, RenditionDef.class);
                        Map<String, String> map = new HashMap<>();
                        if (def.options != null) {
                            def.options.forEach(o -> map.put(o.name, o.value));
                        }
                        if (!map.containsKey(RenditionDefinition2.TIMEOUT)) {
                            map.put(RenditionDefinition2.TIMEOUT, timeoutDefault);
                        }
                        RenditionDefinition2 original = getRenditionDefinition(def.renditionName);
                        new RenditionDefinition2Impl(def.renditionName, def.targetMediaType, map, true, RenditionDefinitionRegistry2Impl.this);
                        if (original != null) {
                            log.debug(readFromMessage + " replaced the rendition " + def.renditionName);
                        }
                    }
                }
            } catch (IllegalArgumentException e) {
                log.error("Error reading " + readFromMessage + " " + e.getMessage());
            }
        }
    };
    configScheduler.run(true, log, cronExpression, initialAndOnErrorCronExpression);
}
Also used : ConfigFileFinder(org.alfresco.util.ConfigFileFinder) ShutdownIndicator(org.alfresco.util.ShutdownIndicator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CronExpression(org.quartz.CronExpression) Pair(org.alfresco.util.Pair) Set(java.util.Set) ConfigScheduler(org.alfresco.util.ConfigScheduler) IOException(java.io.IOException) HashMap(java.util.HashMap) InitializingBean(org.springframework.beans.factory.InitializingBean) TransformServiceRegistry(org.alfresco.transform.client.registry.TransformServiceRegistry) HashSet(java.util.HashSet) Map(java.util.Map) PropertyCheck(org.alfresco.util.PropertyCheck) JsonNode(com.fasterxml.jackson.databind.JsonNode) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) ConfigFileFinder(org.alfresco.util.ConfigFileFinder)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 TransformServiceRegistry (org.alfresco.transform.client.registry.TransformServiceRegistry)1 ConfigFileFinder (org.alfresco.util.ConfigFileFinder)1 ConfigScheduler (org.alfresco.util.ConfigScheduler)1 Pair (org.alfresco.util.Pair)1 PropertyCheck (org.alfresco.util.PropertyCheck)1 ShutdownIndicator (org.alfresco.util.ShutdownIndicator)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 CronExpression (org.quartz.CronExpression)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1