Search in sources :

Example 1 with GPMessage

use of org.geosdi.geoplatform.core.model.GPMessage in project geo-platform by geosdi.

the class GPMessageDAOImpl method findUnreadMessagesByRecipient.

/**
 * @param recipientID
 * @return {@link List<GPMessage>}
 * @throws GPDAOException
 */
@Override
public List<GPMessage> findUnreadMessagesByRecipient(Long recipientID) throws GPDAOException {
    checkArgument(recipientID != null, "The Parameter recipientID must not be null.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<GPMessage> criteriaQuery = super.createCriteriaQuery();
        Root<GPMessage> root = criteriaQuery.from(this.persistentClass);
        criteriaQuery.select(root);
        criteriaQuery.where(builder.equal(root.join("recipient").get("id"), recipientID), builder.equal(root.get("isRead"), FALSE)).orderBy(builder.desc(root.get("creationDate")));
        return this.entityManager.createQuery(criteriaQuery).getResultList();
    } catch (Exception ex) {
        throw new GPDAOException(ex);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) GPMessage(org.geosdi.geoplatform.core.model.GPMessage) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 2 with GPMessage

use of org.geosdi.geoplatform.core.model.GPMessage in project geo-platform by geosdi.

the class GPMessageDAOImpl method findAllMessagesByRecipient.

/**
 * @param recipientID
 * @return {@link List<GPMessage>}
 * @throws GPDAOException
 */
@Override
public List<GPMessage> findAllMessagesByRecipient(Long recipientID) throws GPDAOException {
    checkArgument(recipientID != null, "The Parameter recipientID must not be null.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<GPMessage> criteriaQuery = super.createCriteriaQuery();
        Root<GPMessage> root = criteriaQuery.from(this.persistentClass);
        criteriaQuery.select(root);
        criteriaQuery.where(builder.equal(root.join("recipient").get("id"), recipientID)).orderBy(builder.desc(root.get("creationDate")));
        return this.entityManager.createQuery(criteriaQuery).getResultList();
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) GPMessage(org.geosdi.geoplatform.core.model.GPMessage) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 3 with GPMessage

use of org.geosdi.geoplatform.core.model.GPMessage in project geo-platform by geosdi.

the class GPMessageDAOImpl method markMessageAsRead.

/**
 * @param messageID
 * @return {@link Boolean}
 * @throws GPDAOException
 */
@Override
public Boolean markMessageAsRead(Long messageID) throws GPDAOException {
    checkArgument(messageID != null, "The Parameter messageID must not be null.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaUpdate<GPMessage> criteriaUpdate = super.createCriteriaUpdate();
        Root<GPMessage> root = criteriaUpdate.from(this.persistentClass);
        criteriaUpdate.where(builder.equal(root.get("id"), messageID));
        criteriaUpdate.set(root.get("isRead"), TRUE);
        return (this.entityManager.createQuery(criteriaUpdate).executeUpdate() == 1 ? TRUE : FALSE);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) GPMessage(org.geosdi.geoplatform.core.model.GPMessage) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 4 with GPMessage

use of org.geosdi.geoplatform.core.model.GPMessage in project geo-platform by geosdi.

the class DTOSecurityConverter method convertAccountToDTO.

public IGPAccountDetail convertAccountToDTO(GPAccount account, GPAccountProject accountProject, GPViewport viewport, List<GPMessage> messages) {
    GPLoginUserDetail accountDetail = new GPLoginUserDetail();
    UserTreeOptions usertreeOptions = new UserTreeOptions();
    accountDetail.setId(account.getId());
    // Forced representation
    accountDetail.setUsername(account.getNaturalID());
    accountDetail.setOrganization(account.getOrganization().getName());
    usertreeOptions.setLoadExpandedFolders(account.isLoadExpandedFolders());
    accountDetail.setTreeOptions(usertreeOptions);
    if (account instanceof GPUser) {
        GPUser user = (GPUser) account;
        accountDetail.setName(user.getName());
        accountDetail.setEmail(user.getEmailAddress());
        this.extractGPAuthoritiesInToUser(accountDetail, account.getGPAuthorities());
    }
    if (account.getGsAccount() != null) {
        accountDetail.setAuthkey(account.getGsAccount().getAuthkey());
    }
    accountDetail.setHostXmppServer(hostXmppServer);
    if (accountProject != null) {
        accountDetail.setBaseLayer(accountProject.getBaseLayer());
    }
    if (viewport != null) {
        GPBBox serverBBOX = viewport.getBbox();
        BBoxClientInfo clientBBOX = new BBoxClientInfo(serverBBOX.getMinX(), serverBBOX.getMinY(), serverBBOX.getMaxX(), serverBBOX.getMaxY());
        GPClientViewport clientViewport = new GPClientViewport(viewport.getName(), viewport.getDescription(), clientBBOX, viewport.getZoomLevel(), viewport.isIsDefault());
        accountDetail.setViewport(clientViewport);
    }
    if (messages != null) {
        List<IGPClientMessage> unreadMessages = Lists.newArrayListWithCapacity(messages.size());
        for (GPMessage message : messages) {
            GPClientMessage clientMessage = this.convertMessage(message);
            unreadMessages.add(clientMessage);
            logger.debug("\n*** {}", clientMessage);
        }
        Collections.sort(unreadMessages);
        accountDetail.setUnreadMessages(unreadMessages);
    }
    return (IGPAccountDetail) accountDetail;
}
Also used : BBoxClientInfo(org.geosdi.geoplatform.gui.configuration.map.client.geometry.BBoxClientInfo) IGPAccountDetail(org.geosdi.geoplatform.gui.global.security.IGPAccountDetail) IGPClientMessage(org.geosdi.geoplatform.gui.model.message.IGPClientMessage) GPMessage(org.geosdi.geoplatform.core.model.GPMessage) GPUser(org.geosdi.geoplatform.core.model.GPUser) GPClientMessage(org.geosdi.geoplatform.gui.impl.message.GPClientMessage) IGPClientMessage(org.geosdi.geoplatform.gui.model.message.IGPClientMessage) GPClientViewport(org.geosdi.geoplatform.gui.configuration.map.client.GPClientViewport) UserTreeOptions(org.geosdi.geoplatform.gui.impl.users.options.UserTreeOptions) GPLoginUserDetail(org.geosdi.geoplatform.gui.client.model.security.GPLoginUserDetail) GPBBox(org.geosdi.geoplatform.core.model.GPBBox)

Example 5 with GPMessage

use of org.geosdi.geoplatform.core.model.GPMessage in project geo-platform by geosdi.

the class RSMessageTest method setUp.

@Override
public void setUp() throws Exception {
    // Insert Organization
    this.setUpOrganization();
    // Insert Users
    idUserTest = this.createAndInsertUser(usernameTest, organizationTest, USER);
    userTest = gpWSClient.getUserDetailByUsername(new SearchRequest(usernameTest, CONTENT_EQUALS));
    firstRecipientID = this.createAndInsertUser("first_recipient_RS", organizationTest, USER);
    firstRecipient = gpWSClient.getUserDetail(firstRecipientID);
    latterRecipientID = this.createAndInsertUser("latter_recipient_RS", organizationTest, VIEWER);
    // latterRecipient = gpWSClient.getUserDetail(latterRecipientID);
    // Create message
    message = new GPMessage();
    message.setRecipient(firstRecipient);
    message.setSender(userTest);
    message.setCreationDate(new Date(System.currentTimeMillis()));
    message.setRead(false);
    message.setSubject("Foo subject REST");
    message.setText("Foo message REST.");
    message.addCommand(GPMessageCommandType.NONE);
}
Also used : SearchRequest(org.geosdi.geoplatform.request.SearchRequest) GPMessage(org.geosdi.geoplatform.core.model.GPMessage)

Aggregations

GPMessage (org.geosdi.geoplatform.core.model.GPMessage)23 Test (org.junit.Test)11 MessageDTO.convertToGPMessage (org.geosdi.geoplatform.response.MessageDTO.convertToGPMessage)5 Date (java.util.Date)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 GPAccount (org.geosdi.geoplatform.core.model.GPAccount)3 GPDAOException (org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)3 GPMessageCommandType (org.geosdi.geoplatform.gui.shared.GPMessageCommandType)2 SearchRequest (org.geosdi.geoplatform.request.SearchRequest)2 MarkMessageReadByDateRequest (org.geosdi.geoplatform.request.message.MarkMessageReadByDateRequest)2 MessageDTO (org.geosdi.geoplatform.response.MessageDTO)2 GetMessageResponse (org.geosdi.geoplatform.response.message.GetMessageResponse)2 ArrayList (java.util.ArrayList)1 GregorianCalendar (java.util.GregorianCalendar)1 GPBBox (org.geosdi.geoplatform.core.model.GPBBox)1 GPUser (org.geosdi.geoplatform.core.model.GPUser)1 GPLoginUserDetail (org.geosdi.geoplatform.gui.client.model.security.GPLoginUserDetail)1 GPClientViewport (org.geosdi.geoplatform.gui.configuration.map.client.GPClientViewport)1 BBoxClientInfo (org.geosdi.geoplatform.gui.configuration.map.client.geometry.BBoxClientInfo)1 IGPAccountDetail (org.geosdi.geoplatform.gui.global.security.IGPAccountDetail)1