/**
 * Copyright (c) 2014,2018 Contributors to the Eclipse Foundation
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.eclipse.smarthome.automation.core;

import org.eclipse.smarthome.automation.Rule;
import org.eclipse.smarthome.automation.RuleProvider;
import org.eclipse.smarthome.core.common.registry.DefaultAbstractManagedProvider;
import org.eclipse.smarthome.core.storage.StorageService;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;

/**
 * Implementation of a rule provider that uses the storage service for persistence
 *
 * @author Yordan Mihaylov - Initial Contribution
 * @author Ana Dimova - Persistence implementation
 * @author Kai Kreuzer - refactored (managed) provider and registry implementation
 */
@Component(service = { RuleProvider.class, ManagedRuleProvider.class })
public class ManagedRuleProvider extends DefaultAbstractManagedProvider<Rule, String> implements RuleProvider {

    @Reference(cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.STATIC)
    @Override
    protected void setStorageService(final StorageService storageService) {
        super.setStorageService(storageService);
    }

    @Override
    protected void unsetStorageService(final StorageService storageService) {
        super.unsetStorageService(storageService);
    }

    @Override
    protected String getStorageName() {
        return "automation_rules";
    }

    @Override
    protected String keyToString(String key) {
        return key;
    }

}

@@ -547,32 +547,149 @@
 n.RuleProvider;%0A
+import org.eclipse.smarthome.automation.core.dto.RuleDTOMapper;%0Aimport org.eclipse.smarthome.automation.dto.RuleDTO;%0A
 import org.eclip
@@ -722,23 +722,16 @@
 egistry.
-Default
 Abstract
@@ -1325,16 +1325,96 @@
 ntation%0A
+ * @author Markus Rathgeb - fix mapping between element and persistable element%0A
  */%0A@Com
@@ -1526,15 +1526,8 @@
 nds 
-Default
 Abst
@@ -1558,16 +1558,25 @@
 , String
+, RuleDTO
 %3E implem
@@ -2170,10 +2170,278 @@
 %0A    %7D%0A%0A
+    @Override%0A    protected Rule toElement(String key, RuleDTO persistableElement) %7B%0A        return RuleDTOMapper.map(persistableElement);%0A    %7D%0A%0A    @Override%0A    protected RuleDTO toPersistableElement(Rule element) %7B%0A        return RuleDTOMapper.map(element);%0A    %7D%0A
 %7D%0A

use DTO mapper to store / restore rules (#5897)