/*******************************************************************************
 * This file is part of OpenNMS(R).
 *
 * Copyright (C) 2006-2014 The OpenNMS Group, Inc.
 * OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * OpenNMS(R) is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with OpenNMS(R).  If not, see:
 *      http://www.gnu.org/licenses/
 *
 * For more information contact:
 *     OpenNMS(R) Licensing <license@opennms.org>
 *     http://www.opennms.org/
 *     http://www.opennms.com/
 *******************************************************************************/

package org.opennms.netmgt.collection.persistence.rrd;

import java.util.Collections;

import org.opennms.netmgt.collection.api.CollectionAttribute;
import org.opennms.netmgt.collection.api.ServiceParameters;
import org.opennms.netmgt.dao.api.ResourceStorageDao;
import org.opennms.netmgt.rrd.RrdRepository;
import org.opennms.netmgt.rrd.RrdStrategy;


/**
 * <p>OneToOnePersister class.</p>
 *
 * @author ranger
 * @version $Id: $
 */
public class OneToOnePersister extends BasePersister {

    /**
     * <p>Constructor for OneToOnePersister.</p>
     *
     * @param params a {@link org.opennms.netmgt.collection.api.ServiceParameters} object.
     * @param repository a {@link org.opennms.netmgt.rrd.RrdRepository} object.
     */
    protected OneToOnePersister(ServiceParameters params,  RrdRepository repository, RrdStrategy<?, ?> rrdStrategy, ResourceStorageDao resourceStorageDao) {
        super(params, repository, rrdStrategy, resourceStorageDao);
    }

    /** {@inheritDoc} */
    @Override
    public void visitAttribute(CollectionAttribute attribute) {
        pushShouldPersist(attribute);
        if (shouldPersist()) {
            setBuilder(createBuilder(attribute.getResource(), attribute.getName(), Collections.singleton(attribute.getAttributeType())));
            storeAttribute(attribute);
        }
    }

    /** {@inheritDoc} */
    @Override
    public void completeAttribute(CollectionAttribute attribute) {
        if (shouldPersist()) {
        	commitBuilder();
        }
        popShouldPersist();
    }

}

@@ -1286,16 +1286,127 @@
 ctions;%0A
+import java.util.LinkedHashMap;%0Aimport java.util.Map;%0A%0Aimport org.opennms.netmgt.collection.api.AttributeGroup;
 %0Aimport 
@@ -1574,16 +1574,113 @@
 ageDao;%0A
+import org.opennms.netmgt.model.ResourcePath;%0Aimport org.opennms.netmgt.model.ResourceTypeUtils;%0A
 import o
@@ -1900,16 +1900,52 @@
 ster %7B%0A%0A
+    private String m_group = null;%0A%0A
     /**%0A
@@ -2599,131 +2599,394 @@
     
-setBuilder(createBuilder(attribute.getResource(), attribute.getName(), Collections.singleton(attribute.getAttributeType()))
+final RrdPersistOperationBuilder builder = createBuilder(attribute.getResource(),%0A                                                                     attribute.getName(),%0A                                                                     Collections.singleton(attribute.getAttributeType()));%0A            builder.setAttributeMetadata(%22GROUP%22, m_group);%0A%0A            setBuilder(builder
 );%0A 
@@ -3248,10 +3248,175 @@
 %0A    %7D%0A%0A
+    /** %7B@inheritDoc%7D */%0A    @Override%0A    public void visitGroup(AttributeGroup group) %7B%0A        super.visitGroup(group);%0A%0A        m_group = group.getName();%0A    %7D%0A
 %7D%0A

Store the group name in the .meta if storeByGroup is false