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

fix(Rest): Adding vcs field in component update api #2383

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions libraries/datahandler/src/main/thrift/components.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ struct ComponentDTO {
51: optional string mailinglist,
52: optional string wiki,
53: optional string blog,
56: optional string vcs,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the appropriate json ignore for this new field (like setVcs)

}

struct ReleaseLink{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.eclipse.sw360.datahandler.common.CommonUtils.getSortedMap;
Expand Down Expand Up @@ -147,6 +149,14 @@ public Component createComponent(Component component, User sw360User) throws TEx
public RequestStatus updateComponent(Component component, User sw360User) throws TException {
ComponentService.Iface sw360ComponentClient = getThriftComponentClient();
RequestStatus requestStatus;
if (CommonUtils.isNotNullEmptyOrWhitespace(component.getVcs())) {
String urlRegex = "^(https?://)[a-zA-Z0-9+&@#/%?=~_|!:,.;-]*[a-zA-Z0-9+&@#/%=~_|]$";
Pattern urlPattern = Pattern.compile(urlRegex);
Matcher matcher = urlPattern.matcher(component.getVcs());
boolean isValidUrl=matcher.matches();
if(!isValidUrl)
throw new RuntimeException("sw360 component with name '" + component.getName() + " cannot be updated as vcs url is invalid");
}
if (Sw360ResourceServer.IS_FORCE_UPDATE_ENABLED) {
requestStatus = sw360ComponentClient.updateComponentWithForceFlag(component, sw360User, true);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -675,6 +676,9 @@ public Component convertToComponent(ComponentDTO componentDTO) {
component.setMailinglist(componentDTO.getMailinglist());
component.setWiki(componentDTO.getWiki());
component.setBlog(componentDTO.getBlog());
if(componentDTO.getVcs()!=null && Objects.nonNull(componentDTO.getVcs())) {
component.setVcs(componentDTO.getVcs().trim());
}

return component;
}
Expand Down
Loading