Skip to content

Commit f67b6c1

Browse files
authored
Remove unused code to improve coverage (#113)
Signed-off-by: sBouzols <[email protected]>
1 parent c9e8cb2 commit f67b6c1

File tree

2 files changed

+0
-121
lines changed

2 files changed

+0
-121
lines changed

src/main/java/org/gridsuite/gateway/endpoints/EndPointElementServer.java

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66
*/
77
package org.gridsuite.gateway.endpoints;
88

9-
import lombok.NonNull;
10-
import org.gridsuite.gateway.dto.AccessControlInfos;
119
import org.springframework.http.HttpMethod;
12-
import org.springframework.http.server.RequestPath;
13-
import org.springframework.http.server.reactive.ServerHttpRequest;
1410

1511
import java.util.*;
16-
import java.util.stream.Collectors;
1712

1813
import static org.springframework.http.HttpMethod.*;
1914

@@ -28,56 +23,7 @@ public interface EndPointElementServer extends EndPointServer {
2823
PUT, POST, DELETE
2924
);
3025

31-
static UUID getUuid(String uuid) {
32-
try {
33-
return UUID.fromString(uuid);
34-
} catch (IllegalArgumentException e) {
35-
return null;
36-
}
37-
}
38-
39-
default UUID getElementUuidIfExist(@NonNull RequestPath path) {
40-
return (path.elements().size() > 5) ? getUuid(path.elements().get(5).value()) : null;
41-
}
42-
43-
default boolean isAllowedMethod(HttpMethod httpMethod) {
44-
return ALLOWED_HTTP_METHODS.contains(httpMethod);
45-
}
46-
4726
default Set<String> getUncontrolledRootPaths() {
4827
return Set.of();
4928
}
50-
51-
default boolean isNotControlledRootPath(String rootPath) {
52-
return getUncontrolledRootPaths().contains(rootPath);
53-
}
54-
55-
@Override
56-
default boolean hasElementsAccessControl() {
57-
return true;
58-
}
59-
60-
default Optional<AccessControlInfos> getAccessControlInfos(@NonNull ServerHttpRequest request) {
61-
RequestPath path = Objects.requireNonNull(request.getPath());
62-
UUID elementUuid = getElementUuidIfExist(path);
63-
64-
// /<elements>/{elementUuid} or /<elements>/**?id=
65-
HttpMethod httpMethod = Objects.requireNonNull(request.getMethod());
66-
if (httpMethod.equals(HEAD) || httpMethod.equals(GET)) {
67-
if (elementUuid != null) {
68-
return Optional.of(AccessControlInfos.create(List.of(elementUuid)));
69-
} else {
70-
if (request.getQueryParams().get(QUERY_PARAM_IDS) == null) {
71-
return Optional.empty();
72-
} else {
73-
List<String> ids = request.getQueryParams().get(QUERY_PARAM_IDS);
74-
List<UUID> elementUuids = ids.stream().map(EndPointElementServer::getUuid).filter(Objects::nonNull).collect(Collectors.toList());
75-
return elementUuids.size() == ids.size() ? Optional.of(AccessControlInfos.create(elementUuids)) : Optional.empty();
76-
}
77-
}
78-
} else if (httpMethod.equals(POST) || httpMethod.equals(PUT) || httpMethod.equals(DELETE)) {
79-
return elementUuid == null ? Optional.empty() : Optional.of(AccessControlInfos.create(List.of(elementUuid)));
80-
}
81-
return Optional.empty();
82-
}
8329
}

src/main/java/org/gridsuite/gateway/endpoints/ExploreServer.java

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,15 @@
66
*/
77
package org.gridsuite.gateway.endpoints;
88

