Search in sources :

Example 16 with GPAccountProject

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

the class GPAccountProjectDAOImpl method forceAsDefaultProject.

/**
 * @param accountID
 * @param projectID
 * @return {@link GPAccountProject}
 * @throws GPDAOException
 */
@Override
public GPAccountProject forceAsDefaultProject(Long accountID, Long projectID) throws GPDAOException {
    GPAccountProject oldDefault = this.findDefaultProjectByAccountID(accountID);
    if (oldDefault != null) {
        oldDefault.setDefaultProject(FALSE);
        super.update(oldDefault);
    }
    GPAccountProject newDefault = this.find(accountID, projectID);
    if (newDefault == null)
        return null;
    newDefault.setDefaultProject(TRUE);
    return super.update(newDefault);
}
Also used : GPAccountProject(org.geosdi.geoplatform.core.model.GPAccountProject)

Example 17 with GPAccountProject

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

the class GPAccountProjectDAOImpl method findByProjectID.

/**
 * @param projectID
 * @return {@link List<GPAccountProject>}
 * @throws GPDAOException
 */
@Override
public List<GPAccountProject> findByProjectID(Long projectID) throws GPDAOException {
    checkArgument(projectID != null, "The Parameter projectID 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("project").get("id"), projectID));
        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 18 with GPAccountProject

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

the class GPAccountProjectDAOImpl method findOwnerByProjectID.

/**
 * @param projectID
 * @return {@link GPAccountProject}
 * @throws GPDAOException
 */
@Override
public GPAccountProject findOwnerByProjectID(Long projectID) throws GPDAOException {
    checkArgument(projectID != null, "The Parameter projectID must not be null");
    try {
        CriteriaQuery<GPAccountProject> criteriaQuery = super.createCriteriaQuery();
        Root<GPAccountProject> root = criteriaQuery.from(this.persistentClass);
        criteriaQuery.select(root);
        CriteriaBuilder criteriaBuilder = super.criteriaBuilder();
        criteriaQuery.where(criteriaBuilder.and(criteriaBuilder.equal(root.join("project").get("id"), projectID), criteriaBuilder.equal(root.get("permissionMask"), ADMINISTRATION.getMask())));
        List<GPAccountProject> accountProjects = this.entityManager.createQuery(criteriaQuery).getResultList();
        return ((accountProjects != null) && !(accountProjects.isEmpty()) ? accountProjects.get(0) : null);
    } 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 19 with GPAccountProject

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

the class GPViewportDelegate method saveOrUpdateViewportList.

@Override
public void saveOrUpdateViewportList(ManageViewportRequest request) throws ResourceNotFoundFault, IllegalParameterFault {
    if (request == null) {
        throw new IllegalParameterFault("The ManageViewportRequest " + "must not be null.");
    }
    Long accountProjectID = request.getAccountProjectID();
    ArrayList<GPViewport> viewportList = request.getViewportList();
    GPAccountProject accountProject = this.accountProjectDao.find(accountProjectID);
    if (accountProject == null) {
        throw new ResourceNotFoundFault("AccountProject not found", accountProjectID);
    }
    for (GPViewport viewport : viewportList) {
        long idViewport = 0;
        if (viewport != null && viewport.getId() != null) {
            GPViewport orig = viewportDao.find(viewport.getId());
            if (orig != null) {
                // TODO assert
                EntityCorrectness.checkViewport(orig);
                viewport.setAccountProject(accountProject);
                idViewport = this.updateAndMergeFields(orig, viewport);
            }
        } else if (idViewport == 0) {
            idViewport = this.insertViewport(accountProjectID, viewport);
        }
    }
}
Also used : GPViewport(org.geosdi.geoplatform.core.model.GPViewport) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) GPAccountProject(org.geosdi.geoplatform.core.model.GPAccountProject) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault)

Example 20 with GPAccountProject

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

the class GPJacksonAccountSupportTest method accountProjectDataMapperTest.

@Test
public void accountProjectDataMapperTest() throws Exception {
    GPAccountProject accountProject = jacksonSupport.getDefaultMapper().readValue(Thread.currentThread().getContextClassLoader().getResourceAsStream(ACCOUNT_PROJECT_DATA_JSON), GPAccountProject.class);
    logger.info("\n\n@@@@@@@@@@@@@@@@@@@@@@@@@ACCOUNT_PROJECT_DATA_MAPPING" + " : {}\n\n", accountProject);
    super.marshall(accountProject);
}
Also used : GPAccountProject(org.geosdi.geoplatform.core.model.GPAccountProject) Test(org.junit.Test)

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