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