Search in sources :

Example 1 with GPUser

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

the class LayerService method shareProjectToUsers.

@Override
public boolean shareProjectToUsers(long idSharedProject, List<Long> accountIDsProject, HttpServletRequest httpServletRequest) throws GeoPlatformException {
    boolean result;
    try {
        GPAccount account = this.sessionUtility.getLoggedAccount(httpServletRequest);
        result = this.geoPlatformServiceClient.updateAccountsProjectSharing(new PutAccountsProjectRequest(idSharedProject, accountIDsProject));
        if (result) {
            MessageDTO message = new MessageDTO();
            message.setCommands(Lists.newArrayList(GPMessageCommandType.OPEN_PROJECT));
            message.setCommandsProperties("" + idSharedProject);
            message.setCreationDate(new Date());
            message.setSenderID(account.getId());
            message.setSubject("Project Shared");
            String sharerName;
            if (account instanceof GPUser) {
                GPUser user = (GPUser) account;
                sharerName = user.getName();
            } else {
                sharerName = account.getNaturalID();
            }
            GPProject project = this.geoPlatformServiceClient.getProjectDetail(idSharedProject);
            message.setText(sharerName + " shared with you the " + project.getName() + " project. Do you want to open it?");
            message.setRecipientIDs(accountIDsProject);
            this.geoPlatformServiceClient.insertMultiMessage(message);
        }
    } catch (GPSessionTimeout timeout) {
        throw new GeoPlatformException(timeout);
    } catch (ResourceNotFoundFault | IllegalParameterFault rnf) {
        logger.error("Failed to save Shared project to Accounts for Shared Project with id: " + idSharedProject + "on SecurityService: " + rnf);
        throw new GeoPlatformException(rnf);
    }
    return result;
}
Also used : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) GPUser(org.geosdi.geoplatform.core.model.GPUser) PutAccountsProjectRequest(org.geosdi.geoplatform.request.PutAccountsProjectRequest) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) GPSessionTimeout(org.geosdi.geoplatform.gui.utility.GPSessionTimeout) Date(java.util.Date) GPProject(org.geosdi.geoplatform.core.model.GPProject) GeoPlatformException(org.geosdi.geoplatform.gui.global.GeoPlatformException)

Example 2 with GPUser

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

the class GPAccountDAOImpl method searchPagebleEnabledUsersByOrganization.

/**
 * @param page
 * @param size
 * @param organizationName
 * @param userID
 * @param nameLike
 * @return {@link List<GPAccount>}
 * @throws GPDAOException
 */
