2016-06-16 15:03:03 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.datatransfer.resolver.gis.geonetwork;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
|
|
|
import org.gcube.spatial.data.geonetwork.GeoNetworkReader;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2019-03-15 12:23:04 +01:00
|
|
|
import it.geosolutions.geonetwork.util.GNSearchRequest;
|
|
|
|
import it.geosolutions.geonetwork.util.GNSearchResponse;
|
|
|
|
import it.geosolutions.geonetwork.util.GNSearchResponse.GNMetadata;
|
|
|
|
|
2016-06-16 15:03:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class FilterGetRecords.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* Jun 15, 2016
|
|
|
|
*/
|
|
|
|
public class FilterGetRecords {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private static final String CSW_GET_RECORDS = "csw:GetRecords";
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(FilterGetRecords.class);
|
|
|
|
|
|
|
|
private List<String> foundPublicIds = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new filter get records.
|
2018-04-23 17:07:57 +02:00
|
|
|
*
|
2018-07-20 12:57:00 +02:00
|
|
|
* @param readBody the read body
|
2018-04-23 17:07:57 +02:00
|
|
|
*/
|
2018-07-20 12:57:00 +02:00
|
|
|
public FilterGetRecords(String readBody) {
|
|
|
|
|
|
|
|
if(readBody!=null && !readBody.isEmpty() && readBody.contains(CSW_GET_RECORDS)){
|
|
|
|
logger.info("Is "+CSW_GET_RECORDS+" request, getting public ids");
|
|
|
|
GeoNetworkReader reader;
|
|
|
|
try {
|
|
|
|
reader = GeoNetwork.get();
|
|
|
|
final GNSearchRequest req=new GNSearchRequest();
|
|
|
|
req.addParam(GNSearchRequest.Param.any,"");
|
|
|
|
GNSearchResponse resp=reader.query(req);
|
|
|
|
|
|
|
|
foundPublicIds = new ArrayList<String>();
|
|
|
|
Iterator<GNMetadata> iterator=resp.iterator();
|
|
|
|
while(iterator.hasNext()){
|
|
|
|
foundPublicIds.add(iterator.next().getUUID());
|
|
|
|
}
|
|
|
|
logger.info("Public Metadata ids are: "+foundPublicIds.size());
|
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("Error during sending GNSearchRequest: ",e);
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
logger.trace("Is not a"+CSW_GET_RECORDS+" request, skipping");
|
2016-06-16 15:03:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-05 11:25:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the public file identifiers.
|
|
|
|
*
|
|
|
|
* @return the public file identifiers
|
|
|
|
*/
|
2018-07-20 12:57:00 +02:00
|
|
|
public List<String> getPublicFileIdentifiers(){
|
2017-09-05 11:25:26 +02:00
|
|
|
|
|
|
|
logger.info("Performing query to retrieve the public file identifiers");
|
|
|
|
GeoNetworkReader reader;
|
|
|
|
try {
|
|
|
|
reader = GeoNetwork.get();
|
|
|
|
final GNSearchRequest req=new GNSearchRequest();
|
|
|
|
req.addParam(GNSearchRequest.Param.any,"");
|
|
|
|
GNSearchResponse resp=reader.query(req);
|
|
|
|
|
|
|
|
foundPublicIds = new ArrayList<String>();
|
|
|
|
Iterator<GNMetadata> iterator=resp.iterator();
|
|
|
|
while(iterator.hasNext()){
|
|
|
|
foundPublicIds.add(iterator.next().getUUID());
|
|
|
|
}
|
|
|
|
logger.info("Public Metadata ids are: "+foundPublicIds.size());
|
|
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
logger.error("Error during performing "+CSW_GET_RECORDS+": ",e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundPublicIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-16 15:03:03 +02:00
|
|
|
/**
|
|
|
|
* Gets the found public ids.
|
|
|
|
*
|
|
|
|
* @return the foundPublicIds
|
|
|
|
*/
|
|
|
|
public List<String> getFoundPublicIds() {
|
|
|
|
|
|
|
|
return foundPublicIds==null || foundPublicIds.isEmpty()? null: foundPublicIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-16 18:12:05 +02:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see java.lang.Object#toString()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
builder.append("FilterGetRecords [foundPublicIds=");
|
|
|
|
builder.append(foundPublicIds);
|
|
|
|
builder.append("]");
|
|
|
|
return builder.toString();
|
|
|
|
}
|
2016-06-16 15:03:03 +02:00
|
|
|
}
|