Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into refactor_ui
Browse files Browse the repository at this point in the history
  • Loading branch information
François Prunayre committed Oct 9, 2013
2 parents 4682aa8 + bd6bd2b commit 30c3fc0
Show file tree
Hide file tree
Showing 86 changed files with 4,280 additions and 468 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,6 +14,7 @@ geonetwork*.db
changes-*
web/coverage.ec
*/target/
*/.externalToolBuilders
web/src/main/webapp/data/
web/src/main/webapp/WEB-INF/lucene/
web/src/main/webapp/WEB-INF/metadata_subversion/
Expand Down
154 changes: 133 additions & 21 deletions core/src/main/java/org/fao/geonet/kernel/DataManager.java
Expand Up @@ -27,6 +27,27 @@

package org.fao.geonet.kernel;

import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.Vector;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import jeeves.config.springutil.JeevesApplicationContext;
import jeeves.constants.Jeeves;
import jeeves.exceptions.JeevesException;
Expand All @@ -42,6 +63,7 @@
import jeeves.utils.Xml;
import jeeves.utils.Xml.ErrorHandler;
import jeeves.xlink.Processor;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.fao.geonet.GeonetContext;
Expand All @@ -67,25 +89,6 @@
import org.jdom.Namespace;
import org.jdom.filter.ElementFilter;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.Vector;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* Handles all operations on metadata (select,insert,update,delete etc...).
*
Expand All @@ -101,6 +104,7 @@ public class DataManager {
//---
//--------------------------------------------------------------------------

private static final String MD_ON_HARV = "(SELECT id FROM Metadata WHERE harvestUuid=?)";
/**
*
* @return
Expand Down Expand Up @@ -1592,6 +1596,24 @@ public Element getMetadata(Dbms dbms, String id) throws Exception {
*/
public Element getMetadata(ServiceContext srvContext, String id, boolean forEditing, boolean withEditorValidationErrors, boolean keepXlinkAttributes) throws Exception {
Dbms dbms = (Dbms) srvContext.getResourceManager().open(Geonet.Res.MAIN_DB);

return getMetadata(srvContext, dbms, id, forEditing, withEditorValidationErrors, keepXlinkAttributes);
}

/**
* Retrieves a metadata (in xml) given its id; adds editing information if requested and validation errors if
* requested.
*
* @param srvContext
* @param dbms
* @param id
* @param forEditing Add extra element to build metadocument {@link EditLib#expandElements(String, Element)}
* @param withEditorValidationErrors
* @param keepXlinkAttributes When XLinks are resolved in non edit mode, do not remove XLink attributes.
* @return
* @throws Exception
*/
public Element getMetadata(ServiceContext srvContext, Dbms dbms, String id, boolean forEditing, boolean withEditorValidationErrors, boolean keepXlinkAttributes) throws Exception {
boolean doXLinks = xmlSerializer.resolveXLinks();
Element md = xmlSerializer.selectNoXLinkResolver(dbms, "Metadata", id, false);
if (md == null) return null;
Expand Down Expand Up @@ -2049,6 +2071,69 @@ public synchronized void deleteMetadata(ServiceContext context, Dbms dbms, Strin
searchMan.delete("_id", id+"");
}


/**
* Removes all metadata associated to one harvester. Faster than doing one by one.
*
* @param context
* @param dbms
* @param id
* @throws Exception
*/
public synchronized void deleteBatchMetadata(ServiceContext context,
Dbms dbms, String harvesterId) throws Exception {

// --- remove operations
deleteBatchMetadataOper(dbms, harvesterId, false);

// --- remove categories
deleteBatchAllMetadataCateg(dbms, harvesterId);

dbms.execute(
"DELETE FROM MetadataRating WHERE metadataId in " + DataManager.MD_ON_HARV,
harvesterId);
dbms.execute(
"DELETE FROM Validation WHERE metadataId in " + DataManager.MD_ON_HARV,
harvesterId);

dbms.execute(
"DELETE FROM MetadataStatus WHERE metadataId in " + DataManager.MD_ON_HARV,
harvesterId);


//Notify templates in Batch
String getQuery = "SELECT id, uuid FROM Metadata WHERE harvestUuid=? AND isTemplate like 'n'";
for (Object o : dbms.select(getQuery, harvesterId).getChildren())
{
Element el = (Element) o;
String id = el.getChildText("id");
String uuid = el.getChildText("uuid");
notifyMetadataDelete(dbms, id, uuid);
}

//TODO improve this, try to do it batch too
getQuery = "SELECT id FROM Metadata WHERE harvestUuid=?";
List<String> ids = new LinkedList<String>();
for (Object o : dbms.select(getQuery, harvesterId).getChildren())
{
Element el = (Element) o;
String id = el.getChildText("id");

// --- remove metadata
xmlSerializer.delete(dbms, "Metadata", id, context);

ids.add(id);
}

// --- update search criteria
searchMan.delete("_id", ids);

dbms.execute(
"DELETE FROM Metadata WHERE harvestUuid = ?",
harvesterId);
dbms.commit();
}

/**
*
* @param context
Expand Down Expand Up @@ -2077,7 +2162,21 @@ public void deleteMetadataOper(Dbms dbms, String id, boolean skipAllIntranet) th

dbms.execute(query, Integer.valueOf(id));
}
/**
* Removes all operations stored for all metadata on a harvester.
* @param dbms
* @param harvesterId
* @param skipAllIntranet
* @throws Exception
*/
public void deleteBatchMetadataOper(Dbms dbms, String harvesterId, boolean skipAllIntranet) throws Exception {
String query = "DELETE FROM OperationAllowed WHERE metadataId in " + DataManager.MD_ON_HARV;

if (skipAllIntranet)
query += " AND groupId>1";

dbms.execute(query, harvesterId);
}
/**
* Removes all categories stored for a metadata.
*
Expand All @@ -2091,6 +2190,19 @@ public void deleteAllMetadataCateg(Dbms dbms, String id) throws Exception {
dbms.execute(query, Integer.valueOf(id));
}

/**
* Removes all categories stored for all metadata in a harvester
*
* @param dbms
* @param harvesterId
* @throws Exception
*/
public void deleteBatchAllMetadataCateg(Dbms dbms, String harvesterId) throws Exception {
String query = "DELETE FROM MetadataCateg WHERE metadataId in " + DataManager.MD_ON_HARV;

dbms.execute(query, harvesterId);
}

//--------------------------------------------------------------------------
//---
//--- Metadata thumbnail API
Expand Down Expand Up @@ -2176,7 +2288,7 @@ public void unsetThumbnail(ServiceContext context, Dbms dbms, String id, boolean
private void manageThumbnail(ServiceContext context, Dbms dbms, String id, boolean small, Element env,
String styleSheet, boolean indexAfterChange) throws Exception {
boolean forEditing = false, withValidationErrors = false, keepXlinkAttributes = true;
Element md = getMetadata(context, id, forEditing, withValidationErrors, keepXlinkAttributes);
Element md = getMetadata(context, dbms, id, forEditing, withValidationErrors, keepXlinkAttributes);

if (md == null)
return;
Expand Down Expand Up @@ -3365,4 +3477,4 @@ public void run() {
public enum UpdateDatestamp {
yes, no
}
}
}
16 changes: 16 additions & 0 deletions core/src/main/java/org/fao/geonet/kernel/search/SearchManager.java
Expand Up @@ -924,6 +924,22 @@ public void delete(String fld, String txt) throws Exception {
_indexWriter.deleteDocuments(new Term(fld, txt));
_spatial.writer().delete(txt);
}

/**
* deletes a list of documents.
*
* @param fld
* @param txt
* @throws Exception
*/
public void delete(String fld, List<String> txts) throws Exception {
// possibly remove old document
for(String txt : txts) {
_indexWriter.deleteDocuments(new Term(fld, txt));
}
_spatial.writer().delete(txts);
}


/**
* TODO javadoc.
Expand Down
Expand Up @@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
Expand Down Expand Up @@ -228,6 +229,34 @@ public void delete(String id) throws IOException
}
}


public void delete(List<String> ids) throws IOException
{
_lock.lock();
try {
FilterFactory2 factory = CommonFactoryFinder
.getFilterFactory2(GeoTools.getDefaultHints());

List<Filter> filters = new LinkedList<Filter>();

for(String id : ids) {
filters.add(factory.equals(
factory.property(_idColumn), factory.literal(id)));
}

_index = null;

_featureStore.removeFeatures(factory.or(filters));
try {
SpatialFilter.getJCSCache().clear();
} catch (Throwable e) {
e.printStackTrace();
}
_writes++;
} finally {
_lock.unlock();
}
}
public void commit() throws IOException
{
_lock.lock();
Expand Down
Expand Up @@ -311,6 +311,7 @@ public boolean setValues(Dbms dbms, Map<String, String> values) throws Exception
}
setting.setValue(value);
} catch (Exception e) {
e.printStackTrace();
Log.warning(Geonet.SETTINGS, "Failed to save setting with name: " + key + ", value: " + value + ". Error: " + e.getMessage());
throw e;
}
Expand Down
43 changes: 28 additions & 15 deletions core/src/main/java/org/fao/geonet/util/ISODate.java
Expand Up @@ -129,28 +129,41 @@ public void setDate(String isoDate)

try
{
year = Integer.parseInt(isoDate.substring(0, 4));
month = Integer.parseInt(isoDate.substring(5, 7));
day = Integer.parseInt(isoDate.substring(8, 10));
if (isoDate.contains("T")) {
// Check if iso date contains time info and if using non UTC time zone to parse the date with
// JODAISODate. This class converts to UTC format to avoid timezones issues.
boolean timeZoneInfo = ((isoDate.split("T")[1].contains("+")) || (isoDate.split("T")[1].contains("-")));

isShort = true;
if (timeZoneInfo) {
isoDate = JODAISODate.parseISODateTime(isoDate);
}
}

hour = 0;
min = 0;
sec = 0;
year = Integer.parseInt(isoDate.substring(0, 4));
month = Integer.parseInt(isoDate.substring(5, 7));
day = Integer.parseInt(isoDate.substring(8, 10));

//--- is the date in 'yyyy-mm-dd' or 'yyyy-mm-ddZ' format?
isShort = true;

if (isoDate.length() < 12)
return;
hour = 0;
min = 0;
sec = 0;

isoDate = isoDate.substring(11);
//--- is the date in 'yyyy-mm-dd' or 'yyyy-mm-ddZ' format?

hour = Integer.parseInt(isoDate.substring(0,2));
min = Integer.parseInt(isoDate.substring(3,5));
sec = Integer.parseInt(isoDate.substring(6,8));
if (isoDate.length() < 12)
return;

isoDate = isoDate.substring(11);

hour = Integer.parseInt(isoDate.substring(0,2));
min = Integer.parseInt(isoDate.substring(3,5));
sec = Integer.parseInt(isoDate.substring(6,8));



isShort = false;

isShort = false;
}
catch(Exception e)
{
Expand Down

0 comments on commit 30c3fc0

Please sign in to comment.