Search in sources :

Example 1 with GPOrganization

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

the class GPOrganizationDAOImpl method findByName.

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

Example 2 with GPOrganization

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

the class GPServerDAOImpl method countServers.

/**
 * @param organizationName
 * @param type
 * @param titleOrAliasName
 * @return {@link Integer}
 * @throws GPDAOException
 */
@Override
public Number countServers(String organizationName, GPCapabilityType type, String titleOrAliasName) throws GPDAOException {
    checkArgument((organizationName != null) && !(organizationName.trim().isEmpty()), "The Parameter organizationName must not ne null or an empty string.");
    checkArgument(type != null, "The Parameter type must not ne null.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
        Root<GeoPlatformServer> root = criteriaQuery.from(this.persistentClass);
        List<Predicate> predicates = Lists.newArrayList();
        if ((titleOrAliasName != null) && !(titleOrAliasName.trim().isEmpty())) {
            predicates.add(builder.or(builder.like(builder.lower(root.get("title")), titleOrAliasName.toLowerCase()), builder.like(builder.lower(root.get("aliasName")), titleOrAliasName.toLowerCase())));
        }
        Join<GeoPlatformServer, GPOrganization> join = root.join("organization");
        predicates.add(builder.equal(join.get("name"), organizationName));
        predicates.add(builder.equal(root.get("serverType"), type));
        criteriaQuery.select(builder.count(root));
        criteriaQuery.where(predicates.stream().toArray(Predicate[]::new));
        return this.entityManager.createQuery(criteriaQuery).getSingleResult();
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new GPDAOException(ex);
    }
}
Also used : GeoPlatformServer(org.geosdi.geoplatform.core.model.GeoPlatformServer) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException) GPOrganization(org.geosdi.geoplatform.core.model.GPOrganization) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 3 with GPOrganization

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

the class CSWServiceDelegate method saveServerCSW.

/**
 * @see {@link GeoPlatformCSWService#saveServerCSW(String, String, String)},
 * java.lang.String)
 */
@Override
public ServerCSWDTO saveServerCSW(String alias, String serverUrl, String organization) throws IllegalParameterFault {
    serverUrl = this.deleteQueryStringFromURL(serverUrl);
    GeoPlatformServer server = serverDao.findByServerUrl(serverUrl);
    if (server != null) {
        // If there is already a server with the specified URLs
        return new ServerCSWDTO(server);
    }
    GPOrganization org = organizationDao.findByName(organization);
    if (org == null) {
        throw new IllegalParameterFault("CSW Server to save have an organization that does not exist");
    }
    try {
        CatalogCapabilities capabilities = catalogCapabilitiesBean.bindUrl(serverUrl);
        server = new GeoPlatformServer();
        server.setServerType(GPCapabilityType.CSW);
        server.setServerUrl(serverUrl);
        server.setAliasName(alias);
        server.setOrganization(org);
        server.setTitle(capabilities.getServiceIdentification().getTitle());
        server.setAbstractServer(capabilities.getServiceIdentification().getAbstractText());
        server.setName(capabilities.getServiceProvider().getProviderName());
        // TODO assert
        CSWEntityCorrectness.checkCSWServer(server);
        serverDao.persist(server);
    } catch (Exception ex) {
        logger.error("### MalformedURLException: {}", ex.getMessage());
        throw new IllegalParameterFault("Exception : " + ex.getMessage());
    }
    return new ServerCSWDTO(server);
}
Also used : CatalogCapabilities(org.geosdi.geoplatform.connector.api.capabilities.model.csw.CatalogCapabilities) GeoPlatformServer(org.geosdi.geoplatform.core.model.GeoPlatformServer) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) ServerCSWDTO(org.geosdi.geoplatform.responce.ServerCSWDTO) GPOrganization(org.geosdi.geoplatform.core.model.GPOrganization) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 4 with GPOrganization

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

