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