Skip to content

Commit

Permalink
Managing link roles by link name not ids anymore based on current TS …
Browse files Browse the repository at this point in the history
…implementation
  • Loading branch information
bcdasilv committed Nov 6, 2023
1 parent 0592167 commit f32b29d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
public class FieldUpdatesCollector {

/**
* If empty, no work item links should be included. We expect role IDs (not role names). Invalid
* (not recognized) link role IDs will be ignored. If all link roles are invalid, the request will
* be processed as if no linkRoles were requested (as if this field was empty).
* If empty, no work item links should be included. For the values, we expect role names since
* this is the format utilized in the Teamscale configuration. Invalid (not recognized) link role
* names will be ignored at {@link WorkItemUpdatesServlet}. If all link roles are invalid, the
* request will be processed as if no linkRoles were requested (as if this field was empty).
*/
private final String[] includeLinkRoles;

Expand Down Expand Up @@ -203,9 +204,9 @@ private void createLinkFieldChange(
ILinkedWorkItemStruct linkStruct,
boolean isAdded) {

if (Arrays.stream(includeLinkRoles).anyMatch(linkRole.getId()::equals)) {
if (Arrays.stream(includeLinkRoles).anyMatch(linkRole.getName()::equals)) {
// Note: the link direction is always an out link (we don't need to check) since
// Polarion does not generate a fieldDiff for IN links.
// Polarion does not generate a fieldDiff for IN (aka back) links.
WorkItemFieldDiff fieldChange =
new LinkFieldDiff(
fieldDiff.getFieldName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import com.google.gson.Gson;
import com.polarion.alm.projects.model.IProject;
import com.polarion.alm.tracker.ITrackerService;
import com.polarion.alm.tracker.model.ILinkRoleOpt;
import com.polarion.alm.tracker.model.IModule;
import com.polarion.alm.tracker.model.IWorkItem;
import com.polarion.platform.core.PlatformContext;
import com.polarion.platform.persistence.IDataService;
import com.polarion.platform.persistence.IEnumFactory;
import com.polarion.platform.persistence.IEnumOption;
import com.polarion.platform.persistence.IEnumeration;
import com.polarion.platform.persistence.UnresolvableObjectException;
import com.polarion.platform.persistence.model.IPObjectList;
import com.polarion.platform.persistence.spi.TypedEnumerationFactory;
import com.polarion.platform.security.PermissionDeniedException;
import com.polarion.platform.service.repository.AccessDeniedException;
import com.polarion.platform.service.repository.ResourceException;
Expand All @@ -27,6 +30,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -57,8 +61,8 @@ public class WorkItemUpdatesServlet extends HttpServlet {
private IModule module;

/**
* If empty, no work item links should be included. For the values, we expect role IDs (not role
* names)
* If empty, no work item links should be included. For the values, we expect role names since
* this is the format utilized in the Teamscale configuration
*/
private String[] includeLinkRoles;

Expand Down Expand Up @@ -509,7 +513,7 @@ private boolean validateLinkRoles() {
return false;
}

IEnumeration<IEnumOption> linkRolesEnum;
IEnumeration linkRolesEnum;
try {
// This Polarion method getEnumerationForEnumId returns an unparameterized IEnumeration
// which we parameterize to IEnumeration<IEnumOption>, that's why we add the try/catch
Expand All @@ -530,21 +534,27 @@ private boolean validateLinkRoles() {
}

List<IEnumOption> allLinkRoles = linkRolesEnum.getAllOptions();
if (allLinkRoles != null && !allLinkRoles.isEmpty()) {
Set<String> allLinkRolesStrSet =
allLinkRoles.stream().map(linkRole -> linkRole.getId()).collect(Collectors.toSet());
String[] newLinkRolesList =
Arrays.asList(includeLinkRoles).stream()
.filter(linkRole -> allLinkRolesStrSet.contains(linkRole))
.toArray(String[]::new);
if (newLinkRolesList.length > 0) {
includeLinkRoles = newLinkRolesList;
} else {
includeLinkRoles = null;
}
return true;
if (allLinkRoles == null || allLinkRoles.isEmpty()) {
// if there aren't link roles set up then we cannot validate the requested linkRoles
return false;
}
// if there are not link roles set up then we cannot validate the requested linkRoles
return false;
Set<String> allLinkRolesStrSet = new HashSet<String>();
allLinkRoles.stream().forEach(linkRole -> {
allLinkRolesStrSet.add(linkRole.getName());
String oppositeName = linkRole.getProperty("oppositeName");
if (oppositeName != null && !oppositeName.isEmpty()) {
allLinkRolesStrSet.add(oppositeName);
}
});
String[] newLinkRolesList =
Arrays.asList(includeLinkRoles).stream()
.filter(linkRole -> allLinkRolesStrSet.contains(linkRole))
.toArray(String[]::new);
if (newLinkRolesList.length > 0) {
includeLinkRoles = newLinkRolesList;
} else {
includeLinkRoles = null;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,19 @@ public static WorkItemForJson castWorkItem(
(List<ILinkedWorkItemStruct>) workItem.getLinkedWorkItemsStructsDirect();
List<ILinkedWorkItemStruct> backLinksStruct =
(List<ILinkedWorkItemStruct>) workItem.getLinkedWorkItemsStructsBack();

directLinksStruct.addAll(backLinksStruct); // both direct and back links
List<LinkedWorkItem> linkedItems =
(List<LinkedWorkItem>)
directLinksStruct.stream()
.filter(
linkStruct ->
Arrays.asList(includeLinkRoles)
.contains(linkStruct.getLinkRole().getId()))
.contains(linkStruct.getLinkRole().getName()))
.map(
linkStruct -> {
linkNamesMap.putIfAbsent(
linkStruct.getLinkRole().getId(), linkStruct.getLinkRole());
linkStruct.getLinkRole().getName(), linkStruct.getLinkRole());

return new LinkedWorkItem(
linkStruct.getLinkedItem().getId(),
Expand Down

0 comments on commit f32b29d

Please sign in to comment.