Search in sources :

Example 76 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class MembersPrintController method initFormMemberList.

private void initFormMemberList(String name, String label, List<Identity> members) {
    List<Member> memberWrappers = members.stream().map(m -> createMember(m)).collect(Collectors.toList());
    VelocityContainer listVC = createVelocityContainer("printList");
    listVC.contextPut("label", label);
    listVC.contextPut("avatarBaseURL", avatarBaseURL);
    listVC.contextPut("members", memberWrappers);
    listVC.contextPut("typecss", "o_" + name);
    listVC.contextPut("userPropertyPrintHandlers", userPropertyPrintHandlers);
    // add lookup table so the avatar properties can be read out from the member object that contains the full list of attributes
    Map<String, Integer> handlerLookupMap = new HashMap<String, Integer>();
    for (int i = userPropertyPrintHandlers.size(); i-- > 0; ) {
        UserPropertyHandler handler = userPropertyPrintHandlers.get(i);
        handlerLookupMap.put(handler.getName(), i);
    }
    listVC.contextPut("handlerLookupMap", handlerLookupMap);
    mainVC.put(name, listVC);
}
Also used : Util(org.olat.core.util.Util) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) MediaResource(org.olat.core.gui.media.MediaResource) Event(org.olat.core.gui.control.Event) Member(org.olat.course.nodes.members.Member) HttpServletRequest(javax.servlet.http.HttpServletRequest) MainPanel(org.olat.core.gui.components.panel.MainPanel) UserConstants(org.olat.core.id.UserConstants) Locale(java.util.Locale) Map(java.util.Map) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) BaseSecurityModule(org.olat.basesecurity.BaseSecurityModule) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Translator(org.olat.core.gui.translator.Translator) WindowControl(org.olat.core.gui.control.WindowControl) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) DisplayPortraitManager(org.olat.user.DisplayPortraitManager) Component(org.olat.core.gui.components.Component) Collectors(java.util.stream.Collectors) Mapper(org.olat.core.dispatcher.mapper.Mapper) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) UserManager(org.olat.user.UserManager) BasicController(org.olat.core.gui.control.controller.BasicController) List(java.util.List) Identity(org.olat.core.id.Identity) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) UserRequest(org.olat.core.gui.UserRequest) Roles(org.olat.core.id.Roles) HashMap(java.util.HashMap) Member(org.olat.course.nodes.members.Member) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 77 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class MembersMailController method doSend.

