Search in sources :

Example 6 with GPProject

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

the class GPProjectDAOImpl method getTotalExternalPublic.

/**
 * @return {@link int}
 */
@Override
public Integer getTotalExternalPublic() {
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
        Root<GPProject> root = criteriaQuery.from(this.persistentClass);
        criteriaQuery.select(builder.count(root));
        criteriaQuery.where(builder.equal(root.get("externalPublic"), TRUE));
        return this.entityManager.createQuery(criteriaQuery).getSingleResult().intValue();
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) GPProject(org.geosdi.geoplatform.core.model.GPProject) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 7 with GPProject

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

the class GPProjectDAOImpl method findInternalPublic.

/**
 * @param size
 * @param page
 * @return {@link List<GPProject>}
 * @throws GPDAOException
 */
@Override
public List<GPProject> findInternalPublic(int size, int page) throws GPDAOException {
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<GPProject> criteriaQuery = super.createCriteriaQuery();
        Root<GPProject> root = criteriaQuery.from(this.persistentClass);
        criteriaQuery.select(root);
        criteriaQuery.where(builder.equal(root.get("internalPublic"), TRUE));
        TypedQuery<GPProject> typedQuery = this.entityManager.createQuery(criteriaQuery);
        Integer firstResult = (page == 0) ? 0 : ((page * size));
        typedQuery.setFirstResult(firstResult);
        typedQuery.setMaxResults(size);
        return typedQuery.getResultList();
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) GPProject(org.geosdi.geoplatform.core.model.GPProject) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 8 with GPProject

use of org.geosdi.geoplatform.core.model.GPProject 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)

Example 9 with GPProject

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

the class GPFolderDelegate method insertFolder.

// <editor-fold defaultstate="collapsed" desc="Folder">
// =========================================================================
// === Folder
// =========================================================================
@Override
public Long insertFolder(InsertFolderRequest insertFolderRequest) throws ResourceNotFoundFault, IllegalParameterFault {
    Long projectID = insertFolderRequest.getProjectID();
    GPFolder folder = insertFolderRequest.getFolder();
    if (projectID == null) {
        throw new IllegalParameterFault("The projectID must not be null.");
    }
    if (folder == null) {
        throw new IllegalParameterFault("The GPFolder passed in Request must " + "not be null.");
    }
    GPProject project = projectDao.find(projectID);
    if (project == null) {
        throw new ResourceNotFoundFault("Project not found", projectID);
    }
    // TODO assert
    EntityCorrectness.checkProjectLog(project);
    folder.setProject(project);
    // TODO assert
    EntityCorrectness.checkFolder(folder);
    folderDao.persist(folder);
    return folder.getId();
}
Also used : GPFolder(org.geosdi.geoplatform.core.model.GPFolder) GPProject(org.geosdi.geoplatform.core.model.GPProject) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault)

Example 10 with GPProject

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

the class ProjectDTO method convertToGPProject.

/**
 * Convert an instance of ProjectDTO to {@link GPProject}: will convert all
 * fields unless version and shared fields.
 */
public static GPProject convertToGPProject(@Nonnull(when = NEVER) ProjectDTO projectDTO) {
    checkArgument(projectDTO != null, "The Parameter ProjectDTO must not be null");
    GPProject project = new GPProject();
    project.setId(projectDTO.getId());
    project.setName(projectDTO.getName());
    if (projectDTO.getNumberOfElements() != null) {
        project.setNumberOfElements(projectDTO.getNumberOfElements());
    }
    if (projectDTO.getDescription() != null) {
        project.setDescription(projectDTO.getDescription());
    }
    if (projectDTO.getImagePath() != null) {
        project.setImagePath(projectDTO.getImagePath());
    }
    project.setInternalPublic(projectDTO.isInternalPublic());
    project.setExternalPublic(projectDTO.isExternalPublic());
    project.setShared(projectDTO.isShared());
    return project;
}
Also used : GPProject(org.geosdi.geoplatform.core.model.GPProject)

Aggregations

GPProject (org.geosdi.geoplatform.core.model.GPProject)15 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 GPDAOException (org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)5 GPAccount (org.geosdi.geoplatform.core.model.GPAccount)4 GPFolder (org.geosdi.geoplatform.core.model.GPFolder)3 IllegalParameterFault (org.geosdi.geoplatform.exception.IllegalParameterFault)3 GeoPlatformException (org.geosdi.geoplatform.gui.global.GeoPlatformException)3 GPSessionTimeout (org.geosdi.geoplatform.gui.utility.GPSessionTimeout)3 GPWebServiceMapData (org.geosdi.geoplatform.response.collection.GPWebServiceMapData)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 Date (java.util.Date)1 GPAccountProject (org.geosdi.geoplatform.core.model.GPAccountProject)1 GPUser (org.geosdi.geoplatform.core.model.GPUser)1 PutAccountsProjectRequest (org.geosdi.geoplatform.request.PutAccountsProjectRequest)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