Search in sources :

Example 1 with ExtensionRating

use of org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionRating in project xwiki-platform by xwiki.

the class AbstractExtensionRESTResource method createExtensionVersionFromSolrDocument.

protected ExtensionVersion createExtensionVersionFromSolrDocument(SolrDocument document) {
    XWikiContext xcontext = getXWikiContext();
    ExtensionVersion extension = this.extensionObjectFactory.createExtensionVersion();
    extension.setId(this.<String>getSolrValue(document, Extension.FIELD_ID, true));
    extension.setType(this.<String>getSolrValue(document, Extension.FIELD_TYPE, true));
    extension.setName(this.<String>getSolrValue(document, Extension.FIELD_NAME, false));
    extension.setSummary(this.<String>getSolrValue(document, Extension.FIELD_SUMMARY, false));
    // Recommended
    Boolean recommended = this.<Boolean>getSolrValue(document, RemoteExtension.FIELD_RECOMMENDED, false, false);
    if (recommended == Boolean.TRUE) {
        extension.setRecommended(recommended);
    }
    // SCM
    ExtensionScm scm = new ExtensionScm();
    scm.setUrl(this.<String>getSolrValue(document, Extension.FIELD_SCM, true));
    scm.setConnection(toScmConnection(this.<String>getSolrValue(document, XWikiRepositoryModel.PROP_EXTENSION_SCMCONNECTION, true)));
    scm.setDeveloperConnection(toScmConnection(this.<String>getSolrValue(document, XWikiRepositoryModel.PROP_EXTENSION_SCMDEVCONNECTION, true)));
    if (scm.getUrl() != null || scm.getConnection() != null || scm.getDeveloperConnection() != null) {
        extension.setScm(scm);
    }
    // Issue Management
    ExtensionIssueManagement issueManagement = new ExtensionIssueManagement();
    issueManagement.setSystem(this.<String>getSolrValue(document, XWikiRepositoryModel.PROP_EXTENSION_ISSUEMANAGEMENT_SYSTEM, true));
    issueManagement.setUrl(this.<String>getSolrValue(document, XWikiRepositoryModel.PROP_EXTENSION_ISSUEMANAGEMENT_URL, true));
    if (issueManagement.getSystem() != null || issueManagement.getUrl() != null) {
        extension.setIssueManagement(issueManagement);
    }
    // Rating
    ExtensionRating extensionRating = this.extensionObjectFactory.createExtensionRating();
    extensionRating.setTotalVotes(getSolrValue(document, XWikiRepositoryModel.PROP_RATING_TOTALVOTES, false, 0));
    extensionRating.setAverageVote(getSolrValue(document, XWikiRepositoryModel.PROP_RATING_AVERAGEVOTE, false, 0.0f));
    extension.setRating(extensionRating);
    // Website
    extension.setWebsite(this.<String>getSolrValue(document, Extension.FIELD_WEBSITE, true));
    if (extension.getWebsite() == null) {
        DocumentReference extensionDocumentReference = this.solrDocumentReferenceResolver.resolve(document);
        extension.setWebsite(xcontext.getWiki().getURL(extensionDocumentReference, xcontext));
    }
    // Authors
    Collection<String> authors = this.<String>getSolrValues(document, Extension.FIELD_AUTHORS);
    if (authors != null) {
        for (String authorId : authors) {
            extension.getAuthors().add(resolveExtensionAuthor(authorId));
        }
    }
    // Features
    Collection<String> features = this.<String>getSolrValues(document, Extension.FIELD_FEATURES);
    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());
        }
    }
    // License
    String licenseName = this.<String>getSolrValue(document, Extension.FIELD_LICENSE, true);
    if (licenseName != null) {
        License license = this.extensionObjectFactory.createLicense();
        license.setName(licenseName);
        extension.getLicenses().add(license);
    }
    // Allowed namespaces
    Collection<String> namespaces = this.<String>getSolrValues(document, Extension.FIELD_ALLOWEDNAMESPACES);
    if (namespaces != null && !namespaces.isEmpty()) {
        Namespaces restNamespaces = this.extensionObjectFactory.createNamespaces();
        restNamespaces.withNamespaces(namespaces);
        extension.setAllowedNamespaces(restNamespaces);
    }
    // Version
    extension.setVersion(this.<String>getSolrValue(document, Extension.FIELD_VERSION, true));
    // Properties
    addProperties(extension, this.<String>getSolrValues(document, Extension.FIELD_PROPERTIES));
    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) ExtensionRating(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionRating) ExtensionScm(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionScm) ExtensionVersion(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 2 with ExtensionRating

use of org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionRating in project xwiki-platform by xwiki.

the class AbstractExtensionRESTResource method getExtensionRating.

protected ExtensionRating getExtensionRating(DocumentReference extensionDocumentReference) {
    ExtensionRating extensionRating = this.extensionObjectFactory.createExtensionRating();
    try {
        AverageRatingApi averageRating = new AverageRatingApi(ratingsManager.getAverageRating(extensionDocumentReference));
        extensionRating.setTotalVotes(averageRating.getNbVotes());
        extensionRating.setAverageVote(averageRating.getAverageVote());
    } catch (XWikiException e) {
        extensionRating.setTotalVotes(0);
        extensionRating.setAverageVote(0);
    }
    return extensionRating;
}
Also used : ExtensionRating(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionRating) AverageRatingApi(org.xwiki.ratings.AverageRatingApi) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

ExtensionRating (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionRating)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 ExtensionId (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionId)1 ExtensionIssueManagement (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionIssueManagement)1 ExtensionScm (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionScm)1 ExtensionVersion (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion)1 License (org.xwiki.extension.repository.xwiki.model.jaxb.License)1 Namespaces (org.xwiki.extension.repository.xwiki.model.jaxb.Namespaces)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 AverageRatingApi (org.xwiki.ratings.AverageRatingApi)1