Skip to content

Commit

Permalink
Merge pull request #211 from geonetwork-ga/ecat3.2-dev
Browse files Browse the repository at this point in the history
Ecat3.2 dev
  • Loading branch information
josephjohn136 authored Nov 28, 2019
2 parents 8391610 + 34258e6 commit b84c292
Show file tree
Hide file tree
Showing 104 changed files with 3,151 additions and 2,355 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/org/fao/geonet/utils/XmlRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected final Element executeAndReadResponse(HttpRequestBase httpMethod) throw
final ClientHttpResponse httpResponse = doExecute(httpMethod);

if (httpResponse.getRawStatusCode() > 399) {
httpMethod.releaseConnection();
httpMethod.releaseConnection();
throw new BadServerResponseEx(httpResponse.getStatusText() +
" -- URI: " + httpMethod.getURI() +
" -- Response Code: " + httpResponse.getRawStatusCode());
Expand Down
7 changes: 3 additions & 4 deletions common/src/main/java/org/fao/geonet/utils/XmlResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ public LSInput resolveResource(String type, String namespaceURI, String publicId
}
}
} catch (MalformedURLException e) { // leave this to someone else?
e.printStackTrace();
Log.error(Log.XML_RESOLVER, e.getMessage(), e);
return result;
} catch (URISyntaxException e) { // leave this to someone else?
e.printStackTrace();
Log.error(Log.XML_RESOLVER, e.getMessage(), e);
return result;
}

