001    /**
002     * Copyright 2010 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may
003     * not use this file except in compliance with the License. You may obtain a copy of the License at
004     * http://www.osedu.org/licenses/ECL-2.0 Unless required by applicable law or agreed to in writing, software distributed
005     * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
006     * implied. See the License for the specific language governing permissions and limitations under the License.
007     */
008    
009    package org.kuali.student.lum.program.server.metadata;
010    
011    import java.util.ArrayList;
012    import java.util.List;
013    
014    import org.kuali.student.r1.common.assembly.data.ConstraintMetadata;
015    import org.kuali.student.r1.common.assembly.dictionary.MetadataServiceImpl;
016    import org.kuali.student.r1.common.dictionary.dto.FieldDefinition;
017    import org.kuali.student.r1.common.dictionary.service.DictionaryService;
018    
019    import org.kuali.student.r2.common.dto.ContextInfo;
020    import org.kuali.student.r2.common.dto.DtoConstants.DtoState;
021    import org.kuali.student.r2.lum.clu.CLUConstants;
022    
023    
024    /**
025     * This class provides metadata lookup for service dto objects.
026     * 
027     * @author Kuali Student Team
028     */
029    public class ProgramMetadataServiceImpl extends MetadataServiceImpl {
030    
031        public ProgramMetadataServiceImpl() {
032                    super();
033            }
034    
035            public ProgramMetadataServiceImpl(DictionaryService... dictionaryServices) {
036            super(dictionaryServices);
037        }
038    
039    
040        protected List<ConstraintMetadata> getConstraints(FieldDefinition fd, String type, String state, String nextState,
041                String workflowNode, String documentTypeName) {
042            List<ConstraintMetadata> constraints = new ArrayList<ConstraintMetadata>();
043            ConstraintMetadata constraintMetadata = new ConstraintMetadata();
044            //The nextState should not get a defaulted value when we're using Modify Program Proposal functionality.
045            String nextStateValue = nextState;
046            if (!CLUConstants.PROPOSAL_TYPE_MAJOR_DISCIPLINE_MODIFY.equals(documentTypeName)) {
047                nextStateValue = getNextState(state);
048            }
049    
050            updateConstraintMetadata(constraintMetadata, fd, type, getNonNullState(state), nextStateValue, workflowNode);
051            constraints.add(constraintMetadata);
052    
053            return constraints;
054        }
055    
056        private String getNonNullState(String state) {
057            return (null == state ? DtoState.DRAFT.toString() : state);
058        }
059    
060        private String getNextState(String state) {
061            if (null == state || DtoState.DRAFT.toString().equalsIgnoreCase(state)) {
062                return DtoState.APPROVED.toString();
063            } else if (DtoState.APPROVED.toString().equalsIgnoreCase(state)) {
064                return DtoState.ACTIVE.toString();
065            } else if (DtoState.ACTIVE.toString().equalsIgnoreCase(state)) {
066                return DtoState.SUPERSEDED.toString();
067            }
068            return null;
069        }
070    }