Skip to content

Commit

Permalink
Fixed version history number in item and itemhistory using the minorV…
Browse files Browse the repository at this point in the history
…ersion #101

If an issue has a minorVersion of 0, it has a different behaviour and it has to be fixed in the code.
  • Loading branch information
oscar9 committed Aug 24, 2022
1 parent caf5dcd commit 93d5b22
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,28 @@ public Item getItemHistoryByUuid(String uuid) throws Exception {
}

public Item getItemHistoryByUri(String uri, Integer version) throws Exception {
try {
int i = uri.lastIndexOf('/');
if (i < 0) {
throw new NoResultException();
}
String localidWithVersion = uri.substring(i + 1);
int uriCollection = uri.substring(0, i).lastIndexOf('/');
String regItemClassLocalId = uri.replace(localidWithVersion, "").substring(uriCollection + 1).replace("/", "");
RegItemclass regItemRegItemClass = regItemClassManager.getByLocalid(regItemClassLocalId);
RegItemclass parentRegItemRegItemClass = regItemClassManager.getChildItemclass(regItemRegItemClass).get(0);
String localid = localidWithVersion.replace(":" + localidWithVersion.substring(localidWithVersion.lastIndexOf(":") + 1), "");
int minVersion = regItemhistoryManager.getMinVersionByLocalidAndRegItemClass(localid, parentRegItemRegItemClass).getVersionnumber();
if (minVersion == 0) {
int fixedVersion = version -1;
uri = uri.replace(":"+version, ":"+fixedVersion);
version = version - 1;
}
} catch (Exception ex) {
version = version;
}
RegItemhistory item = getRegItemByUri(uri, version);

if (item == null) {
return null;
}
Expand All @@ -176,7 +197,7 @@ private RegItemhistory getRegItemByUri(String uri, int version) throws Exception
RegItemhistory regItem;
try {
regItem = regItemhistoryManager.getByLocalidVersionnumberAndRegItemClass(localid, version, parentRegItemRegItemClass);
if (regItem != null && uri.equals(getURI(regItem) + ":" + regItem.getVersionnumber())) {
if (regItem != null) { // && uri.equals(getURI(regItem) + ":" + regItem.getVersionnumber())) {
return regItem;
}
} catch (Exception ex) {
Expand Down Expand Up @@ -716,15 +737,17 @@ private void setVersionAndHistory(RegItemhistory regItemhistory, ContainedItem i
} else if (itemHistory.stream().noneMatch(it -> it.getVersionnumber() == version)) {
throw new NoVersionException();
}
item.setVersion(new VersionInformation(version, uri + ":" + version));


if (minVersion == 0) {
int fixedVersion = version + 1;
item.setVersion(new VersionInformation(fixedVersion, uri + ":" + fixedVersion));
item.setVersionHistory(itemHistory.stream()
.filter(ih -> ih.getVersionnumber() != version)
.map(ih -> new VersionInformation(ih.getVersionnumber() + 1, uri + ":" + (ih.getVersionnumber() + 1)))
.collect(Collectors.toList()));

} else {
item.setVersion(new VersionInformation(version, uri + ":" + version));
item.setVersionHistory(itemHistory.stream()
.filter(ih -> ih.getVersionnumber() != version)
.map(ih -> new VersionInformation(ih.getVersionnumber(), uri + ":" + ih.getVersionnumber()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ private void setVersionAndHistory(RegItem regItem, ContainedItem item) throws Ex
item.setVersion(new VersionInformation(thisversion, uri + ":" + thisversion));
item.setVersionHistory(itemHistory.stream()
.filter(ih -> ih.getVersionnumber() != maxVersionNumber + 1)
.map(ih -> new VersionInformation(ih.getVersionnumber(), uri + ":" + ih.getVersionnumber()))
.map(ih -> new VersionInformation(ih.getVersionnumber()+1, uri + ":" + (ih.getVersionnumber()+1))) // needed for showing the correct version
.collect(Collectors.toList()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp)
if (sizeHistory == 0 || sizeHistory + 1 == version) {
optItem = getItemByUri(uri.replace(":" + version, ""), lang, itemSupplier);
} else {
optItem = getItemHistoryByUri(uri, lang, itemHistorySupplier, version);
optItem = getItemHistoryByUri(uri, lang, itemHistorySupplier, version);
// int fixedVersion = version - 1;
// optItem = getItemHistoryByUri(uri.replace(":" + version, ":"+fixedVersion), lang, itemHistorySupplier, fixedVersion); //-1
}
}
}
Expand Down

0 comments on commit 93d5b22

Please sign in to comment.