Search in sources :

Example 1 with ServerInternalFault

use of org.geosdi.geoplatform.exception.ServerInternalFault 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)

Example 2 with ServerInternalFault

use of org.geosdi.geoplatform.exception.ServerInternalFault in project geo-platform by geosdi.

the class GPCatalogFinderService method searchSummaryRecords.

@Override
public PagingLoadResult<SummaryRecord> searchSummaryRecords(PagingLoadConfig config, CatalogFinderBean catalogFinder, HttpServletRequest httpServletRequest) throws Exception {
    int recordsCount;
    ArrayList<SummaryRecord> searchRecords;
    try {
        recordsCount = geoPlatformCSWClient.getRecordsCount(catalogFinder);
        if (recordsCount == 0) {
            logger.info("\n*** No Summary Record found ***");
            searchRecords = new ArrayList<SummaryRecord>(0);
        } else {
            List<SummaryRecordDTO> recordList = geoPlatformCSWClient.searchSummaryRecords(config.getLimit(), config.getOffset() + 1, catalogFinder);
            searchRecords = new ArrayList<SummaryRecord>(recordList.size());
            for (SummaryRecordDTO recordDTO : recordList) {
                searchRecords.add(this.convertSummaryRecordDTO(recordDTO));
            }
        }
    } catch (IllegalParameterFault ex) {
        logger.error("\n*** IllegalParameterFault ***\n{}", ex.getMessage());
        throw new GeoPlatformException(ex.getMessage());
    } catch (ResourceNotFoundFault ex) {
        logger.error("\n*** ResourceNotFoundFault ***\n{}", ex.getMessage());
        throw new GeoPlatformException(ex.getMessage());
    } catch (ServerInternalFault ex) {
        logger.error("\n*** ServerInternalFault ***\n{}", ex.getMessage());
        throw new GeoPlatformException(ex.getMessage());
    }
    return new BasePagingLoadResult<SummaryRecord>(searchRecords, config.getOffset(), recordsCount);
}
Also used : IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) SummaryRecord(org.geosdi.geoplatform.gui.client.model.SummaryRecord) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) SummaryRecordDTO(org.geosdi.geoplatform.responce.SummaryRecordDTO) ServerInternalFault(org.geosdi.geoplatform.exception.ServerInternalFault) GeoPlatformException(org.geosdi.geoplatform.gui.global.GeoPlatformException) BasePagingLoadResult(com.extjs.gxt.ui.client.data.BasePagingLoadResult)

Example 3 with ServerInternalFault

use of org.geosdi.geoplatform.exception.ServerInternalFault in project geo-platform by geosdi.

the class GPCatalogFinderService method searchFullRecords.

@Override
public PagingLoadResult<FullRecord> searchFullRecords(PagingLoadConfig config, CatalogFinderBean catalogFinder, HttpServletRequest httpServletRequest) throws Exception {
    logger.debug("\n--------------------------\n{}\n--------------------------\n", catalogFinder);
    int recordsCount;
    ArrayList<FullRecord> searchRecords;
    try {
        recordsCount = geoPlatformCSWClient.getRecordsCount(catalogFinder);
        if (recordsCount == 0) {
            logger.info("\n*** No Full Record found ***");
            searchRecords = new ArrayList<FullRecord>(0);
        } else {
            List<FullRecordDTO> recordList = geoPlatformCSWClient.searchFullRecords(config.getLimit(), config.getOffset() + 1, catalogFinder);
            searchRecords = new ArrayList<FullRecord>(recordList.size());
            for (FullRecordDTO recordDTO : recordList) {
                searchRecords.add(this.convertFullRecordDTO(recordDTO));
            }
        }
    } catch (IllegalParameterFault ex) {
        logger.error("\n*** IllegalParameterFault ***\n{}", ex.getMessage());
        throw new GeoPlatformException(ex.getMessage());
    } catch (ResourceNotFoundFault ex) {
        logger.error("\n*** ResourceNotFoundFault ***\n{}", ex.getMessage());
        throw new GeoPlatformException(ex.getMessage());
    } catch (ServerInternalFault ex) {
        logger.error("\n*** ServerInternalFault ***\n{}", ex.getMessage());
        throw new GeoPlatformException(ex.getMessage());
    }
    return new BasePagingLoadResult<FullRecord>(searchRecords, config.getOffset(), recordsCount);
}
Also used : IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) FullRecord(org.geosdi.geoplatform.gui.client.model.FullRecord) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) FullRecordDTO(org.geosdi.geoplatform.responce.FullRecordDTO) ServerInternalFault(org.geosdi.geoplatform.exception.ServerInternalFault) GeoPlatformException(org.geosdi.geoplatform.gui.global.GeoPlatformException) BasePagingLoadResult(com.extjs.gxt.ui.client.data.BasePagingLoadResult)

