Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ability to select a BaselineCollection for bulk export #301

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
42939a7
feat: Added the ability to select a BaselineCollection for bulk export
pbezliapovich Nov 21, 2024
e4e9c5f
feat: Export PDF-attachments in addition
grigoriev Nov 27, 2024
7556d2c
Merge branch 'main' into 289-export-pdf-attachments-in-addition
grigoriev Nov 28, 2024
6b40eb8
feat: Export PDF-attachments in addition
grigoriev Nov 28, 2024
9519d7b
Merge remote-tracking branch 'refs/remotes/origin/289-export-pdf-atta…
pbezliapovich Nov 29, 2024
9feeed2
feat: Added the ability to select a BaselineCollection for bulk export
pbezliapovich Dec 3, 2024
c9181c5
feat: Added the ability to select a BaselineCollection for bulk export
pbezliapovich Dec 3, 2024
658925b
chore: resolved merge conflict
pbezliapovich Dec 3, 2024
8ee9203
chore: added tests
pbezliapovich Dec 3, 2024
e937b3a
chore: fixed security hotspot
pbezliapovich Dec 3, 2024
a8a7359
chore: resolved merge conflicts
pbezliapovich Dec 3, 2024
8ab827c
chore: added tests
pbezliapovich Dec 3, 2024
b786fac
chore: fixed sonar issues
pbezliapovich Dec 4, 2024
a8eec84
chore: refactoring after code review
pbezliapovich Dec 4, 2024
c505911
chore: fixed sonar issues
pbezliapovich Dec 4, 2024
e490379
chore: refactoring after code review
pbezliapovich Dec 4, 2024
a709b9e
chore: refactoring after code review
pbezliapovich Dec 4, 2024
db943d7
feat: Bulk-export should support Collections
grigoriev Dec 4, 2024
c3086c3
feat: Bulk-export should support Collections
grigoriev Dec 4, 2024
c47597f
chore: refactoring after code review
pbezliapovich Dec 4, 2024
d67d98c
Merge remote-tracking branch 'origin/285-bulk-export-should-support-c…
pbezliapovich Dec 4, 2024
09229a4
feat: Bulk-export should support Collections
grigoriev Dec 4, 2024
65e4ed5
feat: Bulk-export should support Collections
grigoriev Dec 4, 2024
9a7d9d8
feat: Bulk-export should support Collections
grigoriev Dec 4, 2024
ca3718c
chore: refactoring after code review
pbezliapovich Dec 4, 2024
9f8f9e8
Merge remote-tracking branch 'origin/285-bulk-export-should-support-c…
pbezliapovich Dec 4, 2024
8e96e6a
feat: Bulk-export should support Collections
grigoriev Dec 4, 2024
52890c5
feat: Bulk-export should support Collections
grigoriev Dec 4, 2024
99e3786
chore: refactoring after code review
pbezliapovich Dec 4, 2024
b3f26db
chore: refactoring after code review
pbezliapovich Dec 4, 2024
bd3e7f5
feat: Bulk-export should support Collections
grigoriev Dec 4, 2024
18c7a76
chore: added tests
pbezliapovich Dec 4, 2024
c00c4d0
chore: fixed sonar issues
pbezliapovich Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,47 @@
]
}
},
"/api/projects/{projectId}/collections/{collectionId}": {
"get": {
"operationId": "getCollectionItems",
"parameters": [
{
"description": "Project ID",
"in": "path",
"name": "projectId",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "Collection ID",
"in": "path",
"name": "collectionId",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CollectionItem"
}
}
},
"description": "List of collection item"
}
},
"summary": "Get items from collection",
"tags": [
"Collections"
]
}
},
"/api/projects/{projectId}/name": {
"get": {
"operationId": "getProjectName",
Expand Down Expand Up @@ -1504,6 +1545,20 @@
},
"type": "object"
},
"CollectionItem": {
"description": "Details about the collection item",
"properties": {
"moduleNameWithSpace": {
"description": "The name of the module with spaces",
"type": "string"
},
"revision": {
"description": "The revision of the module",
"type": "string"
}
},
"type": "object"
},
"ConfigurationStatus": {
"properties": {
"details": {
Expand Down Expand Up @@ -1640,6 +1695,7 @@
"documentType": {
"description": "Type of the document",
"enum": [
"BASELINE_COLLECTION",
"LIVE_DOC",
"LIVE_REPORT",
"TEST_RUN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public byte[] convertToPdf(@NotNull ExportParams exportParams, @Nullable ExportM
case LIVE_REPORT -> documentDataHelper.getLiveReport(project, exportParams);
case TEST_RUN -> documentDataHelper.getTestRun(Objects.requireNonNull(project), exportParams);
case WIKI_PAGE -> documentDataHelper.getWikiPage(project, exportParams);
default -> throw new IllegalArgumentException("Unknown document type: " + exportParams.getDocumentType());
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import ch.sbb.polarion.extension.generic.rest.GenericRestApplication;
import ch.sbb.polarion.extension.generic.settings.NamedSettingsRegistry;
import ch.sbb.polarion.extension.pdf_exporter.converter.PdfConverterJobsCleaner;
import ch.sbb.polarion.extension.pdf_exporter.rest.controller.CollectionApiController;
import ch.sbb.polarion.extension.pdf_exporter.rest.controller.CollectionInternalController;
import ch.sbb.polarion.extension.pdf_exporter.rest.controller.ConverterApiController;
import ch.sbb.polarion.extension.pdf_exporter.rest.controller.ConverterInternalController;
import ch.sbb.polarion.extension.pdf_exporter.rest.controller.SettingsApiController;
Expand Down Expand Up @@ -68,6 +70,8 @@ public PdfExporterRestApplication() {
new SettingsInternalController(),
new TestRunAttachmentsApiController(),
new TestRunAttachmentsInternalController(),
new CollectionApiController(),
new CollectionInternalController(),
new UtilityResourcesApiController(),
new UtilityResourcesInternalController()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ch.sbb.polarion.extension.pdf_exporter.rest.controller;

import ch.sbb.polarion.extension.generic.rest.filter.Secured;
import ch.sbb.polarion.extension.generic.service.PolarionService;
import ch.sbb.polarion.extension.pdf_exporter.rest.model.collections.CollectionItem;

import javax.ws.rs.Path;
import java.util.List;

@Secured
@Path("/api")
public class CollectionApiController extends CollectionInternalController {
private static final PolarionService polarionService = new PolarionService();

@Override
public List<CollectionItem> getCollectionItems(String projectId, String collectionId) {
return polarionService.callPrivileged(() -> super.getCollectionItems(projectId, collectionId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ch.sbb.polarion.extension.pdf_exporter.rest.controller;


import ch.sbb.polarion.extension.pdf_exporter.rest.model.collections.CollectionItem;
import ch.sbb.polarion.extension.pdf_exporter.service.PdfExporterPolarionService;
import com.polarion.alm.shared.api.transaction.TransactionalExecutor;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

@Hidden
@Path("/internal")
@Tag(name = "Collections")
public class CollectionInternalController {
private final PdfExporterPolarionService pdfExporterPolarionService;

public CollectionInternalController() {
pdfExporterPolarionService = new PdfExporterPolarionService();
}

@GET
@Path("/projects/{projectId}/collections/{collectionId}")
pbezliapovich marked this conversation as resolved.
Show resolved Hide resolved
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Get items from collection",
responses = {
@ApiResponse(responseCode = "200",
description = "List of collection item",
content = @Content(schema = @Schema(implementation = CollectionItem.class))
)
}
)
public List<CollectionItem> getCollectionItems(@Parameter(description = "Project ID", required = true) @PathParam("projectId") String projectId,
@Parameter(description = "Collection ID", required = true) @PathParam("collectionId") String collectionId) {
return TransactionalExecutor.executeSafelyInReadOnlyTransaction(transaction -> pdfExporterPolarionService.getCollectionItems(projectId, collectionId, transaction));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ch.sbb.polarion.extension.pdf_exporter.rest.model.collections;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "Details about the collection item")
public class CollectionItem {
@Schema(description = "The name of the module with spaces")
private String moduleNameWithSpace;

@Schema(description = "The revision of the module")
private String revision;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

@Schema(description = "Type of the document")
public enum DocumentType {
@Schema(description = "Baseline collection")
BASELINE_COLLECTION,

@Schema(description = "Live document")
LIVE_DOC,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@
import ch.sbb.polarion.extension.generic.settings.SettingName;
import ch.sbb.polarion.extension.generic.util.ScopeUtils;
import ch.sbb.polarion.extension.pdf_exporter.rest.model.attachments.TestRunAttachment;
import ch.sbb.polarion.extension.pdf_exporter.rest.model.collections.CollectionItem;
import ch.sbb.polarion.extension.pdf_exporter.rest.model.settings.stylepackage.StylePackageModel;
import ch.sbb.polarion.extension.pdf_exporter.rest.model.settings.stylepackage.StylePackageWeightInfo;
import ch.sbb.polarion.extension.pdf_exporter.settings.StylePackageSettings;
import ch.sbb.polarion.extension.pdf_exporter.util.WildcardUtils;
import com.polarion.alm.projects.IProjectService;
import com.polarion.alm.shared.api.model.baselinecollection.BaselineCollectionReference;
import com.polarion.alm.shared.api.transaction.ReadOnlyTransaction;
import com.polarion.alm.tracker.ITestManagementService;
import com.polarion.alm.tracker.ITrackerService;
import com.polarion.alm.tracker.model.IModule;
import com.polarion.alm.tracker.model.ITestRun;
import com.polarion.alm.tracker.model.ITestRunAttachment;
import com.polarion.alm.tracker.model.ITrackerProject;
import com.polarion.alm.tracker.model.baselinecollection.IBaselineCollection;
import com.polarion.alm.tracker.model.baselinecollection.IBaselineCollectionElement;
import com.polarion.core.util.StringUtils;
import com.polarion.platform.IPlatformService;
import com.polarion.platform.persistence.IDataService;
Expand All @@ -28,11 +33,13 @@
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class PdfExporterPolarionService extends PolarionService {

Expand Down Expand Up @@ -115,7 +122,7 @@ private boolean isStylePackageSuitable(@Nullable String projectId, @NotNull Stri
return true;
} else {
IDataService dataService = getTrackerService().getDataService();
IPObjectList<IModule> suitableDocuments = dataService.searchInstances(dataService.getPrototype("Module"), model.getMatchingQuery(), "name");
IPObjectList<IModule> suitableDocuments = dataService.searchInstances(dataService.getPrototype("Module"), model.getMatchingQuery(), "name");
pbezliapovich marked this conversation as resolved.
Show resolved Hide resolved
for (IModule suitableDocument : suitableDocuments) {
if (sameDocument(projectId, spaceId, documentName, suitableDocument)) {
return true;
Expand Down Expand Up @@ -165,4 +172,21 @@ private boolean sameDocument(@Nullable String projectId, @NotNull String spaceId
}
return testRunAttachment;
}

public @NotNull List<CollectionItem> getCollectionItems(@NotNull String projectId, @NotNull String collectionId, @NotNull ReadOnlyTransaction transaction) {
List<CollectionItem> collectionItemList = new ArrayList<>();
IBaselineCollection collection = new BaselineCollectionReference(projectId, collectionId).get(transaction).getOldApi();
collection.getElements()
.stream()
.map(IBaselineCollectionElement::getObjectWithRevision)
.filter(IModule.class::isInstance)
.map(IModule.class::cast)
.forEach(module -> {
String moduleNameWithSpace = Arrays.stream(module.getModuleNameWithSpace().split("/"))
.map(String::trim)
.collect(Collectors.joining("/"));
collectionItemList.add(new CollectionItem(moduleNameWithSpace, module.getLastRevision()));
});
return collectionItemList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public DocumentData<ITestRun> getTestRun(@NotNull ITrackerProject project, @NotN
});
}


public DocumentData<IWikiPage> getWikiPage(@Nullable ITrackerProject project, @NotNull ExportParams exportParams) {
return getWikiPage(project, exportParams, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public String getDocumentFileName(@NotNull ExportParams exportParams) {
case LIVE_REPORT -> documentDataHelper.getLiveReport(project, exportParams, false);
case TEST_RUN -> documentDataHelper.getTestRun(project, exportParams, false);
case WIKI_PAGE -> documentDataHelper.getWikiPage(project, exportParams, false);
default -> throw new IllegalArgumentException("Unknown document type: " + exportParams.getDocumentType());
};

FileNameTemplateModel fileNameTemplateModel = getFileNameTemplateModel(ScopeUtils.getScopeFromProject(exportParams.getProjectId()));
Expand Down Expand Up @@ -80,6 +81,7 @@ public String getDocumentFileName(@NotNull ExportParams exportParams) {
yield fileNameTemplateModel.getTestRunNameTemplate();
case WIKI_PAGE:
yield fileNameTemplateModel.getWikiNameTemplate();
default: throw new IllegalArgumentException("Unknown document type: " + documentType);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public String processHtmlForPDF(@NotNull String html, @NotNull ExportParams expo
processingHtml = adjustColumnWidthInReports(processingHtml);
yield removeFloatLeftFromReports(processingHtml);
}
default -> throw new IllegalArgumentException("Unknown document type: " + exportParams.getDocumentType());
};
html = replaceResourcesAsBase64Encoded(html);
html = MediaUtils.removeSvgUnsupportedFeatureHint(html); //note that there is one more replacement attempt before replacing images with base64 representation
Expand All @@ -196,6 +197,7 @@ public String processHtmlForPDF(@NotNull String html, @NotNull ExportParams expo
yield new NumberedListsSanitizer().fixNumberedLists(processingHtml);
}
case LIVE_REPORT, TEST_RUN -> html;
default -> throw new IllegalArgumentException("Unknown document type: " + exportParams.getDocumentType());
};

// ----
Expand All @@ -217,6 +219,7 @@ public String processHtmlForPDF(@NotNull String html, @NotNull ExportParams expo
html = switch (exportParams.getDocumentType()) {
case LIVE_DOC, WIKI_PAGE -> localizeEnums(html, exportParams);
case LIVE_REPORT, TEST_RUN -> html;
default -> throw new IllegalArgumentException("Unknown document type: " + exportParams.getDocumentType());
};

if (exportParams.isEnableCommentsRendering()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ReadOnlyStrictMap<String, RichPageParameter> getParametersDefinition(@Not
FieldsParameter columns = parameterFactory.fields(localization.getString("richpages.widget.table.columns")).build();
SortingParameter sortBy = parameterFactory.sorting(localization.getString("richpages.widget.table.sortBy")).build();
DataSetParameter dataSet = parameterFactory.dataSet(localization.getString("richpages.widget.table.dataSet"))
.allowedPrototypes(PrototypeEnum.Document, PrototypeEnum.TestRun, PrototypeEnum.RichPage)
.allowedPrototypes(PrototypeEnum.Document, PrototypeEnum.TestRun, PrototypeEnum.RichPage, PrototypeEnum.BaselineCollection)
.add("columns", columns)
.add("sortBy", sortBy)
.dependencySource(true)
Expand Down
Loading
Loading