Skip to content

Commit

Permalink
feat: Added the ability to select a BaselineCollection for bulk export
Browse files Browse the repository at this point in the history
Refs: #285
  • Loading branch information
pbezliapovich committed Dec 3, 2024
1 parent 9519d7b commit 9feeed2
Show file tree
Hide file tree
Showing 16 changed files with 299 additions and 86 deletions.
67 changes: 55 additions & 12 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 @@ -1616,13 +1671,6 @@
},
"type": "array"
},
"collectionId" : {
"type" : "string",
"description" : "The unique identifier for the collection"
},
"coverPage" : {
"type" : "string",
"description" : "Cover page settings name"
"coverPage": {
"description": "Cover page settings name",
"type": "string"
Expand All @@ -1644,11 +1692,6 @@
"description": "Local Polarion URLs should be removed from the document",
"type": "boolean"
},
"documentType" : {
"type" : "string",
"description" : "Type of the document",
"enum" : [ "LIVE_DOC", "LIVE_REPORT", "TEST_RUN", "WIKI_PAGE", "BASELINE_COLLECTION" ],
"example" : "LIVE_DOC"
"documentType": {
"description": "Type of the document",
"enum": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ 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);
case BASELINE_COLLECTION -> documentDataHelper.getBaselineCollection(Objects.requireNonNull(project), exportParams);
};
}

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,46 @@
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 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}")
@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 pdfExporterPolarionService.getCollectionItems(projectId, collectionId);
}
}
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 @@ -15,10 +15,7 @@ public enum DocumentType {
TEST_RUN,

@Schema(description = "Wiki page")
WIKI_PAGE,

@Schema(description = "Collection")
BASELINE_COLLECTION;
WIKI_PAGE;

@SuppressWarnings("unused")
@JsonCreator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ public class ExportParams {
@Schema(description = "Internal content")
private String internalContent;

@Schema(description = "The unique identifier for the collection")
private String collectionId;

public @NotNull DocumentType getDocumentType() {
if (documentType == null) {
documentType = DocumentType.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.TransactionalExecutor;
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 Down Expand Up @@ -115,7 +120,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");
for (IModule suitableDocument : suitableDocuments) {
if (sameDocument(projectId, spaceId, documentName, suitableDocument)) {
return true;
Expand Down Expand Up @@ -165,4 +170,23 @@ private boolean sameDocument(@Nullable String projectId, @NotNull String spaceId
}
return testRunAttachment;
}

public @NotNull List<CollectionItem> getCollectionItems(@NotNull String projectId, @NotNull String collectionId) {
List<CollectionItem> collectionItemList = new ArrayList<>();
TransactionalExecutor.executeSafelyInReadOnlyTransaction(transaction -> {
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 -> {
collectionItemList.add(new CollectionItem(module.getModuleNameWithSpace().replaceFirst("\\s*/\\s*", "/"), module.getLastRevision()));
});

return null;
});
return collectionItemList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,6 @@ public DocumentData<ITestRun> getTestRun(@NotNull ITrackerProject project, @NotN
});
}

public DocumentData<IBaselineCollection> getBaselineCollection(@NotNull ITrackerProject project, @NotNull ExportParams exportParams) {
return TransactionalExecutor.executeSafelyInReadOnlyTransaction(transaction -> {

String projectId = project.getId();
String collectionId = exportParams.getCollectionId();
if (projectId == null || collectionId == null) {
throw new IllegalArgumentException("Project id and collection id are required for export");
}

IBaselineCollection collection = new BaselineCollectionReference(projectId, collectionId).get(transaction).getOldApi();

return DocumentData.builder(DocumentType.BASELINE_COLLECTION, collection)
.projectName(project.getName())
.lastRevision(collection.getLastRevision())
.baselineName(getRevisionBaseline(projectId, collection, exportParams.getRevision()))
.id(collectionId)
.title(collection.getName())
.content(null)
.build();
});
}


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,7 +50,6 @@ 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);
case BASELINE_COLLECTION -> documentDataHelper.getBaselineCollection(project, exportParams);
};

FileNameTemplateModel fileNameTemplateModel = getFileNameTemplateModel(ScopeUtils.getScopeFromProject(exportParams.getProjectId()));
Expand Down Expand Up @@ -81,8 +80,6 @@ public String getDocumentFileName(@NotNull ExportParams exportParams) {
yield fileNameTemplateModel.getTestRunNameTemplate();
case WIKI_PAGE:
yield fileNameTemplateModel.getWikiNameTemplate();
case BASELINE_COLLECTION:
yield "Test";
};
}

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

// ----
Expand All @@ -219,7 +217,6 @@ 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;
case BASELINE_COLLECTION -> null;
};

if (exportParams.isEnableCommentsRendering()) {
Expand Down
Loading

0 comments on commit 9feeed2

Please sign in to comment.