diff --git a/pantheon-bundle/frontend/src/app/BulkOperationPublish.tsx b/pantheon-bundle/frontend/src/app/BulkOperationPublish.tsx index 7e3cf9cbf..0b18d2c33 100644 --- a/pantheon-bundle/frontend/src/app/BulkOperationPublish.tsx +++ b/pantheon-bundle/frontend/src/app/BulkOperationPublish.tsx @@ -203,32 +203,19 @@ class BulkOperationPublish extends React.Component { - if (response.status === 201 || response.status === 200) { - this.setState({ - documentsSucceeded: [...this.state.documentsSucceeded, modulePath], - bulkUpdateSuccess: this.state.bulkUpdateSuccess + 1, - }, () => { - this.calculateSuccessProgress(this.state.bulkUpdateSuccess) - } - ) + } else { + Utils.draftExist(backend).then((exist) => { + if (exist) { + this.processDocuments(modulePath, formData, hdrs) } else { - this.setState({ bulkUpdateFailure: this.state.bulkUpdateFailure + 1, documentsFailed: [...this.state.documentsFailed, modulePath] }, () => { - this.calculateFailureProgress(this.state.bulkUpdateFailure) + this.setState({ bulkUpdateWarning: this.state.bulkUpdateWarning + 1, documentsIgnored: [...this.state.documentsIgnored, modulePath] }, () => { + this.calculateWarningProgress(this.state.bulkUpdateWarning) }) } }) - } else { - this.setState({ bulkUpdateWarning: this.state.bulkUpdateWarning + 1, documentsIgnored: [...this.state.documentsIgnored, modulePath] }, () => { - this.calculateWarningProgress(this.state.bulkUpdateWarning) - }) } } @@ -290,5 +277,27 @@ class BulkOperationPublish extends React.Component { + fetch("/content" + modulePath, { + body: formData, + method: "post", + headers: hdrs + }).then(response => { + if (response.status === 201 || response.status === 200) { + this.setState({ + documentsSucceeded: [...this.state.documentsSucceeded, modulePath], + bulkUpdateSuccess: this.state.bulkUpdateSuccess + 1, + }, () => { + this.calculateSuccessProgress(this.state.bulkUpdateSuccess) + } + ) + } else { + this.setState({ bulkUpdateFailure: this.state.bulkUpdateFailure + 1, documentsFailed: [...this.state.documentsFailed, modulePath] }, () => { + this.calculateFailureProgress(this.state.bulkUpdateFailure) + }) + } + }) + } } export { BulkOperationPublish } \ No newline at end of file diff --git a/pantheon-bundle/frontend/src/app/Utils.tsx b/pantheon-bundle/frontend/src/app/Utils.tsx index ee389f1c2..c5036e8d5 100644 --- a/pantheon-bundle/frontend/src/app/Utils.tsx +++ b/pantheon-bundle/frontend/src/app/Utils.tsx @@ -1,5 +1,7 @@ +import { resolve } from "path" + export class Utils { - + /** * fetchHelper * @param endpoint: string @@ -7,15 +9,15 @@ export class Utils { */ static fetchHelper = (endpoint: string, options: object) => { - + if (options !== null) { return fetch(endpoint, options) - .then(Utils.handleErrors) - .then(response => response.json()) + .then(Utils.handleErrors) + .then(response => response.json()) } else { return fetch(endpoint) - .then(Utils.handleErrors) - .then(response => response.json()) + .then(Utils.handleErrors) + .then(response => response.json()) } } @@ -51,4 +53,3 @@ export class Utils { }) } } - \ No newline at end of file diff --git a/pantheon-bundle/frontend/src/app/bulkOperationMetadata.tsx b/pantheon-bundle/frontend/src/app/bulkOperationMetadata.tsx index 0ee0a11f8..6b8c8bf72 100644 --- a/pantheon-bundle/frontend/src/app/bulkOperationMetadata.tsx +++ b/pantheon-bundle/frontend/src/app/bulkOperationMetadata.tsx @@ -61,7 +61,9 @@ class BulkOperationMetadata extends React.Component urlList = new ArrayList<>(); + HashMap> xrefTargetsMap = new HashMap<>(); + if (!documentVariant.getPath().startsWith("/content/docs/")) { content = preprocessWithPattern(content, XREF_PATTERN, urlList); content = preprocessWithPattern(content, TRIANGLE_PATTERN, urlList); } - XrefValidationHelper.getInstance().setObjectsToValidate(urlList); + + if (!urlList.isEmpty()) { + xrefTargetsMap.put(documentVariant.uuid().get(), (ArrayList) urlList); + XrefValidationHelper.setObjectsToValidate(xrefTargetsMap); + } + return content; } diff --git a/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/DocumentVariantRenderServlet.java b/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/DocumentVariantRenderServlet.java index 3d81c745e..97884c632 100644 --- a/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/DocumentVariantRenderServlet.java +++ b/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/DocumentVariantRenderServlet.java @@ -50,6 +50,7 @@ public class DocumentVariantRenderServlet extends SlingSafeMethodsServlet { private final Logger log = LoggerFactory.getLogger(DocumentVariantRenderServlet.class); private AsciidoctorService asciidoctorService; + private XrefValidationHelper xrefValidationHelper; @Activate public DocumentVariantRenderServlet( @@ -94,7 +95,7 @@ protected void doGet(SlingHttpServletRequest request, // only allow forced rerendering if this is a draft version. Released and historical revs are written in stone. boolean draft = latest && variant.hasDraft(); - XrefValidationHelper.getInstance().initList(); + XrefValidationHelper.initList(); String html = asciidoctorService.getDocumentHtml( variant.getParentLocale().getParent(), LocaleUtils.toLocale(variant.getParentLocale().getName()), diff --git a/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/PublishDraftVersion.java b/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/PublishDraftVersion.java index 2e2902e8d..ccadc108b 100644 --- a/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/PublishDraftVersion.java +++ b/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/PublishDraftVersion.java @@ -87,6 +87,7 @@ public void run(SlingHttpServletRequest request, PostResponse response, SlingPos return; } long startTime = System.currentTimeMillis(); + XrefValidationHelper.initList(); super.run(request, response, processors); try { if (response.getError() == null) { @@ -101,13 +102,12 @@ public void run(SlingHttpServletRequest request, PostResponse response, SlingPos .released().get(); // Regenerate the document once more - XrefValidationHelper.getInstance().initList(); asciidoctorService.getDocumentHtml(document, locale, variant, false, new HashMap(),true); events.fireEvent(new DocumentVersionPublishedEvent(documentVersion), 15); ServletUtils.getCustomerPortalUrl(request, response); } }catch (RepositoryException ex){ - logger.error("An error has occured ", ex.getMessage()); + logger.error("An error has occurred ", ex.getMessage()); } log.debug("Operation Publishing draft version, completed"); long elapseTime = System.currentTimeMillis() - startTime; diff --git a/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/util/VersionUploadOperation.java b/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/util/VersionUploadOperation.java index b1f5d0707..59b9e452a 100644 --- a/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/util/VersionUploadOperation.java +++ b/pantheon-bundle/src/main/java/com/redhat/pantheon/servlet/util/VersionUploadOperation.java @@ -127,7 +127,7 @@ protected void versionUpload(SlingHttpServletRequest request, resolver.commit(); Map context = asciidoctorService.buildContextFromRequest(request); - XrefValidationHelper.getInstance().initList(); + XrefValidationHelper.initList(); asciidoctorService.getDocumentHtml(document, localeObj, document.getWorkspace().getCanonicalVariantName(), true, context, true); diff --git a/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/helper/ValidationHelper.java b/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/helper/ValidationHelper.java index 5fbb48fb6..98b53a53a 100644 --- a/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/helper/ValidationHelper.java +++ b/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/helper/ValidationHelper.java @@ -8,6 +8,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.HashMap; import java.util.Optional; /** @@ -17,26 +19,32 @@ public class ValidationHelper { Logger logger = LoggerFactory.getLogger(ValidationHelper.class); public void createXrefValidationNode(DocumentVersion documentVersion, String content) throws PersistenceException { Violations violations = new XrefValidator(documentVersion.getParent(), content).validate(); - Validations validations = documentVersion.validations().getOrCreate(); - if(null != validations.validationType(PantheonConstants.TYPE_XREF).get()){ - try { - validations.validationType(PantheonConstants.TYPE_XREF).get().delete(); - } catch (Exception e) { - logger.error("error while validation node creation",e); - } - } + // Get xrefTargetMap + HashMap> xrefTargetsMap = XrefValidationHelper.getObjectsToValidate(); - if(violations.hasViolations()) { - Validation validation; - ErrorDetails errorDetails = violations.get(PantheonConstants.TYPE_XREF); - if(null == errorDetails || errorDetails.length() ==0){ - return; + if (xrefTargetsMap != null && xrefTargetsMap.containsKey(documentVersion.getParent().uuid().get())) { + Validations validations = documentVersion.validations().getOrCreate(); + if(null != validations.validationType(PantheonConstants.TYPE_XREF).get()){ + try { + validations.validationType(PantheonConstants.TYPE_XREF).get().delete(); + } catch (Exception e) { + logger.error("error while validation node creation",e); + } } - ValidationType validationType = validations.validationType(PantheonConstants.TYPE_XREF).getOrCreate(); - for(int ind=0; ind< errorDetails.length();ind++) { - validation = validationType.page(ind+1).getOrCreate(); - validation.setValidation(violations, ind); + + if(violations.hasViolations()) { + Validation validation; + ErrorDetails errorDetails = violations.get(PantheonConstants.TYPE_XREF); + if(null == errorDetails || errorDetails.length() ==0){ + return; + } + ValidationType validationType = validations.validationType(PantheonConstants.TYPE_XREF).getOrCreate(); + for(int ind=0; ind< errorDetails.length();ind++) { + validation = validationType.page(ind+1).getOrCreate(); + validation.setValidation(violations, ind); + } } } + } } \ No newline at end of file diff --git a/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/helper/XrefValidationHelper.java b/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/helper/XrefValidationHelper.java index bd9836854..bc0319edc 100644 --- a/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/helper/XrefValidationHelper.java +++ b/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/helper/XrefValidationHelper.java @@ -2,36 +2,25 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.List; -import java.util.Map; public class XrefValidationHelper { - private List xRefs; + private static HashMap> xRefs; - private XrefValidationHelper() { + public XrefValidationHelper() { + xRefs = new HashMap>(); } - private static class SingletonHelper{ - private static final XrefValidationHelper INSTANCE = new XrefValidationHelper(); - } - - public static XrefValidationHelper getInstance(){ - return SingletonHelper.INSTANCE; - } - public List getObjectsToValidate() { + public static HashMap> getObjectsToValidate() { return xRefs; } - public void initList() { - xRefs = new ArrayList<>(); + public static void initList() { + XrefValidationHelper.xRefs = new HashMap>(); } - public void setObjectsToValidate(List objectsToValidate) { - if(null == xRefs || objectsToValidate.isEmpty()){ - return; - } - xRefs.addAll(objectsToValidate); + public static void setObjectsToValidate(HashMap> objectsToValidate) { + XrefValidationHelper.xRefs = objectsToValidate; } } diff --git a/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/validators/XrefValidator.java b/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/validators/XrefValidator.java index 9834e77d3..9e571dde1 100644 --- a/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/validators/XrefValidator.java +++ b/pantheon-bundle/src/main/java/com/redhat/pantheon/validation/validators/XrefValidator.java @@ -5,17 +5,18 @@ import com.redhat.pantheon.validation.helper.XrefValidationHelper; import com.redhat.pantheon.validation.model.ErrorDetails; import com.redhat.pantheon.validation.model.Violations; -import org.apache.sling.api.resource.Resource; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; -import org.jsoup.select.Elements; import org.osgi.framework.Constants; import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.jcr.RepositoryException; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * This is a sample validator that @@ -56,7 +57,7 @@ public Violations validate() { private Violations checkIfXrefValid(Violations violations) { return violations.add(PantheonConstants.TYPE_XREF, - checkXref()); + checkXref(XrefValidationHelper.getObjectsToValidate())); } /** @@ -64,25 +65,28 @@ private Violations checkIfXrefValid(Violations violations) { * * @return */ - private ErrorDetails checkXref() { + private ErrorDetails checkXref(HashMap> xrefTargets) { ErrorDetails errorDetails = new ErrorDetails(); try { - List xrefTargets = XrefValidationHelper.getInstance().getObjectsToValidate(); - if(null == xrefTargets || xrefTargets.size()==0){ + if (null == xrefTargets || xrefTargets.size() == 0) { return errorDetails; } - for (String xref : xrefTargets) { - if(!xref.endsWith(".adoc")) { - if(validateIfAnchor(content,xref)<1){ // If it is anchor, it has not yet validated, - errorDetails.add(xref); + for (Map.Entry mapElement : xrefTargets.entrySet()) { + ArrayList targetList = (ArrayList) mapElement.getValue(); + + for (String xref : targetList) { + if (!xref.endsWith(".adoc")) { + if (validateIfAnchor(content, xref) < 1) { // If it is anchor, it has not yet validated, + errorDetails.add(xref); + } + } else { + errorDetails.add(xref); // if it is a adoc file, it's already processed and validated } - }else { - errorDetails.add(xref); // if it is a adoc file, it's already processed and validated } } } catch (Exception ex){ - log.error("error at validation occured",ex); + log.error("error at validation occurred",ex); } return errorDetails; }