Search in sources :

Example 1 with ExtensionId

use of org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionId 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 ExtensionId

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

the class InstallMojo method installExtensions.

private void installExtensions(Marshaller marshaller, Unmarshaller unmarshaller, HttpClient httpClient) throws Exception {
    InstallRequest installRequest = new InstallRequest();
    // Set a job id to save the job result
    installRequest.setId("extension", "provision", UUID.randomUUID().toString());
    installRequest.setInteractive(false);
    // Set the extension list to install
    for (ExtensionId extensionId : this.extensionIds) {
        org.xwiki.extension.ExtensionId extId = new org.xwiki.extension.ExtensionId(extensionId.getId(), extensionId.getVersion());
        getLog().info(String.format("Installing extension [%s]...", extId));
        installRequest.addExtension(extId);
    }
    // Set the namespaces into which to install the extensions
    if (this.namespaces == null || this.namespaces.isEmpty()) {
        installRequest.addNamespace("wiki:xwiki");
    } else {
        for (String namespace : this.namespaces) {
            installRequest.addNamespace(namespace);
        }
    }
    // Set any user for installing pages (if defined)
    if (this.installUserReference != null) {
        installRequest.setProperty("user.reference", new DocumentReference("xwiki", "XWiki", "superadmin"));
    }
    JobRequest request = getModelFactory().toRestJobRequest(installRequest);
    String uri = String.format("%s/jobs?jobType=install&async=false", this.xwikiRESTURL);
    PutMethod putMethod = executePutXml(uri, request, marshaller, httpClient);
    // Verify results
    // Verify that we got a 200 response
    int statusCode = putMethod.getStatusCode();
    if (statusCode < 200 || statusCode >= 300) {
        throw new MojoExecutionException(String.format("Job execution failed. Response status code [%s], reason [%s]", statusCode, putMethod.getResponseBodyAsString()));
    }
    // Get the job status
    JobStatus jobStatus = (JobStatus) unmarshaller.unmarshal(putMethod.getResponseBodyAsStream());
    if (jobStatus.getErrorMessage() != null && jobStatus.getErrorMessage().length() > 0) {
        throw new MojoExecutionException(String.format("Job execution failed. Reason [%s]", jobStatus.getErrorMessage()));
    }
    // Release connection
    putMethod.releaseConnection();
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InstallRequest(org.xwiki.extension.job.InstallRequest) ExtensionId(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionId) JobStatus(org.xwiki.rest.model.jaxb.JobStatus) JobRequest(org.xwiki.rest.model.jaxb.JobRequest) PutMethod(org.apache.commons.httpclient.methods.PutMethod) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 3 with ExtensionId

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

the class AbstractExtensionRESTResource method createExtension.

protected <E extends AbstractExtension> E createExtension(XWikiDocument extensionDocument, String version) {
    BaseObject extensionObject = getExtensionObject(extensionDocument);
    DocumentReference extensionDocumentReference = extensionDocument.getDocumentReference();
    if (extensionObject == null) {
        throw new WebApplicationException(Status.NOT_FOUND);
    }
    AbstractExtension extension;
    ExtensionVersion extensionVersion;
    BaseObject extensionVersionObject;
    if (version == null) {
        extension = this.extensionObjectFactory.createExtension();
        extensionVersion = null;
        extensionVersionObject = null;
    } else {
        extensionVersionObject = repositoryManager.getExtensionVersionObject(extensionDocument, version);
        if (extensionVersionObject == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        extensionVersion = this.extensionObjectFactory.createExtensionVersion();
        extension = extensionVersion;
        extensionVersion.setVersion((String) getValue(extensionVersionObject, XWikiRepositoryModel.PROP_VERSION_VERSION));
    }
    extension.setId((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_ID));
    extension.setType((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_TYPE));
    License license = this.extensionObjectFactory.createLicense();
    license.setName((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_LICENSENAME));
    extension.getLicenses().add(license);
    extension.setRating(getExtensionRating(extensionDocumentReference));
    extension.setSummary((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_SUMMARY));
    extension.setDescription((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_DESCRIPTION));
    extension.setName((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_NAME));
    extension.setCategory((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_CATEGORY));
    extension.setWebsite(StringUtils.defaultIfEmpty((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_WEBSITE), extensionDocument.getExternalURL("view", getXWikiContext())));
    // Recommended
    Integer recommended = getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_RECOMMENDED, 0);
    extension.setRecommended(recommended.intValue() == 1);
    // SCM
    ExtensionScm scm = new ExtensionScm();
    scm.setUrl((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_SCMURL));
    scm.setConnection(toScmConnection((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_SCMCONNECTION)));
    scm.setDeveloperConnection(toScmConnection((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_SCMDEVCONNECTION)));
    extension.setScm(scm);
    // Issue Management
    ExtensionIssueManagement issueManagement = new ExtensionIssueManagement();
    issueManagement.setSystem((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_ISSUEMANAGEMENT_SYSTEM));
    issueManagement.setUrl((String) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_ISSUEMANAGEMENT_URL));
    if (StringUtils.isNotEmpty(issueManagement.getSystem()) || StringUtils.isNotEmpty(issueManagement.getUrl())) {
        extension.setIssueManagement(issueManagement);
    }
    // Authors
    List<String> authors = (List<String>) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_AUTHORS);
    if (authors != null) {
        for (String authorId : authors) {
            extension.getAuthors().add(resolveExtensionAuthor(authorId));
        }
    }
    // Features
    List<String> features;
    if (extensionVersionObject != null) {
        features = (List<String>) getValue(extensionVersionObject, XWikiRepositoryModel.PROP_VERSION_FEATURES);
    } else {
        features = (List<String>) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_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());
        }
    }
    // Allowed namespaces
    List<String> namespaces = (List<String>) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_ALLOWEDNAMESPACES);
    Integer namespacesEmpty = (Integer) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_ALLOWEDNAMESPACES_EMPTY);
    if (namespaces != null && (!namespaces.isEmpty() || namespacesEmpty == 1)) {
        Namespaces restNamespaces = this.extensionObjectFactory.createNamespaces();
        restNamespaces.withNamespaces(namespaces);
        extension.setAllowedNamespaces(restNamespaces);
    }
    // Repositories
    if (extensionVersionObject != null) {
        List<String> repositories = (List<String>) getValue(extensionVersionObject, XWikiRepositoryModel.PROP_VERSION_REPOSITORIES);
        extensionVersion.withRepositories(toExtensionRepositories(repositories));
    }
    // Properties
    addProperties(extension, (List<String>) getValue(extensionObject, XWikiRepositoryModel.PROP_EXTENSION_PROPERTIES));
    // Dependencies
    if (extensionVersion != null) {
        List<BaseObject> dependencies = extensionDocument.getXObjects(XWikiRepositoryModel.EXTENSIONDEPENDENCY_CLASSREFERENCE);
        if (dependencies != null) {
            for (BaseObject dependencyObject : dependencies) {
                if (dependencyObject != null) {
                    if (StringUtils.equals(getValue(dependencyObject, XWikiRepositoryModel.PROP_DEPENDENCY_EXTENSIONVERSION, (String) null), version)) {
                        ExtensionDependency dependency = extensionObjectFactory.createExtensionDependency();
                        dependency.setId((String) getValue(dependencyObject, XWikiRepositoryModel.PROP_DEPENDENCY_ID));
                        dependency.setConstraint((String) getValue(dependencyObject, XWikiRepositoryModel.PROP_DEPENDENCY_CONSTRAINT));
                        dependency.setOptional(getBooleanValue(dependencyObject, XWikiRepositoryModel.PROP_DEPENDENCY_OPTIONAL, false));
                        List<String> repositories = (List<String>) getValue(dependencyObject, XWikiRepositoryModel.PROP_DEPENDENCY_REPOSITORIES);
                        dependency.withRepositories(toExtensionRepositories(repositories));
                        extensionVersion.getDependencies().add(dependency);
                    }
                }
            }
        }
    }
    return (E) extension;
}
Also used : ExtensionIssueManagement(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionIssueManagement) Namespaces(org.xwiki.extension.repository.xwiki.model.jaxb.Namespaces) WebApplicationException(javax.ws.rs.WebApplicationException) AbstractExtension(org.xwiki.extension.repository.xwiki.model.jaxb.AbstractExtension) License(org.xwiki.extension.repository.xwiki.model.jaxb.License) ExtensionId(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionId) ExtensionDependency(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionDependency) BaseObject(com.xpn.xwiki.objects.BaseObject) ExtensionScm(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionScm) List(java.util.List) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference) ExtensionVersion(org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion)

Example 4 with ExtensionId

use of org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionId 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

ExtensionId (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionId)4 DocumentReference (org.xwiki.model.reference.DocumentReference)4 ExtensionIssueManagement (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionIssueManagement)3 ExtensionScm (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionScm)3 ExtensionVersion (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionVersion)3 License (org.xwiki.extension.repository.xwiki.model.jaxb.License)3 Namespaces (org.xwiki.extension.repository.xwiki.model.jaxb.Namespaces)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 BaseObject (com.xpn.xwiki.objects.BaseObject)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 PutMethod (org.apache.commons.httpclient.methods.PutMethod)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 InstallRequest (org.xwiki.extension.job.InstallRequest)1 AbstractExtension (org.xwiki.extension.repository.xwiki.model.jaxb.AbstractExtension)1 ExtensionDependency (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionDependency)1 ExtensionRating (org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionRating)1 JobRequest (org.xwiki.rest.model.jaxb.JobRequest)1 JobStatus (org.xwiki.rest.model.jaxb.JobStatus)1