Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
Allow configuration of PagedTRS ímplementation, to be able to specify (
Browse files Browse the repository at this point in the history
…#36)

the "base" & "changelog" relative paths.
  • Loading branch information
jadelkhoury committed Oct 23, 2019
1 parent 8de387b commit 60a3b92
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
36 changes: 33 additions & 3 deletions src/main/java/org/eclipse/lyo/oslc4j/trs/server/InmemPagedTrs.java
Expand Up @@ -68,6 +68,16 @@ public class InmemPagedTrs implements PagedTrs, ResourceEventHandler {
*/
private final int basePageLimit;

/**
* The relative path of the base, may contain URI template parameters.
*/
private final String baseRelativePath;

/**
* The relative path of the changeLog, may contain URI template parameters.
*/
private final String changeLogRelativePath;

/**
* List of base resources
*/
Expand All @@ -78,6 +88,24 @@ public class InmemPagedTrs implements PagedTrs, ResourceEventHandler {
*/
private final List<ChangeLog> changelogResources = new ArrayList<>();

/**
* @param basePageLimit Max items per Base page
* @param changelogPageLimit Max items per Changelog page
* @param uriBase Set it via eg <pre>UriBuilder.fromUri(OSLC4JUtils.getServletURI()).path("trs").build()</pre>
* @param baseRelativePath The relative path of the base, may contain URI template parameters.
* @param changeLogRelativePath The relative path of the changeLog, may contain URI template parameters.
* @param baseResourceUris Initial set of the TRS Base resource URIs
*/
public InmemPagedTrs(final int basePageLimit, final int changelogPageLimit, final URI uriBase,
final String baseRelativePath, final String changeLogRelativePath, final Collection<URI> baseResourceUris) {
this.basePageLimit = basePageLimit;
this.changelogPageLimit = changelogPageLimit;
this.uriBase = uriBase;
this.baseRelativePath = baseRelativePath;
this.changeLogRelativePath = changeLogRelativePath;
initBase(baseResourceUris);
}

/**
* @param basePageLimit Max items per Base page
* @param changelogPageLimit Max items per Changelog page
Expand All @@ -89,6 +117,8 @@ public InmemPagedTrs(final int basePageLimit, final int changelogPageLimit, fina
this.basePageLimit = basePageLimit;
this.changelogPageLimit = changelogPageLimit;
this.uriBase = uriBase;
this.baseRelativePath = "base";
this.changeLogRelativePath = "changelog";
initBase(baseResourceUris);
}

Expand Down Expand Up @@ -303,18 +333,18 @@ private Base getLastBaseResource() {
}

private URI createBaseUri() {
final URI uri = getUriBuilder().path("base").build();
final URI uri = getUriBuilder().path(this.baseRelativePath).build();
return uri;
}

private URI createBasePageUri(final int pageId) {
final URI uri = getUriBuilder().path("base").path(String.valueOf(pageId)).build();
final URI uri = getUriBuilder().path(this.baseRelativePath).path(String.valueOf(pageId)).build();
return uri;
}

private URI createChangelogUri() {
final int nextPageId = this.changelogResources.size() + 1;
final URI uri = getUriBuilder().path("changelog").path(String.valueOf(nextPageId)).build();
final URI uri = getUriBuilder().path(this.changeLogRelativePath).path(String.valueOf(nextPageId)).build();
return uri;
}

Expand Down
Expand Up @@ -54,8 +54,8 @@
@OslcService(TRSConstants.TRS_NAMESPACE)
public class TrackedResourceSetService {
private static final Logger log = LoggerFactory.getLogger(TrackedResourceSetService.class);
private static final String BASE_PATH = "base";
private static final String CHANGELOG_PATH = "changeLog";
public static final String BASE_PATH = "base";
public static final String CHANGELOG_PATH = "changeLog";
public static final String RESOURCE_PATH = "/trs";

/**
Expand Down

0 comments on commit 60a3b92

Please sign in to comment.