public static Assignment addHint(Assignment assignment, Hint hint) { assignment.setHints( Stream.concat(assignment.getHints().stream(), Stream.of(hint)).collect(toList())); return assignment; }
/** * Creates an Assignment object from a request, returns null if correct parameters not present or * empty * * @param request * @return */ public static Optional<Assignment> createAssignment(HttpServletRequest request) { String artifact = request.getParameter("artifact"); String name = request.getParameter("name"); String participantDescription = request.getParameter("participantDescription"); String spectatorDescription = request.getParameter("spectatorDescription"); String creatorName = request.getParameter("creatorName"); String creatorOrganisation = request.getParameter("creatorOrganisation"); String creatorLink = request.getParameter("creatorLink"); Optional<Assignment> assignmentOpt = Optional.empty(); try { if (!(artifact.isEmpty() || name.isEmpty() || participantDescription.isEmpty() || spectatorDescription.isEmpty() || creatorName.isEmpty() || creatorOrganisation.isEmpty() || creatorLink.isEmpty())) { Assignment assignment = new Assignment(); assignment.setArtifact(artifact); assignment.setName(name); assignment.setParticipantDescription(participantDescription); assignment.setSpectatorDescription(spectatorDescription); assignment.setCreatorName(creatorName); assignment.setCreatorOrganisation(creatorOrganisation); assignment.setCreatorLink(creatorLink); assignmentOpt = Optional.of(assignment); } } catch (NullPointerException ex) { // parameter not available } return assignmentOpt; }