Skip to content

Commit

Permalink
Delete all configs process
Browse files Browse the repository at this point in the history
  • Loading branch information
Clara Wiatrowski committed Jun 30, 2022
1 parent b228e20 commit a064796
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 5 deletions.
Expand Up @@ -104,7 +104,8 @@ DomainConfigurations are posted as pairs
<Constants.DOMAIN_IDENTIFIER>domainName=configurationName
These configurations are added/included in the harvest definition
--%><%@ page import="java.util.ArrayList,
--%><%@ page
import="java.util.ArrayList,
java.util.List,
java.util.HashMap,
java.util.Map,
Expand Down Expand Up @@ -134,8 +135,7 @@ DomainConfigurations are posted as pairs
dk.netarkivet.harvester.datamodel.eav.EAV.AttributeAndType,
com.antiaction.raptor.dao.AttributeTypeBase,
com.antiaction.raptor.dao.AttributeBase"
pageEncoding="UTF-8"
%><%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"
pageEncoding="UTF-8"%><%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"
%><fmt:setLocale value="<%=HTMLUtils.getLocale(request)%>" scope="page"
/><fmt:setBundle scope="page" basename="<%=dk.netarkivet.harvester.Constants.TRANSLATIONS_BUNDLE%>"/>
<%!private static final I18n I18N
Expand Down Expand Up @@ -201,7 +201,7 @@ DomainConfigurations are posted as pairs

<h3 class="page_heading"><fmt:message key="pagetitle;selective.harvest"/></h3>

