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

Support to use remote backend with prefix #748

Merged
merged 2 commits into from
Feb 22, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ public ResponseEntity<StateConsumerList> getWorkspaceStateConsumers(@PathVariabl

@Transactional
@GetMapping(produces = "application/vnd.api+json", path = "organizations/{organizationName}/workspaces")
public ResponseEntity<WorkspaceList> listWorkspace(@PathVariable("organizationName") String organizationName, @RequestParam("search[tags]") String searchTags, Principal principal) {
log.info("Searching: {} {}", organizationName, searchTags);
return ResponseEntity.of(Optional.ofNullable(remoteTfeService.listWorkspace(organizationName, searchTags, (JwtAuthenticationToken) principal)));
public ResponseEntity<WorkspaceList> listWorkspace(@PathVariable("organizationName") String organizationName, @RequestParam("search[tags]") Optional<String> searchTags, @RequestParam("search[name]") Optional<String> searchName, Principal principal) {
log.info("Searching Tags: {} {}", organizationName, searchTags.isPresent() ? searchTags.get(): null);
log.info("Searching Names: {} {}", organizationName, searchName.isPresent() ? searchName.get(): null);
return ResponseEntity.of(Optional.ofNullable(remoteTfeService.listWorkspace(organizationName, searchTags, searchName, (JwtAuthenticationToken) principal)));
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,26 +304,39 @@ StateConsumerList getWorkspaceStateConsumers(String workspaceId, JwtAuthenticati

}

WorkspaceList listWorkspace(String organizationName, String searchTags, JwtAuthenticationToken currentUser) {
WorkspaceList listWorkspace(String organizationName, Optional<String> searchTags, Optional<String> searchName, JwtAuthenticationToken currentUser) {
WorkspaceList workspaceList = new WorkspaceList();
workspaceList.setData(new ArrayList());

List<String> listTags = Arrays.stream(searchTags.split(",")).toList();
log.info("Searching workspaces with tags: {}", searchTags);
for (Workspace workspace : organizationRepository.getOrganizationByName(organizationName).getWorkspace()) {
List<WorkspaceTag> workspaceTagList = workspace.getWorkspaceTag();
int matchingTags = 0;

for (WorkspaceTag workspaceTag : workspaceTagList) {
Tag tag = tagRepository.getReferenceById(UUID.fromString(workspaceTag.getTagId()));
if (listTags.indexOf(tag.getName()) > -1) {
matchingTags++;
if (searchTags.isPresent()) {
String searchTagData = searchTags.get();
List<String> listTags = Arrays.stream(searchTagData.split(",")).toList();
log.info("Searching workspaces with tags: {}", searchTags);
for (Workspace workspace : organizationRepository.getOrganizationByName(organizationName).getWorkspace()) {
List<WorkspaceTag> workspaceTagList = workspace.getWorkspaceTag();
int matchingTags = 0;

for (WorkspaceTag workspaceTag : workspaceTagList) {
Tag tag = tagRepository.getReferenceById(UUID.fromString(workspaceTag.getTagId()));
if (listTags.indexOf(tag.getName()) > -1) {
matchingTags++;
}
}
log.info("Workspace {} Tags Count {} Searching Tag Quantity {} Matched {}", workspace.getName(), workspaceTagList.size(), listTags.size(), matchingTags);
if (matchingTags == listTags.size()) {
workspaceList.getData().add(getWorkspace(organizationName, workspace.getName(), new HashMap(), currentUser).getData());
}
}
log.info("Workspace {} Tags Count {} Searching Tag Quantity {} Matched {}", workspace.getName(), workspaceTagList.size(), listTags.size(), matchingTags);
if (matchingTags == listTags.size()) {
workspaceList.getData().add(getWorkspace(organizationName, workspace.getName(), new HashMap(), currentUser).getData());
}
}

if (searchName.isPresent()) {
String searchNameData = searchName.get();
log.info("Searching workspaces with name prefix: {}", searchNameData);
Optional<List<Workspace>> workspaceListByName = workspaceRepository.findWorkspacesByOrganizationNameAndNameStartingWith(organizationName, searchNameData);
if(workspaceListByName.isPresent())
for (Workspace workspace : workspaceListByName.get()) {
workspaceList.getData().add(getWorkspace(organizationName, workspace.getName(), new HashMap(), currentUser).getData());
}
}
return workspaceList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import org.terrakube.api.rs.workspace.Workspace;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

public interface WorkspaceRepository extends JpaRepository<Workspace, UUID> {

Workspace getByOrganizationNameAndName(String organizationName, String workspaceName);

Optional<List<Workspace>> findWorkspacesByOrganizationNameAndNameStartingWith(String organizationName, String workspaceNameStartingWidth);
}
Loading