updated logger

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@152691 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-09-05 16:01:09 +00:00
parent c50a0ca79a
commit d869aa8b50
2 changed files with 66 additions and 66 deletions

View File

@ -278,6 +278,7 @@ public class GeonetworkResolver extends HttpServlet{
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
* This call is authenticated
*/
@SuppressWarnings("resource")
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {
@ -411,12 +412,12 @@ public class GeonetworkResolver extends HttpServlet{
}
logger.info("Sending CSW POST request to URL: "+gnCSWlURL);
logger.info("Content-Type: "+req.getContentType());
logger.debug("Content-Type: "+req.getContentType());
//DEBUG
//logger.debug("POST - BODY : "+byteArray.toString());
InputStream in = httpUtils.post(gnCSWlURL, new ByteArrayInputStream(byteArray.toByteArray()), req.getContentType(), req.getParameterMap());
//END DEBUG
logger.info("Response return Content-Type: "+httpUtils.getLastContentType());
logger.debug("Response return Content-Type: "+httpUtils.getLastContentType());
resp.setContentType(httpUtils.getLastContentType());
OutputStream out = resp.getOutputStream();
@ -428,16 +429,18 @@ public class GeonetworkResolver extends HttpServlet{
try{
ReusableInputStream reus = new ReusableInputStream(in);
if(theVisibility.equals(VISIBILITY.PRV)){
logger.info("Private VISIBILITY performing so getting public file identifiers to apply filtering..");
FilterGetRecords filterGetRecords = new FilterGetRecords(byteArray.toString());
if(filterGetRecords.getFoundPublicIds()!=null && filterGetRecords.getFoundPublicIds().size()>0){
logger.info("I'm removing list of public IDs with "+filterGetRecords.getFoundPublicIds() +" IDs. Is it right?");
in = GetResponseRecordFilter.overrideResponseIdsByListIds(in, filterGetRecords.getFoundPublicIds(), "Replaced a public UUID, please ignore");
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, filterGetRecords.getFoundPublicIds(), "Replaced a public UUID, please ignore");
}
}else {
ReusableInputStream reus = new ReusableInputStream(in);
logger.info("Public VISIBILITY performing check on ownership..");
logger.info("Public VISIBILITY perfoming check on ownership...");
Document doc = GetResponseRecordFilter.inputStreamToW3CDocument(reus);
List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc, "gmd:fileIdentifier");
List<String> noMatchingOwner = new ArrayList<String>();
@ -449,14 +452,17 @@ public class GeonetworkResolver extends HttpServlet{
}
}
if(noMatchingOwner.size()>0){
logger.debug("Removing "+noMatchingOwner.size()+" layer/s not macthing the owner: "+theOwner);
logger.info("Removing "+noMatchingOwner.size()+" layer/s not macthing the owner: "+theOwner);
in = GetResponseRecordFilter.overrideResponseIdsByListIds(reus, noMatchingOwner, "Replaced UUID owned by another user, please ignore");
}else{
logger.info("No replace on UUIDs was applied for the owner: "+theOwner);
in = reus;
}
}
ReusableInputStream reusIs = new ReusableInputStream(in);
int bytes = IOUtils.copy(reusIs, out);
logger.debug("POST - RETURN : "+IOUtils.toString(reusIs));
//logger.trace("POST - RETURN : "+IOUtils.toString(reusIs));
if(bytes==0)
logger.warn("ResponseBody is empty, returning empty resp");

View File

@ -13,8 +13,6 @@ import it.geosolutions.geonetwork.util.GNSearchResponse.GNMetadata;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@ -33,14 +31,12 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.httpclient.HttpStatus;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datatransfer.resolver.gis.GeonetworkInstance;
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
import org.gcube.datatransfer.resolver.gis.geonetwork.GNAuthentication;
import org.gcube.datatransfer.resolver.gis.geonetwork.HTTPCallsUtils;
import org.gcube.datatransfer.resolver.gis.geonetwork.HTTPCallsUtils.HttpResponse;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.gcube.spatial.data.geonetwork.model.Account.Type;
import org.gcube.spatial.data.geonetwork.model.faults.MissingServiceEndpointException;
import org.slf4j.Logger;
@ -50,10 +46,12 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* The Class GetResponseRecordFilter.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 16, 2016
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 5, 2017
*/
public class GetResponseRecordFilter {
@ -243,8 +241,6 @@ public class GetResponseRecordFilter {
}
}
/**
* W3 c document to input stream.
*
@ -269,8 +265,6 @@ public class GetResponseRecordFilter {
// return out.toString();
}
/**
* File identifiers to ids.
*
@ -371,59 +365,59 @@ public class GetResponseRecordFilter {
}
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
File file = new File("GetResponseRecords.xml");
List<String> idsToRemove = new ArrayList<String>();
idsToRemove.add("39d7207e-3bec-4086-98c4-8d9c787db9c4");
idsToRemove.add("geo_fea_trenches");
String scope = "/d4science.research-infrastructures.eu";
// /**
// * The main method.
// *
// * @param args the arguments
// */
// public static void main(String[] args) {
//
// File file = new File("GetResponseRecords.xml");
// List<String> idsToRemove = new ArrayList<String>();
// idsToRemove.add("39d7207e-3bec-4086-98c4-8d9c787db9c4");
// idsToRemove.add("geo_fea_trenches");
//
// String scope = "/d4science.research-infrastructures.eu";
//// try {
//// InputStream is = GetResponseRecordFilter.overrideResponseIdsByListIds(new FileInputStream(file), idsToRemove);
//// System.out.println(IOUtils.toString(is));
//// }
//// catch (IOException e) {
//// // TODO Auto-generated catch block
//// e.printStackTrace();
//// }
////
// try {
// InputStream is = GetResponseRecordFilter.overrideResponseIdsByListIds(new FileInputStream(file), idsToRemove);
// System.out.println(IOUtils.toString(is));
//
// long start = System.currentTimeMillis();
// Document doc = GetResponseRecordFilter.inputStreamToW3CDocument(new FileInputStream(file));
// List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc, "gmd:fileIdentifier");
// System.out.println("UUIDs: "+fileIdentifiers);
// HTTPCallsUtils httpUtils = new HTTPCallsUtils();
//
// ScopeProvider.instance.set(scope);
// GeonetworkInstance gIntance = new GeonetworkInstance(scope, true, LoginLevel.ADMIN, Type.SCOPE);
// Configuration config = gIntance.getGeonetworkPublisher().getConfiguration();
//
// //System.out.println(GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileIdentifiers.get(0), config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword()));
//
// List<String> owners = new ArrayList<String>();
//
// for (String fileId : fileIdentifiers) {
// owners.add(GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword()));
// }
//
// for (String ow : owners) {
// System.out.println(ow);
// }
//
// System.out.println("End in ms: "+(System.currentTimeMillis()-start));
//
//// System.out.println("IDs: "+ids.toString());
// }
// catch (IOException e) {
// catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
try {
long start = System.currentTimeMillis();
Document doc = GetResponseRecordFilter.inputStreamToW3CDocument(new FileInputStream(file));
List<String> fileIdentifiers = GetResponseRecordFilter.getTextContentStringsForTagName(doc, "gmd:fileIdentifier");
System.out.println("UUIDs: "+fileIdentifiers);
HTTPCallsUtils httpUtils = new HTTPCallsUtils();
ScopeProvider.instance.set(scope);
GeonetworkInstance gIntance = new GeonetworkInstance(scope, true, LoginLevel.ADMIN, Type.SCOPE);
Configuration config = gIntance.getGeonetworkPublisher().getConfiguration();
//System.out.println(GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileIdentifiers.get(0), config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword()));
List<String> owners = new ArrayList<String>();
for (String fileId : fileIdentifiers) {
owners.add(GetResponseRecordFilter.getMetaOwnerNameByFileIdentifier(fileId, config.getGeoNetworkEndpoint(),config.getAdminAccount().getUser(), config.getAdminAccount().getPassword()));
}
for (String ow : owners) {
System.out.println(ow);
}
System.out.println("End in ms: "+(System.currentTimeMillis()-start));
// System.out.println("IDs: "+ids.toString());
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// }
}