Search in sources :

Example 1 with EntityCorrectnessException

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);
            }
        }
    }
}
Also used : EntityCorrectnessException(org.geosdi.geoplatform.services.development.EntityCorrectnessException) GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPProject(org.geosdi.geoplatform.core.model.GPProject) GPAccountProject(org.geosdi.geoplatform.core.model.GPAccountProject) Roster(org.jivesoftware.smack.Roster) Message(org.jivesoftware.smack.packet.Message) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) Presence(org.jivesoftware.smack.packet.Presence)

Aggregations

GPAccount (org.geosdi.geoplatform.core.model.GPAccount)1 GPAccountProject (org.geosdi.geoplatform.core.model.GPAccountProject)1 GPProject (org.geosdi.geoplatform.core.model.GPProject)1 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)1 EntityCorrectnessException (org.geosdi.geoplatform.services.development.EntityCorrectnessException)1 Roster (org.jivesoftware.smack.Roster)1 Message (org.jivesoftware.smack.packet.Message)1 Presence (org.jivesoftware.smack.packet.Presence)1