Expand All @@ -141,8 +141,7 @@ public LSInput resolveResource(String type, String namespaceURI, String publicId
try {
elResult = isXmlInCache(externalRef.toString());
} catch (CacheException e) {
Log.error(Log.XML_RESOLVER, "Request to cache for " + externalRef + " failed.");
e.printStackTrace();
Log.error(Log.XML_RESOLVER, "Request to cache for " + externalRef + " failed.", e);
}

if (elResult == null) { // use XMLRequest to get the XML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void logout(HttpServletRequest request,
UserSession userSession = (UserSession) tmp;
userSession.clear();
}
httpSession.invalidate();
}

}
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/org/fao/geonet/constants/Geonet.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public final class Geonet {

public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy_HHmm");
public static final String BATCHEDIT_BACKUP_BUCKET = "https://s3-ap-southeast-2.amazonaws.com/ga-ecat3-batchedit/";
public static final String BATCHEDIT_REPORT = "be_report";
public static final String BATCHEDIT_BACKUP = "be_backup";
public static final String BATCHEDIT_PROGRESS = "be_progress";
public static final String CSV_DOWNLOAD_STATUS = "csv_download_status";

/**
* Container for file names.
*/
Expand Down Expand Up @@ -479,6 +484,8 @@ public static final class SearchResult {
*/
public static final String ECAT_ID = "eCatId";

public static final String KEYWORD = "keyword";

/**
* Attrset used in Z39.50 search
*/
Expand Down Expand Up @@ -545,13 +552,15 @@ public static final class SortBy {
public static final String RATING = "rating";
public static final String POPULARITY = "popularity";
public static final String DATE = "changeDate";
public static final String PUBLICATION_DATE = "publicationDate";

/**
* Parameter name: {@value #_TITLE} - Title not tokenized mainly used for sorting
* purpose
*/
public static final String TITLE = "title";
public static final String SCALE_DENOMINATOR = "denominator";
public static final String ECATID = "eCatId";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.fao.geonet.GeonetContext;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.kernel.SchemaManager;
import org.fao.geonet.utils.Log;
import org.jdom.Element;

import java.nio.file.Path;
Expand Down Expand Up @@ -69,8 +70,7 @@ public Element exec(Element params, ServiceContext context) throws Exception {
schemas.addContent(schemaElem);
}
} catch (Exception e) {
context.error("Failed to load guiservices for schema " + schema + ": " + e.getMessage());
e.printStackTrace();
Log.error(Geonet.GEONETWORK, "Failed to load guiservices for schema "+schema+": "+e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@ public class BatchEditReport implements Serializable {
private List<String> processInfo;

public List<String> getErrorInfo() {
if (errorInfo == null) {
errorInfo = new ArrayList<>();
if(this.errorInfo == null){
return new ArrayList<String>();
}
return errorInfo;
return new ArrayList<String>(this.errorInfo);
}

public void setErrorInfo(List<String> errorInfo) {
this.errorInfo = new ArrayList<String>(errorInfo);
}

public List<String> getProcessInfo() {
if (processInfo == null) {
processInfo = new ArrayList<>();
if(this.processInfo == null){
return new ArrayList<String>();
}
return processInfo;
return new ArrayList<String>(this.processInfo);
}

public void setProcessInfo(List<String> processInfo) {
this.processInfo = new ArrayList<String>(processInfo);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public BatchEditReport removeOrAddElements(ApplicationContext context, ServiceCo
XPath _xpath, Document metadata, List<BatchEditParam> listOfUpdates, String mode) {

BatchEditReport report = new BatchEditReport();

final SchemaManager schemaManager = context.getBean(SchemaManager.class);
String headerVal = header.getKey();
EditElement editElement = EditElementFactory.getElementType(headerVal);
Expand All @@ -117,6 +118,9 @@ public BatchEditReport removeOrAddElements(ApplicationContext context, ServiceCo
}

if(StringUtils.isNotEmpty(csvr.get(headerVal).trim())){

List<String> errs = report.getErrorInfo();

if(editElement != null){

if(checkDependencies(headerVal, csvr) && mode.equals("remove")){
Expand All @@ -133,7 +137,7 @@ public BatchEditReport removeOrAddElements(ApplicationContext context, ServiceCo

} catch (Exception e) {
//Log.error(Geonet.SEARCH_ENGINE, "Unable to remove existing element for eCatId/UUID " + id +" for the value " + csvr.get(headerVal) +", " + e.getLocalizedMessage());
report.getErrorInfo().add("Unable to remove existing element for the value " + csvr.get(headerVal) +", " + e.getMessage());
errs.add("Unable to remove existing element for the value " + csvr.get(headerVal) +", " + e.getMessage());
}
}

Expand All @@ -150,7 +154,7 @@ public BatchEditReport removeOrAddElements(ApplicationContext context, ServiceCo
}
} catch (Exception e) {
//Log.error(Geonet.SEARCH_ENGINE, "Unable to set the attribute for eCatId/UUID " + id +" for the value " + csvr.get(headerVal) +", " + e.getMessage());
report.getErrorInfo().add("Unable to set the attribute for the value, " + headerVal + ": "+ csvr.get(headerVal) +", " + e.getMessage());
errs.add("Unable to set the attribute for the value, " + headerVal + ": "+ csvr.get(headerVal) +", " + e.getMessage());
}
} else {
try {
Expand All @@ -165,9 +169,10 @@ public BatchEditReport removeOrAddElements(ApplicationContext context, ServiceCo
}
} catch (Exception e) {
//Log.error(Geonet.SEARCH_ENGINE, "Unable to set text for eCatId/UUID " + id +" for the value " + csvr.get(headerVal) +", " + e.getLocalizedMessage());
report.getErrorInfo().add("Unable to set text for the value, " + headerVal + ": "+ csvr.get(headerVal) +", " + e.getMessage());
errs.add("Unable to set text for the value, " + headerVal + ": "+ csvr.get(headerVal) +", " + e.getMessage());
}
}
report.setErrorInfo(errs);
}

return report;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public void removeAndAddElement(CSVBatchEdit batchEdit, ApplicationContext conte
}

}catch(BatchEditException e){
report.getErrorInfo().add(e.getMessage());
List<String> errs = report.getErrorInfo();
errs.add(e.getMessage());
report.setErrorInfo(errs);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public void removeAndAddElement(CSVBatchEdit batchEdit, ApplicationContext conte
}
}
}catch(BatchEditException e){
report.getErrorInfo().add(e.getMessage());
List<String> errs = report.getErrorInfo();
errs.add(e.getMessage());
report.setErrorInfo(errs);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public void removeAndAddElement(CSVBatchEdit batchEdit, ApplicationContext conte


}catch(Exception e){
report.getErrorInfo().add("Unable to process : " + headerVal + ", exception: " +e.getMessage());
List<String> errs = report.getErrorInfo();
errs.add("Unable to process : " + headerVal + ", exception: " +e.getMessage());
report.setErrorInfo(errs);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.commons.csv.CSVRecord;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.exceptions.BatchEditException;
import org.fao.geonet.utils.Log;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import org.jdom.xpath.XPath;
Expand Down Expand Up @@ -60,7 +59,9 @@ public void removeAndAddElement(CSVBatchEdit batchEdit, ApplicationContext conte
try {
rootE = getCitationDateElement(batchEdit, values);
} catch (BatchEditException e) {
report.getErrorInfo().add(e.getMessage());
List<String> errs = report.getErrorInfo();
errs.add(e.getMessage());
report.setErrorInfo(errs);
}

String strEle = out.outputString(rootE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.fao.geonet.kernel.batchedit;

import org.fao.geonet.constants.Geonet;
import org.fao.geonet.utils.Log;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public void removeAndAddElement(CSVBatchEdit batchEdit, ApplicationContext conte
rootE = getKeywordElementWithThesaurus(keyword, context, serContext);

} catch (BatchEditException e) {
report.getErrorInfo().add(e.getMessage());
List<String> errs = report.getErrorInfo();
errs.add(e.getMessage());
report.setErrorInfo(errs);
}

if (rootE != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public void removeAndAddElement(CSVBatchEdit batchEdit, ApplicationContext conte
if(headerVal.equalsIgnoreCase(Geonet.EditType.MD_PARENT))
rootE = getMdparentElement(context, serContext, batchEdit, values);
} catch (BatchEditException e) {
report.getErrorInfo().add(e.getMessage());
List<String> errs = report.getErrorInfo();
errs.add(e.getMessage());
report.setErrorInfo(errs);
}

if (rootE != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public void removeAndAddElement(CSVBatchEdit batchEdit, ApplicationContext conte
rootE = additionalInformation(name, desc, linkage, protocol, function);
}
} catch (BatchEditException e) {
report.getErrorInfo().add(e.getMessage());
List<String> errs = report.getErrorInfo();
errs.add(e.getMessage());
report.setErrorInfo(errs);
}

if(rootE != null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ private void load(ServletContext servletContext, String luceneConfigXmlFile) {
fieldBoost.put(name, Float.parseFloat(boost));
} catch (Exception exc) {
// TODO: handle exception
exc.printStackTrace();
Log.error(Geonet.SEARCH_ENGINE, "LuceneConfig error: " + exc.getMessage(), exc);
}
}
}
Expand Down Expand Up @@ -481,8 +481,7 @@ private void loadClassParameters(int type, String field, String clazz, List<?> c
} catch (ClassNotFoundException e) {
Log.warning(Geonet.SEARCH_ENGINE,
" Class not found for parameter: " + name
+ ", type: " + paramType);
e.printStackTrace();
+ ", type: " + paramType, e);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public void execute(JobExecutionContext context)
indexTracker.optimize();
} catch (Exception e) {
Log.error(Geonet.INDEX_ENGINE,
"Optimize task failed: " + e.getMessage());
e.printStackTrace();
"Optimize task failed: " + e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ private static SortField makeSortField(String sortBy, boolean sortOrder, String
sortType = SortField.Type.INT;
sortBy = "_" + sortBy;
} else if (sortBy.equals(Geonet.SearchResult.SortBy.SCALE_DENOMINATOR)) {
sortType = SortField.Type.INT;
} else if (sortBy.equals(Geonet.SearchResult.SortBy.ECATID)) {
sortType = SortField.Type.INT;
} else if (sortBy.equals(Geonet.SearchResult.SortBy.DATE)
|| sortBy.equals(Geonet.SearchResult.SortBy.TITLE)) {
Expand Down Expand Up @@ -1059,13 +1061,13 @@ public static String analyzeText(String field, String requestStr, PerFieldAnalyz
}
} catch (Exception e) {
// TODO why swallow
e.printStackTrace();
Log.error(Geonet.SEARCH_ENGINE, "analyzeText error:" + e.getMessage(), e);
} finally {
if (ts != null) {
try {
ts.close();
} catch (IOException e) {
e.printStackTrace();
Log.error(Geonet.SEARCH_ENGINE, "analyzeText error closing TokenStream:" + e.getMessage(), e);
}
}
}
Expand Down Expand Up @@ -1429,6 +1431,11 @@ private void computeQuery(ServiceContext srvContext, Element request, ServiceCon
eCatId.setText(eCatId.getText().replace(",", " or "));
}

Element keyword = request.getChild(Geonet.SearchResult.KEYWORD);
if (keyword != null) {
keyword.setText(keyword.getText() + "*");
}

_summaryConfig = _luceneConfig.getSummaryTypes().get(resultType);

final Element summaryItemsEl = request.getChild(Geonet.SearchResult.SUMMARY_ITEMS);
Expand Down Expand Up @@ -1654,6 +1661,10 @@ private void computeQuery(ServiceContext srvContext, Element request, ServiceCon
sortBy = Geonet.SearchResult.SortBy.TITLE;
}

if(sortBy.startsWith(Geonet.SearchResult.SortBy.PUBLICATION_DATE)){
sortBy = Geonet.SearchResult.SortBy.PUBLICATION_DATE;
}

boolean sortOrder = (Util.getParam(request, Geonet.SearchResult.SORT_ORDER, "").equals(""));
if (Log.isDebugEnabled(Geonet.SEARCH_ENGINE))
Log.debug(Geonet.SEARCH_ENGINE, "Sorting by : " + sortBy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public static Set<String> parse(Path filepath) {
Log.warning(Geonet.INDEX_ENGINE, "Invalid stopwords file: " + file.toAbsolutePath());
}
} catch (IOException x) {
Log.warning(Geonet.INDEX_ENGINE, x.getMessage() + " (this exception is swallowed)");
x.printStackTrace();
Log.warning(Geonet.INDEX_ENGINE, x.getMessage() + " (this exception is swallowed)", x);
}
if (stopwords != null) {
if (Log.isDebugEnabled(Geonet.INDEX_ENGINE))
Expand Down
Loading

0 comments on commit b84c292

Please sign in to comment.