Skip to content

Commit 1fb849d

Browse files
authoredSep 4, 2024
Merge pull request #55 from exadel-inc/feature/deletereport
[ELI_46] Delete report button.
2 parents 533b54f + 136a910 commit 1fb849d

File tree

13 files changed

+198
-7
lines changed

13 files changed

+198
-7
lines changed
 

‎core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/cache/GridResourcesCache.java

+2
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ public interface GridResourcesCache {
1010
CopyOnWriteArrayList<GridResource> getGridResourcesList();
1111

1212
void setGridResourcesList(List<GridResource> gridResources);
13+
14+
void clearCache();
1315
}

‎core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/cache/impl/GridResourcesCacheImpl.java

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public synchronized void setGridResourcesList(List<GridResource> gridResources)
3737
gridResourcesCache.asMap().put(BROKEN_LINKS_MAP_KEY, new CopyOnWriteArrayList<>(gridResources));
3838
}
3939

40+
@Override
41+
public void clearCache() {
42+
gridResourcesCache.invalidateAll();
43+
}
44+
4045
@SuppressWarnings("UnstableApiUsage")
4146
@Override
4247
public CopyOnWriteArrayList<GridResource> getGridResourcesList() {

‎core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/DataFeedService.java

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.exadel.etoolbox.linkinspector.core.services.data.models.DataFilter;
1818
import com.exadel.etoolbox.linkinspector.core.services.data.models.GridResource;
19+
import com.exadel.etoolbox.linkinspector.core.services.exceptions.DataFeedException;
1920
import org.apache.sling.api.resource.Resource;
2021

2122
import java.util.List;
@@ -59,4 +60,9 @@ public interface DataFeedService {
5960
* @param valuesMap - {@code Map<String, String>} property location as key and new url as value
6061
*/
6162
void modifyDataFeed(Map<String, String> valuesMap);
63+
64+
/**
65+
* Method for deleting data in data feed
66+
*/
67+
void deleteDataFeed() throws DataFeedException;
6268
}

‎core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/DataFeedServiceImpl.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
package com.exadel.etoolbox.linkinspector.core.services.data.impl;
1616

1717
import com.adobe.granite.ui.components.ds.ValueMapResource;
18-
import com.exadel.etoolbox.linkinspector.api.Link;
1918
import com.exadel.etoolbox.linkinspector.core.models.ui.GridViewItem;
2019
import com.exadel.etoolbox.linkinspector.core.services.cache.GridResourcesCache;
2120
import com.exadel.etoolbox.linkinspector.core.services.data.DataFeedService;
2221
import com.exadel.etoolbox.linkinspector.core.services.data.GridResourcesGenerator;
2322
import com.exadel.etoolbox.linkinspector.core.services.data.models.DataFilter;
23+
import com.exadel.etoolbox.linkinspector.core.services.exceptions.DataFeedException;
2424
import com.exadel.etoolbox.linkinspector.core.services.helpers.LinkHelper;
2525
import com.exadel.etoolbox.linkinspector.core.services.util.CsvUtil;
2626
import com.exadel.etoolbox.linkinspector.core.services.helpers.RepositoryHelper;
@@ -183,6 +183,20 @@ public void modifyDataFeed(Map<String, String> valuesMap) {
183183
}
184184
}
185185

