Search in sources :

Example 1 with GeoPlatformServer

use of org.geosdi.geoplatform.core.model.GeoPlatformServer 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 2 with GeoPlatformServer

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

the class GPServerDAOImpl method findByServerUrl.

/**
 * @param serverUrl
 * @return {@link GeoPlatformServer}
 * @throws GPDAOException
 */
@Override
public GeoPlatformServer findByServerUrl(String serverUrl) throws GPDAOException {
    checkArgument(((serverUrl != null) && !(serverUrl.trim().isEmpty())), "The Parameter serverUrl must not be null or an empty string.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<GeoPlatformServer> criteriaQuery = super.createCriteriaQuery();
        Root<GeoPlatformServer> root = criteriaQuery.from(this.persistentClass);
        criteriaQuery.select(root);
        criteriaQuery.where(builder.equal(root.get("serverUrl"), serverUrl));
        List<GeoPlatformServer> servers = this.entityManager.createQuery(criteriaQuery).getResultList();
        return ((servers != null) && !(servers.isEmpty()) ? servers.get(0) : null);
    } 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) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 3 with GeoPlatformServer

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

the class GPServerDAOImpl method findAll.

/**
 * @param type
 * @return {@link List<GeoPlatformServer>}
 * @throws GPDAOException
 */
@Override
public List<GeoPlatformServer> findAll(GPCapabilityType type) throws GPDAOException {
    checkArgument(type != null, "The Parameter type must not ne null.");
    try {
        CriteriaBuilder builder = super.criteriaBuilder();
        CriteriaQuery<GeoPlatformServer> criteriaQuery = super.createCriteriaQuery();
        Root<GeoPlatformServer> root = criteriaQuery.from(this.persistentClass);
        criteriaQuery.select(root);
        criteriaQuery.where(builder.equal(root.get("serverType"), type));
        return this.entityManager.createQuery(criteriaQuery).getResultList();
    } 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) GPDAOException(org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)

Example 4 with GeoPlatformServer

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

the class CSWServiceDelegate method getServerDetailCSW.

/**
 * @see GeoPlatformCSWService#getServerDetailCSW(java.lang.Long)
 */
@Override
public GeoPlatformServer getServerDetailCSW(Long serverID) throws ResourceNotFoundFault {
    GeoPlatformServer server = serverDao.find(serverID);
    if (server == null) {
        throw new ResourceNotFoundFault("Server not found", serverID);
    }
    // TODO assert
    CSWEntityCorrectness.checkCSWServerLog(server);
    return server;
}
Also used : GeoPlatformServer(org.geosdi.geoplatform.core.model.GeoPlatformServer) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault)

Example 5 with GeoPlatformServer

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

the class CSWServiceDelegate method searchFullRecords.

/**
 * TODO Factorize source code for search*Records methods.
 * <p>
 * Changed wrt searchSummaryRecords: 1 - ElementSetType.FULL 2 - Downcast to
 * RecordType
 * <p>
 * TODO GMD list.
 */
@Override
public List<FullRecordDTO> searchFullRecords(int num, int start, CatalogFinderBean catalogFinder) throws Exception {
    logger.trace("\n*** searchFullRecords ***\n{}", catalogFinder);
    GeoPlatformServer server = this.getCSWServerByID(catalogFinder.getServerID());
    CatalogGetRecordsRequest<GetRecordsResponseType> request = this.createGetRecordsRequest(server.getServerUrl());
    request.setTypeName(TypeName.RECORD_V202);
    request.setOutputSchema(OutputSchema.CSW_V202);
    request.setElementSetName(ElementSetType.FULL.value());
    request.setResultType(ResultType.RESULTS.value());
    request.setConstraintLanguage(ConstraintLanguage.FILTER);
    request.setConstraintLanguageVersion(ConstraintLanguageVersion.V110);
    request.setCatalogFinder(catalogFinder);
    // Pagination search
    request.setMaxRecords(BigInteger.valueOf(num));
    request.setStartPosition(BigInteger.valueOf(start));
    logger.debug("\n*** Num: {} *** Start: {} ***", request.getMaxRecords(), request.getStartPosition());
    GetRecordsResponseType response = this.createGetRecordsResponse(request);
    logger.debug("\n*** Records matched: {} *** Records returned: {} *** Record next: {} ***", response.getSearchResults().getNumberOfRecordsMatched(), response.getSearchResults().getNumberOfRecordsReturned(), response.getSearchResults().getNextRecord());
    if (response.getSearchResults().getNumberOfRecordsReturned().intValue() != response.getSearchResults().getAbstractRecord().size()) {
        throw new ServerInternalFault("CSW Catalog Server Error: incorrect number of records, expected " + response.getSearchResults().getNumberOfRecordsReturned() + " but was " + response.getSearchResults().getAbstractRecord().size());
    }
    List<JAXBElement<? extends AbstractRecordType>> records = response.getSearchResults().getAbstractRecord();
    logger.trace("\n*** Record list size: {} ***", records.size());
    List<FullRecordDTO> recordListDTO = Lists.<FullRecordDTO>newArrayListWithCapacity(records.size());
    for (JAXBElement<? extends AbstractRecordType> r : records) {
        RecordType record = (RecordType) r.getValue();
        recordListDTO.add(this.convertFullRecords(record, server));
    }
    return recordListDTO;
}
Also used : GeoPlatformServer(org.geosdi.geoplatform.core.model.GeoPlatformServer) FullRecordDTO(org.geosdi.geoplatform.responce.FullRecordDTO) ServerInternalFault(org.geosdi.geoplatform.exception.ServerInternalFault) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

GeoPlatformServer (org.geosdi.geoplatform.core.model.GeoPlatformServer)40 Test (org.junit.Test)15 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)9 ServerDTO (org.geosdi.geoplatform.response.ServerDTO)8 GPOrganization (org.geosdi.geoplatform.core.model.GPOrganization)6 GPDAOException (org.geosdi.geoplatform.persistence.dao.exception.GPDAOException)6 ServerCSWDTO (org.geosdi.geoplatform.responce.ServerCSWDTO)3 Ignore (org.junit.Ignore)3 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 JAXBElement (javax.xml.bind.JAXBElement)2 IllegalParameterFault (org.geosdi.geoplatform.exception.IllegalParameterFault)2 ServerInternalFault (org.geosdi.geoplatform.exception.ServerInternalFault)2 PaginatedSearchRequest (org.geosdi.geoplatform.request.PaginatedSearchRequest)2 WSSaveServerRequest (org.geosdi.geoplatform.request.server.WSSaveServerRequest)2 RasterLayerDTO (org.geosdi.geoplatform.response.RasterLayerDTO)2 IOException (java.io.IOException)1 URL (java.net.URL)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1