Skip to content

Commit

Permalink
Harvester / GeoNetwork / Remove logo and source from harvested nodes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
François Prunayre committed Dec 17, 2013
1 parent 9894b11 commit ed2cbb5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Expand Up @@ -25,6 +25,7 @@

import jeeves.server.UserSession;
import jeeves.server.context.ServiceContext;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.DailyRollingFileAppender;
import org.apache.log4j.PatternLayout;
Expand Down Expand Up @@ -62,9 +63,11 @@
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import static org.quartz.JobKey.jobKey;
Expand Down Expand Up @@ -250,13 +253,25 @@ public static void shutdownScheduler() throws SchedulerException {
public synchronized void destroy() throws Exception {
doUnschedule();

// TODO: Remove all sources related to the harvestUuid

final MetadataRepository metadataRepository = context.getBean(MetadataRepository.class);
final SourceRepository sourceRepository = context.getBean(SourceRepository.class);

final Specifications<Metadata> ownedByHarvester = Specifications.where(MetadataSpecs.hasHarvesterUuid(getParams().uuid));
Set<String> sources = new HashSet<String>();
for (Integer id : metadataRepository.findAllIdsBy(ownedByHarvester)) {
sources.add(metadataRepository.findOne(id).getSourceInfo().getSourceId());
dataMan.deleteMetadata(context, "" + id);
}

// Remove all sources related to the harvestUuid if they are not linked to any record anymore
for (String sourceUuid : sources) {
Long ownedBySource =
metadataRepository.count(Specifications.where(MetadataSpecs.hasSource(sourceUuid)));
if (ownedBySource == 0 && !sourceUuid.equals(params.uuid)) {
removeIcon(sourceUuid);
sourceRepository.delete(sourceUuid);
}
}

doDestroy();
}
Expand Down Expand Up @@ -641,14 +656,18 @@ public AbstractParams getParams() {
* @throws SQLException
*/
protected void doDestroy() throws SQLException {
File icon = new File(Resources.locateLogosDir(context), params.uuid + ".gif");
removeIcon(params.uuid);

context.getBean(SourceRepository.class).delete(params.uuid);
// FIXME: Should also delete the categories we have created for servers
}

private void removeIcon(String uuid) {
File icon = new File(Resources.locateLogosDir(context), uuid+ ".gif");

if (!icon.delete() && icon.exists()) {
Log.warning(Geonet.HARVESTER + "." + getType(), "Unable to delete icon: " + icon);
}

context.getBean(SourceRepository.class).delete(params.uuid);
// FIXME: Should also delete the categories we have created for servers
}

/**
Expand Down
Expand Up @@ -340,8 +340,6 @@ private String addMetadata(RecordInfo ri, Element md, Element info, boolean loca
MetadataRepository metadataRepository = context.getBean(MetadataRepository.class);
Metadata metadata = metadataRepository.findOne(iId);

dataMan.setTemplateExt(iId, MetadataType.lookup(isTemplate), null);
dataMan.setHarvestedExt(iId, params.uuid);

if(!localRating) {
String rating = general.getChildText("rating");
Expand All @@ -356,6 +354,9 @@ private String addMetadata(RecordInfo ri, Element md, Element info, boolean loca

metadataRepository.save(metadata);

dataMan.setTemplateExt(iId, MetadataType.lookup(isTemplate), null);
dataMan.setHarvestedExt(iId, params.uuid);

String pubDir = Lib.resource.getDir(context, "public", id);
String priDir = Lib.resource.getDir(context, "private", id);

Expand Down

0 comments on commit ed2cbb5

Please sign in to comment.