Example 4 with ServerInternalFault

use of org.geosdi.geoplatform.exception.ServerInternalFault in project geo-platform by geosdi.

the class GPCatalogFinderService method getRecordById.

@Override
public String getRecordById(Long serverID, String identifier, String moduleName, HttpServletRequest httpServletRequest) throws Exception {
    try {
        String url = httpServletRequest.getSession().getServletContext().getRealPath("/" + moduleName + "/csw-template");
        logger.trace("PATH @@@@@@@@@@@@@@@@@@ {}", url);
        String response = geoPlatformCSWClient.getRecordById(serverID, identifier);
        response = this.deAccent(response);
        String fileName = url + "/" + System.currentTimeMillis() + "-" + identifier + ".xml";
        File file = new File(fileName);
        FileUtils.writeStringToFile(file, response);
        logger.debug("Name FILE Created  @@@@@@@@@@@@@@@@@@@@@@@@@@@ {}", file.getName());
        return file.getName();
    } catch (IOException ex) {
        logger.error("\n*** IOException ***\n{}", ex.getMessage());
        throw new GeoPlatformException(ex.getMessage());
    } catch (IllegalParameterFault ex) {
        logger.error("\n*** IllegalParameterFault ***\n{}", ex.getMessage());
        throw new GeoPlatformException(ex.getMessage());
    } catch (ResourceNotFoundFault ex) {
        logger.error("\n*** ResourceNotFoundFault ***\n{}", ex.getMessage());
        throw new GeoPlatformException(ex.getMessage());
    } catch (ServerInternalFault ex) {
        logger.error("\n*** ServerInternalFault ***\n{}", ex.getMessage());
        throw new GeoPlatformException(ex.getMessage());
    }
}
Also used : IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) IOException(java.io.IOException) ServerInternalFault(org.geosdi.geoplatform.exception.ServerInternalFault) GeoPlatformException(org.geosdi.geoplatform.gui.global.GeoPlatformException) File(java.io.File)

Example 5 with ServerInternalFault

use of org.geosdi.geoplatform.exception.ServerInternalFault in project geo-platform by geosdi.

the class CSWServiceDelegate method searchSummaryRecords.

/**
 * TODO Factorize source code for search*Records methods.
 * <p>
 * TODO GMD list.
 */
@Override
public List<SummaryRecordDTO> searchSummaryRecords(int num, int start, CatalogFinderBean catalogFinder) throws Exception {
    logger.trace("\n*** searchSummaryRecords ***\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.SUMMARY.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<SummaryRecordDTO> recordListDTO = new ArrayList<SummaryRecordDTO>(records.size());
    for (JAXBElement<? extends AbstractRecordType> record : records) {
        SummaryRecordType summary = (SummaryRecordType) record.getValue();
        recordListDTO.add(this.convertSummaryRecords(summary, server));
    }
    return recordListDTO;
}
Also used : GeoPlatformServer(org.geosdi.geoplatform.core.model.GeoPlatformServer) ArrayList(java.util.ArrayList) SummaryRecordDTO(org.geosdi.geoplatform.responce.SummaryRecordDTO) ServerInternalFault(org.geosdi.geoplatform.exception.ServerInternalFault) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

ServerInternalFault (org.geosdi.geoplatform.exception.ServerInternalFault)5 IllegalParameterFault (org.geosdi.geoplatform.exception.IllegalParameterFault)3 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)3 GeoPlatformException (org.geosdi.geoplatform.gui.global.GeoPlatformException)3 BasePagingLoadResult (com.extjs.gxt.ui.client.data.BasePagingLoadResult)2 JAXBElement (javax.xml.bind.JAXBElement)2 GeoPlatformServer (org.geosdi.geoplatform.core.model.GeoPlatformServer)2 FullRecordDTO (org.geosdi.geoplatform.responce.FullRecordDTO)2 SummaryRecordDTO (org.geosdi.geoplatform.responce.SummaryRecordDTO)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 FullRecord (org.geosdi.geoplatform.gui.client.model.FullRecord)1 SummaryRecord (org.geosdi.geoplatform.gui.client.model.SummaryRecord)1