/*
 * Copyright 2012-2013 inBloom, Inc. and its affiliates.
 *
 * 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.common.domain;

import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jstokes
 * @author pghosh
 */
@Component
public class ContainerDocumentHolder {
    private final Map<String, ContainerDocument> containerDocumentMap = new HashMap<String, ContainerDocument>();

    public ContainerDocumentHolder() {
        init();
    }

    public ContainerDocumentHolder(final Map<String, ContainerDocument> containerDocumentMap) {
        this.containerDocumentMap.putAll(containerDocumentMap);
    }

    public ContainerDocument getContainerDocument(final String entityName) {
        return containerDocumentMap.get(entityName);
    }

    public boolean isContainerDocument(final String entityName) {
        return containerDocumentMap.containsKey(entityName);
    }

    private void init() {
        final List<String> parentKeys = Arrays.asList("studentId", "schoolId", "schoolYear");
        final ContainerDocument attendance = ContainerDocument.builder().forCollection("attendance")
                .forField("attendanceEvent")
                .withParent(parentKeys).build();

        final List<String> containerKeysForReportCard = Arrays.asList("studentId", "gradingPeriodId");
        final List<String> parentKeysForGRCSAR = Arrays.asList("studentId", "schoolYear");
        final ContainerDocument reportCard = ContainerDocument.builder().forCollection("reportCard")
                .forField("reportCard")
                .withParent(parentKeysForGRCSAR)
                .persistAs("yearlyTranscript")
                .asContainerSubdoc(true)
                .withContainerDocKeys(containerKeysForReportCard).build();
        final ContainerDocument grade = ContainerDocument.builder().forCollection("grade")
                .forField("grade")
                .withParent(parentKeysForGRCSAR)
                .persistAs("yearlyTranscript")
                .asContainerSubdoc(true).build();
        final ContainerDocument studentAcademicRecord = ContainerDocument.builder().forCollection("studentAcademicRecord")
                .forField("studentAcademicRecord")
                .withParent(parentKeysForGRCSAR)
                .persistAs("yearlyTranscript")
                .asContainerSubdoc(true)
                .build();

        containerDocumentMap.put("attendance", attendance);
        containerDocumentMap.put("reportCard", reportCard);
        containerDocumentMap.put("grade", grade);
        containerDocumentMap.put("studentAcademicRecord", studentAcademicRecord);
    }
}

@@ -648,16 +648,62 @@
 omain;%0A%0A
+import org.slc.sli.api.constants.EntityNames;%0A
 import o
@@ -1747,80 +1747,158 @@
 er()
-.forCollection(%22attendance%22)%0A                .forField(%22attendanceEvent%22
+%0A                .forCollection(EntityNames.ATTENDANCE)%0A                .forField(%22attendanceEvent%22)%0A                .persistAs(EntityNames.ATTENDANCE
 )%0A  
@@ -2215,35 +2215,63 @@
 er()
-.forCollection(%22reportCard%22
+%0A                .forCollection(EntityNames.REPORT_CARD
 )%0A  
@@ -2294,28 +2294,39 @@
 orField(
-%22reportCard%22
+EntityNames.REPORT_CARD
 )%0A      
@@ -2602,30 +2602,57 @@
 er()
-.forCollection(%22grade%22
+%0A                .forCollection(EntityNames.GRADE
 )%0A  
@@ -2675,23 +2675,33 @@
 orField(
-%22grade%22
+EntityNames.GRADE
 )%0A      
@@ -2927,97 +2927,138 @@
 er()
-.forCollection(%22studentAcademicRecord%22)%0A                .forField(%22studentAcademicRecord%22
+%0A                .forCollection(EntityNames.STUDENT_ACADEMIC_RECORD)%0A                .forField(EntityNames.STUDENT_ACADEMIC_RECORD
 )%0A  
@@ -3256,20 +3256,30 @@
 put(
-%22attendance%22
+EntityNames.ATTENDANCE
 , at
@@ -3326,20 +3326,31 @@
 put(
-%22reportCard%22
+EntityNames.REPORT_CARD
 , re
@@ -3397,15 +3397,25 @@
 put(
-%22grade%22
+EntityNames.GRADE
 , gr
@@ -3457,31 +3457,43 @@
 put(
-%22studentAcademicRecord%22
+EntityNames.STUDENT_ACADEMIC_RECORD
 , st

Use constant entity names