@Override
public List<GPAccount> searchPagebleEnabledUsersByOrganization(Integer page, Integer size, String organizationName, Long userID, String nameLike) throws GPDAOException {
    checkArgument((organizationName != null) && !(organizationName.trim().isEmpty()), "The Paramater organizationName must not be null or an Empty String.");
    checkArgument(userID != null, "The Parameter userID must not be null.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<GPAccount> criteriaQuery = super.createCriteriaQuery();
        Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
        Root<GPUser> userRoot = builder.treat(root, GPUser.class);
        criteriaQuery.select(root);
        List<Predicate> predicates = Lists.newArrayList();
        if ((nameLike != null) && !(nameLike.trim().isEmpty()))
            predicates.add(builder.like(builder.lower(userRoot.get("username")), nameLike.toLowerCase()));
        predicates.add(builder.equal(root.get("enabled"), TRUE));
        predicates.add(builder.equal(root.join("organization").get("name"), organizationName));
        predicates.add(builder.notEqual(root.get("id"), userID));
        predicates.add(builder.isNotNull(userRoot.get("username")));
        criteriaQuery.where(predicates.stream().toArray(Predicate[]::new)).orderBy(builder.asc(userRoot.get("username")));
        Query 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 : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPUser(org.geosdi.geoplatform.core.model.GPUser) Query(javax.persistence.Query) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 3 with GPUser

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

the class GPAccountDAOImpl method findByUsername.

/**
 * @param username
 * @return {@link GPUser}
 * @throws Exception
 */
@Override
public GPUser findByUsername(String username) throws GPDAOException {
    checkArgument((username != null) && !(username.trim().isEmpty()), "The Parameter username must not be null or an empty String.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<GPAccount> criteriaQuery = super.createCriteriaQuery();
        Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
        Root<GPUser> userRoot = builder.treat(root, GPUser.class);
        criteriaQuery.select(root);
        criteriaQuery.where(super.criteriaBuilder().equal(userRoot.get("username"), username));
        List<GPAccount> accounts = this.entityManager.createQuery(criteriaQuery).getResultList();
        return ((accounts != null) && !(accounts.isEmpty()) ? (GPUser) accounts.get(0) : null);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPUser(org.geosdi.geoplatform.core.model.GPUser) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 4 with GPUser

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

the class GPAccountDAOImpl method countUsers.

/**
 * @param organizationName
 * @param nameLike
 * @return {@link Number}
 * @throws GPDAOException
 */
@Override
public Number countUsers(String organizationName, String nameLike) throws GPDAOException {
    checkArgument((organizationName != null) && !(organizationName.trim().isEmpty()), "The Paramater organizationName must not be null or an Empty String.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
        Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
        Root<GPUser> userRoot = builder.treat(root, GPUser.class);
        criteriaQuery.select(builder.count(root));
        List<Predicate> predicates = Lists.newArrayList();
        predicates.add(builder.equal(root.join("organization").get("name"), organizationName));
        predicates.add(builder.isNotNull(userRoot.get("username")));
        if ((nameLike != null) && !(nameLike.isEmpty()))
            predicates.add(builder.like(builder.lower(userRoot.get("username")), nameLike.toLowerCase()));
        criteriaQuery.where(predicates.stream().toArray(size -> new Predicate[size]));
        return this.entityManager.createQuery(criteriaQuery).getSingleResult();
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPApplication(org.geosdi.geoplatform.core.model.GPApplication) FALSE(java.lang.Boolean.FALSE) GPAccountDAO(org.geosdi.geoplatform.core.dao.GPAccountDAO) GPUser(org.geosdi.geoplatform.core.model.GPUser) Profile(org.springframework.context.annotation.Profile) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) Query(javax.persistence.Query) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) javax.persistence.criteria(javax.persistence.criteria) GPAbstractJpaDAO(org.geosdi.geoplatform.persistence.dao.jpa.GPAbstractJpaDAO) Repository(org.springframework.stereotype.Repository) TRUE(java.lang.Boolean.TRUE) GPUser(org.geosdi.geoplatform.core.model.GPUser) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 5 with GPUser

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

the class GPAccountDAOImpl method countAccounts.

/**
 * @param nameLike
 * @return {@link Number}
 * @throws GPDAOException
 */
@Override
public Number countAccounts(String nameLike) throws GPDAOException {
    checkArgument(((nameLike != null) && !(nameLike.trim().isEmpty())), "The Parameter nameLike must not be null or an empty string.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
        Root<GPAccount> root = criteriaQuery.from(this.persistentClass);
        Root<GPUser> userRoot = builder.treat(root, GPUser.class);
        Root<GPApplication> applicationRoot = builder.treat(root, GPApplication.class);
        criteriaQuery.select(builder.count(root));
        criteriaQuery.where(builder.or(builder.like(builder.lower(userRoot.get("username")), nameLike.toLowerCase()), builder.like(builder.lower(applicationRoot.get("appID")), nameLike.toLowerCase())));
        return entityManager.createQuery(criteriaQuery).getSingleResult();
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPUser(org.geosdi.geoplatform.core.model.GPUser) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPApplication(org.geosdi.geoplatform.core.model.GPApplication)

Aggregations

GPUser (org.geosdi.geoplatform.core.model.GPUser)33 Test (org.junit.Test)15 GPAccount (org.geosdi.geoplatform.core.model.GPAccount)8 IllegalParameterFault (org.geosdi.geoplatform.exception.IllegalParameterFault)7 InsertAccountRequest (org.geosdi.geoplatform.request.InsertAccountRequest)7 GeoPlatformException (org.geosdi.geoplatform.gui.global.GeoPlatformException)6 GPDAOException (org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)6 GPOrganization (org.geosdi.geoplatform.core.model.GPOrganization)4 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)4 UserDTO (org.geosdi.geoplatform.response.UserDTO)4 Query (javax.persistence.Query)3 ClientErrorException (javax.ws.rs.ClientErrorException)3 GPRestExceptionMessage (org.geosdi.geoplatform.exception.rs.GPRestExceptionMessage)3 PaginatedSearchRequest (org.geosdi.geoplatform.request.PaginatedSearchRequest)3 SearchRequest (org.geosdi.geoplatform.request.SearchRequest)3 ArrayList (java.util.ArrayList)2 GPApplication (org.geosdi.geoplatform.core.model.GPApplication)2 GPSessionTimeout (org.geosdi.geoplatform.gui.utility.GPSessionTimeout)2 UserDTOResponse (org.geosdi.geoplatform.response.UserDTOResponse)2 BasePagingLoadResult (com.extjs.gxt.ui.client.data.BasePagingLoadResult)1