org.opentestsystem.authoring.testauth.publish.CompletePublisherHelper.java Source code

Java tutorial

Introduction

Here is the source code for org.opentestsystem.authoring.testauth.publish.CompletePublisherHelper.java

Source

/*******************************************************************************
 * Educational Online Test Delivery System
 * Copyright (c) 2013 American Institutes for Research
 * 
 * Distributed under the AIR Open Source License, Version 1.0
 * See accompanying file AIR-License-1_0.txt or at
 * http://www.smarterapp.org/documents/American_Institutes_for_Research_Open_Source_Software_License.pdf
 ******************************************************************************/
package org.opentestsystem.authoring.testauth.publish;

import static org.opentestsystem.authoring.testauth.publish.PublisherUtil.FIXEDFORM_SEGMENT_FILTER;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.joda.time.DateTime;
import org.opentestsystem.authoring.testauth.domain.AffinityGroup;
import org.opentestsystem.authoring.testauth.domain.Assessment;
import org.opentestsystem.authoring.testauth.domain.BlueprintElement;
import org.opentestsystem.authoring.testauth.domain.BlueprintReferenceType;
import org.opentestsystem.authoring.testauth.domain.Item;
import org.opentestsystem.authoring.testauth.domain.ScoringRule;
import org.opentestsystem.authoring.testauth.domain.Segment;
import org.opentestsystem.authoring.testauth.publish.domain.Complete;
import org.opentestsystem.authoring.testauth.publish.domain.Purpose;
import org.opentestsystem.authoring.testauth.publish.domain.PurposeBaseContent;
import org.opentestsystem.authoring.testauth.publish.domain.TestComputationRule;
import org.opentestsystem.authoring.testauth.publish.domain.TestItem;
import org.opentestsystem.authoring.testauth.publish.domain.TestSpecification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.google.common.collect.Iterables;

@Component("completePublisherHelper")
public class CompletePublisherHelper extends BasePublisherHelper implements PublisherHelper {
    private static final Logger LOGGER = LoggerFactory.getLogger(CompletePublisherHelper.class);

    @Override
    public TestSpecification<Complete> createTestSpec(final Assessment assessment, final DateTime publishDate,
            final String version, final Purpose purpose,
            final TestSpecification<? extends PurposeBaseContent> seedingTestSpec) {
        final long start = System.currentTimeMillis();
        final TestSpecification<Complete> testSpec = doGeneralTestSpecificationSetup(assessment, publishDate,
                version, purpose, Complete.class);

        final Complete specContent = new Complete();
        // administration.setComment("comment");
        final String assessmentId = assessment.getId();
        final List<Item> itemList = retrieveItemsForAssessment(assessmentId);
        final List<Segment> segmentList = retrieveSegmentList(assessmentId);
        final List<BlueprintElement> blueprintElementList = getActiveBlueprintElements(assessmentId);
        specContent.setBlueprintElementList(blueprintElementList);
        final List<AffinityGroup> affinityGroupList = getActiveAffinityGroups(assessmentId);
        final long dataRetrieval = System.currentTimeMillis();
        final Map<BlueprintReferenceType, Map<String, String>> blueprintReferenceMap = buildBlueprintReferenceMap(
                assessment, segmentList, blueprintElementList, affinityGroupList);
        specContent.setBlueprintReferenceMap(blueprintReferenceMap);
        final long blueprintReferenceMapCreation = System.currentTimeMillis();

        // ITEMPOOL
        specContent.setItemPool(setupItemPoolData(assessment, itemList, segmentList, affinityGroupList, version));
        final Map<String, TestItem> testItemMap = buildTestItemMap(specContent.getItemPool().getTestItemList());
        final long itemPoolCreation = System.currentTimeMillis();

        // BLUEPRINT (counts, different levels of the hierarchy)
        specContent.setTestBlueprintList(
                setupBlueprintData(assessment, itemList, segmentList, blueprintElementList, affinityGroupList));
        final long blueprintCreation = System.currentTimeMillis();

        // SEGMENT
        specContent.setAdministrationSegmentList(setupAdminSegmentData(assessment, itemList, segmentList,
                specContent.getTestBlueprintList(), blueprintElementList, affinityGroupList));
        final long segmentCreation = System.currentTimeMillis();

        // FORM
        long formCreation = segmentCreation;
        if (Iterables.any(segmentList, FIXEDFORM_SEGMENT_FILTER)) {
            specContent.setTestFormList(setupTestFormData(assessment, segmentList, itemList, testItemMap));
            formCreation = System.currentTimeMillis();
        }

        // top-level pool property
        specContent.setPoolPropertyList(
                buildTopLevelPoolPropertyList(assessmentId, itemList, segmentList, testItemMap));
        final long poolCreation = System.currentTimeMillis();

        // PERFORMANCE LEVELS
        specContent.setTestPerformanceLevelList(setupPerformanceLevelData(assessmentId, blueprintReferenceMap));
        final long performanceCreation = System.currentTimeMillis();

        // SCORING RULES
        final List<ScoringRule> scoringRuleList = retrieveScoringRules(assessmentId);
        specContent.setScoringRuleData(setupScoringRuleData(assessmentId, blueprintReferenceMap, scoringRuleList,
                blueprintElementList, true));
        final Map<String, Collection<TestComputationRule>> scoringRuleReferenceMap = buildScoringRuleReferenceMap(
                specContent.getScoringRuleData().getComputationRuleList());
        final long scoringCreation = System.currentTimeMillis();

        // REPORTING MEASURES
        specContent.setTestReportingMeasureList(
                setupReportingMeasureData(assessmentId, blueprintReferenceMap, scoringRuleReferenceMap));
        final long reportingCreation = System.currentTimeMillis();
        logStats(start, dataRetrieval, blueprintReferenceMapCreation, itemPoolCreation, blueprintCreation,
                segmentCreation, formCreation, poolCreation, performanceCreation, scoringCreation,
                reportingCreation);

        testSpec.setContent(specContent);
        return testSpec;
    }

    private void logStats(final long start, final long dataRetrieval, final long blueprintReferenceMapCreation,
            final long itemPoolCreation, final long blueprintCreation, final long segmentCreation,
            final long formCreation, final long poolCreation, final long performanceCreation,
            final long scoringCreation, final long reportingCreation) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("data retrieval: " + (dataRetrieval - start) + "ms\n" + "reference map creation: "
                    + (blueprintReferenceMapCreation - dataRetrieval) + "ms\n" + "item pool: "
                    + (itemPoolCreation - blueprintReferenceMapCreation) + "ms\n" + "blueprint: "
                    + (blueprintCreation - itemPoolCreation) + "ms\n" + "admin segment: "
                    + (segmentCreation - blueprintCreation) + "ms\n" + "form: " + (formCreation - segmentCreation)
                    + "ms\n" + "test poolproperty: " + (poolCreation - formCreation) + "ms\n"
                    + "performance level: " + (performanceCreation - poolCreation) + "ms\n" + "scoring rule: "
                    + (scoringCreation - performanceCreation) + "ms\n" + "reporting measure: "
                    + (reportingCreation - scoringCreation) + "ms\n" + "total time: "
                    + (System.currentTimeMillis() - start) + "ms");
        }
    }
}