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);
}
}
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);
}
}
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);
}
}
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;
}
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);
}
Aggregations