Search in sources :

Example 11 with GPAccountProject

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

the class MapService method loadViewportElements.

@Override
public List<GPClientViewport> loadViewportElements(HttpServletRequest httpServletRequest) throws GeoPlatformException {
    GPAccount account;
    Long projectID;
    try {
        account = this.sessionUtility.getLoggedAccount(httpServletRequest);
        projectID = this.sessionUtility.getDefaultProject(httpServletRequest);
    } catch (GPSessionTimeout timeout) {
        throw new GeoPlatformException(timeout);
    }
    Collection<GPViewport> viewportCollectionElements = null;
    try {
        GPAccountProject accountProject = this.geoPlatformServiceClient.getAccountProjectByAccountAndProjectIDs(account.getId(), projectID);
        viewportCollectionElements = this.geoPlatformServiceClient.getAccountProjectViewports(accountProject.getId()).getViewports();
    } catch (ResourceNotFoundFault rnff) {
        logger.error("Error on MapService: " + rnff);
        throw new GeoPlatformException(rnff);
    }
    return this.convertServerViewportToDTO(viewportCollectionElements);
}
Also used : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) GPViewport(org.geosdi.geoplatform.core.model.GPViewport) GPAccountProject(org.geosdi.geoplatform.core.model.GPAccountProject) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) GPSessionTimeout(org.geosdi.geoplatform.gui.utility.GPSessionTimeout) GeoPlatformException(org.geosdi.geoplatform.gui.global.GeoPlatformException)

Example 12 with GPAccountProject

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

the class GPAccountProjectDAOImpl method count.

/**
 * @param accountID
 * @param nameProject
 * @return {@link Number}
 * @throws GPDAOException
 */
@Override
public Number count(Long accountID, String nameProject) throws GPDAOException {
    checkArgument(accountID != null, "The Parameter accountID must not be null.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
        Root<GPAccountProject> root = criteriaQuery.from(this.persistentClass);
        criteriaQuery.select(builder.count(root));
        List<Predicate> predicates = Lists.newArrayList();
        predicates.add(builder.equal(root.join("account").get("id"), accountID));
        if ((nameProject != null) && !(nameProject.trim().isEmpty()))
            predicates.add(builder.like(builder.lower(root.get("project").get("name")), nameProject.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 : FALSE(java.lang.Boolean.FALSE) GPAccountProject(org.geosdi.geoplatform.core.model.GPAccountProject) Profile(org.springframework.context.annotation.Profile) TypedQuery(javax.persistence.TypedQuery) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) GPAccountProjectDAO(org.geosdi.geoplatform.core.dao.GPAccountProjectDAO) javax.persistence.criteria(javax.persistence.criteria) ADMINISTRATION(org.springframework.security.acls.domain.BasePermission.ADMINISTRATION) GPAbstractJpaDAO(org.geosdi.geoplatform.persistence.dao.jpa.GPAbstractJpaDAO) Repository(org.springframework.stereotype.Repository) TRUE(java.lang.Boolean.TRUE) GPAccountProject(org.geosdi.geoplatform.core.model.GPAccountProject) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 13 with GPAccountProject

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

the class GPAccountProjectDAOImpl method removeByProjectID.

/**
 * @param projectID
 * @return {@link Boolean}
 * @throws GPDAOException
 */
@Override
public Boolean removeByProjectID(Long projectID) throws GPDAOException {
    checkArgument(projectID != null, "The Parameter projectID must not be null.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaDelete<GPAccountProject> criteriaDelete = super.createCriteriaDelete();
        Root<GPAccountProject> root = criteriaDelete.from(super.getPersistentClass());
        criteriaDelete.where(builder.equal(root.join("project").get("id"), projectID));
        return ((this.entityManager.createQuery(criteriaDelete).executeUpdate() == 1) ? TRUE : FALSE);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : GPAccountProject(org.geosdi.geoplatform.core.model.GPAccountProject) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 14 with GPAccountProject

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

the class GPAccountProjectDAOImpl method findByAccountID.

/**
 * @param accountID
 * @return {@link List<GPAccountProject>}
 * @throws GPDAOException
 */
@Override
public List<GPAccountProject> findByAccountID(Long accountID) throws GPDAOException {
    checkArgument(accountID != null, "The Parameter accountID must not be null.");
    try {
        CriteriaQuery<GPAccountProject> criteriaQuery = super.createCriteriaQuery();
        Root<GPAccountProject> root = criteriaQuery.from(this.persistentClass);
        criteriaQuery.select(root);
        criteriaQuery.where(super.criteriaBuilder().equal(root.join("account").get("id"), accountID));
        return this.entityManager.createQuery(criteriaQuery).getResultList();
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : GPAccountProject(org.geosdi.geoplatform.core.model.GPAccountProject) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 15 with GPAccountProject

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

the class GPAccountProjectDAOImpl method searchAccountProjectsByAccountID.

/**
 * @param page
 * @param size
 * @param accountID
 * @param projectName
 * @return {@link List < GPAccountProject >}
 * @throws GPDAOException
 */
@Override
public List<GPAccountProject> searchAccountProjectsByAccountID(Integer page, Integer size, Long accountID, String projectName) throws GPDAOException {
    checkArgument(accountID != null, "The Parameter accountID must not be null.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<GPAccountProject> criteriaQuery = super.createCriteriaQuery();
        Root<GPAccountProject> root = criteriaQuery.from(this.persistentClass);
        criteriaQuery.select(root);
        List<Predicate> predicates = Lists.newArrayList();
        predicates.add(builder.equal(root.join("account").get("id"), accountID));
        if ((projectName != null) && !(projectName.trim().isEmpty()))
            predicates.add(builder.like(builder.lower(root.get("project").get("name")), projectName.toLowerCase()));
        criteriaQuery.where(predicates.stream().toArray(Predicate[]::new)).orderBy(builder.asc(root.get("defaultProject")));
        TypedQuery<GPAccountProject> typedQuery = this.entityManager.createQuery(criteriaQuery);
        if ((page != null) && (size != null)) {
            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 : GPAccountProject(org.geosdi.geoplatform.core.model.GPAccountProject) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Aggregations

GPAccountProject (org.geosdi.geoplatform.core.model.GPAccountProject)20 GPDAOException (org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)11 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)7 GPAccount (org.geosdi.geoplatform.core.model.GPAccount)4 IllegalParameterFault (org.geosdi.geoplatform.exception.IllegalParameterFault)4 GPViewport (org.geosdi.geoplatform.core.model.GPViewport)3 GeoPlatformException (org.geosdi.geoplatform.gui.global.GeoPlatformException)3 GPSessionTimeout (org.geosdi.geoplatform.gui.utility.GPSessionTimeout)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Lists (com.google.common.collect.Lists)1 FALSE (java.lang.Boolean.FALSE)1 TRUE (java.lang.Boolean.TRUE)1 List (java.util.List)1 TypedQuery (javax.persistence.TypedQuery)1 javax.persistence.criteria (javax.persistence.criteria)1 GPAccountProjectDAO (org.geosdi.geoplatform.core.dao.GPAccountProjectDAO)1 GPProject (org.geosdi.geoplatform.core.model.GPProject)1 GPAbstractJpaDAO (org.geosdi.geoplatform.persistence.dao.jpa.GPAbstractJpaDAO)1 ManageViewportRequest (org.geosdi.geoplatform.request.viewport.ManageViewportRequest)1 EntityCorrectnessException (org.geosdi.geoplatform.services.development.EntityCorrectnessException)1