Clover Coverage Report - Kuali Student 1.2-M4-SNAPSHOT (Aggregated)
Coverage timestamp: Wed Jul 20 2011 11:14:35 EDT
../../../../../../img/srcFileCovDistChart0.png 41% of files have more coverage
63   156   29   7
38   125   0.46   9
9     3.22  
1    
 
  ProgramUtils       Line # 33 63 0% 29 110 0% 0.0
 
No Tests
 
1    package org.kuali.student.lum.program.client;
2   
3    import java.util.HashMap;
4    import java.util.List;
5    import java.util.Map;
6    import java.util.Set;
7    import java.util.TreeSet;
8   
9    import org.kuali.student.common.assembly.data.Data;
10    import org.kuali.student.common.assembly.data.ModelDefinition;
11    import org.kuali.student.common.assembly.data.QueryPath;
12    import org.kuali.student.common.ui.client.application.Application;
13    import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
14    import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView;
15    import org.kuali.student.common.ui.client.mvc.DataModel;
16    import org.kuali.student.common.ui.client.mvc.View;
17    import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
18    import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
19    import org.kuali.student.common.validation.dto.ValidationResultInfo;
20    import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration;
21    import org.kuali.student.lum.common.client.configuration.Configuration;
22    import org.kuali.student.lum.common.client.configuration.ConfigurationManager;
23    import org.kuali.student.lum.program.client.properties.ProgramProperties;
24   
25    import com.google.gwt.event.shared.EventHandler;
26    import com.google.gwt.event.shared.GwtEvent;
27    import com.google.gwt.event.shared.HandlerManager;
28    import com.google.gwt.i18n.client.DateTimeFormat;
29   
30    /**
31    * @author Igor
32    */
 