186+
@Override
187+
public void deleteDataFeed() throws DataFeedException {
188+
try (ResourceResolver serviceResourceResolver = repositoryHelper.getServiceResourceResolver()) {
189+
removePreviousDataFeed(serviceResourceResolver);
190+
removeCsvReport(serviceResourceResolver);
191+
removePendingNode(serviceResourceResolver);
192+
gridResourcesCache.clearCache();
193+
serviceResourceResolver.commit();
194+
} catch (PersistenceException e) {
195+
LOG.error("Failed to delete data feed", e);
196+
throw new DataFeedException("Exception Deleting Data Feed");
197+
}
198+
}
199+
186200
private List<GridResource> dataFeedToGridResources(ResourceResolver resourceResolver) {
187201
List<GridResource> gridResources = new ArrayList<>();
188202
JSONArray jsonArray = JsonUtil.getJsonArrayFromFile(JSON_FEED_PATH, resourceResolver);
@@ -218,6 +232,10 @@ private void removePreviousDataFeed(ResourceResolver resourceResolver) {
218232
LinkInspectorResourceUtil.removeResource(JSON_FEED_PATH, resourceResolver);
219233
}
220234

235+
private void removeCsvReport(ResourceResolver resourceResolver) {
236+
LinkInspectorResourceUtil.removeResource(CSV_REPORT_PATH, resourceResolver);
237+
}
238+
221239
private void saveGridResourcesToJcr(ResourceResolver resourceResolver, JSONArray jsonArray) {
222240
LinkInspectorResourceUtil.saveFileToJCR(
223241
JSON_FEED_PATH,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.exadel.etoolbox.linkinspector.core.services.exceptions;
2+
3+
public class DataFeedException extends Exception {
4+
public DataFeedException(String message) {
5+
super(message);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.exadel.etoolbox.linkinspector.core.servlets;
2+
3+
import com.exadel.etoolbox.linkinspector.core.services.data.DataFeedService;
4+
import com.exadel.etoolbox.linkinspector.core.services.exceptions.DataFeedException;
5+
import org.apache.commons.httpclient.HttpStatus;
6+
import org.apache.sling.api.SlingHttpServletRequest;
7+
import org.apache.sling.api.SlingHttpServletResponse;
8+
import org.apache.sling.api.servlets.HttpConstants;
9+
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
10+
import org.osgi.service.component.annotations.Component;
11+
import org.osgi.service.component.annotations.Reference;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
14+
15+
import javax.servlet.Servlet;
16+
17+
@Component(service = {Servlet.class},
18+
property = {
19+
"sling.servlet.methods=" + HttpConstants.METHOD_DELETE,
20+
"sling.servlet.paths=" + "/bin/etoolbox/link-inspector/delete-report"
21+
}
22+
)
23+
public class DeleteReportServlet extends SlingAllMethodsServlet {
24+
25+
private static final Logger LOG = LoggerFactory.getLogger(DeleteReportServlet.class);
26+
27+
@Reference
28+
private DataFeedService dataFeedService;
29+
30+
@Override
31+
protected void doDelete(SlingHttpServletRequest request, SlingHttpServletResponse response) {
32+
try {
33+
dataFeedService.deleteDataFeed();
34+
response.setStatus(HttpStatus.SC_OK);
35+
} catch (DataFeedException e) {
36+
LOG.error(e.getMessage());
37+
response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
38+
}
39+
}
40+
}

‎core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/mocks/MockDataFeedService.java

+5
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ public List<GridResource> dataFeedToGridResources() {
2929
public void modifyDataFeed(Map<String, String> valuesMap) {
3030
// No operation
3131
}
32+
33+
@Override
34+
public void deleteDataFeed() {
35+
// No operation
36+
}
3237
}

‎ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/css/console-ui.less

+5-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ tr.elc-card {
115115
display: none;
116116
}
117117

118-
.foundation-collection-item-link-type{
118+
.collection-item_link-type{
119119
width:30%;
120120
}
121121

@@ -131,6 +131,10 @@ tr.elc-card {
131131
width:30%
132132
}
133133

134+
.collection-item_status_code {
135+
text-align: center;
136+
}
137+
134138
#elc-filter-options.elc-filter-active, #elc-filter-options.elc-filter-active:hover {
135139
background-color: #d3d3d3;
136140
}

‎ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/js.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ console-ui.conf.js
88
console-ui.replace.js
99
console-ui.filter.js
1010
console-ui.pagination.js
11-
console-ui.run.js
11+
console-ui.run.js
12+
console-ui.delete.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
/**
16+
* EToolbox Link Inspector clientlib.
17+
* "Delete Report" action definition.
18+
*/
19+
(function (window, document, $, ELC, Granite, Coral) {
20+
'use strict';
21+
const DIALOG_TITLE_LABEL = Granite.I18n.get('Delete Report');
22+
const CANCEL_LABEL = Granite.I18n.get('Cancel');
23+
const SUBMIT_FILTER_LABEL = Granite.I18n.get('Delete');
24+
const ERROR_MSG = Granite.I18n.get('Something went wrong');
25+
26+
function onFilterAction(name, el, config, collection, selections) {
27+
const dialog = document.querySelector('#delete-dialog');
28+
dialog.show();
29+
}
30+
31+
function initDeleteDialog(){
32+
const dialog = new Coral.Dialog().set({
33+
id : 'delete-dialog',
34+
closable: Coral.Dialog.closable.ON,
35+
backdrop: Coral.Dialog.backdrop.STATIC,
36+
interaction: 'off',
37+
header :{
38+
innerHTML : DIALOG_TITLE_LABEL
39+
}
40+
});
41+
42+
$('<p>').html('Are you sure you want to delete the report?').appendTo(dialog.content);
43+
44+
const $cancelBtn = $('<button is="coral-button" variant="default" coral-close>').text(CANCEL_LABEL);
45+
const $updateBtn =
46+
$('<button data-dialog-action is="coral-button" variant="primary" coral-close>').text(SUBMIT_FILTER_LABEL);
47+
48+
$cancelBtn.appendTo(dialog.footer);
49+
$updateBtn.appendTo(dialog.footer);
50+
51+
function onDeleteDialogSubmit(){
52+
dialog.trigger('coral-overlay:close');
53+
$.ajax({
54+
url: '/bin/etoolbox/link-inspector/delete-report',
55+
type: 'DELETE',
56+
success: function(){
57+
window.location.reload();
58+
},
59+
error: function(){
60+
var alertPopup = new Coral.Alert().set({
61+
variant: "error",
62+
header: {
63+
innerHTML: 'ERROR'
64+
},
65+
content: {
66+
textContent: ERROR_MSG
67+
}
68+
});
69+
alertPopup.classList.add('elc-coral-alert');
70+
document.body.append(alertPopup);
71+
}
72+
});
73+
}
74+
75+
dialog.on('click', '[data-dialog-action]', onDeleteDialogSubmit);
76+
dialog.on('coral-overlay:close', function (event) {
77+
dialog.remove();
78+
initDeleteDialog();
79+
});
80+
81+
document.body.appendChild(dialog);
82+
}
83+
84+
$(window).adaptTo('foundation-registry').register('foundation.collection.action.action', {
85+
name: 'cq-admin.etoolbox.linkinspector.action.delete-report',
86+
handler: onFilterAction
87+
});
88+
89+
$(document).ready(function () {
90+
initDeleteDialog();
91+
});
92+
93+
})(window, document, Granite.$, Granite.ELC, Granite, Coral);

‎ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/js/console-ui.replace.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
var BACKUP_CHECKBOX_LABEL = Granite.I18n.get('Backup before replacement');
3030
var CSV_OUT_CHECKBOX_LABEL = Granite.I18n.get('Download CSV with updated items');
3131
var DRY_RUN_TOOLTIP = Granite.I18n.get("If checked, no changes will be applied in the repository");
32-
var REPLACEMENT_DESCRIPTION = Granite.I18n.get('* Replacement will be applied within the detected broken links scope');
32+
var REPLACEMENT_DESCRIPTION = Granite.I18n.get('* Replacement will be applied within the selected broken links scope');
3333
var REPLACEMENT_ACL_DESCRIPTION = Granite.I18n.get('** User should have sufficient read/write permissions in order to complete replacement successfully and create the backup package');
3434
var VALIDATION_MSG = Granite.I18n.get('Replacement can\'t be the same as pattern');
3535
var LINK_TO_UPDATE_LABEL = Granite.I18n.get('The following links will be updated:');
@@ -63,7 +63,7 @@
6363
advancedMode: data.advancedMode,
6464
selected: data.selected
6565
}].filter(function (item) {
66-
return item.pattern && item.replacement && item.pattern !== item.replacement;
66+
return !item.advancedMode || item.pattern && item.replacement && item.pattern !== item.replacement;
6767
});
6868
ELC.bulkLinksUpdate(replacementList, buildReplaceRequest);
6969
});

‎ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/gridConfig/gridConfig.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<img itemprop="thumbnail" width="192" src="${model.thumbnail}" alt="">
1010
</td>
1111

12-
<td class="foundation-collection-item-keys" is="coral-table-cell">
12+
<td class="foundation-collection-item-keys collection-item_status_code" is="coral-table-cell">
1313
<div data-sly-set.statuscode="${model.linkStatusCode == '200' ? 'ok' : 'error'}"
1414
class="status" title="HTTP Status ${model.linkStatusCode}">
1515
<coral-icon icon="circle" class="elc-link-status--${statuscode}"></coral-icon>
@@ -19,7 +19,7 @@
1919
</div>
2020
</td>
2121

22-
<td class="foundation-collection-item-title foundation-collection-item-link-type" is="coral-table-cell">
22+
<td class="foundation-collection-item-title collection-item_link-type" is="coral-table-cell">
2323
<div class="elc-complex-col">
2424
<h4 class="elc-primary-info" title="${model.link}">${model.link}</h4>
2525
<span class="elc-secondary-info">${model.linkType}</span>

‎ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/link-inspector/.content.xml

+10
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@
133133
text="Filter"
134134
title="Filter"
135135
variant="minimal"/>
136+
<deleteReport
137+
jcr:primaryType="nt:unstructured"
138+
sling:resourceType="granite/ui/components/coral/foundation/collection/action"
139+
granite:id="elc-delete-report"
140+
action="cq-admin.etoolbox.linkinspector.action.delete-report"
141+
icon="delete"
142+
target=".etoolbox-link-inspector"
143+
text="Delete"
144+
title="Delete"
145+
variant="minimal"/>
136146
</primary>
137147
<secondary jcr:primaryType="nt:unstructured">
138148
<options

0 commit comments

Comments
 (0)