use of org.geosdi.geoplatform.services.development.EntityCorrectnessException in project geo-platform by geosdi.
the class GPTrackingServiceImpl method sendSharedProjectNotification.
/**
* @see GPTrackingService#sendSharedProjectNotification(java.lang.Long,
* org.geosdi.geoplatform.services.XMPPSubjectServerEnum, java.lang.String,
* org.geosdi.geoplatform.responce.collection.XmppAttributesMap)
*/
@Override
public void sendSharedProjectNotification(Long projectID, XMPPSubjectEnum subject, String text, XmppAttributesMap attributesMap) throws ResourceNotFoundFault {
GPProject project = projectDao.find(projectID);
if (project == null) {
throw new ResourceNotFoundFault("Project not found", projectID);
}
// TODO assert
EntityCorrectness.checkProjectLog(project);
if (!project.isShared()) {
// TODO assert
throw new EntityCorrectnessException("The Project must be shared.");
}
List<GPAccountProject> accounts = accountProjectDao.findNotOwnersByProjectID(projectID);
// TODO assert
EntityCorrectness.checkAccountProjectListLog(accounts);
Roster roster = this.connection.getRoster();
Message message = this.createUnknowMessage(subject, text, attributesMap);
for (GPAccountProject accountProject : accounts) {
GPAccount account = accountProject.getAccount();
// TODO assert
EntityCorrectness.checkAccountLog(account);
// If user have this project as default
if (accountProject.isDefaultProject()) {
// Username for User
String naturalID = account.getNaturalID();
String recipient = this.createXmppUri(naturalID);
logger.trace("\n\n*** Recipient XMPP uri: {} ***", recipient);
// If user is online send the message
Presence presence = roster.getPresence(recipient);
if (presence.isAvailable()) {
logger.info("\n*** Send Message to online user \"{}\" ***", naturalID);
message.setTo(recipient);
connection.sendPacket(message);
}
}
}
}
Aggregations