use of org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion in project xwiki-platform by xwiki.
the class AbstractExtensionRESTResource method createExtensionVersionFromQueryResult.
protected ExtensionVersion createExtensionVersionFromQueryResult(Object[] entry) {
XWikiContext xcontext = getXWikiContext();
String documentName = (String) entry[0];
String documentSpace = (String) entry[1];
ExtensionVersion extension = this.extensionObjectFactory.createExtensionVersion();
extension.setId(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_ID));
extension.setType(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_TYPE));
extension.setName(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_NAME));
extension.setSummary(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_SUMMARY));
// Recommended
Integer recommended = this.<Integer>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_RECOMMENDED);
extension.setRecommended(recommended != null && recommended.intValue() == 1);
// SCM
ExtensionScm scm = new ExtensionScm();
scm.setUrl(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_SCMURL));
scm.setConnection(toScmConnection(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_SCMCONNECTION)));
scm.setDeveloperConnection(toScmConnection(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_SCMDEVCONNECTION)));
extension.setScm(scm);
// Issue Management
ExtensionIssueManagement issueManagement = new ExtensionIssueManagement();
issueManagement.setSystem(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_ISSUEMANAGEMENT_SYSTEM));
issueManagement.setUrl(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_ISSUEMANAGEMENT_URL));
if (StringUtils.isNotEmpty(issueManagement.getSystem()) || StringUtils.isNotEmpty(issueManagement.getUrl())) {
extension.setIssueManagement(issueManagement);
}
// Rating
DocumentReference extensionDocumentReference = new DocumentReference(xcontext.getWikiId(), documentSpace, documentName);
// FIXME: this adds potentially tons of new request to what used to be carefully crafted to produce a single
// request for the whole search... Should be cached in a filed of the document (like the last version is for
// example).
extension.setRating(getExtensionRating(extensionDocumentReference));
// Website
extension.setWebsite(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_WEBSITE));
if (StringUtils.isBlank(extension.getWebsite())) {
extension.setWebsite(xcontext.getWiki().getURL(new DocumentReference(xcontext.getWikiId(), documentSpace, documentName), "view", xcontext));
}
// Authors
for (String authorId : ListClass.getListFromString(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_AUTHORS), "|", false)) {
extension.getAuthors().add(resolveExtensionAuthor(authorId));
}
// Features
List<String> features = ListClass.getListFromString(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_FEATURES), "|", false);
if (features != null && !features.isEmpty()) {
for (String feature : features) {
org.xwiki.extension.ExtensionId extensionId = ExtensionIdConverter.toExtensionId(feature, null);
ExtensionId extensionFeature = this.extensionObjectFactory.createExtensionId();
extensionFeature.setId(extensionId.getId());
if (extensionId.getVersion() != null) {
extensionFeature.setVersion(extensionId.getVersion().getValue());
}
extension.getExtensionFeatures().add(extensionFeature);
extension.getFeatures().add(extensionFeature.getId());
}
}
// Allowed namespaces
String namespacesString = this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_ALLOWEDNAMESPACES);
Integer namespacesEmpty = (Integer) getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_ALLOWEDNAMESPACES_EMPTY);
if (namespacesString != null && (!namespacesString.isEmpty() || namespacesEmpty == 1)) {
List<String> namespaces = ListClass.getListFromString(namespacesString, "|", false);
Namespaces restNamespaces = this.extensionObjectFactory.createNamespaces();
restNamespaces.withNamespaces(namespaces);
extension.setAllowedNamespaces(restNamespaces);
}
// License
License license = this.extensionObjectFactory.createLicense();
license.setName(this.<String>getQueryValue(entry, XWikiRepositoryModel.PROP_EXTENSION_LICENSENAME));
extension.getLicenses().add(license);
// Version
extension.setVersion((String) entry[EPROPERTIES_INDEX.size()]);
return extension;
}
Aggregations