当前位置: 首页>>代码示例>>Java>>正文


Java Ebean.find方法代码示例

本文整理汇总了Java中io.ebean.Ebean.find方法的典型用法代码示例。如果您正苦于以下问题:Java Ebean.find方法的具体用法?Java Ebean.find怎么用?Java Ebean.find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.ebean.Ebean的用法示例。


在下文中一共展示了Ebean.find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getReservations

import io.ebean.Ebean; //导入方法依赖的package包/类
@SubjectNotPresent
public Result getReservations(Optional<String> start, Optional<String> end, Optional<Long> roomId) {
    PathProperties pp = PathProperties.parse("(startAt, endAt, noShow, " +
            "user(firstName, lastName, email, userIdentifier), " +
            "enrolment(exam(name, examOwners(firstName, lastName, email), parent(examOwners(firstName, lastName, email)))), " +
            "machine(name, ipAddress, otherIdentifier, room(name, roomCode)))");
    Query<Reservation> query = Ebean.find(Reservation.class);
    pp.apply(query);
    ExpressionList<Reservation> el = query.where()
            .isNotNull("enrolment")
            .ne("enrolment.exam.state", Exam.State.DELETED);
    if (start.isPresent()) {
        DateTime startDate = ISODateTimeFormat.dateTimeParser().parseDateTime(start.get());
        el = el.ge("startAt", startDate.toDate());
    }

    if (end.isPresent()) {
        DateTime endDate = ISODateTimeFormat.dateTimeParser().parseDateTime(end.get());
        el = el.lt("endAt", endDate.toDate());
    }
    if (roomId.isPresent()) {
        el = el.eq("machine.room.id", roomId.get());
    }
    Set<Reservation> reservations = el.orderBy("startAt").findSet();
    return ok(reservations, pp);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:27,代码来源:ReservationAPIController.java

示例2: setUp

import io.ebean.Ebean; //导入方法依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Ebean.deleteAll(Ebean.find(ExamEnrolment.class).findList());
    exam = Ebean.find(Exam.class).fetch("examSections").fetch("examSections.sectionQuestions").where().idEq(1L).findUnique();
    initExamSectionQuestions(exam);

    user = Ebean.find(User.class, userId);
    ExamRoom room = Ebean.find(ExamRoom.class, 1L);
    machine = room.getExamMachines().get(0);
    machine.setIpAddress("127.0.0.1"); // so that the IP check won't fail
    machine.update();
    reservation.setMachine(machine);
    reservation.setUser(user);
    reservation.setStartAt(DateTime.now().minusMinutes(10));
    reservation.setEndAt(DateTime.now().plusMinutes(70));
    reservation.save();
    enrolment.setExam(exam);
    enrolment.setUser(user);
    enrolment.setReservation(reservation);
    enrolment.save();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:24,代码来源:StudentExamControllerTest.java

示例3: removeCourse

import io.ebean.Ebean; //导入方法依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result removeCourse(Long eid, Long cid) {
    Exam exam = Ebean.find(Exam.class, eid);
    if (exam == null) {
        return notFound("sitnet_error_exam_not_found");
    }
    User user = getLoggedUser();
    if (!isAllowedToUpdate(exam, user)) {
        return forbidden("sitnet_error_future_reservations_exist");
    }
    if (exam.isOwnedOrCreatedBy(user) || user.hasRole("ADMIN", getSession())) {
        exam.setCourse(null);
        exam.save();
        return ok(exam);
    } else {
        return forbidden("sitnet_error_access_forbidden");
    }
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:19,代码来源:ExamController.java

示例4: testEnableRoom

import io.ebean.Ebean; //导入方法依赖的package包/类
@Test
@RunAsAdmin
public void testEnableRoom() throws Exception {

    // Setup
    ExamRoom room = Ebean.find(ExamRoom.class, 1L);
    room.setState(ExamRoom.State.INACTIVE.toString());
    room.update();

    // Execute
    Result result = request(Helpers.POST, "/app/rooms/" + 1, null);
    assertThat(result.status()).isEqualTo(200);

    // Verify (both response and database)
    JsonNode node = Json.parse(contentAsString(result));
    ExamRoom deserialized = deserialize(ExamRoom.class, node);
    assertThat(deserialized.getState()).isEqualTo(ExamRoom.State.ACTIVE.toString());

    room = Ebean.find(ExamRoom.class, 1L);
    assertThat(room.getState()).isEqualTo(ExamRoom.State.ACTIVE.toString());
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:22,代码来源:RoomControllerTest.java

示例5: revokeUserPermission

import io.ebean.Ebean; //导入方法依赖的package包/类
@Restrict({@Group("ADMIN")})
public Result revokeUserPermission() {
    DynamicForm df = formFactory.form().bindFromRequest();
    String permissionString = df.get("permission");
    User user = Ebean.find(User.class, df.get("id"));
    if (user == null) {
        return notFound();
    }
    if (user.getPermissions().stream().anyMatch(p -> p.getValue().equals(permissionString))) {
        Permission permission = Ebean.find(Permission.class).where()
                .eq("type", Permission.Type.valueOf(permissionString))
                .findUnique();
        user.getPermissions().remove(permission);
        user.update();
    }
    return ok();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:18,代码来源:UserController.java

示例6: listExams

import io.ebean.Ebean; //导入方法依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result listExams(Optional<List<Long>> courseIds, Optional<List<Long>> sectionIds, Optional<List<Long>> tagIds) {
    User user = getLoggedUser();
    List<Long> courses = courseIds.orElse(Collections.emptyList());
    List<Long> sections = sectionIds.orElse(Collections.emptyList());
    List<Long> tags = tagIds.orElse(Collections.emptyList());
    PathProperties pp = PathProperties.parse("(id, name, course(id, code), examSections(id, name))");
    Query<Exam> query = Ebean.find(Exam.class);
    pp.apply(query);
    ExpressionList<Exam> el = query.where().isNotNull("name").isNotNull("course");
    if (!user.hasRole("ADMIN", getSession())) {
        el = el.eq("examOwners", user);
    }
    if (!courses.isEmpty()) {
        el = el.in("course.id", courses);
    }
    if (!sections.isEmpty()) {
        el = el.in("examSections.id", sections);
    }
    if (!tags.isEmpty()) {
        el = el.in("examSections.sectionQuestions.question.parent.tags.id", tags);
    }
    return ok(el.findList(), pp);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:25,代码来源:ExamController.java

示例7: addInspectionComment

import io.ebean.Ebean; //导入方法依赖的package包/类
@Restrict({@Group("ADMIN"), @Group("TEACHER")})
public Result addInspectionComment(Long id) {
    Exam exam = Ebean.find(Exam.class, id);
    if (exam == null) {
        return notFound("Inspection not found");
    }
    DynamicForm df = formFactory.form().bindFromRequest();
    InspectionComment ic = new InspectionComment();
    User user = getLoggedUser();
    AppUtil.setCreator(ic, user);
    AppUtil.setModifier(ic, user);
    ic.setComment(df.get("comment"));
    ic.setExam(exam);
    ic.save();
    return ok(ic, PathProperties.parse("(creator(firstName, lastName, email), created, comment)"));
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:17,代码来源:ReviewController.java

示例8: sendInspectionMessage

import io.ebean.Ebean; //导入方法依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result sendInspectionMessage(Long eid) {

    Exam exam = Ebean.find(Exam.class, eid);
    if (exam == null) {
        return notFound("sitnet_error_exam_not_found");
    }
    JsonNode body = request().body().asJson();
    if (!body.has("msg")) {
        return badRequest("no message received");
    }
    User loggedUser = getLoggedUser();
    List<ExamInspection> inspections = Ebean.find(ExamInspection.class)
            .fetch("user")
            .fetch("exam")
            .where()
            .eq("exam.id", exam.getId())
            .ne("user.id", loggedUser.getId())
            .findList();

    Set<User> recipients = inspections.stream()
            .map(ExamInspection::getUser)
            .collect(Collectors.toSet());

    // add owners to list, except those how are already in the list and self
    if (exam.getParent() != null) {
        for (User owner : exam.getParent().getExamOwners()) {
            if (owner.equals(loggedUser)) {
                continue;
            }
            recipients.add(owner);
        }
    }
    actor.scheduler().scheduleOnce(Duration.create(1, TimeUnit.SECONDS), () -> {
        for (User user : recipients) {
            emailComposer.composeInspectionMessage(user, loggedUser, exam, body.get("msg").asText());
        }
    }, actor.dispatcher());
    return ok();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:41,代码来源:ReviewController.java

示例9: updateGradeEvaluations

import io.ebean.Ebean; //导入方法依赖的package包/类
private static void updateGradeEvaluations(Exam exam, AutoEvaluationConfig newConfig) {
    AutoEvaluationConfig config = exam.getAutoEvaluationConfig();

    Map<Integer, GradeEvaluation> gradeMap = config.asGradeMap();
    List<Integer> handledEvaluations = new ArrayList<>();
    GradeScale gs = exam.getGradeScale() == null ? exam.getCourse().getGradeScale() : exam.getGradeScale();
    // Handle proposed entries, persist new ones where necessary
    for (GradeEvaluation src : newConfig.getGradeEvaluations()) {
        Grade grade = Ebean.find(Grade.class, src.getGrade().getId());
        if (grade != null && gs.getGrades().contains(grade)) {
            GradeEvaluation ge = gradeMap.get(grade.getId());
            if (ge == null) {
                ge = new GradeEvaluation();
                ge.setGrade(grade);
                ge.setAutoEvaluationConfig(config);
                config.getGradeEvaluations().add(ge);
            }
            ge.setPercentage(src.getPercentage());
            ge.save();
            handledEvaluations.add(grade.getId());
        } else {
            throw new IllegalArgumentException("unknown grade");
        }
    }
    // Remove obsolete entries
    gradeMap.entrySet().stream()
            .filter(entry -> !handledEvaluations.contains(entry.getKey()))
            .forEach(entry -> {
                entry.getValue().delete();
                config.getGradeEvaluations().remove(entry.getValue());
            });
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:33,代码来源:ExamController.java

示例10: findAvailableMachines

import io.ebean.Ebean; //导入方法依赖的package包/类
@Restrict({@Group("ADMIN")})
public Result findAvailableMachines(Long reservationId) {
    Reservation reservation = Ebean.find(Reservation.class, reservationId);
    if (reservation == null) {
        return notFound();
    }
    PathProperties props = PathProperties.parse("(id, name)");
    Query<ExamMachine> query = Ebean.createQuery(ExamMachine.class);
    props.apply(query);

    List<ExamMachine> candidates = query.where()
            .eq("room", reservation.getMachine().getRoom())
            .ne("outOfService", true)
            .ne("archived", true)
            .findList();

    Iterator<ExamMachine> it = candidates.listIterator();
    while (it.hasNext()) {
        ExamMachine machine = it.next();
        if (!machine.hasRequiredSoftware(reservation.getEnrolment().getExam())) {
            it.remove();
        }
        if (machine.isReservedDuring(reservation.toInterval())) {
            it.remove();
        }
    }
    return ok(candidates, props);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:29,代码来源:ReservationController.java

示例11: reportStudentActivity

import io.ebean.Ebean; //导入方法依赖的package包/类
@Restrict({@Group("ADMIN")})
public Result reportStudentActivity(Long studentId, String from, String to) throws IOException {

    final DateTime start = DateTime.parse(from, DTF);
    final DateTime end = DateTime.parse(to, DTF);

    User student = Ebean.find(User.class, studentId);
    if (student == null) {
        return notFound("sitnet_error_not_found");
    }

    List<ExamParticipation> participations = Ebean.find(ExamParticipation.class)
            .fetch("exam")
            .where()
            .gt("started", start)
            .lt("ended", end)
            .eq("user.id", studentId)
            .findList();

    Workbook wb = new XSSFWorkbook();
    Sheet studentSheet = wb.createSheet("student");
    String[] studentHeaders = {"id", "first name", "last name", "email", "language"};
    addHeader(studentSheet, studentHeaders);
    Row dataRow = studentSheet.createRow(1);
    int index = 0;
    dataRow.createCell(index++).setCellValue(student.getId());
    dataRow.createCell(index++).setCellValue(student.getFirstName());
    dataRow.createCell(index++).setCellValue(student.getLastName());
    dataRow.createCell(index++).setCellValue(student.getEmail());
    dataRow.createCell(index).setCellValue(student.getLanguage().getCode());
    generateParticipationSheet(wb, participations, false);
    response().setHeader("Content-Disposition", "attachment; filename=\"student_activity.xlsx\"");
    return ok(encode(wb));
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:35,代码来源:StatisticsController.java

示例12: insertExamMachine

import io.ebean.Ebean; //导入方法依赖的package包/类
@Restrict({@Group("ADMIN")})
public Result insertExamMachine(Long id) {

    ExamRoom room = Ebean.find(ExamRoom.class, id);
    if (room == null) {
        return notFound();
    }
    ExamMachine machine = bindForm(ExamMachine.class);
    room.getExamMachines().add(machine);
    room.save();

    machine.save();

    return ok(Json.toJson(machine));
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:16,代码来源:ExamMachineController.java

示例13: updateSoftware

import io.ebean.Ebean; //导入方法依赖的package包/类
@Restrict(@Group({"ADMIN"}))
public Result updateSoftware(Long id, String name) {
    Software software = Ebean.find(Software.class, id);
    if (software == null) {
        return notFound();
    }
    software.setName(name);
    software.setStatus("ACTIVE");
    software.update();

    return ok(Json.toJson(software));
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:13,代码来源:ExamMachineController.java

示例14: removeSoftware

import io.ebean.Ebean; //导入方法依赖的package包/类
@Restrict(@Group({"ADMIN"}))
public Result removeSoftware(Long id) {
    Software software = Ebean.find(Software.class, id);
    if (software == null) {
        return notFound();
    }
    software.setStatus("DISABLED");
    software.update();

    return ok();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:12,代码来源:ExamMachineController.java

示例15: downloadFeedbackAttachment

import io.ebean.Ebean; //导入方法依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN"), @Group("STUDENT")})
public Result downloadFeedbackAttachment(Long id) {
    User user = getLoggedUser();
    Exam exam;
    if (user.hasRole("STUDENT", getSession())) {
        exam = Ebean.find(Exam.class).where().idEq(id).eq("creator", user).findUnique();
    } else {
        exam = Ebean.find(Exam.class, id);
    }
    if (exam == null || exam.getExamFeedback() == null || exam.getExamFeedback().getAttachment() == null) {
        return notFound();
    }
    return serveAttachment(exam.getExamFeedback().getAttachment());
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:15,代码来源:AttachmentController.java


注:本文中的io.ebean.Ebean.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。