Search in sources :

Example 21 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project OpenOLAT by OpenOLAT.

the class AssessmentToolManagerTest method assessmentTool_coach.

@Test
public void assessmentTool_coach() {
    // course
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-author-1");
    ICourse course = CoursesWebService.createEmptyCourse(author, "course-assessment-tool", "course long name", null);
    // members as participant and coach
    Identity assessedIdentity1 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-1");
    Identity assessedIdentity2 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-2");
    Identity assessedIdentity3 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-3");
    Identity assessedIdentity4 = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-4");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("ast-coach-1");
    RepositoryEntry entry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
    RepositoryEntry refEntry = JunitTestHelper.createAndPersistRepositoryEntry();
    String subIdent = UUID.randomUUID().toString();
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "assessment-tool-bg-1", "assessment-tool-bg-1-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group1, entry);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "assessment-tool-bg-2", "assessment-tool-bg-2-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group2, entry);
    businessGroupRelationDao.addRole(assessedIdentity1, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity2, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity3, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(coach, group1, GroupRoles.coach.name());
    dbInstance.commitAndCloseSession();
    // some datas
    assessmentEntryDao.createAssessmentEntry(assessedIdentity1, null, entry, subIdent, refEntry, 3.0f, Boolean.FALSE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity2, null, entry, subIdent, refEntry, 5.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity3, null, entry, subIdent, refEntry, 8.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(assessedIdentity4, null, entry, subIdent, refEntry, 9.0f, Boolean.TRUE, null, null);
    assessmentEntryDao.createAssessmentEntry(null, UUID.randomUUID().toString(), entry, subIdent, refEntry);
    dbInstance.commitAndCloseSession();
    // coach of group 1 with id 1 and id2
    List<BusinessGroup> coachedGroups = Collections.singletonList(group1);
    AssessmentToolSecurityCallback assessmentCallback = new AssessmentToolSecurityCallback(false, false, false, true, coachedGroups);
    SearchAssessedIdentityParams params = new SearchAssessedIdentityParams(entry, subIdent, refEntry, assessmentCallback);
    // statistics
    AssessmentStatistics statistics = assessmentToolManager.getStatistics(coach, params);
    Assert.assertEquals(4.0d, statistics.getAverageScore().doubleValue(), 0.0001);
    Assert.assertEquals(1, statistics.getCountFailed());
    Assert.assertEquals(1, statistics.getCountPassed());
    // check assessed identities list
    List<Identity> assessedIdentities = assessmentToolManager.getAssessedIdentities(coach, params);
    Assert.assertNotNull(assessedIdentities);
    Assert.assertEquals(2, assessedIdentities.size());
    // number of assessed identities
    int numOfAssessedIdentities = assessmentToolManager.getNumberOfAssessedIdentities(coach, params);
    Assert.assertEquals(2, numOfAssessedIdentities);
    // check only the queries
    AssessmentMembersStatistics participantStatistics = assessmentToolManager.getNumberOfParticipants(coach, params);
    Assert.assertNotNull(participantStatistics);
    int numOfInitialLanches = assessmentToolManager.getNumberOfInitialLaunches(coach, params);
    // not launched, only simulated
    Assert.assertEquals(0, numOfInitialLanches);
    List<IdentityShort> assessedShortIdentities = assessmentToolManager.getShortAssessedIdentities(coach, params, 120);
    Assert.assertNotNull(assessedShortIdentities);
    Assert.assertEquals(2, assessedShortIdentities.size());
    List<AssessmentEntry> assessmentEntries = assessmentToolManager.getAssessmentEntries(coach, params, AssessmentEntryStatus.notStarted);
    Assert.assertNotNull(assessmentEntries);
    Assert.assertEquals(0, assessmentEntries.size());
    // separate check with more options in the search parameters
    // add by group key
    params.setBusinessGroupKeys(Collections.singletonList(group1.getKey()));
    // assessed groups
    List<AssessedBusinessGroup> assessedGroups = assessmentToolManager.getBusinessGroupStatistics(coach, params);
    Assert.assertNotNull(assessedGroups);
    Assert.assertEquals(1, assessedGroups.size());
    // check assessed identities list
    List<Identity> assessedIdentitiesAlt = assessmentToolManager.getAssessedIdentities(coach, params);
    Assert.assertNotNull(assessedIdentitiesAlt);
    Assert.assertEquals(2, assessedIdentitiesAlt.size());
    // number of assessed identities
    int numOfAssessedIdentitiesAlt = assessmentToolManager.getNumberOfAssessedIdentities(coach, params);
    Assert.assertEquals(2, numOfAssessedIdentitiesAlt);
    List<IdentityShort> assessedShortIdentitiesAlt = assessmentToolManager.getShortAssessedIdentities(coach, params, 120);
    Assert.assertNotNull(assessedShortIdentitiesAlt);
    Assert.assertEquals(2, assessedShortIdentitiesAlt.size());
    List<AssessmentEntry> assessmentEntriesAlt = assessmentToolManager.getAssessmentEntries(coach, params, AssessmentEntryStatus.notStarted);
    Assert.assertNotNull(assessmentEntriesAlt);
    Assert.assertEquals(0, assessmentEntriesAlt.size());
}
Also used : AssessmentMembersStatistics(org.olat.modules.assessment.model.AssessmentMembersStatistics) BusinessGroup(org.olat.group.BusinessGroup) AssessedBusinessGroup(org.olat.course.assessment.model.AssessedBusinessGroup) IdentityShort(org.olat.basesecurity.IdentityShort) AssessmentToolSecurityCallback(org.olat.modules.assessment.ui.AssessmentToolSecurityCallback) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) AssessmentStatistics(org.olat.course.assessment.model.AssessmentStatistics) SearchAssessedIdentityParams(org.olat.course.assessment.model.SearchAssessedIdentityParams) AssessedBusinessGroup(org.olat.course.assessment.model.AssessedBusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 22 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project OpenOLAT by OpenOLAT.

the class UserWebService method getOriginalPortraitHead.

/**
 * Retrieves the portrait of an user
 * @response.representation.200.mediaType application/octet-stream
 * @response.representation.200.doc The portrait as image
 * @response.representation.404.doc The identity or the portrait not found
 * @param identityKey The identity key of the user being searched
 * @return The image
 */
@HEAD
@Path("{identityKey}/portrait/{size}")
@Produces({ "image/jpeg", "image/jpg", MediaType.APPLICATION_OCTET_STREAM })
public Response getOriginalPortraitHead(@PathParam("identityKey") Long identityKey, @PathParam("size") String size) {
    try {
        IdentityShort identity = BaseSecurityManager.getInstance().loadIdentityShortByKey(identityKey);
        if (identity == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        DisplayPortraitManager portraitManager = DisplayPortraitManager.getInstance();
        File portrait = null;
        if ("master".equals(size)) {
            portrait = portraitManager.getMasterPortrait(identity.getName());
        } else if ("big".equals(size)) {
            portrait = portraitManager.getBigPortrait(identity.getName());
        } else if ("small".equals(size)) {
            portrait = portraitManager.getSmallPortrait(identity.getName());
        }
        if (portrait == null || !portrait.exists()) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        Date lastModified = new Date(portrait.lastModified());
        return Response.ok().lastModified(lastModified).build();
    } catch (Throwable e) {
        throw new WebApplicationException(e);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) DisplayPortraitManager(org.olat.user.DisplayPortraitManager) IdentityShort(org.olat.basesecurity.IdentityShort) File(java.io.File) Date(java.util.Date) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) Produces(javax.ws.rs.Produces)

Example 23 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project OpenOLAT by OpenOLAT.

the class UserWebService method getPortrait.

/**
 * Retrieves the portrait of an user
 * @response.representation.200.mediaType application/octet-stream
 * @response.representation.200.doc The portrait as image
 * @response.representation.404.doc The identity or the portrait not found
 * @param identityKey The identity key of the user being searched
 * @param request The REST request
 * @return The image
 */
@GET
@Path("{identityKey}/portrait")
@Produces({ "image/jpeg", "image/jpg", MediaType.APPLICATION_OCTET_STREAM })
public Response getPortrait(@PathParam("identityKey") Long identityKey, @Context Request request) {
    try {
        IdentityShort identity = BaseSecurityManager.getInstance().loadIdentityShortByKey(identityKey);
        if (identity == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        File portrait = DisplayPortraitManager.getInstance().getBigPortrait(identity.getName());
        if (portrait == null || !portrait.exists()) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        Date lastModified = new Date(portrait.lastModified());
        Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
        if (response == null) {
            response = Response.ok(portrait).lastModified(lastModified).cacheControl(cc);
        }
        return response.build();
    } catch (Throwable e) {
        throw new WebApplicationException(e);
    }
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) IdentityShort(org.olat.basesecurity.IdentityShort) File(java.io.File) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project OpenOLAT by OpenOLAT.

the class UserWebService method postPortrait.

/**
 * Upload the portrait of an user
 * @response.representation.200.mediaType application/octet-stream
 * @response.representation.200.doc The portrait as image
 * @response.representation.401.doc Not authorized
 * @response.representation.404.doc The identity or the portrait not found
 * @param identityKey The user key identifier of the user being searched
 * @param file The image
 * @param request The REST request
 * @return The image
 */
@POST
@Path("{identityKey}/portrait")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response postPortrait(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
    MultipartReader partsReader = null;
    try {
        IdentityShort identity = BaseSecurityManager.getInstance().loadIdentityShortByKey(identityKey);
        if (identity == null) {
            return Response.serverError().status(Status.NOT_FOUND).build();
        }
        Identity authIdentity = getUserRequest(request).getIdentity();
        if (!isUserManager(request) && !identity.getKey().equals(authIdentity.getKey())) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
        partsReader = new MultipartReader(request);
        File tmpFile = partsReader.getFile();
        String filename = partsReader.getFilename();
        DisplayPortraitManager.getInstance().setPortrait(tmpFile, filename, identity.getName());
        return Response.ok().build();
    } catch (Throwable e) {
        throw new WebApplicationException(e);
    } finally {
        MultipartReader.closeQuietly(partsReader);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) IdentityShort(org.olat.basesecurity.IdentityShort) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) File(java.io.File) MultipartReader(org.olat.restapi.support.MultipartReader) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 25 with IdentityShort

use of org.olat.basesecurity.IdentityShort in project OpenOLAT by OpenOLAT.

the class AssessedIdentityListProvider method getResult.

@Override
public void getResult(String searchValue, ListReceiver receiver) {
    SearchAssessedIdentityParams params = new SearchAssessedIdentityParams(courseEntry, subIdent, referenceEntry, assessmentCallback);
    params.setSearchString(searchValue);
    int maxEntries = MAX_ENTRIES;
    List<IdentityShort> res = assessmentToolManager.getShortAssessedIdentities(coach, params, maxEntries);
    boolean hasMore = false;
    for (Iterator<IdentityShort> it_res = res.iterator(); (hasMore = it_res.hasNext()) && maxEntries > 0; ) {
        maxEntries--;
        IdentityShort ident = it_res.next();
        String key = ident.getKey().toString();
        String displayKey = ident.getName();
        String displayText = userManager.getUserDisplayName(ident);
        receiver.addEntry(key, displayKey, displayText, CSSHelper.CSS_CLASS_USER);
    }
    if (hasMore) {
        receiver.addEntry(".....", ".....");
    }
}
Also used : IdentityShort(org.olat.basesecurity.IdentityShort) SearchAssessedIdentityParams(org.olat.course.assessment.model.SearchAssessedIdentityParams)

Aggregations

IdentityShort (org.olat.basesecurity.IdentityShort)32 File (java.io.File)8 HashMap (java.util.HashMap)8 Path (javax.ws.rs.Path)8 WebApplicationException (javax.ws.rs.WebApplicationException)8 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 Produces (javax.ws.rs.Produces)6 HEAD (javax.ws.rs.HEAD)4 Identity (org.olat.core.id.Identity)4 ICourse (org.olat.course.ICourse)4 SearchAssessedIdentityParams (org.olat.course.assessment.model.SearchAssessedIdentityParams)4 BusinessGroup (org.olat.group.BusinessGroup)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 HashSet (java.util.HashSet)2 EntityManager (javax.persistence.EntityManager)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Response (javax.ws.rs.core.Response)2