Skip to content

Commit

Permalink
Upping versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Jan 19, 2024
1 parent 0d07625 commit 05d44d7
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import nl.vpro.domain.media.MediaObject;
import nl.vpro.domain.page.Page;
import nl.vpro.domain.page.PageIdMatch;
import nl.vpro.domain.page.update.DeleteResult;
import nl.vpro.domain.page.update.PageUpdate;
import nl.vpro.domain.page.update.*;
import nl.vpro.jackson2.Jackson2Mapper;
import nl.vpro.rs.client.Utils;

Expand Down Expand Up @@ -79,23 +78,12 @@ protected Result<Void> save(@NotNull @Valid PageUpdate update, boolean wait) {
limiter.acquire();
try {

Result<String> result = handleResponse(
pageUpdateApiClient.getPageUpdateRestService().save(update, wait),
update, STRING, String.class
);
// temporary, later we may do Result<SaveResult>
if (result.isOk()) {
log.info(result.getEntity());
return Result.<Void>builder().status(result.getStatus()).build();
} else {
if ((! retryErrors) || (! result.needsRetry())) {
log.warn(result.getErrors());
return Result.<Void>builder().status(result.getStatus()).errors(result.getErrors()).build();
}
}
limiter.setCurrentRateToMinRate();
log.warn("Retrying {}", update);
SaveResult result = pageUpdateApiClient.getPageUpdateRestService().save(update, wait);
limiter.upRate();
return Result.success(null);

} catch (ProcessingException e) {
limiter.downRate();
return exceptionToResult(e);
}
}
Expand All @@ -108,50 +96,33 @@ public PageUpdate get(@NotNull String url) {
return Utils.wrapNotFound(() -> pageUpdateApiClient.getPageUpdateRestService().load(url, false, match)).orElse(null);
}

