Search in sources :

Example 1 with User

use of org.hisp.dhis.user.User in project dhis2-core by dhis2.

the class Preheat method put.

@SuppressWarnings("unchecked")
public <T extends IdentifiableObject> Preheat put(PreheatIdentifier identifier, T object) {
    if (object == null)
        return this;
    Class<? extends IdentifiableObject> klass = (Class<? extends IdentifiableObject>) getRealClass(object.getClass());
    if (PreheatIdentifier.UID == identifier || PreheatIdentifier.AUTO == identifier) {
        if (!map.containsKey(PreheatIdentifier.UID))
            map.put(PreheatIdentifier.UID, new HashMap<>());
        if (!map.get(PreheatIdentifier.UID).containsKey(klass))
            map.get(PreheatIdentifier.UID).put(klass, new HashMap<>());
        if (User.class.isAssignableFrom(klass)) {
            if (!map.get(PreheatIdentifier.UID).containsKey(UserCredentials.class)) {
                map.get(PreheatIdentifier.UID).put(UserCredentials.class, new HashMap<>());
            }
            User user = (User) object;
            Map<String, IdentifiableObject> identifierMap = map.get(PreheatIdentifier.UID).get(UserCredentials.class);
            if (!StringUtils.isEmpty(user.getUid()) && !identifierMap.containsKey(user.getUid())) {
                identifierMap.put(user.getUid(), user.getUserCredentials());
            }
        }
        Map<String, IdentifiableObject> identifierMap = map.get(PreheatIdentifier.UID).get(klass);
        String key = PreheatIdentifier.UID.getIdentifier(object);
        if (!StringUtils.isEmpty(key) && !identifierMap.containsKey(key)) {
            identifierMap.put(key, object);
        }
    }
    if (PreheatIdentifier.CODE == identifier || PreheatIdentifier.AUTO == identifier) {
        if (!map.containsKey(PreheatIdentifier.CODE))
            map.put(PreheatIdentifier.CODE, new HashMap<>());
        if (!map.get(PreheatIdentifier.CODE).containsKey(klass))
            map.get(PreheatIdentifier.CODE).put(klass, new HashMap<>());
        if (User.class.isAssignableFrom(klass)) {
            if (!map.get(PreheatIdentifier.CODE).containsKey(UserCredentials.class)) {
                map.get(PreheatIdentifier.CODE).put(UserCredentials.class, new HashMap<>());
            }
            User user = (User) object;
            Map<String, IdentifiableObject> identifierMap = map.get(PreheatIdentifier.CODE).get(UserCredentials.class);
            identifierMap.put(user.getCode(), user.getUserCredentials());
        }
        Map<String, IdentifiableObject> identifierMap = map.get(PreheatIdentifier.CODE).get(klass);
        String key = PreheatIdentifier.CODE.getIdentifier(object);
        if (!StringUtils.isEmpty(key) && !identifierMap.containsKey(key)) {
            identifierMap.put(key, object);
        }
    }
    return this;
}
Also used : User(org.hisp.dhis.user.User) HashMap(java.util.HashMap) UserCredentials(org.hisp.dhis.user.UserCredentials) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 2 with User

use of org.hisp.dhis.user.User in project dhis2-core by dhis2.

the class ActivityReportingServiceImpl method handleLostToFollowUp.

@SuppressWarnings("finally")
@Override
public Notification handleLostToFollowUp(LostEvent lostEvent) throws NotAllowedException {
    Notification notification = new Notification();
    try {
        ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(lostEvent.getId());
        programStageInstance.setDueDate(DateUtils.getMediumDate(lostEvent.getDueDate()));
        programStageInstance.setStatus(EventStatus.fromInt(lostEvent.getStatus()));
        if (lostEvent.getComment() != null) {
            List<MessageConversation> conversationList = new ArrayList<>();
            MessageConversation conversation = new MessageConversation(lostEvent.getName(), currentUserService.getCurrentUser(), MessageType.PRIVATE);
            conversation.addMessage(new Message(lostEvent.getComment(), null, currentUserService.getCurrentUser()));
            conversation.setRead(true);
            conversationList.add(conversation);
            programStageInstance.setMessageConversations(conversationList);
            messageService.saveMessageConversation(conversation);
        }
        programStageInstanceService.updateProgramStageInstance(programStageInstance);
        // send SMS
        if (programStageInstance.getProgramInstance().getEntityInstance().getTrackedEntityAttributeValues() != null && lostEvent.getSMS() != null) {
            List<User> recipientsList = new ArrayList<>();
            for (TrackedEntityAttributeValue attrValue : programStageInstance.getProgramInstance().getEntityInstance().getTrackedEntityAttributeValues()) {
                if (ValueType.PHONE_NUMBER == attrValue.getAttribute().getValueType()) {
                    User user = new User();
                    user.setPhoneNumber(attrValue.getValue());
                    recipientsList.add(user);
                }
            }
            Set<User> recipients = new HashSet<>();
            recipients.addAll(recipientsList);
            smsSender.sendMessage(lostEvent.getName(), lostEvent.getSMS(), null, currentUserService.getCurrentUser(), recipients, false);
        }
        notification.setMessage("Success");
    } catch (Exception e) {
        e.printStackTrace();
        notification.setMessage("Fail");
    } finally {
        return notification;
    }
}
Also used : User(org.hisp.dhis.user.User) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) ArrayList(java.util.ArrayList) Notification(org.hisp.dhis.api.mobile.model.LWUITmodel.Notification) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) NotAllowedException(org.hisp.dhis.api.mobile.NotAllowedException) HashSet(java.util.HashSet)