33    public class ProgramUtils {
34   
35    public static DateTimeFormat df = DateTimeFormat.getFormat("dd-MMM-yyyy");
36   
 
37  0 toggle private ProgramUtils() {
38    }
39   
 
40  0 toggle public static void addCredentialProgramDataToVariation(Data variationData, DataModel model) {
41  0 Data credentialProgram = new Data();
42   
43    // this should mimic the formats in VariationInformationEditConfiguration::createReadOnlySection
44  0 credentialProgram.set(ProgramConstants.INSTITUTION, model.<Data>get(ProgramConstants.CREDENTIAL_PROGRAM + "/" + ProgramConstants.INSTITUTION));
45  0 credentialProgram.set(ProgramConstants.PROGRAM_LEVEL, model.<String>get(ProgramConstants.CREDENTIAL_PROGRAM + "/" + ProgramConstants.PROGRAM_LEVEL));
46  0 credentialProgram.set(ProgramConstants.RUNTIME_DATA, model.<Data>get(ProgramConstants.CREDENTIAL_PROGRAM + "/" + ProgramConstants.RUNTIME_DATA));
47   
48  0 variationData.set(ProgramConstants.CREDENTIAL_PROGRAM, credentialProgram);
49    }
50   
 
51  0 toggle public static Data createNewSpecializationBasedOnMajor(DataModel programModel) {
52  0 Data newSpecializationData = new Data();
53  0 newSpecializationData.set(ProgramConstants.STATE, programModel.<String>get(ProgramConstants.STATE));
54  0 newSpecializationData.set(ProgramConstants.TYPE, ProgramConstants.VARIATION_TYPE_KEY);
55  0 newSpecializationData.set(ProgramConstants.PROGRAM_REQUIREMENTS, new Data());
56   
57    //Manually copy default values here... we don't have access to the metadata and we only want to default the first time
58  0 newSpecializationData.set(ProgramConstants.FINANCIAL_CONTROL_DIVISION, programModel.<Data>get(ProgramConstants.FINANCIAL_CONTROL_DIVISION)==null?null:programModel.<Data>get(ProgramConstants.FINANCIAL_CONTROL_DIVISION).copy());
59  0 newSpecializationData.set(ProgramConstants.FINANCIAL_CONTROL_UNIT, programModel.<Data>get(ProgramConstants.FINANCIAL_CONTROL_UNIT)==null?null:programModel.<Data>get(ProgramConstants.FINANCIAL_CONTROL_UNIT).copy());
60  0 newSpecializationData.set(ProgramConstants.FINANCIAL_RESOURCES_DIVISION, programModel.<Data>get(ProgramConstants.FINANCIAL_RESOURCES_DIVISION)==null?null:programModel.<Data>get(ProgramConstants.FINANCIAL_RESOURCES_DIVISION).copy());
61  0 newSpecializationData.set(ProgramConstants.FINANCIAL_RESOURCES_UNIT, programModel.<Data>get(ProgramConstants.FINANCIAL_RESOURCES_UNIT)==null?null:programModel.<Data>get(ProgramConstants.FINANCIAL_RESOURCES_UNIT).copy());
62  0 newSpecializationData.set(ProgramConstants.CURRICULUM_OVERSIGHT_DIVISION, programModel.<Data>get(ProgramConstants.CURRICULUM_OVERSIGHT_DIVISION)==null?null:programModel.<Data>get(ProgramConstants.CURRICULUM_OVERSIGHT_DIVISION).copy());
63  0 newSpecializationData.set(ProgramConstants.CURRICULUM_OVERSIGHT_UNIT, programModel.<Data>get(ProgramConstants.CURRICULUM_OVERSIGHT_UNIT)==null?null:programModel.<Data>get(ProgramConstants.CURRICULUM_OVERSIGHT_UNIT).copy());
64  0 newSpecializationData.set(ProgramConstants.DEPLOYMENT_DIVISION, programModel.<Data>get(ProgramConstants.DEPLOYMENT_DIVISION)==null?null:programModel.<Data>get(ProgramConstants.DEPLOYMENT_DIVISION).copy());
65  0 newSpecializationData.set(ProgramConstants.DEPLOYMENT_UNIT, programModel.<Data>get(ProgramConstants.DEPLOYMENT_UNIT)==null?null:programModel.<Data>get(ProgramConstants.DEPLOYMENT_UNIT).copy());
66  0 newSpecializationData.set(ProgramConstants.STUDENT_OVERSIGHT_DIVISION, programModel.<Data>get(ProgramConstants.STUDENT_OVERSIGHT_DIVISION)==null?null:programModel.<Data>get(ProgramConstants.STUDENT_OVERSIGHT_DIVISION).copy());
67  0 newSpecializationData.set(ProgramConstants.STUDENT_OVERSIGHT_UNIT, programModel.<Data>get(ProgramConstants.STUDENT_OVERSIGHT_UNIT)==null?null:programModel.<Data>get(ProgramConstants.STUDENT_OVERSIGHT_UNIT).copy());
68   
69  0 addCredentialProgramDataToVariation(newSpecializationData, programModel);
70  0 return newSpecializationData;
71    }
72   
73   
74   
 
75  0 toggle public static void retrofitValidationResults(List<ValidationResultInfo> validationResults) {
76  0 for (ValidationResultInfo validationResult : validationResults) {
77  0 String key = validationResult.getElement();
78  0 if (ProgramConstants.RICH_TEXT_KEYS.contains(key)) {
79  0 key = key + "/plain";
80  0 validationResult.setElement(key);
81    }
82    }
83    }
84   
 
85  0 toggle public static void handleValidationErrorsForSpecializations(List<ValidationResultInfo> validationResults, DataModel programModel) {
86  0 Set<Integer> failedSpecializations = new TreeSet<Integer>();
87  0 for (ValidationResultInfo validationResult : validationResults) {
88  0 String element = validationResult.getElement();
89  0 if (element.contains(ProgramConstants.VARIATIONS)) {
90  0 String fdPath = element;
91  0 if (element.matches(".*/[0-9]+")){
92    //If path ends in number then strip it off, it is for an individual item in a list element
93  0 fdPath = element.substring(0,element.lastIndexOf("/"));
94    }
95  0 FieldDescriptor fd = Application.getApplicationContext().getPathToFieldMapping(null, fdPath);
96   
97    //If field descriptor found, display error on the field, otherwise display a generic error message.
98  0 if(fd!=null){
99  0 fd.getFieldElement().processValidationResult(validationResult);
100    }else{
101  0 int specializationIndex = Integer.parseInt(element.split("/")[1]);
102  0 failedSpecializations.add(specializationIndex);
103    }
104    }
105    }
106  0 if (!failedSpecializations.isEmpty()) {
107  0 final Data variationMap = programModel.get(ProgramConstants.VARIATIONS);
108  0 StringBuilder validationMessage = new StringBuilder();
109  0 for (Integer failedSpecialization : failedSpecializations) {
110  0 Data data = variationMap.get(failedSpecialization);
111  0 validationMessage.append(data.get(ProgramConstants.LONG_TITLE)).append(", ");
112    }
113  0 String resultMessage = validationMessage.toString();
114    //Cutoff ', ' from the result
115  0 resultMessage = resultMessage.substring(0, resultMessage.length() - 2);
116   
117  0 if (failedSpecializations.size() == 1) {
118  0 KSNotifier.add(new KSNotification(ProgramProperties.get().major_variationFailed(resultMessage), false, true, 5000));
119    } else {
120  0 KSNotifier.add(new KSNotification(ProgramProperties.get().major_variationsFailed(resultMessage), false, true, 5000));
121    }
122    }
123    }
124   
125   
 
126  0 toggle public static void syncMetadata(AbstractProgramConfigurer configurer, ModelDefinition modelDefinition) {
127  0 ConfigurationManager configurationManager = configurer.getProgramSectionConfigManager();
128  0 for (Configuration conf : configurationManager.getConfigurations()) {
129  0 if (conf instanceof AbstractSectionConfiguration) {
130  0 AbstractSectionConfiguration configuration = (AbstractSectionConfiguration) conf;
131  0 View view = configuration.getView(false);
132  0 if (view != null && view instanceof SectionView) {
133  0 SectionView sectionView = (SectionView) view;
134  0 sectionView.updateMetadata(modelDefinition);
135    }
136    }
137    }
138    }
139   
 
140  0 toggle public static void unregisterUnusedHandlers(HandlerManager eventBus) {
141  0 HashMap<GwtEvent.Type, EventHandler> eventsMap = ProgramRegistry.getSpecializationHandlers();
142  0 if (eventsMap != null) {
143  0 for (Map.Entry<GwtEvent.Type, EventHandler> typeEventHandlerEntry : eventsMap.entrySet()) {
144  0 eventBus.removeHandler(typeEventHandlerEntry.getKey(), typeEventHandlerEntry.getValue());
145    }
146    }
147    }
148   
 
149  0 toggle public static String getProgramId(DataModel programModel) {
150  0 return programModel.get(ProgramConstants.ID);
151    }
152   
 
153  0 toggle public static String getProgramState(DataModel programModel) {
154  0 return programModel.get( ProgramConstants.STATE);
155    }
156    }