Details
-
Improvement
-
Resolution: Unresolved
-
Neutral
-
None
-
2.0.4
Description
A client would like to have a similar code structure to the getOrCreateTag method applied to the getTag methods as well:
getOrCreateTag structure:
public final Node getOrCreateTag(String tagName) throws RepositoryException { if (!isLicenseValid()) { throw new IllegalStateException("License is not valid"); } return getOrCreate(tagName); } protected Node getOrCreate(String tagName) throws RepositoryException { tagName = nodeNameHelper.getValidatedName(tagName); final Session session = getTagsSession(); final Node parentNode = NodeUtil.createPath(session.getRootNode(), getParentPath(tagName), NodeTypes.Folder.NAME, false); if (parentNode.hasNode(tagName)) { return parentNode.getNode(tagName); } else { final Node node = parentNode.addNode(tagName, TAG_NODE_TYPE); session.save(); return node; } }
Current getTag structure:
public final Optional<Node> getTag(String tagName) throws RepositoryException { if (!isLicenseValid()) { throw new IllegalStateException("License is not valid"); } tagName = nodeNameHelper.getValidatedName(tagName); return executeQuery(WORKSPACE, String.format("SELECT * FROM [%s] as t WHERE name(t)='%s'", TAG_NODE_TYPE, tagName)).stream().findFirst(); }
Suggested structure:
public final Optional<Node> getTag(String tagName) throws RepositoryException {
if (!isLicenseValid()) {
throw new IllegalStateException("License is not valid");
}
return getTagInternal(tagName);
}
protected Optional<Node> getTagInternal(String tagName) throws RepositoryException {
tagName = nodeNameHelper.getValidatedName(tagName);
return executeQuery(WORKSPACE, String.format("SELECT * FROM [%s] as t WHERE name(t)='%s'", TAG_NODE_TYPE, tagName)).stream().findFirst();
}
This way, overriding the method would be doable by extension without modifying the class itself.
Checklists
Acceptance criteria