Example 3 with User

use of org.hisp.dhis.user.User in project dhis2-core by dhis2.

the class CredentialsExpiryAlertTask method run.

// -------------------------------------------------------------------------
// Implementation
// -------------------------------------------------------------------------
@Override
public void run() {
    boolean isExpiryAlertEnabled = (Boolean) systemSettingManager.getSystemSetting(SettingKey.CREDENTIALS_EXPIRY_ALERT);
    if (!isExpiryAlertEnabled) {
        log.info(String.format("%s aborted. Expiry alerts are disabled", KEY_TASK));
        return;
    }
    log.info(String.format("%s has started", KEY_TASK));
    List<User> users = userService.getExpiringUsers();
    Map<String, String> content = new HashMap<>();
    for (User user : users) {
        if (user.getEmail() != null) {
            content.put(user.getEmail(), createText(user));
        }
    }
    log.info(String.format("Users added for alert: %d", content.size()));
    sendExpiryAlert(content);
}
Also used : User(org.hisp.dhis.user.User)

Example 4 with User

use of org.hisp.dhis.user.User in project dhis2-core by dhis2.

the class ActivityReportingServiceImpl method findUser.

@Override
public Collection<org.hisp.dhis.api.mobile.model.User> findUser(String keyword) throws NotAllowedException {
    Collection<User> users = new HashSet<>();
    Collection<org.hisp.dhis.api.mobile.model.User> userList = new HashSet<>();
    if (keyword != null) {
        int index = keyword.indexOf(' ');
        if (index != -1 && index == keyword.lastIndexOf(' ')) {
            String[] keys = keyword.split(" ");
            keyword = keys[0] + "  " + keys[1];
        }
    }
    UserQueryParams params = new UserQueryParams();
    params.setQuery(keyword);
    users = userService.getUsers(params);
    for (User userCore : users) {
        org.hisp.dhis.api.mobile.model.User user = new org.hisp.dhis.api.mobile.model.User();
        user.setId(userCore.getId());
        user.setSurname(userCore.getSurname());
        user.setFirstName(userCore.getFirstName());
        userList.add(user);
    }
    return userList;
}
Also used : User(org.hisp.dhis.user.User) UserQueryParams(org.hisp.dhis.user.UserQueryParams) HashSet(java.util.HashSet)

Example 5 with User

use of org.hisp.dhis.user.User in project dhis2-core by dhis2.

the class MessageConversationController method postObject.

private void postObject(HttpServletResponse response, HttpServletRequest request, MessageConversation messageConversation) throws WebMessageException {
    List<User> users = new ArrayList<>(messageConversation.getUsers());
    messageConversation.getUsers().clear();
    for (OrganisationUnit ou : messageConversation.getOrganisationUnits()) {
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(ou.getUid());
        if (organisationUnit == null) {
            throw new WebMessageException(WebMessageUtils.conflict("Organisation Unit does not exist: " + ou.getUid()));
        }
        messageConversation.getUsers().addAll(organisationUnit.getUsers());
    }
    for (User u : users) {
        User user = userService.getUser(u.getUid());
        if (user == null) {
            throw new WebMessageException(WebMessageUtils.conflict("User does not exist: " + u.getUid()));
        }
        messageConversation.getUsers().add(user);
    }
    for (UserGroup ug : messageConversation.getUserGroups()) {
        UserGroup userGroup = userGroupService.getUserGroup(ug.getUid());
        if (userGroup == null) {
            throw new WebMessageException(WebMessageUtils.notFound("User Group does not exist: " + ug.getUid()));
        }
        messageConversation.getUsers().addAll(userGroup.getMembers());
    }
    if (messageConversation.getUsers().isEmpty()) {
        throw new WebMessageException(WebMessageUtils.conflict("No recipients selected."));
    }
    String metaData = MessageService.META_USER_AGENT + request.getHeader(ContextUtils.HEADER_USER_AGENT);
    int id = messageService.sendPrivateMessage(messageConversation.getSubject(), messageConversation.getText(), metaData, messageConversation.getUsers());
    org.hisp.dhis.message.MessageConversation conversation = messageService.getMessageConversation(id);
    response.addHeader("Location", MessageConversationSchemaDescriptor.API_ENDPOINT + "/" + conversation.getUid());
    webMessageService.send(WebMessageUtils.created("Message conversation created"), response, request);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) ArrayList(java.util.ArrayList) UserGroup(org.hisp.dhis.user.UserGroup)

Aggregations

User (org.hisp.dhis.user.User)715 Test (org.junit.jupiter.api.Test)254 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)168 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)132 DataElement (org.hisp.dhis.dataelement.DataElement)85 ArrayList (java.util.ArrayList)79 List (java.util.List)78 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)63 HashSet (java.util.HashSet)62 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)59 UserGroup (org.hisp.dhis.user.UserGroup)53 Date (java.util.Date)51 Transactional (org.springframework.transaction.annotation.Transactional)49 HashMap (java.util.HashMap)46 Program (org.hisp.dhis.program.Program)44 DataSet (org.hisp.dhis.dataset.DataSet)43 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)43 ClassPathResource (org.springframework.core.io.ClassPathResource)41 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)38 Set (java.util.Set)37