| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.r2.core.class1.enumerationmanagemnet.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 | |
|
| 24 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 25 | |
import org.kuali.student.r2.common.dto.StatusInfo; |
| 26 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
| 27 | |
import org.kuali.student.r2.common.exceptions.AlreadyExistsException; |
| 28 | |
import org.kuali.student.r2.common.exceptions.DataValidationErrorException; |
| 29 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
| 30 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
| 31 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
| 32 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
| 33 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
| 34 | |
import org.kuali.student.r2.common.exceptions.ReadOnlyException; |
| 35 | |
import org.kuali.student.r2.common.exceptions.VersionMismatchException; |
| 36 | |
import org.kuali.student.r2.common.util.constants.EnumerationManagementServiceConstants; |
| 37 | |
import org.kuali.student.r2.core.class1.enumerationmanagement.dao.EnumContextValueDao; |
| 38 | |
import org.kuali.student.r2.core.class1.enumerationmanagement.dao.EnumeratedValueDao; |
| 39 | |
import org.kuali.student.r2.core.class1.enumerationmanagement.dao.EnumerationDao; |
| 40 | |
import org.kuali.student.r2.core.class1.enumerationmanagement.model.EnumeratedValueEntity; |
| 41 | |
import org.kuali.student.r2.core.class1.enumerationmanagement.model.EnumerationEntity; |
| 42 | |
import org.kuali.student.r2.core.enumerationmanagement.dto.EnumeratedValueInfo; |
| 43 | |
import org.kuali.student.r2.core.enumerationmanagement.dto.EnumerationInfo; |
| 44 | |
import org.kuali.student.r2.core.enumerationmanagement.service.EnumerationManagementService; |
| 45 | |
import org.springframework.transaction.annotation.Transactional; |
| 46 | |
|
| 47 | |
@WebService(name = "EnumerationManagementService", serviceName = "EnumerationManagementService", portName = "EnumerationManagementService", targetNamespace = EnumerationManagementServiceConstants.NAMESPACE) |
| 48 | |
@Transactional(readOnly = true, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class}) |
| 49 | 0 | public class EnumerationManagementServiceImpl implements EnumerationManagementService { |
| 50 | |
|
| 51 | |
private EnumerationDao enumDao; |
| 52 | |
private EnumeratedValueDao enumValueDao; |
| 53 | |
private EnumContextValueDao enumContextValueDao; |
| 54 | |
|
| 55 | |
public EnumerationDao getEnumDao() { |
| 56 | 0 | return enumDao; |
| 57 | |
} |
| 58 | |
|
| 59 | |
public void setEnumDao(EnumerationDao enumDao) { |
| 60 | 0 | this.enumDao = enumDao; |
| 61 | 0 | } |
| 62 | |
|
| 63 | |
public EnumeratedValueDao getEnumValueDao() { |
| 64 | 0 | return enumValueDao; |
| 65 | |
} |
| 66 | |
|
| 67 | |
public void setEnumValueDao(EnumeratedValueDao enumValueDao) { |
| 68 | 0 | this.enumValueDao = enumValueDao; |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
public EnumContextValueDao getEnumContextValueDao() { |
| 72 | 0 | return enumContextValueDao; |
| 73 | |
} |
| 74 | |
|
| 75 | |
public void setEnumContextValueDao(EnumContextValueDao enumContextValueDao) { |
| 76 | 0 | this.enumContextValueDao = enumContextValueDao; |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
@Override |
| 80 | |
@Transactional(readOnly=true) |
| 81 | |
public List<EnumerationInfo> getEnumerations(ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 82 | |
|
| 83 | 0 | List<EnumerationEntity> enumEntities = this.enumDao.findEnumerations(); |
| 84 | 0 | List<EnumerationInfo> enumInfos = new ArrayList<EnumerationInfo>(enumEntities.size()); |
| 85 | |
|
| 86 | 0 | for (EnumerationEntity enumeration : enumEntities){ |
| 87 | 0 | enumInfos.add(enumeration.toDto()); |
| 88 | |
} |
| 89 | |
|
| 90 | 0 | return enumInfos; |
| 91 | |
|
| 92 | |
} |
| 93 | |
|
| 94 | |
@Override |
| 95 | |
public EnumerationInfo getEnumeration(String enumerationKey, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 96 | |
|
| 97 | 0 | EnumerationEntity entity = enumDao.find(enumerationKey); |
| 98 | |
|
| 99 | 0 | if(entity == null) |
| 100 | 0 | throw new DoesNotExistException(enumerationKey); |
| 101 | |
|
| 102 | 0 | return entity.toDto(); |
| 103 | |
} |
| 104 | |
|
| 105 | |
@Override |
| 106 | |
public List<EnumeratedValueInfo> getEnumeratedValues(String enumerationKey, String contextTypeKey, String contextValue, Date contextDate, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 107 | |
|
| 108 | 0 | List<EnumeratedValueEntity> enumeratedValues = null; |
| 109 | |
|
| 110 | 0 | if(enumerationKey != null && contextTypeKey != null && contextValue != null && contextDate != null){ |
| 111 | 0 | enumeratedValues = enumValueDao.getByContextAndDate(enumerationKey, contextTypeKey, contextValue, contextDate); |
| 112 | |
} |
| 113 | 0 | else if(enumerationKey != null && contextTypeKey != null && contextValue != null){ |
| 114 | 0 | enumeratedValues = enumValueDao.getByContextTypeAndValue(enumerationKey, contextTypeKey, contextValue); |
| 115 | |
} |
| 116 | 0 | else if(enumerationKey != null && contextDate != null){ |
| 117 | 0 | enumeratedValues = enumValueDao.getByDate(enumerationKey, contextDate); |
| 118 | |
} |
| 119 | 0 | else if(enumerationKey != null){ |
| 120 | 0 | enumeratedValues = enumValueDao.getByEnumerationKey(enumerationKey); |
| 121 | |
} |
| 122 | |
|
| 123 | 0 | if(enumeratedValues == null) |
| 124 | 0 | throw new DoesNotExistException(enumerationKey); |
| 125 | |
|
| 126 | 0 | List<EnumeratedValueInfo> enumeratedValueInfos = new ArrayList<EnumeratedValueInfo>(enumeratedValues.size()); |
| 127 | 0 | for (EnumeratedValueEntity enumeratedValue : enumeratedValues){ |
| 128 | 0 | enumeratedValueInfos.add(enumeratedValue.toDto()); |
| 129 | |
} |
| 130 | |
|
| 131 | 0 | return enumeratedValueInfos; |
| 132 | |
} |
| 133 | |
|
| 134 | |
@Override |
| 135 | |
public List<ValidationResultInfo> validateEnumeratedValue(String validationTypeKey, String enumerationKey, String code, EnumeratedValueInfo enumeratedValueInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 136 | 0 | return null; |
| 137 | |
} |
| 138 | |
|
| 139 | |
@Override |
| 140 | |
@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
| 141 | |
public EnumeratedValueInfo updateEnumeratedValue(String enumerationKey, String code, EnumeratedValueInfo enumeratedValueInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
| 142 | 0 | EnumerationEntity enumerationEntity = enumDao.find(enumeratedValueInfo.getEnumerationKey()); |
| 143 | 0 | if(enumerationEntity == null) |
| 144 | 0 | throw new DoesNotExistException(enumeratedValueInfo.getEnumerationKey()); |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | 0 | EnumeratedValueEntity entity = new EnumeratedValueEntity(enumeratedValueInfo); |
| 159 | |
|
| 160 | 0 | EnumeratedValueEntity existing = enumValueDao.find(entity.getId()); |
| 161 | 0 | if( existing == null) { |
| 162 | 0 | throw new DoesNotExistException(entity.getId()); |
| 163 | |
} |
| 164 | 0 | enumValueDao.merge(entity); |
| 165 | |
|
| 166 | 0 | return enumValueDao.find(entity.getId()).toDto(); |
| 167 | |
} |
| 168 | |
|
| 169 | |
@Override |
| 170 | |
public StatusInfo deleteEnumeratedValue(String enumerationKey, String code, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
| 171 | 0 | StatusInfo status = new StatusInfo(); |
| 172 | 0 | status.setSuccess(Boolean.TRUE); |
| 173 | |
|
| 174 | 0 | EnumeratedValueEntity enumeratedValue = enumValueDao.getByEnumerationKeyAndCode(enumerationKey, code); |
| 175 | 0 | if (null != enumeratedValue) { |
| 176 | 0 | enumValueDao.remove(enumeratedValue); |
| 177 | |
} else |
| 178 | 0 | status.setSuccess(Boolean.FALSE); |
| 179 | |
|
| 180 | 0 | return status; |
| 181 | |
} |
| 182 | |
|
| 183 | |
@Override |
| 184 | |
@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
| 185 | |
public EnumeratedValueInfo addEnumeratedValue(String enumerationKey, String code, EnumeratedValueInfo enumeratedValueInfo, ContextInfo contextInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
| 186 | 0 | EnumerationEntity enumerationEntity = enumDao.find(enumeratedValueInfo.getEnumerationKey()); |
| 187 | 0 | if(enumerationEntity == null) |
| 188 | 0 | throw new DoesNotExistException(enumeratedValueInfo.getEnumerationKey()); |
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | 0 | EnumeratedValueEntity entity = new EnumeratedValueEntity(enumeratedValueInfo); |
| 203 | |
|
| 204 | 0 | EnumeratedValueEntity existing = enumValueDao.find(entity.getId()); |
| 205 | 0 | if( existing != null) { |
| 206 | 0 | throw new AlreadyExistsException(); |
| 207 | |
} |
| 208 | 0 | enumValueDao.persist(entity); |
| 209 | |
|
| 210 | 0 | return enumValueDao.find(entity.getId()).toDto(); |
| 211 | |
|
| 212 | |
} |
| 213 | |
|
| 214 | |
} |