<form method="post" action="Definitions-edit-selective-harvest.jsp">
<form id="selective-harvest-form" method="post" action="Definitions-edit-selective-harvest.jsp">
<%
// create hidden fields
if (hdd == null) {
Expand Down Expand Up @@ -347,7 +347,25 @@ if (hdd != null) {
<tr>
<th width="45%"><fmt:message key="domain"/></th>
<th width="35%"><fmt:message key="choose.configuration"/></th>
<th width="10%"><fmt:message key="remove.from.list"/></th>
<th width="10%">
<fmt:message key="remove.from.list"/>
<%
if (sparseDomainConfigurations.size() > 0) {
%>
<div id="deleteAll">
( <a onclick="document.getElementById('confirmDeleteAll').style.display = 'block'; document.getElementById('deleteAll').style.display = 'none';">
<fmt:message key="remove.all.from.list" />
</a> )
</div>

<div id="confirmDeleteAll" style="display:none;">
( <fmt:message key="remove.all.from.list" /> : <a onclick="var e = document.createElement('input'); e.type = 'hidden'; e.name = '<%=Constants.DELETEALL_CONFIGS_PARAM%>'; e.value=true; document.getElementById('selective-harvest-form').appendChild(e); document.getElementById('selective-harvest-form').submit();"><fmt:message key="remove.all.from.list.confirm" /></a> / <a onclick="document.getElementById('confirmDeleteAll').style.display = 'none'; document.getElementById('deleteAll').style.display = 'block';"><fmt:message key="remove.all.from.list.cancel" /></a> )
</div>

<%
}
%>
</th>
</tr>
<%
// New definitions do not contain any domains
Expand Down
Expand Up @@ -272,6 +272,13 @@ public abstract List<String> getListOfSeedsOfDomainOfHarvestDefinition(String ha
*/
public abstract void removeDomainConfiguration(Long harvestId, SparseDomainConfiguration key);

/**
* Remove all Domain configuration from a specific PartialHarvest.
*
* @param harvestId Id for a specific PartialHarvest
*/
public abstract void removeAllConfigurations(Long harvestId);

/**
* Update the given PartialHarvest (i.e. Selective Harvest) with a new time for the next harvestrun. If no selective
* harvest matching the given id is found in the storage, the method should silently return.
Expand Down
Expand Up @@ -1276,6 +1276,36 @@ public void removeDomainConfiguration(Long harvestId, SparseDomainConfiguration
HarvestDBConnection.release(connection);
}
}

/*
* Removes all the entry in harvest_configs, that binds a certain this PartialHarvest. TODO maybe
* update the edition as well.
*/
@Override
public void removeAllConfigurations(Long harvestId) {
if (harvestId == null) {
// Don't need to do anything, if PartialHarvest is not
// yet stored in database
log.warn("No removal of domainConfiguration, " + "as harvestId is null");
return;
}
Connection connection = HarvestDBConnection.get();
PreparedStatement s = null;
try {
s = connection.prepareStatement(
"DELETE FROM harvest_configs WHERE harvest_id = ? ");
s.setLong(1, harvestId);
s.executeUpdate();
} catch (SQLException e) {
log.warn("Exception thrown while removing all domainconfiguration: {}", ExceptionUtils.getSQLExceptionCause(e),
e);
} finally {
DBUtils.closeStatementIfOpen(s);
DBUtils.rollbackIfNeeded(connection,
"removing all DomainConfiguration from harvest w/id " + harvestId + " failed", harvestId);
HarvestDBConnection.release(connection);
}
}

@Override
public void updateNextdate(long harvestId, Date nextdate) {
Expand Down
Expand Up @@ -109,6 +109,8 @@ private Constants() {
public static final String DELETEDOMAIN_PARAM = "deletedomain";

public static final String DELETECONFIG_PARAM = "deleteconfig";

public static final String DELETEALL_CONFIGS_PARAM = "deleteallconfigs";

public static final String EDITION_PARAM = "edition";

Expand Down
Expand Up @@ -113,6 +113,15 @@ public static void processRequest(PageContext context, I18n i18n, List<String> u
return;
}

String deleteAllConfigs = request.getParameter(Constants.DELETEALL_CONFIGS_PARAM);
// Case where we are removing a configuration
// In this we make the delete, and then return;
if (deleteAllConfigs != null && Boolean.valueOf(deleteAllConfigs) == true ) {
HTMLUtils.forwardOnEmptyParameter(context, Constants.DELETEALL_CONFIGS_PARAM);
deleteAllConfigs(context, i18n);
return;
}

PartialHarvest hdd = updateHarvestDefinition(context, i18n, unknownDomains, illegalDomains);

ExtendedFieldValueDefinition.processRequest(context, i18n, hdd, ExtendedFieldTypes.HARVESTDEFINITION);
Expand Down Expand Up @@ -249,6 +258,26 @@ private static void deleteConfig(PageContext context, I18n i18n, String deleteCo
hddao.removeDomainConfiguration(sph.getOid(), key);
}

/**
* Delete all configuration from a harvestdefinition.
*
* @param context The web server context for the JSP page.
* @param i18n Translation information for this site section.
* @param deleteConfig the configuration to delete, in the form of a domain name, a colon, a configuration name.
*/
private static void deleteAllConfigs(PageContext context, I18n i18n) {
HTMLUtils.forwardOnEmptyParameter(context, Constants.HARVEST_PARAM, Constants.SCHEDULE_PARAM);
ServletRequest request = context.getRequest();
String name = request.getParameter(Constants.HARVEST_PARAM);
HarvestDefinitionDAO hddao = HarvestDefinitionDAO.getInstance();
if (!hddao.exists(name)) {
HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;harvestdefinition.0.does.not.exist", name);
throw new ForwardedToErrorPage("Harvestdefinition '" + name + "' does not exist");
}
SparsePartialHarvest sph = hddao.getSparsePartialHarvest(name);
hddao.removeAllConfigurations(sph.getOid());
}

/**
* Extract domain configuration list from a map of parameters. All key that starts with Constants.DOMAIN_IDENTIFIER
* are treated as a concatenation of : DOMAIN_IDENTIFIER + domain name. The corresponding value in the map is
Expand Down
Expand Up @@ -524,6 +524,9 @@ redirecting = Redirecting
remove = Remove

remove.from.list = Remove from list
remove.all.from.list = delete all
remove.all.from.list.confirm = Confirm
remove.all.from.list.cancel = Cancel

renew.alias = Renew alias

Expand Down Expand Up @@ -716,6 +719,7 @@ valid.until.0 = valid until {0}
wednesday = Wednesday

yes = Yes

harvestdefinition.schedule.edit.minutes=minutes

errormsg;configuration.exists.0=Configuration {0} already exists
Expand Down
Expand Up @@ -508,6 +508,9 @@ redirecting = Redirigerer
remove = Fjern

remove.from.list = Fjern fra listen
remove.all.from.list = slet alt
remove.all.from.list.confirm = At bekr\u00E6fte
remove.all.from.list.cancel = At annullere

renew.alias = Forny alias

Expand Down Expand Up @@ -699,6 +702,7 @@ valid.until.0 = gyldig indtil {0}
wednesday = Onsdag

yes = Ja

harvestdefinition.templates.hide.inactive=Skjul Inaktiv
harvestdefinition.templates.show.inactive=Vis Inaktiv
harvestdefinition.templates.default.template=Default Skabelon
Expand Down
Expand Up @@ -516,6 +516,9 @@ redirecting = Umleitung
remove = Entferne

remove.from.list = Entferne von Liste
remove.all.from.list = alles l\u00F6sschen
remove.all.from.list.confirm = Best\u00E4tigen
remove.all.from.list.cancel = Abbrechen

renew.alias = Erneuere Alias

Expand Down Expand Up @@ -707,6 +710,7 @@ valid.until.0 = G\u00FCltig bis {0}
wednesday = Mittwoch

yes = Ja

harvestdefinition.schedule.edit.minutes=Minuten

errormsg;configuration.exists.0=Die Konfiguration {0} existiert bereits
Expand Down
Expand Up @@ -519,6 +519,9 @@ redirecting = Redirection en cours
remove = Supprimer

remove.from.list = Supprimer de la liste
remove.all.from.list = supprimer tout
remove.all.from.list.confirm = Confirmer
remove.all.from.list.cancel = Annuler

renew.alias = Renouveler l'alias

Expand Down Expand Up @@ -711,6 +714,7 @@ valid.until.0 = valable jusqu''au {0}
wednesday = Mercredi

yes = Oui

harvestdefinition.schedule.edit.minutes=minutes

errormsg;configuration.exists.0=La configuration {0} existe d\u00E9j\u00E0
Expand Down
Expand Up @@ -500,6 +500,9 @@ redirecting = Redirezione
remove = Rimuovere

remove.from.list = Rimuovere dalla lista
remove.all.from.list = Cancella tutto
remove.all.from.list.confirm = Confirmer
remove.all.from.list.cancel = Annuler

renew.alias = Rinnovare l'alias

Expand Down

0 comments on commit a064796

Please sign in to comment.