/*
 * Copyright 2012 Shared Learning Collaborative, LLC
 *
 * 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 org.slc.sli.api.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import org.slc.sli.api.representation.EntityBody;
import org.slc.sli.api.service.Treatment;
import org.slc.sli.domain.Entity;
import org.slc.sli.domain.Repository;

/**
 * Add the "updated" and "created" fields to the response body.
 *
 * @author jnanney
 *
 */
@Component
public class MetaDataTreatment implements Treatment {

    @Autowired
    private Repository<Entity> repo;

    public static final String METADATA = "metaData";


    @Override
    public EntityBody toStored(EntityBody exposed, EntityDefinition defn) {
        exposed.remove(METADATA);
        return exposed;
    }

    @Override
    public EntityBody toExposed(EntityBody stored, EntityDefinition defn, Entity entity) {
        if(stored.get("entityType").equals("roles") ||
                stored.get("entityType").equals("applicationAuthorization") ||
                stored.get("entityType").equals("application") ||
                stored.get("entityType").equals("onboarding")) {
            stored.put(METADATA, entity.getMetaData());
        }
        
        return stored;
    }

}

@@ -1448,24 +1448,26 @@
 y entity) %7B%0A
+//
         if(s
@@ -1505,24 +1505,26 @@
 %22roles%22) %7C%7C%0A
+//
             
@@ -1582,32 +1582,34 @@
 horization%22) %7C%7C%0A
+//
                 
@@ -1658,16 +1658,18 @@
 on%22) %7C%7C%0A
+//
         
@@ -1721,24 +1721,26 @@
 arding%22)) %7B%0A
+//
             
@@ -1783,16 +1783,18 @@
 ata());%0A
+//
         
@@ -1795,16 +1795,68 @@
       %7D%0A
+        stored.put(METADATA, entity.getMetaData());%0A
         

revert change to fix sdk test failur while investigating