the class GPOrganizationDelegate method deleteOrganization.

@Override
public Boolean deleteOrganization(Long organizationID) throws ResourceNotFoundFault {
    GPOrganization organization = organizationDao.find(organizationID);
    if (organization == null) {
        throw new ResourceNotFoundFault("Organization not found", organizationID);
    }
    // TODO assert
    EntityCorrectness.checkOrganizationLog(organization);
    return organizationDao.removeById(organization.getId());
}
Also used : ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) GPOrganization(org.geosdi.geoplatform.core.model.GPOrganization)

Example 5 with GPOrganization

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

the class GPServerDelegate method saveServer.

@Override
public ServerDTO saveServer(WSSaveServerRequest saveServerReq) throws IllegalParameterFault {
    if (saveServerReq == null) {
        throw new IllegalParameterFault("The WSSaveServerRequest must " + "not be null.");
    }
    Long id = saveServerReq.getId();
    String serverUrl = saveServerReq.getServerUrl();
    String organization = saveServerReq.getOrganization();
    String aliasServerName = saveServerReq.getAliasServerName();
    try {
        URL serverURL = new URL(serverUrl);
    } catch (MalformedURLException e) {
        logger.error("MalformedURLException: " + e);
        throw new IllegalParameterFault("Malformed URL");
    }
    GPOrganization org = organizationDao.findByName(organization);
    if (org == null) {
        throw new IllegalParameterFault("Server to save have an organization that does not exist");
    }
    GeoPlatformServer server;
    if (id != null) {
        // Existent server
        server = serverDao.find(id);
    } else {
        // New server
        if (this.isURLServerAlreadyExists(serverUrl)) {
            throw new IllegalParameterFault("Duplicated Server URL");
        }
        server = new GeoPlatformServer();
        server.setServerType(WMS);
    }
    server.setAliasName(aliasServerName);
    server.setServerUrl(serverUrl);
    server.setAuthServer(new GPAuthServer(saveServerReq.getUsername(), saveServerReq.getPassword()));
    server.setProxy(saveServerReq.isProxy());
    server.setOrganization(org);
    serverDao.persist(server);
    return new ServerDTO(server);
}
Also used : GeoPlatformServer(org.geosdi.geoplatform.core.model.GeoPlatformServer) ServerDTO(org.geosdi.geoplatform.response.ServerDTO) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) MalformedURLException(java.net.MalformedURLException) GPAuthServer(org.geosdi.geoplatform.core.model.GPAuthServer) GPOrganization(org.geosdi.geoplatform.core.model.GPOrganization) URL(java.net.URL)

Aggregations

GPOrganization (org.geosdi.geoplatform.core.model.GPOrganization)20 GeoPlatformServer (org.geosdi.geoplatform.core.model.GeoPlatformServer)6 IllegalParameterFault (org.geosdi.geoplatform.exception.IllegalParameterFault)6 GPUser (org.geosdi.geoplatform.core.model.GPUser)4 Test (org.junit.Test)4 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)3 GPDAOException (org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)3 InsertAccountRequest (org.geosdi.geoplatform.request.InsertAccountRequest)3 MalformedURLException (java.net.MalformedURLException)2 ShortAccountDTO (org.geosdi.geoplatform.response.ShortAccountDTO)2 IOException (java.io.IOException)1 URL (java.net.URL)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 CatalogCapabilities (org.geosdi.geoplatform.connector.api.capabilities.model.csw.CatalogCapabilities)1 GPApplication (org.geosdi.geoplatform.core.model.GPApplication)1 GPAuthServer (org.geosdi.geoplatform.core.model.GPAuthServer)1 GPRestExceptionMessage (org.geosdi.geoplatform.exception.rs.GPRestExceptionMessage)1 GeoPlatformException (org.geosdi.geoplatform.gui.global.GeoPlatformException)1 AreaInfo (org.geosdi.geoplatform.gui.responce.AreaInfo)1