diff --git a/all/pom.xml b/all/pom.xml index f6f563fe..a6d4acb6 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -45,7 +45,6 @@ com.exadel.etoolbox etoolbox-link-inspector.ui.apps - zip /apps/etoolbox-link-inspector-packages/application/install @@ -56,15 +55,18 @@ com.exadel.etoolbox etoolbox-link-inspector.ui.content - zip /apps/etoolbox-link-inspector-packages/content/install com.exadel.etoolbox etoolbox-link-inspector.ui.config - zip /apps/etoolbox-link-inspector-packages/application/install + + com.exadel.etoolbox + etoolbox-contractor.all + /apps/etoolbox-link-inspector-packages/lib/install + @@ -146,6 +148,11 @@ ${project.version} zip - + + com.exadel.etoolbox + etoolbox-contractor.all + 1.0.0-SNAPSHOT + zip + diff --git a/core/pom.xml b/core/pom.xml index a7a9f4d3..bcb48b9c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -156,6 +156,13 @@ Import-Package: javax.annotation;version=0.0.0,* jackson-core test + + + + com.exadel.etoolbox + etoolbox-contractor.core + + com.adobe.aem diff --git a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsButton.java b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsButton.java deleted file mode 100644 index 611dc9af..00000000 --- a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsButton.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.exadel.etoolbox.linkinspector.core.models.ui; - -import org.apache.commons.lang3.StringUtils; -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.api.resource.ResourceResolver; -import org.apache.sling.models.annotations.DefaultInjectionStrategy; -import org.apache.sling.models.annotations.Model; -import org.apache.sling.models.annotations.injectorspecific.SlingObject; - -import javax.inject.Inject; -import java.util.Optional; - -/** - * Represents the Stats button in the UI grid. After clicking this button, the popover represented - * by {@link StatsModal} is displayed. - */ -@Model( - adaptables = SlingHttpServletRequest.class, - defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL -) -public class StatsButton { - @SlingObject - private ResourceResolver resourceResolver; - - @Inject - private String statsResourcePath; - - /** - * Checks existence of the resource that encloses generation statistics data. - * - * @return true, if the resource exists - */ - public boolean statsResourceExists() { - return Optional.ofNullable(statsResourcePath) - .filter(StringUtils::isNotBlank) - .map(resourceResolver::getResource) - .isPresent(); - } -} \ No newline at end of file diff --git a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsModal.java b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsModel.java similarity index 92% rename from core/src/main/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsModal.java rename to core/src/main/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsModel.java index 980faccc..8cf6026c 100644 --- a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsModal.java +++ b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsModel.java @@ -15,6 +15,7 @@ package com.exadel.etoolbox.linkinspector.core.models.ui; import com.exadel.etoolbox.linkinspector.core.services.data.GridResourcesGenerator; +import lombok.Getter; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.apache.sling.api.resource.Resource; @@ -38,26 +39,30 @@ adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL ) -public class StatsModal { +public class StatsModel { private static final String ARRAY_VALUES_SEPARATOR = ", "; private static final String ALL_STATUS_CODES_MSG = "All error codes outside the range '200-207'"; @ValueMapValue + @Getter private String lastGenerated; @ValueMapValue + @Getter private String searchPath; @ValueMapValue private String[] excludedPaths; @ValueMapValue + @Getter private boolean checkActivation; @ValueMapValue private boolean skipModifiedAfterActivation; @ValueMapValue + @Getter private String lastModifiedBoundary; @ValueMapValue @@ -67,6 +72,7 @@ public class StatsModal { private String[] excludedLinksPatterns; @ValueMapValue + @Getter private String excludeTags; @ValueMapValue @@ -76,30 +82,14 @@ public class StatsModal { private String[] statistics; - public String getLastGenerated() { - return lastGenerated; - } - - public String getSearchPath() { - return searchPath; - } - public String getExcludedPaths() { return arrayToStringValue(excludedPaths); } - public boolean getCheckActivation() { - return checkActivation; - } - public boolean getSkipModifiedAfterActivation() { return checkActivation && skipModifiedAfterActivation; } - public String getLastModifiedBoundary() { - return lastModifiedBoundary; - } - public String getExcludedProperties() { return arrayToStringValue(excludedProperties); } @@ -108,10 +98,6 @@ public String getExcludedLinksPatterns() { return arrayToStringValue(excludedLinksPatterns); } - public String getExcludeTags() { - return excludeTags; - } - /** * Represents the value of the 'Status codes' field from the {@link GridResourcesGenerator} configuration used * during data feed generation @@ -147,6 +133,10 @@ public Map getStatistics() { LinkedHashMap::new)); } + public boolean isValid() { + return StringUtils.isNotBlank(lastGenerated) && StringUtils.isNotBlank(searchPath); + } + /** * Transforms array of Strings to a single comma separated String * @param stringArray - the input array diff --git a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/schedulers/DataFeedGenerationTask.java b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/schedulers/DataFeedGenerationTask.java index 7a8fb638..2b404eaa 100644 --- a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/schedulers/DataFeedGenerationTask.java +++ b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/schedulers/DataFeedGenerationTask.java @@ -14,9 +14,9 @@ package com.exadel.etoolbox.linkinspector.core.schedulers; +import com.exadel.etoolbox.contractor.ContractorException; +import com.exadel.etoolbox.contractor.service.tasking.Contractor; import com.exadel.etoolbox.linkinspector.core.services.job.DataFeedJobExecutor; -import com.exadel.etoolbox.linkinspector.core.services.job.SlingJobUtil; -import org.apache.sling.event.jobs.JobManager; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; @@ -39,22 +39,18 @@ public class DataFeedGenerationTask implements Runnable { @ObjectClassDefinition(name = "EToolbox Link Inspector - Data Feed Generation Task") public @interface Config { - @AttributeDefinition(name = "Cron-job expression") + @AttributeDefinition(name = "Cron expression") String scheduler_expression() default "0 0 5 1/1 * ? *"; - @AttributeDefinition(name = "Concurrent task", - description = "Whether or not to schedule this task concurrently") - boolean scheduler_concurrent() default false; - @AttributeDefinition(name = "Enabled", - description = "Whether or not to enable this task") + description = "Whether to enable this task") boolean enabled() default false; } private static final Logger LOG = LoggerFactory.getLogger(DataFeedGenerationTask.class); @Reference - private JobManager jobManager; + private Contractor contractor; private boolean enabled; @@ -67,8 +63,12 @@ public void run() { LOG.debug("The Data Feed Generation scheduled task is not enabled"); return; } - LOG.debug("The Data Feed Generation scheduled task started"); - SlingJobUtil.addJob(jobManager, DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC, Collections.emptyMap()); + LOG.debug("The Data Feed Generation scheduled task is going to start"); + try { + contractor.runExclusive(DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC); + } catch (ContractorException e) { + LOG.error("An error occurred while running the scheduled Data Feed Generation task", e); + } } /** @@ -87,6 +87,6 @@ protected void activate(Config config) { protected void deactivate() { LOG.debug("Deactivating DataFeedGenerationTask, sling jobs with the topic {} will be stopped and removed", DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC); - SlingJobUtil.stopAndRemoveJobs(jobManager, DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC); + contractor.discardAll(DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC); } } \ No newline at end of file diff --git a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/GenerationStatsProps.java b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/GenerationStatsProps.java index fab9177d..e51f527d 100644 --- a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/GenerationStatsProps.java +++ b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/GenerationStatsProps.java @@ -14,10 +14,12 @@ package com.exadel.etoolbox.linkinspector.core.services.data; +import com.exadel.etoolbox.linkinspector.core.models.ui.StatsModel; + /** * Lists the JCR property names for generation statistics data written * by {@link GridResourcesGenerator#generateGridResources}. Further, these property names are used to map the statistics - * values to the {@link com.exadel.etoolbox.linkinspector.core.models.ui.StatsModal} fields + * values to the {@link StatsModel} fields */ public final class GenerationStatsProps { private GenerationStatsProps() {} diff --git a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImpl.java b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImpl.java index 2b87af22..505dc932 100644 --- a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImpl.java +++ b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImpl.java @@ -17,14 +17,18 @@ import com.day.cq.replication.ReplicationActionType; import com.day.cq.replication.ReplicationStatus; import com.day.crx.JcrConstants; +import com.exadel.etoolbox.contractor.entity.Context; +import com.exadel.etoolbox.contractor.service.tasking.Contractor; import com.exadel.etoolbox.linkinspector.api.Link; import com.exadel.etoolbox.linkinspector.core.services.data.GenerationStatsProps; import com.exadel.etoolbox.linkinspector.core.services.data.GridResourcesGenerator; import com.exadel.etoolbox.linkinspector.core.services.data.ConfigService; import com.exadel.etoolbox.linkinspector.core.services.helpers.LinkHelper; import com.exadel.etoolbox.linkinspector.core.services.data.models.GridResource; +import com.exadel.etoolbox.linkinspector.core.services.job.DataFeedJobExecutor; import com.exadel.etoolbox.linkinspector.core.services.util.LinkInspectorResourceUtil; import com.exadel.etoolbox.linkinspector.core.services.util.LinksCounter; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.StopWatch; @@ -32,6 +36,7 @@ import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceUtil; +import org.apache.sling.event.jobs.Job; import org.apache.sling.jcr.resource.api.JcrResourceConstants; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; @@ -68,6 +73,8 @@ public class GridResourcesGeneratorImpl implements GridResourcesGenerator { private LinkHelper linkHelper; @Reference private ConfigService configService; + @Reference + private Contractor contractor; private ExecutorService executorService; @@ -77,21 +84,35 @@ public class GridResourcesGeneratorImpl implements GridResourcesGenerator { @Override public List generateGridResources(String gridResourceType, ResourceResolver resourceResolver) { StopWatch stopWatch = StopWatch.createStarted(); + String searchPath = configService.getSearchPath(); - LOG.debug("Start broken links collecting, path: {}", searchPath); + Map> linkToGridResourcesMap; + + try (Context context = contractor.newJobContext( + DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC, + "Scanning " + searchPath)) { + + LOG.debug("Start broken links collecting, path: {}", searchPath); + Resource rootResource = resourceResolver.getResource(searchPath); + if (rootResource == null) { + LOG.warn("Search path resource is null, link inspector report generation is stopped"); + context.feedback().state(Job.JobState.DROPPED).message("Search path resource not found").send(); + return Collections.emptyList(); + } - Resource rootResource = resourceResolver.getResource(searchPath); - if (rootResource == null) { - LOG.warn("Search path resource is null, link inspector report generation is stopped"); - return Collections.emptyList(); - } + linkToGridResourcesMap = new HashMap<>(); + int traversedNodesCounter = getGridResourcesViaTraversing( + rootResource, + gridResourceType, + linkToGridResourcesMap, + context); - Map> linkToGridResourcesMap = new HashMap<>(); - int traversedNodesCounter = getGridResourcesViaTraversing(rootResource, gridResourceType, linkToGridResourcesMap); - LOG.debug("Traversal is completed in {} ms, path: {}, traversed nodes count: {}", - stopWatch.getTime(TimeUnit.MILLISECONDS), searchPath, traversedNodesCounter); + LOG.info("Traversal is completed in {} ms, path: {}, traversed nodes count: {}", + stopWatch.getTime(TimeUnit.MILLISECONDS), searchPath, traversedNodesCounter); + context.feedback("Completed"); + } - if (linkToGridResourcesMap.isEmpty()) { + if (MapUtils.isEmpty(linkToGridResourcesMap)) { LOG.warn("Collecting reported links is completed in {} ms, path: {}. No links reported after traversing", stopWatch.getTime(TimeUnit.MILLISECONDS), searchPath); LinksCounter emptyCounter = new LinksCounter(); @@ -113,7 +134,9 @@ public List generateGridResources(String gridResourceType, Resourc private int getGridResourcesViaTraversing(Resource resource, String gridResourceType, - Map> allLinkToGridResourcesMap) { + Map> allLinkToGridResourcesMap, + Context context) { + context.feedback("Scanning {}", resource.getPath()); int traversedNodesCount = 0; if (!isAllowedResource(resource)) { return traversedNodesCount; @@ -129,7 +152,7 @@ private int getGridResourcesViaTraversing(Resource resource, Iterator children = resource.listChildren(); while (children.hasNext()) { Resource child = children.next(); - traversedNodesCount += getGridResourcesViaTraversing(child, gridResourceType, allLinkToGridResourcesMap); + traversedNodesCount += getGridResourcesViaTraversing(child, gridResourceType, allLinkToGridResourcesMap, context); } return traversedNodesCount; } diff --git a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/servlets/GenerateDataFeedServlet.java b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/servlets/GenerateDataFeedServlet.java deleted file mode 100644 index 13f40f10..00000000 --- a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/servlets/GenerateDataFeedServlet.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.exadel.etoolbox.linkinspector.core.servlets; - -import com.exadel.etoolbox.linkinspector.core.services.job.DataFeedJobExecutor; -import com.exadel.etoolbox.linkinspector.core.services.job.SlingJobUtil; -import org.apache.jackrabbit.api.security.user.Group; -import org.apache.jackrabbit.api.security.user.User; -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.api.SlingHttpServletResponse; -import org.apache.sling.api.servlets.HttpConstants; -import org.apache.sling.api.servlets.SlingSafeMethodsServlet; -import org.apache.sling.event.jobs.JobManager; -import org.apache.sling.servlets.annotations.SlingServletResourceTypes; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; -import org.osgi.service.component.propertytypes.ServiceDescription; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.jcr.RepositoryException; -import javax.servlet.Servlet; -import java.util.Collections; -import java.util.Iterator; -import java.util.Optional; - -@Component(service = {Servlet.class}) -@SlingServletResourceTypes( - resourceTypes = "/bin/etoolbox/link-inspector/datafeed/generate", - methods = HttpConstants.METHOD_GET -) -@ServiceDescription("The servlet for manual triggering data feed generation") -public class GenerateDataFeedServlet extends SlingSafeMethodsServlet { - private static final Logger LOG = LoggerFactory.getLogger(GenerateDataFeedServlet.class); - - private static final String ADMIN_GROUP_ID = "administrators"; - - @Reference - private transient JobManager jobManager; - - @Override - protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) { - boolean isAdmin = Optional.of(request.getResourceResolver()) - .map(resourceResolver -> resourceResolver.adaptTo(User.class)) - .filter(this::isAdminUser) - .isPresent(); - if (isAdmin) { - SlingJobUtil.addJob( - jobManager, - DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC, - Collections.emptyMap() - ); - } else { - LOG.debug("Data feed generation was not triggered, user is not admin nor a member of '{}' group", - ADMIN_GROUP_ID); - } - } - - private boolean isAdminUser(User user) { - if (user.isAdmin()) { - return true; - } - try { - Iterator groupIterator = user.memberOf(); - while (groupIterator.hasNext()) { - String groupId = groupIterator.next().getID(); - if (groupId.equals(ADMIN_GROUP_ID)) { - return true; - } - } - } catch (RepositoryException e) { - LOG.error("Failed to check if user is admin", e); - } - return false; - } -} \ No newline at end of file diff --git a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/servlets/JobStatusServlet.java b/core/src/main/java/com/exadel/etoolbox/linkinspector/core/servlets/JobStatusServlet.java deleted file mode 100644 index a8f8ca2d..00000000 --- a/core/src/main/java/com/exadel/etoolbox/linkinspector/core/servlets/JobStatusServlet.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.exadel.etoolbox.linkinspector.core.servlets; - -import com.exadel.etoolbox.linkinspector.core.services.job.DataFeedJobExecutor; -import com.exadel.etoolbox.linkinspector.core.services.job.SlingJobUtil; -import com.exadel.etoolbox.linkinspector.core.services.util.ServletUtil; -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.api.SlingHttpServletResponse; -import org.apache.sling.api.servlets.HttpConstants; -import org.apache.sling.api.servlets.SlingAllMethodsServlet; -import org.apache.sling.event.jobs.JobManager; -import org.apache.sling.servlets.annotations.SlingServletResourceTypes; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; - -import javax.json.Json; -import javax.servlet.Servlet; - -@Component(service = {Servlet.class}) -@SlingServletResourceTypes( - resourceTypes = "/bin/etoolbox/link-inspector/job-status", - methods = HttpConstants.METHOD_GET -) -public class JobStatusServlet extends SlingAllMethodsServlet { - - private static final String JOB_STATUS = "status"; - - @Reference - private JobManager jobManager; - - @Override - protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) { - - String jobStatus = SlingJobUtil.getJobStatus(jobManager, DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC); - - String jsonResponse = Json.createObjectBuilder() - .add(JOB_STATUS, jobStatus) - .build() - .toString(); - - ServletUtil.writeJsonResponse(response, jsonResponse); - } -} diff --git a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsButtonTest.java b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsButtonTest.java deleted file mode 100644 index 4656b84e..00000000 --- a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsButtonTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.exadel.etoolbox.linkinspector.core.models.ui; - -import com.day.crx.JcrConstants; -import io.wcm.testing.mock.aem.junit5.AemContext; -import io.wcm.testing.mock.aem.junit5.AemContextExtension; -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.jcr.resource.api.JcrResourceConstants; -import org.apache.sling.testing.mock.sling.ResourceResolverType; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import static org.junit.jupiter.api.Assertions.*; - -@ExtendWith(AemContextExtension.class) -class StatsButtonTest { - private static final String STATS_RESOURCE_PATH_PARAM = "statsResourcePath"; - private static final String TEST_RESOURCE_PATH = "/content/link-inspector/data/stats"; - - private final AemContext context = new AemContext(ResourceResolverType.RESOURCERESOLVER_MOCK); - - private StatsButton fixture; - - @BeforeEach - public void setup() { - context.request().setAttribute(STATS_RESOURCE_PATH_PARAM, TEST_RESOURCE_PATH); - context.addModelsForClasses(StatsButton.class); - fixture = context.request().adaptTo(StatsButton.class); - } - - @Test - void testResourceExists() { - context.create().resource( - TEST_RESOURCE_PATH, - JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, - JcrConstants.NT_UNSTRUCTURED); - - assertTrue(fixture.statsResourceExists()); - } - - @Test - void testResourceNotExist() { - assertFalse(fixture.statsResourceExists()); - } -} \ No newline at end of file diff --git a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsModalTest.java b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsPanelTest.java similarity index 94% rename from core/src/test/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsModalTest.java rename to core/src/test/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsPanelTest.java index 9341e97c..bf650054 100644 --- a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsModalTest.java +++ b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/models/ui/StatsPanelTest.java @@ -35,7 +35,7 @@ import static org.junit.jupiter.api.Assertions.*; @ExtendWith(AemContextExtension.class) -class StatsModalTest { +class StatsPanelTest { private static final String TEST_RESOURCE_PATH = "/content/link-inspector/data/stats"; private static final String TEST_LAST_GENERATED = ZonedDateTime.now().format(DateTimeFormatter.RFC_1123_DATE_TIME); private static final String TEST_SEARCH_PATH = "/content/search-path"; @@ -62,7 +62,7 @@ class StatsModalTest { @BeforeEach void setup() { - context.addModelsForClasses(StatsModal.class); + context.addModelsForClasses(StatsModel.class); } @Test @@ -70,13 +70,13 @@ void testEmptyResourceProps() { Resource statsResource = context.create().resource(TEST_RESOURCE_PATH, JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, JcrConstants.NT_UNSTRUCTURED); - StatsModal model = statsResource.adaptTo(StatsModal.class); + StatsModel model = statsResource.adaptTo(StatsModel.class); assertNotNull(model); assertNull(model.getLastGenerated()); assertNull(model.getSearchPath()); assertEquals(StringUtils.EMPTY, model.getExcludedPaths()); - assertFalse(model.getCheckActivation()); + assertFalse(model.isCheckActivation()); assertFalse(model.getSkipModifiedAfterActivation()); assertNull(model.getLastModifiedBoundary()); assertEquals(StringUtils.EMPTY, model.getExcludedProperties()); @@ -108,13 +108,13 @@ void testAllResourceProps() { Resource statsResource = context.create().resource(TEST_RESOURCE_PATH, stats); - StatsModal model = statsResource.adaptTo(StatsModal.class); + StatsModel model = statsResource.adaptTo(StatsModel.class); assertNotNull(model); assertEquals(TEST_LAST_GENERATED, model.getLastGenerated()); assertEquals(TEST_SEARCH_PATH, model.getSearchPath()); assertEquals(EXPECTED_EXCLUDED_PATHS, model.getExcludedPaths()); - assertEquals(TEST_CHECK_ACTIVATION, model.getCheckActivation()); + assertEquals(TEST_CHECK_ACTIVATION, model.isCheckActivation()); assertEquals(TEST_SKIP_MODIFIED_AFTER_ACTIVATION, model.getSkipModifiedAfterActivation()); assertEquals(TEST_LAST_MOD_BOUNDARY, model.getLastModifiedBoundary()); assertEquals(EXPECTED_EXCLUDED_PROPS, model.getExcludedProperties()); @@ -131,7 +131,7 @@ void testAllStatusCodes() { JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, JcrConstants.NT_UNSTRUCTURED, GenerationStatsProps.PN_ALLOWED_STATUS_CODES, -1); - StatsModal model = statsResource.adaptTo(StatsModal.class); + StatsModel model = statsResource.adaptTo(StatsModel.class); assertNotNull(model); assertEquals(ALL_STATUS_CODES_MSG, model.getAllowedStatusCodes()); diff --git a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/schedulers/DataFeedGenerationTaskTest.java b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/schedulers/DataFeedGenerationTaskTest.java index 739bd37e..364acc71 100644 --- a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/schedulers/DataFeedGenerationTaskTest.java +++ b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/schedulers/DataFeedGenerationTaskTest.java @@ -14,55 +14,71 @@ package com.exadel.etoolbox.linkinspector.core.schedulers; +import com.exadel.etoolbox.contractor.ContractorException; +import com.exadel.etoolbox.contractor.service.tasking.Contractor; import com.exadel.etoolbox.linkinspector.core.services.job.DataFeedJobExecutor; -import com.exadel.etoolbox.linkinspector.core.services.job.SlingJobUtil; import junitx.util.PrivateAccessor; -import org.apache.sling.event.jobs.JobManager; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.MockedStatic; +import java.util.concurrent.atomic.AtomicReference; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; class DataFeedGenerationTaskTest { - private static final String JOB_MANAGER_FIELD = "jobManager"; private final DataFeedGenerationTask fixture = new DataFeedGenerationTask(); + private final Contractor contractor = mock(Contractor.class); @BeforeEach void setup() throws NoSuchFieldException { - JobManager jobManager = mock(JobManager.class); - PrivateAccessor.setField(fixture, JOB_MANAGER_FIELD, jobManager); + PrivateAccessor.setField(fixture, "contractor", contractor); } @Test - void testRun() { + void testRun() throws ContractorException { DataFeedGenerationTask.Config config = mock(DataFeedGenerationTask.Config.class); when(config.enabled()).thenReturn(true); - try (MockedStatic slingJobUtil = mockStatic(SlingJobUtil.class)) { - fixture.activate(config); - fixture.run(); - slingJobUtil.verify(() -> SlingJobUtil.addJob(any(JobManager.class), eq(DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC), anyMap())); - } + + AtomicReference runTopic = new AtomicReference<>(); + when(contractor.runExclusive(anyString())).then(invocation -> { + runTopic.set(invocation.getArgument(0)); + return null; + }); + + fixture.activate(config); + fixture.run(); + assertEquals(DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC, runTopic.get()); } @Test - void testRunNotEnabled() { + void testRunNotEnabled() throws ContractorException { DataFeedGenerationTask.Config config = mock(DataFeedGenerationTask.Config.class); when(config.enabled()).thenReturn(false); - try (MockedStatic slingJobUtil = mockStatic(SlingJobUtil.class)) { - fixture.activate(config); - fixture.run(); - slingJobUtil.verifyNoInteractions(); - } + + AtomicReference runTopic = new AtomicReference<>(); + when(contractor.runExclusive(anyString())).then(invocation -> { + runTopic.set(invocation.getArgument(0)); + return null; + }); + + fixture.activate(config); + fixture.run(); + assertNull(runTopic.get()); } @Test void testDeactivate() { - try (MockedStatic slingJobUtil = mockStatic(SlingJobUtil.class)) { - fixture.deactivate(); - slingJobUtil.verify(() -> SlingJobUtil.stopAndRemoveJobs(any(JobManager.class), eq(DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC))); - } + AtomicReference discardTopic = new AtomicReference<>(); + when(contractor.discardAll(anyString())).then(invocation -> { + discardTopic.set(invocation.getArgument(0)); + return null; + }); + + fixture.deactivate(); + assertEquals(DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC, discardTopic.get()); } } \ No newline at end of file diff --git a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/DataFeedServiceImplTest.java b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/DataFeedServiceImplTest.java index 07477e37..dc88d5af 100644 --- a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/DataFeedServiceImplTest.java +++ b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/DataFeedServiceImplTest.java @@ -14,11 +14,12 @@ package com.exadel.etoolbox.linkinspector.core.services.data.impl; +import com.exadel.etoolbox.contractor.service.tasking.Contractor; +import com.exadel.etoolbox.contractor.util.ContractorUtil; import com.exadel.etoolbox.linkinspector.api.LinkResolver; import com.exadel.etoolbox.linkinspector.core.services.cache.GridResourcesCache; import com.exadel.etoolbox.linkinspector.core.services.cache.impl.GridResourcesCacheImpl; import com.exadel.etoolbox.linkinspector.core.services.data.ConfigService; -import com.exadel.etoolbox.linkinspector.core.services.data.GenerationStatsProps; import com.exadel.etoolbox.linkinspector.core.services.data.GridResourcesGenerator; import com.exadel.etoolbox.linkinspector.core.services.data.models.DataFilter; import com.exadel.etoolbox.linkinspector.core.services.data.models.GridResource; @@ -47,8 +48,6 @@ import org.mockito.stubbing.Answer; import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -74,8 +73,6 @@ class DataFeedServiceImplTest { private static final String REPOSITORY_HELPER_FIELD = "repositoryHelper"; private static final String LINK_HELPER_FIELD = "linkHelper"; private static final String CONFIG_FIELD = "configService"; - private static final String CUSTOM_LINK_FIELD = "customLinkResolver"; - private static final String EXTERNAL_LINK_CHECKER_FIELD = "externalLinkChecker"; private static final String DATAFEED_PATH = "/content/etoolbox-link-inspector/data/datafeed.json"; private static final String CSV_REPORT_PATH = "/content/etoolbox-link-inspector/download/report.csv"; @@ -88,7 +85,7 @@ class DataFeedServiceImplTest { private final DataFeedServiceImpl fixture = new DataFeedServiceImpl(); @BeforeEach - void setup() throws NoSuchFieldException, IOException, URISyntaxException { + void setup() throws NoSuchFieldException { PrivateAccessor.setField(fixture, REPOSITORY_HELPER_FIELD, getRepositoryHelperFromContext()); PrivateAccessor.setField(fixture, GRID_RESOURCES_CACHE_FIELD, getGridResourcesCacheFromContext()); GridResourcesGeneratorImpl gridResourcesGenerator = getGridResourcesGenerator(); @@ -173,6 +170,7 @@ void testGenerateCsv_printItemException() { Answer answer = invocationOnMock -> { throw new IOException(); }; + //noinspection unchecked csvUtil.when(() -> CsvUtil.itemsToCsvByteArray(anyCollection(), any(BiConsumer.class), any(String[].class))) .thenCallRealMethod(); csvUtil.when(() -> CsvUtil.wrapIfContainsSemicolon(anyString())) @@ -188,7 +186,7 @@ void testGenerateCsv_printItemException() { } } - private GridResourcesGeneratorImpl getGridResourcesGenerator() throws NoSuchFieldException, IOException, URISyntaxException { + private GridResourcesGeneratorImpl getGridResourcesGenerator() throws NoSuchFieldException { GridResourcesGeneratorImpl gridResourcesGenerator = new GridResourcesGeneratorImpl(); List linkResolvers = Arrays.asList( @@ -199,6 +197,10 @@ private GridResourcesGeneratorImpl getGridResourcesGenerator() throws NoSuchFiel PrivateAccessor.setField(linkHelper, "linkResolvers", linkResolvers); PrivateAccessor.setField(gridResourcesGenerator, LINK_HELPER_FIELD, linkHelper); + Contractor contractor = mock(Contractor.class); + when(contractor.newJobContext(anyString(), anyString())).thenReturn(ContractorUtil.EMPTY_CONTEXT); + PrivateAccessor.setField(gridResourcesGenerator, "contractor", contractor); + ConfigService configService = mock(ConfigServiceImpl.class); when(configService.getExcludedLinksPatterns()).thenReturn(new String[0]); when(configService.getSearchPath()).thenReturn(TEST_FOLDER_PATH); @@ -218,6 +220,7 @@ private RepositoryHelper getRepositoryHelperFromContext() throws NoSuchFieldExce return repositoryHelper; } + @SuppressWarnings("UnstableApiUsage") private GridResourcesCache getGridResourcesCacheFromContext() throws NoSuchFieldException { GridResourcesCache gridResourcesCache = new GridResourcesCacheImpl(); Cache> cache = CacheBuilder.newBuilder() diff --git a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImplTest.java b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImplTest.java index 79184889..ac55897f 100644 --- a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImplTest.java +++ b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/data/impl/GridResourcesGeneratorImplTest.java @@ -22,6 +22,7 @@ import com.exadel.etoolbox.linkinspector.core.services.helpers.RepositoryHelper; import com.exadel.etoolbox.linkinspector.core.services.helpers.impl.LinkHelperImpl; import com.exadel.etoolbox.linkinspector.core.services.helpers.impl.RepositoryHelperImpl; +import com.exadel.etoolbox.linkinspector.core.services.mocks.MockContractor; import com.exadel.etoolbox.linkinspector.core.services.mocks.MockHttpClientBuilderFactory; import com.exadel.etoolbox.linkinspector.core.services.mocks.MockCustomLinkResolver; import com.exadel.etoolbox.linkinspector.core.services.mocks.MockRepositoryHelper; @@ -158,6 +159,7 @@ void setup() { context.registerInjectActivateService(configService); context.registerInjectActivateService(new LinkHelperImpl()); + context.registerInjectActivateService(new MockContractor()); fixture = context.registerInjectActivateService(new GridResourcesGeneratorImpl()); } diff --git a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/mocks/MockContractor.java b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/mocks/MockContractor.java new file mode 100644 index 00000000..9092049f --- /dev/null +++ b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/services/mocks/MockContractor.java @@ -0,0 +1,86 @@ +package com.exadel.etoolbox.linkinspector.core.services.mocks; + +import com.exadel.etoolbox.contractor.entity.Context; +import com.exadel.etoolbox.contractor.entity.ManagedTask; +import com.exadel.etoolbox.contractor.entity.Task; +import com.exadel.etoolbox.contractor.entity.TaskInfo; +import com.exadel.etoolbox.contractor.service.tasking.Contractor; +import com.exadel.etoolbox.contractor.util.ContractorUtil; +import org.apache.sling.event.jobs.Job; +import org.apache.sling.event.jobs.consumer.JobExecutionContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; + +public class MockContractor implements Contractor { + @Override + public Context newContext(@NotNull String s, @NotNull String s1, String s2) { + return ContractorUtil.EMPTY_CONTEXT; + } + + @Override + public Context newJobContext(@NotNull String s, String s1) { + return ContractorUtil.EMPTY_CONTEXT; + } + + @Override + public Context newJobContext(@NotNull Job job, @NotNull JobExecutionContext jobExecutionContext) { + return ContractorUtil.EMPTY_CONTEXT; + } + + @Override + public @Nullable TaskInfo getInfo(@NotNull String id) { + return null; + } + + @Override + public @NotNull List getAllInfo(String s) { + return Collections.emptyList(); + } + + @Override + public @NotNull TaskInfo run(@NotNull String topic) { + return newTaskInfo(topic); + } + + @Override + public @NotNull TaskInfo run(@NotNull Task task, String topic, String title) { + return newTaskInfo(topic); + } + + @Override + public @NotNull TaskInfo run(@NotNull ManagedTask managedTask, String topic, String title) { + return newTaskInfo(topic); + } + + @Override + public @NotNull TaskInfo runExclusive(@NotNull String topic) { + return newTaskInfo(topic); + } + + @Override + public @NotNull TaskInfo runExclusive(@NotNull Task task, @NotNull String topic, String title) { + return newTaskInfo(topic); + } + + @Override + public @NotNull TaskInfo runExclusive(@NotNull ManagedTask managedTask, @NotNull String topic, String title) { + return newTaskInfo(topic); + } + + @Override + public TaskInfo discard(@NotNull String id) { + return TaskInfo.builder().id(id).build(); + } + + @Override + public List discardAll(@NotNull String topic) { + return Collections.emptyList(); + } + + private static TaskInfo newTaskInfo(String topic) { + return TaskInfo.builder().topic(topic).build(); + } +} diff --git a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/servlets/GenerateDataFeedServletTest.java b/core/src/test/java/com/exadel/etoolbox/linkinspector/core/servlets/GenerateDataFeedServletTest.java deleted file mode 100644 index 734d5b2e..00000000 --- a/core/src/test/java/com/exadel/etoolbox/linkinspector/core/servlets/GenerateDataFeedServletTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.exadel.etoolbox.linkinspector.core.servlets; - -import com.exadel.etoolbox.linkinspector.core.services.job.DataFeedJobExecutor; -import com.exadel.etoolbox.linkinspector.core.services.job.SlingJobUtil; -import io.wcm.testing.mock.aem.junit5.AemContextExtension; -import junitx.util.PrivateAccessor; -import org.apache.jackrabbit.api.security.user.Group; -import org.apache.jackrabbit.api.security.user.User; -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.api.SlingHttpServletResponse; -import org.apache.sling.api.resource.ResourceResolver; -import org.apache.sling.event.jobs.JobManager; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.MockedStatic; - -import javax.jcr.RepositoryException; -import java.util.Collections; -import java.util.Iterator; - -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; - -@ExtendWith(AemContextExtension.class) -class GenerateDataFeedServletTest { - private static final String JOB_MANAGER_FIELD = "jobManager"; - - private static final String ADMIN_GROUP_ID = "administrators"; - private static final String TEST_GROUP_ID = "test"; - - private final GenerateDataFeedServlet fixture = new GenerateDataFeedServlet(); - - SlingHttpServletRequest requestMock; - SlingHttpServletResponse responseMock; - ResourceResolver resourceResolverMock; - User userMock; - JobManager jobManager; - - @BeforeEach - void setup() throws NoSuchFieldException { - requestMock = mock(SlingHttpServletRequest.class); - responseMock = mock(SlingHttpServletResponse.class); - resourceResolverMock = mock(ResourceResolver.class); - userMock = mock(User.class); - - jobManager = mock(JobManager.class); - PrivateAccessor.setField(fixture, JOB_MANAGER_FIELD, jobManager); - - when(requestMock.getResourceResolver()).thenReturn(resourceResolverMock); - when(resourceResolverMock.adaptTo(User.class)).thenReturn(userMock); - } - - @Test - void testDoGet_adminUser() { - when(userMock.isAdmin()).thenReturn(true); - - verifySlingJobAdded(); - } - - @Test - void testDoGet_memberOfAdmin() throws RepositoryException { - Group groupMock = mockGroup(); - when(groupMock.getID()).thenReturn(ADMIN_GROUP_ID); - - verifySlingJobAdded(); - } - - @Test - void testDoGet_notAdmin() throws RepositoryException { - Group groupMock = mockGroup(); - when(groupMock.getID()).thenReturn(TEST_GROUP_ID); - - verifySlingJobNotAdded(); - } - - @Test - void testDoGet_repoException() throws RepositoryException { - when(userMock.isAdmin()).thenReturn(false); - when(userMock.memberOf()).thenThrow(new RepositoryException()); - - verifySlingJobNotAdded(); - } - - private Group mockGroup() throws RepositoryException { - Group groupMock = mock(Group.class); - Iterator groups = Collections.singletonList(groupMock).iterator(); - - when(userMock.isAdmin()).thenReturn(false); - when(userMock.memberOf()).thenReturn(groups); - - return groupMock; - } - - private void verifySlingJobAdded() { - try (MockedStatic slingJobUtil = mockStatic(SlingJobUtil.class)) { - fixture.doGet(requestMock, responseMock); - - slingJobUtil.verify(() -> - SlingJobUtil.addJob(any(JobManager.class), eq(DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC), anyMap()) - ); - } - } - - private void verifySlingJobNotAdded() { - try (MockedStatic slingJobUtil = mockStatic(SlingJobUtil.class)) { - fixture.doGet(requestMock, responseMock); - - slingJobUtil.verifyNoInteractions(); - } - } -} \ No newline at end of file diff --git a/core/src/test/resources/OSGI-INF/com.exadel.etoolbox.linkinspector.core.services.mocks.MockContractor.xml b/core/src/test/resources/OSGI-INF/com.exadel.etoolbox.linkinspector.core.services.mocks.MockContractor.xml new file mode 100644 index 00000000..ceab27d4 --- /dev/null +++ b/core/src/test/resources/OSGI-INF/com.exadel.etoolbox.linkinspector.core.services.mocks.MockContractor.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/pom.xml b/pom.xml index a9dcb6b9..2d60130f 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,15 @@ EToolbox Link Inspector + + + etoolbox-contractor@repsy + EToolbox Contractor Repository + https://repsy.io/onestepcloser/maven/etoolbox-contractor + default + + + @@ -208,7 +217,7 @@ Bundle-DocURL: biz.netcentric.aem aem-nodetypes - 6.5.5.0 + 6.5.7.0 @@ -507,6 +516,12 @@ Bundle-DocURL: test + + com.exadel.etoolbox + etoolbox-contractor.core + 1.0.0-SNAPSHOT + provided + org.apache.sling org.apache.sling.api diff --git a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/css/console-ui.less b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/css/console-ui.less index 477f33b3..89c4c813 100644 --- a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/css/console-ui.less +++ b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/css/console-ui.less @@ -12,6 +12,21 @@ * limitations under the License. */ +.elc-report-container { + display: flex; + flex-direction: row; + height: 100%; +} + +.elc-report-stats { + background-color: #fdfdfd; + display: flex; + flex-direction: column; + padding: 0 1rem; + min-width: 150px; + width: 12%; +} + tr.elc-card { .card-page { padding-left: 2.8125rem; @@ -101,14 +116,10 @@ tr.elc-card { color: #FF0000; } -.elc-run-button { - border: none; - background: none !important; - padding: 0 !important; - font-family: arial, sans-serif; - cursor: pointer; - color: blue; - margin: 0 0.5rem; +.elc-download-report-button { + align-self: center; + display: flex; + margin: 1rem 0; } .foundation-collection-selectall { diff --git a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/js/console-ui.run.js b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/js/console-ui.run.js index 9c5b4fa2..4efaf394 100644 --- a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/js/console-ui.run.js +++ b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/clientlibs/link-inspector-ui/js/console-ui.run.js @@ -14,72 +14,35 @@ /** * EToolbox Link Inspector clientlib. - * Job status check and run functionality. + * Logic for running a manual scan */ -(function (document, $) { +(function (window, document, $) { 'use strict'; - const TRIGGER_DATA_FEED_GENERATION = '/content/etoolbox-link-inspector/servlet/triggerDataFeedGeneration'; - const CHECK_JOB_STATUS = '/content/etoolbox-link-inspector/servlet/jobStatus'; + const TRIGGER_DATA_FEED_GENERATION = '/content/etoolbox/contractor/servlet/task'; + const ui = $(window).adaptTo('foundation-ui'); - function jobIsActive() { - let isActive = false; - $.ajax({ - url: CHECK_JOB_STATUS, - type: 'GET', - async: false, - success: function (data) { - isActive = data && data.status && data.status == 'ACTIVE' | 'QUEUED' | 'GIVEN_UP'; - } + Coral.commons.ready($('body'), onReady); + $(document).on('click', '#scan', onScanClicked); + + function onReady() { + $('#wait').on('contractor-ticker:end', function () { + setTimeout(() => window.location.reload(), 1000); }); - return isActive; } - function onRunAction(callback) { + function onScanClicked() { + const formData = new FormData(); + formData.append('topic', 'etoolbox/link-inspector/job/datafeed/generate'); + formData.append('exclusive', 'true'); $.ajax({ url: TRIGGER_DATA_FEED_GENERATION, - type: 'GET', - success: callback + type: 'POST', + data: formData, + processData: false, + contentType: false + }).error(function (e) { + ui.notify('Error', e.responseText || e.statusText, 'error'); }); } - - function createInProgressMessage($popover) { - const $container = $('

').text('Job status: '); - $('...in progress').appendTo($container); - $('
').appendTo($container); - $('scan may take some time to complete').appendTo($container);; - $popover.find('coral-popover-content').append($container); - } - - function createRunJobMessage($popover) { - const $container = $('

'); - $('').appendTo($container); - $popover.find('coral-popover-content').append($container); - } - - function beforeOpenPopover(e) { - jobIsActive() ? createInProgressMessage($(e.currentTarget)) : createRunJobMessage($(e.currentTarget)); - } - - function beforeClosePopover(e) { - removeLastChild($(e.currentTarget)); - } - - function removeLastChild($popover){ - const $popoverContent = $popover.find('coral-popover-content'); - $popoverContent.children().last().remove(); - } - - $(document).on('coral-overlay:beforeopen', '.elc-coral-popover', beforeOpenPopover); - - $(document).on('coral-overlay:beforeclose', '.elc-coral-popover', beforeClosePopover); - - $(document).on('click', '.elc-run-button', function() { - onRunAction(function() { - const $popover = $('.elc-coral-popover'); - removeLastChild($popover); - createInProgressMessage($popover); - }); - }); - -})(document, Granite.$); \ No newline at end of file +})(window, document, Granite.$); \ No newline at end of file diff --git a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsButton/statsButton.html b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsButton/statsButton.html deleted file mode 100644 index fd734f64..00000000 --- a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsButton/statsButton.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - Last Run Details - - - \ No newline at end of file diff --git a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsModal/.content.xml b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsModal/.content.xml deleted file mode 100644 index b3625921..00000000 --- a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsModal/.content.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - \ No newline at end of file diff --git a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsButton/.content.xml b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsPanel/.content.xml similarity index 100% rename from ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsButton/.content.xml rename to ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsPanel/.content.xml diff --git a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsModal/statsModal.html b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsPanel/statsPanel.html similarity index 71% rename from ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsModal/statsModal.html rename to ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsPanel/statsPanel.html index ed483e08..7361177e 100644 --- a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsModal/statsModal.html +++ b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/components/stats/statsPanel/statsPanel.html @@ -1,5 +1,9 @@ - - + + +
+

Report

+ + @@ -15,12 +19,23 @@ - - - + + + + + + Currently no data + +
\ No newline at end of file diff --git a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/options/_rep_policy.xml b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/options/_rep_policy.xml index ecb2b363..e69de29b 100644 --- a/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/options/_rep_policy.xml +++ b/ui.apps/src/main/content/jcr_root/apps/etoolbox-link-inspector/options/_rep_policy.xml @@ -1,21 +0,0 @@ - - - - - \ No newline at end of file diff --git a/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/link-inspector/.content.xml b/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/link-inspector/.content.xml index 33c46a72..59391b3e 100644 --- a/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/link-inspector/.content.xml +++ b/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/link-inspector/.content.xml @@ -102,6 +102,18 @@ sling:resourceType="etoolbox-link-inspector/components/gridDatasource" itemResourceType="etoolbox-link-inspector/components/gridConfig"/> + + @@ -145,6 +157,14 @@ variant="minimal"/> + - - + variant="secondary"/> diff --git a/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/servlet/jobStatus/.content.xml b/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/servlet/jobStatus/.content.xml deleted file mode 100644 index e0baeff6..00000000 --- a/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/servlet/jobStatus/.content.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - \ No newline at end of file diff --git a/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/servlet/jobStatus/_rep_policy.xml b/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/servlet/jobStatus/_rep_policy.xml deleted file mode 100644 index ecb2b363..00000000 --- a/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/servlet/jobStatus/_rep_policy.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - \ No newline at end of file diff --git a/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/servlet/triggerDataFeedGeneration/.content.xml b/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/servlet/triggerDataFeedGeneration/.content.xml deleted file mode 100644 index 5cfe548f..00000000 --- a/ui.content/src/main/content/jcr_root/content/etoolbox-link-inspector/servlet/triggerDataFeedGeneration/.content.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - \ No newline at end of file