Coverage Report - org.kuali.student.core.enumerationmanagement.service.impl.EnumerationManagementServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
EnumerationManagementServiceImpl
2%
2/79
0%
0/46
2.364
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.core.enumerationmanagement.service.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Date;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.jws.WebService;
 23  
 import javax.jws.soap.SOAPBinding;
 24  
 
 25  
 import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
 26  
 import org.kuali.student.common.dto.StatusInfo;
 27  
 import org.kuali.student.common.exceptions.AlreadyExistsException;
 28  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 29  
 import org.kuali.student.common.exceptions.InvalidParameterException;
 30  
 import org.kuali.student.common.exceptions.MissingParameterException;
 31  
 import org.kuali.student.common.exceptions.OperationFailedException;
 32  
 import org.kuali.student.common.exceptions.PermissionDeniedException;
 33  
 import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo;
 34  
 import org.kuali.student.common.search.dto.SearchRequest;
 35  
 import org.kuali.student.common.search.dto.SearchResult;
 36  
 import org.kuali.student.common.search.dto.SearchResultTypeInfo;
 37  
 import org.kuali.student.common.search.dto.SearchTypeInfo;
 38  
 import org.kuali.student.common.search.service.SearchManager;
 39  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 40  
 import org.kuali.student.core.enumerationmanagement.EnumerationException;
 41  
 import org.kuali.student.core.enumerationmanagement.dao.EnumerationManagementDAO;
 42  
 import org.kuali.student.core.enumerationmanagement.dto.EnumeratedValueInfo;
 43  
 import org.kuali.student.core.enumerationmanagement.dto.EnumerationInfo;
 44  
 import org.kuali.student.core.enumerationmanagement.entity.EnumeratedValue;
 45  
 import org.kuali.student.core.enumerationmanagement.entity.Enumeration;
 46  
 import org.kuali.student.core.enumerationmanagement.service.EnumerationManagementService;
 47  
 import org.kuali.student.core.enumerationmanagement.service.impl.util.EnumerationAssembler;
 48  
 import org.slf4j.Logger;
 49  
 import org.slf4j.LoggerFactory;
 50  
 import org.springframework.transaction.annotation.Transactional;
 51  
 
 52  
 @WebService(endpointInterface = "org.kuali.student.core.enumerationmanagement.service.EnumerationManagementService", serviceName = "EnumerationManagementService", portName = "EnumerationManagementService", targetNamespace = "http://student.kuali.org/wsdl/EnumerationManagementService")
 53  
 @Transactional(readOnly=true,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 54  
 @SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
 55  
 public class EnumerationManagementServiceImpl implements EnumerationManagementService{
 56  
     
 57  1
         final static Logger logger = LoggerFactory.getLogger(EnumerationManagementServiceImpl.class);
 58  
         
 59  
     private SearchManager searchManager;
 60  
 
 61  
     private EnumerationManagementDAO enumDAO;
 62  
         
 63  1
         public EnumerationManagementServiceImpl() {}
 64  
     
 65  
     private List<ValidationResultInfo> validateEnumeratedValue(EnumeratedValueInfo value){
 66  0
             return null; //FIXME need real validation
 67  
     }
 68  
      
 69  
         @Override
 70  
         public EnumerationInfo getEnumeration(String enumerationKey)
 71  
                         throws DoesNotExistException, InvalidParameterException,
 72  
                         MissingParameterException, OperationFailedException {
 73  
         
 74  0
         Enumeration enumerationMetaEntity = null;
 75  0
         if (enumerationKey != null)
 76  0
                 enumerationMetaEntity = enumDAO.fetch(Enumeration.class, enumerationKey);
 77  0
         EnumerationInfo enumerationMeta = null;
 78  0
         if(enumerationMetaEntity != null){
 79  0
                 enumerationMeta = new EnumerationInfo();
 80  0
                 EnumerationAssembler.toEnumerationInfo(enumerationMetaEntity, enumerationMeta);
 81  
         }
 82  0
         return enumerationMeta;
 83  
         }
 84  
 
 85  
         @Override
 86  
         public List<EnumerationInfo> getEnumerations()
 87  
                         throws OperationFailedException {
 88  0
         List<Enumeration> entities =  this.enumDAO.findEnumerations();
 89  
         
 90  0
         List<EnumerationInfo> dtos = EnumerationAssembler.toEnumerationMetaList(entities);
 91  
        
 92  0
         return dtos;
 93  
         }
 94  
         
 95  
         @Override
 96  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 97  
         public EnumeratedValueInfo addEnumeratedValue(String enumerationKey,
 98  
                         EnumeratedValueInfo enumeratedValue) throws AlreadyExistsException,
 99  
                         InvalidParameterException, MissingParameterException,
 100  
                         OperationFailedException, PermissionDeniedException {
 101  
             Enumeration meta;
 102  
                 try {                    
 103  0
                         meta = enumDAO.fetch(Enumeration.class, enumeratedValue.getEnumerationKey());                        
 104  0
                 } catch (DoesNotExistException e) {
 105  0
                         throw new InvalidParameterException("Enumeration does not exist for key:"+enumerationKey);
 106  0
                 }
 107  
                 
 108  0
             if(meta != null){
 109  0
                     List<ValidationResultInfo> results = this.validateEnumeratedValue(enumeratedValue);
 110  
             
 111  0
                     if(null != results) {
 112  0
                         for(ValidationResultInfo result:results){
 113  0
                             if(result !=null && ValidationResultInfo.ErrorLevel.ERROR.equals(result.getErrorLevel())){
 114  0
                                 throw new EnumerationException("addEnumeratedValue failed because the EnumeratdValue failed to pass validation against its EnumerationMeta - With Messages: " + result.toString());//FIXME need to get messages here
 115  
                             }
 116  
                         }
 117  
                     }
 118  
             }
 119  
             
 120  0
             EnumeratedValue valueEntity = new EnumeratedValue();
 121  0
             EnumerationAssembler.toEnumeratedValueEntity(enumeratedValue, valueEntity);
 122  0
             valueEntity.setEnumeration(meta);
 123  
             
 124  0
         enumDAO.addEnumeratedValue(enumerationKey, valueEntity);
 125  
         
 126  
 
 127  0
         return enumeratedValue;
 128  
         }
 129  
 
 130  
         @Override
 131  
         public List<EnumeratedValueInfo> getEnumeratedValues(String enumerationKey,
 132  
                         String contextType, String contextValue, Date contextDate)
 133  
                         throws DoesNotExistException, InvalidParameterException,
 134  
                         MissingParameterException, OperationFailedException {
 135  
 
 136  0
         List<EnumeratedValue> enumeratedValueEntityList = new ArrayList<EnumeratedValue>();
 137  0
         if(enumerationKey != null && contextType != null && contextValue != null && contextDate != null){
 138  0
                 enumeratedValueEntityList = enumDAO.fetchEnumeratedValuesWithContextAndDate(enumerationKey, contextType, contextValue, contextDate);
 139  
         }
 140  0
         else if(enumerationKey != null && contextType != null && contextValue != null){
 141  0
                 enumeratedValueEntityList = enumDAO.fetchEnumeratedValuesWithContext(enumerationKey, contextType, contextValue);
 142  
         }
 143  0
         else if(enumerationKey != null && contextDate != null){
 144  0
                 enumeratedValueEntityList = enumDAO.fetchEnumeratedValuesWithDate(enumerationKey, contextDate);
 145  
         }
 146  0
         else if(enumerationKey != null){
 147  0
                 enumeratedValueEntityList = enumDAO.fetchEnumeratedValues(enumerationKey);
 148  
         }
 149  
         
 150  0
         List<EnumeratedValueInfo> enumeratedValueList = EnumerationAssembler.toEnumeratedValueList(enumeratedValueEntityList);
 151  0
         return enumeratedValueList;
 152  
         }
 153  
 
 154  
 
 155  
         @Override
 156  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 157  
         public EnumeratedValueInfo updateEnumeratedValue(String enumerationKey,
 158  
                         String code, EnumeratedValueInfo enumeratedValue)
 159  
                         throws DoesNotExistException, InvalidParameterException,
 160  
                         MissingParameterException, OperationFailedException,
 161  
                         PermissionDeniedException {
 162  
         
 163  
         Enumeration meta;
 164  
         try {           
 165  0
             meta = enumDAO.fetch(Enumeration.class, enumeratedValue.getEnumerationKey());           
 166  0
         } catch (DoesNotExistException e) {
 167  0
             throw new InvalidParameterException("Enumeration does not exist for key:"+enumerationKey);
 168  0
         }
 169  
             
 170  0
             if(meta != null){
 171  0
                 List<ValidationResultInfo> results = this.validateEnumeratedValue(enumeratedValue);
 172  
 
 173  0
                 if(null != results) {
 174  0
                     for(ValidationResultInfo result:results){
 175  0
                         if(result !=null && ValidationResultInfo.ErrorLevel.ERROR.equals(result.getErrorLevel())){
 176  0
                             throw new EnumerationException("addEnumeratedValue failed because the EnumeratdValue failed to pass validation against its EnumerationMeta - With Messages: " + result.toString());//FIXME need to get messages here
 177  
                         }
 178  
                     }
 179  
                 }
 180  
             }
 181  
 
 182  0
             EnumeratedValue enumeratedValueEntity = new EnumeratedValue();    
 183  0
             EnumerationAssembler.toEnumeratedValueEntity(enumeratedValue, enumeratedValueEntity);
 184  0
             enumeratedValueEntity =  enumDAO.updateEnumeratedValue(meta, code, enumeratedValueEntity);
 185  0
             EnumerationAssembler.toEnumeratedValueInfo(enumeratedValueEntity, enumeratedValue);
 186  
         
 187  0
         return enumeratedValue;
 188  
         }
 189  
         
 190  
         @Override
 191  
     @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 192  
         public StatusInfo removeEnumeratedValue(String enumerationKey, String code) {
 193  0
         enumDAO.removeEnumeratedValue(enumerationKey, code);
 194  0
         return new StatusInfo();
 195  
     }
 196  
         
 197  
         
 198  
         @Override
 199  
         public SearchCriteriaTypeInfo getSearchCriteriaType(
 200  
                         String searchCriteriaTypeKey) throws DoesNotExistException,
 201  
                         InvalidParameterException, MissingParameterException,
 202  
                         OperationFailedException {
 203  
 
 204  0
                 return searchManager.getSearchCriteriaType(searchCriteriaTypeKey);
 205  
         }
 206  
 
 207  
         @Override
 208  
         public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes()
 209  
                         throws OperationFailedException {
 210  0
                 return searchManager.getSearchCriteriaTypes();
 211  
         }
 212  
 
 213  
         @Override
 214  
         public SearchResultTypeInfo getSearchResultType(String searchResultTypeKey)
 215  
                         throws DoesNotExistException, InvalidParameterException,
 216  
                         MissingParameterException, OperationFailedException {
 217  0
                 checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey");
 218  0
                 return searchManager.getSearchResultType(searchResultTypeKey);
 219  
         }
 220  
 
 221  
         @Override
 222  
         public List<SearchResultTypeInfo> getSearchResultTypes()
 223  
                         throws OperationFailedException {
 224  0
                 return searchManager.getSearchResultTypes();
 225  
         }
 226  
 
 227  
         @Override
 228  
         public SearchTypeInfo getSearchType(String searchTypeKey)
 229  
                         throws DoesNotExistException, InvalidParameterException,
 230  
                         MissingParameterException, OperationFailedException {
 231  0
                 checkForMissingParameter(searchTypeKey, "searchTypeKey");
 232  0
                 return searchManager.getSearchType(searchTypeKey);
 233  
         }
 234  
 
 235  
         @Override
 236  
         public List<SearchTypeInfo> getSearchTypes()
 237  
                         throws OperationFailedException {
 238  0
                 return searchManager.getSearchTypes();
 239  
         }
 240  
 
 241  
         @Override
 242  
         public List<SearchTypeInfo> getSearchTypesByCriteria(
 243  
                         String searchCriteriaTypeKey) throws DoesNotExistException,
 244  
                         InvalidParameterException, MissingParameterException,
 245  
                         OperationFailedException {
 246  0
                 checkForMissingParameter(searchCriteriaTypeKey, "searchCriteriaTypeKey");
 247  0
                 return searchManager.getSearchTypesByCriteria(searchCriteriaTypeKey);
 248  
         }
 249  
 
 250  
         @Override
 251  
         public List<SearchTypeInfo> getSearchTypesByResult(
 252  
                         String searchResultTypeKey) throws DoesNotExistException,
 253  
                         InvalidParameterException, MissingParameterException,
 254  
                         OperationFailedException {
 255  0
                 checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey");
 256  0
                 return searchManager.getSearchTypesByResult(searchResultTypeKey);
 257  
         }
 258  
 
 259  
         @Override
 260  
         public SearchResult search(SearchRequest searchRequest) throws MissingParameterException {
 261  0
                 return searchManager.search(searchRequest, enumDAO);
 262  
         }
 263  
         
 264  
         /**
 265  
          * Check for missing parameter and throw localized exception if missing
 266  
          *
 267  
          * @param param
 268  
          * @param parameter name
 269  
          * @throws MissingParameterException
 270  
          */
 271  
         private void checkForMissingParameter(Object param, String paramName)
 272  
                         throws MissingParameterException {
 273  0
                 if (param == null) {
 274  0
                         throw new MissingParameterException(paramName + " can not be null");
 275  
                 }
 276  0
         }
 277  
 
 278  
         public void setSearchManager(SearchManager searchManager) {
 279  0
                 this.searchManager = searchManager;
 280  0
         }
 281  
 
 282  
         public void setEnumDAO(EnumerationManagementDAO enumDAO) {
 283  0
                 this.enumDAO = enumDAO;
 284  0
         }
 285  
 
 286  
     @Override
 287  
     public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
 288  
         // TODO Kamal - THIS METHOD NEEDS JAVADOCS
 289  0
         return null;
 290  
     }
 291  
 
 292  
     @Override
 293  
     public List<String> getObjectTypes() {
 294  
         // TODO Kamal - THIS METHOD NEEDS JAVADOCS
 295  0
         return null;
 296  
     }
 297  
 }