private void doSend(UserRequest ureq) {
    ContactList contactList = new ContactList("");
    if (courseEnv == null) {
        if (coachEl != null && coachEl.isAtLeastSelected(1)) {
            List<Long> identityKeys = new ArrayList<>(coachList.size());
            for (Member coach : coachList) {
                identityKeys.add(coach.getKey());
            }
            List<Identity> coaches = securityManager.loadIdentityByKeys(identityKeys);
            contactList.addAllIdentites(coaches);
        }
        if (participantEl != null && participantEl.isAtLeastSelected(1)) {
            List<Long> identityKeys = new ArrayList<>(participantList.size());
            for (Member participant : participantList) {
                identityKeys.add(participant.getKey());
            }
            List<Identity> participants = securityManager.loadIdentityByKeys(identityKeys);
            contactList.addAllIdentites(participants);
        }
        if (waitingEl != null && waitingEl.isAtLeastSelected(1)) {
            List<Long> identityKeys = new ArrayList<>(waitingList.size());
            for (Member waiter : waitingList) {
                identityKeys.add(waiter.getKey());
            }
            List<Identity> waiters = securityManager.loadIdentityByKeys(identityKeys);
            contactList.addAllIdentites(waiters);
        }
    } else {
        if (ownerEl != null && ownerEl.isAtLeastSelected(1)) {
            RepositoryEntry courseRepositoryEntry = courseEnv.getCourseGroupManager().getCourseEntry();
            List<Identity> owners = repositoryService.getMembers(courseRepositoryEntry, GroupRoles.owner.name());
            contactList.addAllIdentites(owners);
        }
        if (coachEl != null && coachEl.isAtLeastSelected(1)) {
            Set<Long> sendToWhatYouSee = new HashSet<>();
            for (Member coach : coachList) {
                sendToWhatYouSee.add(coach.getKey());
            }
            CourseGroupManager cgm = courseEnv.getCourseGroupManager();
            avoidInvisibleMember(cgm.getCoachesFromBusinessGroups(), contactList, sendToWhatYouSee);
            avoidInvisibleMember(cgm.getCoaches(), contactList, sendToWhatYouSee);
        }
        if (participantEl != null && participantEl.isAtLeastSelected(1)) {
            Set<Long> sendToWhatYouSee = new HashSet<>();
            for (Member participant : participantList) {
                sendToWhatYouSee.add(participant.getKey());
            }
            CourseGroupManager cgm = courseEnv.getCourseGroupManager();
            avoidInvisibleMember(cgm.getParticipantsFromBusinessGroups(), contactList, sendToWhatYouSee);
            avoidInvisibleMember(cgm.getParticipants(), contactList, sendToWhatYouSee);
        }
    }
    if (individualEl != null && individualEl.isAtLeastSelected(1) && selectedMembers != null && selectedMembers.size() > 0) {
        List<Long> identityKeys = new ArrayList<>(selectedMembers.size());
        for (Member member : selectedMembers) {
            identityKeys.add(member.getKey());
        }
        List<Identity> selectedIdentities = securityManager.loadIdentityByKeys(identityKeys);
        contactList.addAllIdentites(selectedIdentities);
    }
    if (externalEl != null && externalEl.isAtLeastSelected(1)) {
        String value = externalAddressesEl.getValue();
        if (StringHelper.containsNonWhitespace(value)) {
            for (StringTokenizer tokenizer = new StringTokenizer(value, ",\r\n", false); tokenizer.hasMoreTokens(); ) {
                String email = tokenizer.nextToken().trim();
                contactList.add(new EMailIdentity(email, getLocale()));
            }
        }
    }
    doSendEmailToMember(ureq, contactList);
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) ArrayList(java.util.ArrayList) ContactList(org.olat.core.util.mail.ContactList) RepositoryEntry(org.olat.repository.RepositoryEntry) StringTokenizer(java.util.StringTokenizer) EMailIdentity(org.olat.core.util.mail.ui.EMailIdentity) EMailIdentity(org.olat.core.util.mail.ui.EMailIdentity) Identity(org.olat.core.id.Identity) Member(org.olat.course.nodes.members.Member) HashSet(java.util.HashSet)

Example 78 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class MembersTableController method doSendEmailToMember.

private void doSendEmailToMember(MemberView member, UserRequest ureq) {
    if (!editable)
        return;
    ContactList memberList;
    Identity identity = securityManager.loadIdentityByKey(member.getIdentityKey());
    String fullName = userManager.getUserDisplayName(identity);
    if (courseEnv == null) {
        memberList = new ContactList(translate("members.to", new String[] { fullName, businessGroup.getName() }));
    } else {
        memberList = new ContactList(translate("members.to", new String[] { fullName, courseEnv.getCourseTitle() }));
    }
    memberList.add(identity);
    doSendEmailToMember(memberList, ureq);
}
Also used : ContactList(org.olat.core.util.mail.ContactList) Identity(org.olat.core.id.Identity)

Example 79 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class MembersTableController method getMembersFromIdentity.

