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