@Override
@Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
public StatementTreeViewInfo createCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException {
checkForMissingParameter(courseId, "courseId");
checkForMissingParameter(statementTreeViewInfo, "statementTreeViewInfo");
List<ValidationResultInfo> validationResults = validateCourseStatement(courseId, statementTreeViewInfo, contextInfo);
if (ValidatorUtils.hasErrors(validationResults)) {
throw new DataValidationErrorException("Validation error!", validationResults);
}
if (findStatementReference(courseId, statementTreeViewInfo, contextInfo) != null) {
throw new InvalidParameterException("Statement is already referenced by this course");
}
try {
StatementTreeViewInfo tree = statementService.createStatementTreeView(statementTreeViewInfo);
RefStatementRelationInfo relation = new RefStatementRelationInfo();
relation.setRefObjectId(courseId);
relation.setRefObjectTypeKey(CourseAssemblerConstants.COURSE_TYPE);
relation.setStatementId(tree.getId());
relation.setType(CourseAssemblerConstants.COURSE_REFERENCE_TYPE);
relation.setState(CourseAssemblerConstants.ACTIVE);
statementService.createRefStatementRelation(R1R2ConverterUtil.convert(relation, org.kuali.student.r1.core.statement.dto.RefStatementRelationInfo.class));
} catch (Exception e) {
throw new OperationFailedException("Unable to create clu/tree relation", e);
}
return statementTreeViewInfo;
}