Search in sources :

Example 6 with ExtensionVersion

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;
}
Also used : ExtensionIssueManagement(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionIssueManagement) Namespaces(org.xwiki.extension.repository.xwiki.model.jaxb.Namespaces) License(org.xwiki.extension.repository.xwiki.model.jaxb.License) XWikiContext(com.xpn.xwiki.XWikiContext) ExtensionId(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionId) ExtensionScm(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionScm) ExtensionVersion(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

ExtensionVersion (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion)6 ExtensionId (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionId)3 ExtensionIssueManagement (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionIssueManagement)3 ExtensionScm (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionScm)3 License (org.xwiki.extension.repository.xwiki.model.jaxb.License)3 Namespaces (org.xwiki.extension.repository.xwiki.model.jaxb.Namespaces)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 HashMap (java.util.HashMap)2 ExtensionDependency (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionDependency)2 ExtensionsSearchResult (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult)2 BaseObject (com.xpn.xwiki.objects.BaseObject)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 DefaultExtensionDependency (org.xwiki.extension.DefaultExtensionDependency)1 ExtensionId (org.xwiki.extension.ExtensionId)1 AbstractExtension (org.xwiki.extension.repository.xwiki.model.jaxb.AbstractExtension)1 ExtensionRating (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionRating)1 TestExtension (org.xwiki.repository.test.TestExtension)1