use of org.xwiki.extension.version.Version in project xwiki-platform by xwiki.
the class FlavorSearchJob method findValidVersion.
private Extension findValidVersion(String flavorId, String namespace) {
IterableResult<Version> versions;
try {
versions = this.repositoryManager.resolveVersions(flavorId, 0, -1);
if (versions.getSize() == 0) {
this.logger.debug("Could not find any version for the flavor extension [{}]", flavorId);
return null;
}
List<Version> versionList = new ArrayList<Version>(versions.getSize());
for (Version version : versions) {
versionList.add(version);
}
return findValidVersion(flavorId, namespace, versionList);
} catch (ResolveException e) {
this.logger.debug("Failed to resolve versions for extension id [{}]", flavorId, e);
}
return null;
}
use of org.xwiki.extension.version.Version in project xwiki-platform by xwiki.
the class ExtensionVersionsRESTResource method getExtensionVersions.
@GET
public ExtensionVersions getExtensionVersions(@PathParam("extensionId") String extensionId, @QueryParam(Resources.QPARAM_LIST_START) @DefaultValue("0") int offset, @QueryParam(Resources.QPARAM_LIST_NUMBER) @DefaultValue("-1") int number, @QueryParam(Resources.QPARAM_VERSIONS_RANGES) String ranges) throws QueryException, InvalidVersionRangeException {
Query query = createExtensionsSummariesQuery(null, "extension.id = :extensionId", 0, -1, true);
query.bindValue("extensionId", extensionId);
ExtensionVersions extensions = this.extensionObjectFactory.createExtensionVersions();
getExtensionSummaries(extensions.getExtensionVersionSummaries(), query);
// Filter by ranges
if (StringUtils.isNotBlank(ranges)) {
VersionConstraint constraint = this.extensionFactory.getVersionConstraint(ranges);
if (constraint.getVersion() != null) {
throw new InvalidVersionRangeException("Invalid ranges syntax [" + ranges + "]");
}
for (Iterator<ExtensionVersionSummary> it = extensions.getExtensionVersionSummaries().iterator(); it.hasNext(); ) {
if (!constraint.containsVersion(new DefaultVersion(it.next().getVersion()))) {
it.remove();
}
}
}
// Order by version
final Map<String, Version> versionCache = new HashMap<>();
Collections.sort(extensions.getExtensionVersionSummaries(), new Comparator<ExtensionVersionSummary>() {
@Override
public int compare(ExtensionVersionSummary o1, ExtensionVersionSummary o2) {
return toVersion(o1.getVersion()).compareTo(toVersion(o2.getVersion()));
}
private Version toVersion(String versionString) {
Version version = versionCache.get(versionString);
if (version == null) {
version = extensionFactory.getVersion(versionString);
versionCache.put(versionString, version);
}
return version;
}
});
extensions.setTotalHits(extensions.getExtensionVersionSummaries().size());
extensions.setOffset(offset);
if (offset > 0 || (number > -1 && offset + number < extensions.getExtensionVersionSummaries().size())) {
if (offset >= extensions.getExtensionVersionSummaries().size() || number == 0) {
extensions.getExtensionVersionSummaries().clear();
} else {
List<ExtensionVersionSummary> limited = new ArrayList<ExtensionVersionSummary>(extensions.getExtensionVersionSummaries());
extensions.getExtensionVersionSummaries().clear();
extensions.withExtensionVersionSummaries(limited.subList(offset < 0 ? 0 : offset, number < 0 ? extensions.getExtensionVersionSummaries().size() : offset + number));
}
}
return extensions;
}
Aggregations