9-
import lombok.NonNull;
109
import org.gridsuite.gateway.ServiceURIsConfig;
11-
import org.gridsuite.gateway.dto.AccessControlInfos;
12-
import org.slf4j.Logger;
13-
import org.slf4j.LoggerFactory;
14-
import org.springframework.http.HttpMethod;
15-
import org.springframework.http.server.RequestPath;
16-
import org.springframework.http.server.reactive.ServerHttpRequest;
1710
import org.springframework.stereotype.Component;
1811

19-
import java.util.*;
2012

2113
/**
2214
* @author Slimane Amar <slimane.amar at rte-france.com>
2315
*/
2416
@Component(value = ExploreServer.ENDPOINT_NAME)
2517
public class ExploreServer implements EndPointElementServer {
26-
private static final Logger LOGGER = LoggerFactory.getLogger(ExploreServer.class);
2718

2819
public static final String ENDPOINT_NAME = "explore";
2920

@@ -36,11 +27,6 @@ public ExploreServer(ServiceURIsConfig servicesURIsConfig) {
3627
this.servicesURIsConfig = servicesURIsConfig;
3728
}
3829

39-
@Override
40-
public UUID getElementUuidIfExist(@NonNull RequestPath path) {
41-
return (path.elements().size() > 7) ? EndPointElementServer.getUuid(path.elements().get(7).value()) : null;
42-
}
43-
4430
@Override
4531
public String getEndpointBaseUri() {
4632
return servicesURIsConfig.getExploreServerBaseUri();
@@ -50,57 +36,4 @@ public String getEndpointBaseUri() {
5036
public String getEndpointName() {
5137
return ENDPOINT_NAME;
5238
}
53-
54-
@Override
55-
public boolean hasElementsAccessControl() {
56-
return true;
57-
}
58-
59-
private UUID getUniqueOptionalUuidFromParam(@NonNull ServerHttpRequest request, @NonNull String queryParamName) {
60-
List<String> ids = request.getQueryParams().get(queryParamName);
61-
if (ids != null && ids.size() != 1) {
62-
throw new IllegalArgumentException("There must be only one " + queryParamName);
63-
}
64-
if (ids != null) {
65-
UUID uuid = EndPointElementServer.getUuid(ids.get(0));
66-
if (uuid == null) {
67-
throw new IllegalArgumentException(queryParamName + " must be an UUID");
68-
}
69-
return uuid;
70-
}
71-
return null;
72-
}
73-
74-
@Override
75-
public Optional<AccessControlInfos> getAccessControlInfos(@NonNull ServerHttpRequest request) {
76-
RequestPath path = Objects.requireNonNull(request.getPath());
77-
UUID elementUuid = getElementUuidIfExist(path);
78-
if (Objects.requireNonNull(request.getMethod()) != HttpMethod.POST) {
79-
return EndPointElementServer.super.getAccessControlInfos(request);
80-
}
81-
// Elements creation
82-
if (elementUuid != null) {
83-
return Optional.of(AccessControlInfos.create(List.of(elementUuid)));
84-
}
85-
try {
86-
List<UUID> uuidsToControl = new ArrayList<>();
87-
UUID duplicateFromUuid = getUniqueOptionalUuidFromParam(request, QUERY_PARAM_DUPLICATE_FROM_ID);
88-
if (duplicateFromUuid != null) {
89-
uuidsToControl.add(duplicateFromUuid);
90-
}
91-
UUID parentDirectoryUuid = getUniqueOptionalUuidFromParam(request, QUERY_PARAM_PARENT_DIRECTORY_ID);
92-
if (parentDirectoryUuid != null) {
93-
uuidsToControl.add(parentDirectoryUuid);
94-
}
95-
if (uuidsToControl.isEmpty()) {
96-
// At least one of the param is required
97-
return Optional.empty();
98-
}
99-
// Check resources access
100-
return Optional.of(AccessControlInfos.create(uuidsToControl));
101-
} catch (IllegalArgumentException e) {
102-
LOGGER.error(e.getMessage());
103-
return Optional.empty();
104-
}
105-
}
10639
}

0 commit comments

Comments
 (0)