public Result<DeleteResult> delete(@NotNull String id) {
public DeleteResult delete(@NotNull String id) {
limiter.acquire();
PageIdMatch match = id.startsWith("crid:") ? PageIdMatch.CRID : PageIdMatch.URL;
try {
return handleResponse(
pageUpdateApiClient.getPageUpdateRestService()
.delete(id, false, 1, false, match, null, null), id, STRING, DeleteResult.class
);
} catch (ProcessingException e) {
return exceptionToResult(e);
}
return pageUpdateApiClient.getPageUpdateRestService()
.delete(id, false, 1, false, match);

}


public Result<DeleteResult> deleteWhereStartsWith(@NotNull String prefix) {
public DeleteResult deleteWhereStartsWith(@NotNull String prefix) {
limiter.acquire();
PageIdMatch match = prefix.startsWith("crid:") ? PageIdMatch.CRID : PageIdMatch.URL;

int batchSize = 10000;
try {
DeleteResult result = null;
while (true) {
Result<DeleteResult> r = handleResponse(
pageUpdateApiClient.getPageUpdateRestService()
.delete(prefix, true, batchSize, true, match, null,null), prefix, STRING, DeleteResult.class
);
log.info("Batch deleted {}: {}", prefix, r);
if (result == null) {
result = r.getEntity();
} else {
result = result.and(r.getEntity());
}
if (r.isOk()) {
if (r.getEntity().getCount() == 0) {
return Result.<DeleteResult>builder()
.entity(result)
.status(Result.Status.SUCCESS)
.build();
}
}
DeleteResult result = null;
while (true) {
DeleteResult r = pageUpdateApiClient.getPageUpdateRestService()
.delete(prefix, true, batchSize, true, match);
log.info("Batch deleted {}: {}", prefix, r);
if (result != null) {
result = result.and(r);
} else {
result = r;
}
if (r.getCount() == 0) {
return result;
}

} catch (ProcessingException e) {
return exceptionToResult(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,33 @@ public void testSaveInvalid() {
@Test
public void testDelete() {
String id = "http://BESTAATNIET";
Result<DeleteResult> result = util.delete(id);
assertThat(result.getStatus()).isEqualTo(Result.Status.SUCCESS);
assertThat(result.getErrors()).isNull();
DeleteResult result = util.delete(id);
log.info("{}", result);
}

@Test
public void accesDenied() {
String willCauseDeny = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<pageUpdate:page xmlns:pageUpdate=\"urn:vpro:pages:update:2013\" xmlns:pages=\"urn:vpro:pages:2013\" type=\"PLAYER\" url=\"http://cultura-sample.localhost/speel.RBX_NTR_632457.html\" publishStart=\"2014-09-23T19:00:00+02:00\">\n" +
" <pageUpdate:crid>crid://vpro/media/cultura/RBX_NTR_632457</pageUpdate:crid>\n" +
" <pageUpdate:broadcaster>NTR</pageUpdate:broadcaster>\n" +
" <pageUpdate:title>Blaudzun te gast met zijn favoriete platen</pageUpdate:title>\n" +
" <pageUpdate:embeds>\n" +
" <pageUpdate:embed midRef=\"RBX_NTR_632457\">\n" +
" <pageUpdate:title>Blaudzun te gast met zijn favoriete platen</pageUpdate:title>\n" +
" <pageUpdate:description>Een grote bril, een ietwat apart kapsel en een gitaar. Dat is Johannes Sigmond uit Arnhem, ook wel bekend als Blaudzun. Blaudzun was een gegarandeerd feest op elk festival van afgelopen zomer! Vanavond komt deze singer-songwriter naar Winfrieds Woonkamer om zijn favoriete platen aan jou te laten horen. Zijn lijst van dit uur:1. The Jig - Bike Ride2. Prince - I Would Die 4 You3. Child Of Lov ft Damon Albarn - One Day4. Anne Murray - Paths Of Victory5. Outkast - Roses6. Mulatu Astatke - Yekermo Sew7. Earl Sweatshirt - Burgundy 8. Nina Simone - Sinnerman9. TLC - Waterfalls10. The Roots - Singing Man</pageUpdate:description>\n" +
" </pageUpdate:embed>\n" +
" </pageUpdate:embeds>\n" +
" <pageUpdate:image type=\"PICTURE\">\n" +
" <pageUpdate:title>Blaudzun_-_2012-05-05.jpg</pageUpdate:title>\n" +
" <pageUpdate:description>Blaudzun te gast met zijn favoriete platen</pageUpdate:description>\n" +
" <pageUpdate:imageLocation>\n" +
" <pageUpdate:url>http://images.poms.omroep.nl/image/s360/289017.jpg</pageUpdate:url>\n" +
" </pageUpdate:imageLocation>\n" +
" </pageUpdate:image>\n" +
"</pageUpdate:page>\n";
String willCauseDeny = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<pageUpdate:page xmlns:pageUpdate="urn:vpro:pages:update:2013" xmlns:pages="urn:vpro:pages:2013" type="PLAYER" url="http://cultura-sample.localhost/speel.RBX_NTR_632457.html" publishStart="2014-09-23T19:00:00+02:00">
<pageUpdate:crid>crid://vpro/media/cultura/RBX_NTR_632457</pageUpdate:crid>
<pageUpdate:broadcaster>NTR</pageUpdate:broadcaster>
<pageUpdate:title>Blaudzun te gast met zijn favoriete platen</pageUpdate:title>
<pageUpdate:embeds>
<pageUpdate:embed midRef="RBX_NTR_632457">
<pageUpdate:title>Blaudzun te gast met zijn favoriete platen</pageUpdate:title>
<pageUpdate:description>Een grote bril, een ietwat apart kapsel en een gitaar. Dat is Johannes Sigmond uit Arnhem, ook wel bekend als Blaudzun. Blaudzun was een gegarandeerd feest op elk festival van afgelopen zomer! Vanavond komt deze singer-songwriter naar Winfrieds Woonkamer om zijn favoriete platen aan jou te laten horen. Zijn lijst van dit uur:1. The Jig - Bike Ride2. Prince - I Would Die 4 You3. Child Of Lov ft Damon Albarn - One Day4. Anne Murray - Paths Of Victory5. Outkast - Roses6. Mulatu Astatke - Yekermo Sew7. Earl Sweatshirt - Burgundy 8. Nina Simone - Sinnerman9. TLC - Waterfalls10. The Roots - Singing Man</pageUpdate:description>
</pageUpdate:embed>
</pageUpdate:embeds>
<pageUpdate:image type="PICTURE">
<pageUpdate:title>Blaudzun_-_2012-05-05.jpg</pageUpdate:title>
<pageUpdate:description>Blaudzun te gast met zijn favoriete platen</pageUpdate:description>
<pageUpdate:imageLocation>
<pageUpdate:url>http://images.poms.omroep.nl/image/s360/289017.jpg</pageUpdate:url>
</pageUpdate:imageLocation>
</pageUpdate:image>
</pageUpdate:page>
""";
//System.out.println(willCauseError);
PageUpdate update = JAXB.unmarshal(new StringReader(willCauseDeny), PageUpdate.class);
Result<Void> result = util.save(update);
Expand All @@ -79,7 +80,7 @@ public void accesDenied() {
@Test
public void deleteWhereStartsWith() {
log.info("{}", util);
Result<DeleteResult> result = util.deleteWhereStartsWith("http://bla/bloe");
log.info("{}", result.getEntity());
DeleteResult result = util.deleteWhereStartsWith("http://bla/bloe");
log.info("{}", result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class MediaRestClient extends AbstractApiClient implements MediaRestClien

public static final TriFunction<Method, Object[], String, Level> DEFAULT_HEADER_LEVEL = (m, a, s) -> s.equals(Headers.NPO_WARNING_HEADER) ? Level.WARN : Level.DEBUG;

@Setter
private int defaultMax = 50;

private final RateLimiter throttle = RateLimiter.create(1.0);
Expand All @@ -108,6 +109,7 @@ public class MediaRestClient extends AbstractApiClient implements MediaRestClien

private FrameCreatorRestService frameCreatorRestService;

@Setter
private Map<String, Object> headers;

Supplier<VersionResult> version;
Expand All @@ -130,7 +132,6 @@ public class MediaRestClient extends AbstractApiClient implements MediaRestClien
@Setter
private boolean validateInput = false;


@Getter
@Setter
private AssemblageConfig.Steal stealCrids = AssemblageConfig.Steal.IF_DELETED;
Expand Down Expand Up @@ -389,10 +390,6 @@ public void setUserNamePassword(String semicolonSeperated) {
}
}

public void setHeaders(Map<String, Object> headers) {
this.headers = headers;
}

public String getVersion() {
if (version == null) {
version = () -> Suppliers.memoizeWithExpiration(() -> {
Expand Down Expand Up @@ -725,37 +722,29 @@ public String set(MediaUpdate<?> mediaUpdate, String errors) {
public Iterator<MemberUpdate> getAllMembers(String mid) {
return BatchedReceiver.<MemberUpdate>builder()
.batchSize(240)
.batchGetter((offset, max) -> {
return getBackendRestService().getGroupMembers(EntityType.NoSegments.media, mid, offset, max, ASC, followMerges, owner, deletes).iterator();
})
.batchGetter((offset, max) -> getBackendRestService().getGroupMembers(EntityType.NoSegments.media, mid, offset, max, ASC, followMerges, owner, deletes).iterator())
.build();
}

public Iterator<MemberUpdate> getAllEpisodes(String mid) {
return BatchedReceiver.<MemberUpdate>builder()
.batchSize(defaultMax)
.batchGetter((offset, max) -> {
return getBackendRestService().getGroupEpisodes(mid, offset, max, ASC, followMerges, owner, deletes).iterator();
})
.batchGetter((offset, max) -> getBackendRestService().getGroupEpisodes(mid, offset, max, ASC, followMerges, owner, deletes).iterator())
.build();
}


public Iterator<Member> getAllFullMembers(String mid) {
return BatchedReceiver.<Member>builder()
.batchSize(defaultMax)
.batchGetter((offset, max) -> {
return getBackendRestService().getFullGroupMembers(EntityType.NoSegments.media, mid, offset, max, ASC, followMerges, deletes).iterator();
})
.batchGetter((offset, max) -> getBackendRestService().getFullGroupMembers(EntityType.NoSegments.media, mid, offset, max, ASC, followMerges, deletes).iterator())
.build();
}

public Iterator<Member> getAllFullEpisodes(String mid) {
return BatchedReceiver.<Member>builder()
.batchSize(defaultMax)
.batchGetter((offset, max) -> {
return getBackendRestService().getFullGroupEpisodes(mid, offset, max, ASC, followMerges, deletes).iterator();
})
.batchGetter((offset, max) -> getBackendRestService().getFullGroupEpisodes(mid, offset, max, ASC, followMerges, deletes).iterator())
.build();
}

Expand Down Expand Up @@ -784,10 +773,6 @@ public String deleteSubtitles(SubtitlesId id) {
}
}

public void setDefaultMax(int max) {
this.defaultMax = max;
}


public double getThrottleRate() {
return this.throttle.getRate();
Expand Down
10 changes: 4 additions & 6 deletions pages-backend-api-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<groupId>nl.vpro.shared</groupId>
<artifactId>vpro-shared-client-resteasy</artifactId>
</dependency>
<dependency>
<groupId>nl.vpro.shared</groupId>
<artifactId>vpro-shared-rs-client</artifactId>
</dependency>
<dependency>
<groupId>nl.vpro.pages</groupId>
<artifactId>pages-rs-services</artifactId>
Expand All @@ -41,11 +45,5 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<!-- TODO: drop this too -->
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ public String toString() {
@Override
protected void buildResteasy(ResteasyClientBuilder builder) {
builder
.register(authentication);
.register(authentication)
;
}


Expand Down
Loading

0 comments on commit 05d44d7

Please sign in to comment.