@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"); // Validate 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; }
public RefStatementRelation toRefStatementRelation(boolean isUpdate, RefStatementRelationInfo refStatementRelationInfo) throws DoesNotExistException, VersionMismatchException, InvalidParameterException { RefStatementRelation refStatement; if (isUpdate) { refStatement = this.statementDao.fetch(RefStatementRelation.class, refStatementRelationInfo.getId()); if (refStatement == null) { throw new DoesNotExistException("RefStatementRelation does not exist for id: " + refStatementRelationInfo.getId()); } if (!String.valueOf(refStatement.getVersionNumber()).equals(refStatementRelationInfo.getMetaInfo().getVersionInd())) { throw new VersionMismatchException("RefStatementRelation to be updated is not the current version"); } } else { refStatement = new RefStatementRelation(); } BeanUtils.copyProperties(refStatementRelationInfo, refStatement, new String[]{"attributes", "metaInfo", "type", "statementId"}); // make sure refObjectType exist this.statementDao.fetch(ObjectType.class, refStatementRelationInfo.getRefObjectTypeKey()); // Copy generic attributes refStatement.setAttributes(toGenericAttributes(RefStatementRelationAttribute.class, refStatementRelationInfo.getAttributes(), refStatement, this.statementDao)); RefStatementRelationType type = this.statementDao.fetch(RefStatementRelationType.class, refStatementRelationInfo.getType()); refStatement.setRefStatementRelationType(type); Statement statement = this.statementDao.fetch(Statement.class, refStatementRelationInfo.getStatementId()); refStatement.setStatement(statement); return refStatement; }
@Override @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) public RefStatementRelationInfo updateRefStatementRelation(final String refStatementRelationId, final RefStatementRelationInfo refStatementRelationInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { checkForNullOrEmptyParameter(refStatementRelationId, "refStatementRelationId"); checkForMissingParameter(refStatementRelationInfo, "refStatementRelationInfo"); refStatementRelationInfo.setId(refStatementRelationId); RefStatementRelation refStatementRel = statementAssembler.toRefStatementRelation(true, refStatementRelationInfo); RefStatementRelation updatedRefStatementRel = statementDao.update(refStatementRel); RefStatementRelationInfo dto = StatementAssembler.toRefStatementRelationInfo(updatedRefStatementRel); return dto; }
public static RefStatementRelationInfo toRefStatementRelationInfo(RefStatementRelation entity) { RefStatementRelationInfo dto = new RefStatementRelationInfo(); BeanUtils.copyProperties(entity, dto, new String[]{"refStatementRelationType", "statement", "attributes", "metaInfo"}); // Copy generic attributes dto.setAttributes(toAttributeMap(entity.getAttributes())); dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber())); dto.setStatementId(entity.getStatement().getId()); dto.setType(entity.getRefStatementRelationType().getId()); // dto.setRefObjectTypeKey(entity.getRefStatementRelationType().getObjectSubTypeList().get(0).g) return dto; }
@Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) public RefStatementRelationInfo createRefStatementRelation(final RefStatementRelationInfo refStatementRelationInfo) throws AlreadyExistsException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { checkForMissingParameter(refStatementRelationInfo, "refStatementRelationInfo"); Statement statement = this.statementDao.fetch(Statement.class, refStatementRelationInfo.getStatementId()); RefStatementRelationType type = this.statementDao.fetch(RefStatementRelationType.class, refStatementRelationInfo.getType()); // make sure refObjectType exist this.statementDao.fetch(ObjectType.class, refStatementRelationInfo.getRefObjectTypeKey()); RefStatementRelation entity = new RefStatementRelation(); BeanUtils.copyProperties(refStatementRelationInfo, entity, new String[] { "statementId", "attributes", "metaInfo", "type", "id"}); entity.setRefStatementRelationType(type); entity.setStatement(statement); List<RefStatementRelationAttribute> attributes = StatementAssembler.toGenericAttributes(RefStatementRelationAttribute.class, refStatementRelationInfo.getAttributes(), entity, this.statementDao); entity.setAttributes(attributes); RefStatementRelation newEntity = this.statementDao.create(entity); RefStatementRelationInfo newDto = StatementAssembler.toRefStatementRelationInfo(newEntity); return newDto; }
case CREATE: RefStatementRelationInfo created = statementService.createRefStatementRelation(relation); relation.setMetaInfo(created.getMetaInfo()); break; case UPDATE: RefStatementRelationInfo updated = statementService.updateRefStatementRelation(relation.getId(), relation); relation.setMetaInfo(updated.getMetaInfo()); break; case DELETE: statementService.deleteRefStatementRelation(relation.getId()); break;
/** * @param courseId * @param statementTreeViewInfo * @return reference exists * @throws InvalidParameterException * @throws MissingParameterException * @throws OperationFailedException * @throws DoesNotExistException */ private RefStatementRelationInfo findStatementReference(String courseId, StatementTreeViewInfo statementTreeViewInfo, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, DoesNotExistException { List<RefStatementRelationInfo> course = R1R2ConverterUtil.convertLists(statementService.getRefStatementRelationsByRef(CourseAssemblerConstants.COURSE_TYPE, courseId), RefStatementRelationInfo.class); if (course != null) { for (RefStatementRelationInfo refRelation : course) { if (refRelation.getStatementId().equals(statementTreeViewInfo.getId())) { return refRelation; } } } return null; }
@Override @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class}) public StatusInfo deleteCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { checkForMissingParameter(courseId, "courseId"); checkForMissingParameter(statementTreeViewInfo, "statementTreeViewInfo"); RefStatementRelationInfo relation = findStatementReference(courseId, statementTreeViewInfo, contextInfo); if (relation != null) { statementService.deleteRefStatementRelation(relation.getId()); statementService.deleteStatementTreeView(statementTreeViewInfo.getId()); StatusInfo result = new StatusInfo(); return result; } throw new DoesNotExistException("Course does not have this StatemenTree"); }
@Override @Transactional(readOnly = true) public List<StatementTreeViewInfo> getCourseStatements(String courseId, String nlUsageTypeKey, String language, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { checkForMissingParameter(courseId, "courseId"); CluInfo clu = cluService.getClu(courseId, contextInfo); if (!CourseAssemblerConstants.COURSE_TYPE.equals(clu.getTypeKey())) { throw new DoesNotExistException("Specified CLU is not a Course"); } List<RefStatementRelationInfo> relations = R1R2ConverterUtil.convertLists(statementService.getRefStatementRelationsByRef(CourseAssemblerConstants.COURSE_TYPE, clu.getId()), RefStatementRelationInfo.class); if (relations == null) { return new ArrayList<StatementTreeViewInfo>(0); } List<StatementTreeViewInfo> tree = new ArrayList<StatementTreeViewInfo>(relations.size()); for (RefStatementRelationInfo relation : relations) { tree.add(statementService.getStatementTreeView(relation.getStatementId())); } return tree; }
relation = new RefStatementRelationInfo(); relation.setId(UUIDHelper.genStringUUID(null)); } else { try { relation.setType("clu.prerequisites"); // FIXME Derive from statement and rule types relation.setType(ProgramAssemblerConstants.PROGRAM_REFERENCE_TYPE); relation.setRefObjectId(clu.getId()); relation.setRefObjectTypeKey(ProgramAssemblerConstants.PROGRAM_REQUIREMENT); relation.setStatementId(statement.getId()); relation.setState(DtoConstants.STATE_ACTIVE);
StatementTreeViewInfo statementTree = new StatementTreeViewInfo(); if (relations != null) { statementTreeViewAssembler.assemble(statementService.getStatementTreeView(relations.get(0).getStatementId()), statementTree, shallowBuild, contextInfo);