Skip to content

Commit

Permalink
chore: fixed security hotspot
Browse files Browse the repository at this point in the history
Refs: #285
  • Loading branch information
pbezliapovich committed Dec 3, 2024
1 parent 8ee9203 commit e937b3a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,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 @@ -173,15 +175,18 @@ private boolean sameDocument(@Nullable String projectId, @NotNull String spaceId

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 -> {
collectionItemList.add(new CollectionItem(module.getModuleNameWithSpace().replaceFirst("\\s*/\\s*", "/"), module.getLastRevision()));
});
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 @@ -249,10 +249,10 @@ void testGetCollectionItems() {
IModule mockModule1 = mock(IModule.class);
IModule mockModule2 = mock(IModule.class);

when(mockModule1.getModuleNameWithSpace()).thenReturn("space1/Module1");
when(mockModule1.getModuleNameWithSpace()).thenReturn("space1 / Module1 test");
when(mockModule1.getLastRevision()).thenReturn("1");

when(mockModule2.getModuleNameWithSpace()).thenReturn("space2/Module2");
when(mockModule2.getModuleNameWithSpace()).thenReturn("space2 / Module2 test");
when(mockModule2.getLastRevision()).thenReturn("2");

IBaselineCollectionElement mockElement1 = mock(IBaselineCollectionElement.class);
Expand All @@ -273,10 +273,10 @@ void testGetCollectionItems() {

assertNotNull(result);
assertEquals(2, result.size());
assertEquals("space1/Module1", result.get(0).getModuleNameWithSpace());
assertEquals("space1/Module1 test", result.get(0).getModuleNameWithSpace());
assertEquals("1", result.get(0).getRevision());

assertEquals("space2/Module2", result.get(1).getModuleNameWithSpace());
assertEquals("space2/Module2 test", result.get(1).getModuleNameWithSpace());
assertEquals("2", result.get(1).getRevision());
}
}
Expand Down

0 comments on commit e937b3a

Please sign in to comment.