private List<MemberView> getMembersFromIdentity(UserRequest ureq, List<Identity> identities, Map<Long, BusinessGroupMembership> groupmemberships, Map<Long, Date> recentLaunches, Map<Long, Date> initialLaunches) {
    if (!deduplicateList) {
        duplicateCatcher = new HashSet<>();
    }
    List<MemberView> memberList = new ArrayList<>();
    for (Identity identity : identities) {
        MemberView member = new MemberView(identity, userPropertyHandlers, getLocale());
        if (userLastTimeVisible) {
            if (repoEntry == null) {
                BusinessGroupMembership groupmembership = groupmemberships.get(identity.getKey());
                if (groupmembership != null) {
                    member.setFirstTime(groupmembership.getCreationDate());
                    member.setLastTime(groupmembership.getLastModified());
                }
            } else {
                member.setFirstTime(initialLaunches.get(identity.getKey()));
                member.setLastTime(recentLaunches.get(identity.getKey()));
            }
        }
        if (!duplicateCatcher.contains(member)) {
            memberList.add(member);
            if (!identity.equals(ureq.getIdentity())) {
                forgeChatLink(member);
            }
        }
        duplicateCatcher.add(member);
    }
    return memberList;
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) MemberView(org.olat.group.ui.main.MemberView)

Example 80 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class InfoMessagesWebService method createEmptyCourse.

/**
 * Creates a new info message
 * @response.representation.200.qname {http://www.example.com}infoMessageVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The info message
 * @response.representation.200.example {@link org.olat.commons.info.restapi.Examples#SAMPLE_INFOMESSAGEVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param resName The OLAT Resourceable name
 * @param resId The OLAT Resourceable id
 * @param resSubPath The resource sub path (optional)
 * @param businessPath The business path
 * @param authorKey The identity key of the author
 * @param title The title
 * @param message The message
 * @param request The HTTP request
 * @return It returns the id of the newly info message
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createEmptyCourse(@QueryParam("resName") final String resName, @QueryParam("resId") final Long resId, @QueryParam("resSubPath") String resSubPath, @QueryParam("businessPath") String businessPath, @QueryParam("authorKey") Long authorKey, @QueryParam("title") String title, @QueryParam("message") String message, @Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    OLATResourceable ores = new OLATResourceable() {

        @Override
        public String getResourceableTypeName() {
            return resName;
        }

        @Override
        public Long getResourceableId() {
            return resId;
        }
    };
    Identity author;
    UserRequest ureq = getUserRequest(request);
    if (authorKey == null) {
        author = ureq.getIdentity();
    } else {
        BaseSecurity securityManager = BaseSecurityManager.getInstance();
        author = securityManager.loadIdentityByKey(authorKey, false);
        if (author == null) {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    }
    InfoMessageFrontendManager messageManager = CoreSpringFactory.getImpl(InfoMessageFrontendManager.class);
    InfoMessage msg = messageManager.createInfoMessage(ores, resSubPath, businessPath, author);
    msg.setTitle(title);
    msg.setMessage(message);
    messageManager.sendInfoMessage(msg, null, ureq.getLocale(), ureq.getIdentity(), Collections.<Identity>emptyList());
    InfoMessageVO infoVO = new InfoMessageVO(msg);
    return Response.ok(infoVO).build();
}
Also used : InfoMessageFrontendManager(org.olat.commons.info.InfoMessageFrontendManager) OLATResourceable(org.olat.core.id.OLATResourceable) InfoMessage(org.olat.commons.info.InfoMessage) Identity(org.olat.core.id.Identity) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) BaseSecurity(org.olat.basesecurity.BaseSecurity) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

Identity (org.olat.core.id.Identity)3749 Test (org.junit.Test)1956 RepositoryEntry (org.olat.repository.RepositoryEntry)898 BusinessGroup (org.olat.group.BusinessGroup)560 ArrayList (java.util.ArrayList)550 Date (java.util.Date)312 URI (java.net.URI)272 ICourse (org.olat.course.ICourse)266 HttpResponse (org.apache.http.HttpResponse)260 File (java.io.File)211 AssessmentManager (org.olat.course.assessment.AssessmentManager)210 Path (javax.ws.rs.Path)182 OLATResource (org.olat.resource.OLATResource)172 OLATResourceable (org.olat.core.id.OLATResourceable)156 Roles (org.olat.core.id.Roles)154 HashMap (java.util.HashMap)151 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)142 HashSet (java.util.HashSet)136 List (java.util.List)132 Produces (javax.ws.rs.Produces)130