Skip to content

Commit

Permalink
thing
Browse files Browse the repository at this point in the history
Signed-off-by: Veselin Vlasakiev <veselin.vlasakiev@ft.com>
  • Loading branch information
vlasakievft committed Dec 6, 2023
1 parent b8e43db commit 7f06302
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class CheckPublicationPolicy implements ApiFilter {
private static final String PUBLICATION = "publication";
private static final String PUBLICATION_PREFIX = "PBLC_READ_";
private static final String PINK_FT = "88fdde6c-2aa4-4f78-af02-9f680097cfd6";
private static final String THING = "http://www.ft.com/thing/";
private final JsonConverter jsonConverter;

public CheckPublicationPolicy(JsonConverter jsonConverter) {
Expand Down Expand Up @@ -57,7 +58,8 @@ private static Boolean checkAccess(Set<String> policies, List<String> publicatio

private static List<String> convertObjectToStringList(Object obj) {
if (obj instanceof Collection) {
return new ObjectMapper().convertValue(obj, new TypeReference<List<String>>() {});
List<String> p = new ObjectMapper().convertValue(obj, new TypeReference<List<String>>() {});
return p.stream().map(var -> var.replaceFirst(THING, "")).collect(Collectors.toList());
} else {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CheckPublicationPolicyTest {
@Test
public void ShouldReturnOK() {
String entity =
"{ \"type\":\"http://www.ft.com/ontology/content/Article\", \"bodyXML\": \"<body>something here</body>\",\"publication\":[\"8e6c705e-1132-42a2-8db0-c295e29e8658\",\"88fdde6c-2aa4-4f78-af02-9f680097cfd6\"] }";
"{ \"type\":\"http://www.ft.com/ontology/content/Article\", \"bodyXML\": \"<body>something here</body>\",\"publication\":[\"http://www.ft.com/thing/8e6c705e-1132-42a2-8db0-c295e29e8658\",\"http://www.ft.com/thing/88fdde6c-2aa4-4f78-af02-9f680097cfd6\"] }";
MutableResponse validResponse =
new MutableResponse(new MultivaluedHashMap<>(), entity.getBytes());
validResponse.setStatus(200);
Expand All @@ -47,7 +47,7 @@ public void ShouldReturnOK() {
@Test
public void ShouldReturn403() {
String entity =
"{ \"type\":\"http://www.ft.com/ontology/content/Article\", \"bodyXML\": \"<body>something here</body>\",\"publication\":[\"88fdde6c-2aa4-4f78-af02-9f680097cfd6\"] }";
"{ \"type\":\"http://www.ft.com/ontology/content/Article\", \"bodyXML\": \"<body>something here</body>\",\"publication\":[\"http://www.ft.com/thing/88fdde6c-2aa4-4f78-af02-9f680097cfd6\"] }";
MutableResponse validResponse =
new MutableResponse(new MultivaluedHashMap<>(), entity.getBytes());
validResponse.setStatus(200);
Expand All @@ -65,7 +65,7 @@ public void ShouldReturn403() {
@Test
public void ShouldReturnOkWithNoPublicationReadPolicyFtPink() {
String entity =
"{ \"type\":\"http://www.ft.com/ontology/content/Article\", \"bodyXML\": \"<body>something here</body>\",\"publication\":[\"88fdde6c-2aa4-4f78-af02-9f680097cfd6\"] }";
"{ \"type\":\"http://www.ft.com/ontology/content/Article\", \"bodyXML\": \"<body>something here</body>\",\"publication\":[\"http://www.ft.com/thing/88fdde6c-2aa4-4f78-af02-9f680097cfd6\"] }";
MutableResponse validResponse =
new MutableResponse(new MultivaluedHashMap<>(), entity.getBytes());
validResponse.setStatus(200);
Expand All @@ -81,7 +81,7 @@ public void ShouldReturnOkWithNoPublicationReadPolicyFtPink() {
@Test
public void ShouldDeniedAccessNoPublicationPolicyNonPinkFt() {
String entity =
"{ \"type\":\"http://www.ft.com/ontology/content/Article\", \"bodyXML\": \"<body>something here</body>\",\"publication\":[\"8e6c705e-1132-42a2-8db0-c295e29e8658\"] }";
"{ \"type\":\"http://www.ft.com/ontology/content/Article\", \"bodyXML\": \"<body>something here</body>\",\"publication\":[\"http://www.ft.com/thing/8e6c705e-1132-42a2-8db0-c295e29e8658\"] }";
MutableResponse validResponse =
new MutableResponse(new MultivaluedHashMap<>(), entity.getBytes());
validResponse.setStatus(200);
Expand Down

0 comments on commit 7f06302

Please sign in to comment.