use of org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionDependency in project xwiki-platform by xwiki.
the class RepositoryTest method addExtension.
private void addExtension() throws Exception {
// Create extension
ExtensionsPage extensionsPage = ExtensionsPage.gotoPage();
ExtensionInlinePage extensionInline = extensionsPage.contributeExtension(this.baseExtension.getName());
Assert.assertEquals(this.baseExtension.getName(), extensionInline.getName());
extensionInline.setDescription(this.baseExtension.getDescription());
extensionInline.setInstallation("extension installation");
extensionInline.setLicenseName(this.baseLicense.getName());
extensionInline.setSource("http://source");
extensionInline.setSummary(this.baseExtension.getSummary());
extensionInline.setType(this.baseExtension.getType());
ExtensionPage extensionPage = extensionInline.clickSaveAndView();
// Test summary
getDriver().findElementsWithoutWaiting(By.xpath("//tt[text()=\"" + this.baseExtension.getSummary() + "\"]"));
Assert.assertFalse(extensionPage.isValidExtension());
// Add versions
// TODO: add XR UI to manipulate versions
getRepositoryTestUtils().addVersionObject(this.baseExtension);
getRepositoryTestUtils().addVersionObject(this.baseExtension, "10.0", getUtil().getAttachmentURL("Extension", this.baseExtension.getName(), this.baseExtension.getFile().getName()));
getRepositoryTestUtils().addVersionObject(this.baseExtension, "2.0", "attach:" + this.baseExtension.getFile().getName());
// Add dependencies
// TODO: add XR UI to manipulate dependencies
getRepositoryTestUtils().addDependencies(this.baseExtension, "10.0");
// Add attachment
getRepositoryTestUtils().attachFile(this.baseExtension);
// Wait until all asynchronous tasks are done
getRepositoryTestUtils().waitUntilReady();
// Check livetable
extensionsPage = ExtensionsPage.gotoPage();
ExtensionsLiveTableElement livetable = extensionsPage.getLiveTable();
livetable.filterName(this.baseExtension.getName());
extensionPage = livetable.clickExtensionName(this.baseExtension.getName());
// Validate extension state
Assert.assertTrue(extensionPage.isValidExtension());
// //////////////////////////////////////////
// Validate REST
// //////////////////////////////////////////
// //////////////////////////////////////////
// 1.0
// //////////////////////////////////////////
// Resolve
ExtensionVersion extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, this.baseExtension.getId().getId(), "1.0");
Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
Assert.assertEquals(this.baseExtension.getType(), extension.getType());
Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
Assert.assertEquals(this.baseExtension.getDescription(), extension.getDescription());
Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
Assert.assertEquals("1.0", extension.getVersion());
Assert.assertEquals(getUtil().getURL(Arrays.asList("Extension", this.baseExtension.getName()), ""), extension.getWebsite());
// File
Assert.assertEquals(this.sizeOfFile, getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, this.baseExtension.getId().getId(), "1.0").length);
// //////////////////////////////////////////
// 2.0
// //////////////////////////////////////////
// Resolve
extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, this.baseExtension.getId().getId(), "2.0");
Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
Assert.assertEquals(this.baseExtension.getType(), extension.getType());
Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
Assert.assertEquals(this.baseExtension.getDescription(), extension.getDescription());
Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
Assert.assertEquals("2.0", extension.getVersion());
Assert.assertEquals(getUtil().getURL(Arrays.asList("Extension", this.baseExtension.getName()), ""), extension.getWebsite());
// File
Assert.assertEquals(this.sizeOfFile, getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, this.baseExtension.getId().getId(), "2.0").length);
// //////////////////////////////////////////
// 10.0
// //////////////////////////////////////////
// Resolve
extension = getUtil().rest().getResource(Resources.EXTENSION_VERSION, null, this.baseExtension.getId().getId(), "10.0");
Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
Assert.assertEquals(this.baseExtension.getType(), extension.getType());
Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
Assert.assertEquals("10.0", extension.getVersion());
Assert.assertEquals(getUtil().getURL(Arrays.asList("Extension", this.baseExtension.getName()), ""), extension.getWebsite());
ExtensionDependency dependency1 = extension.getDependencies().get(0);
Assert.assertEquals("dependencyid1", dependency1.getId());
Assert.assertEquals("1.0", dependency1.getConstraint());
ExtensionDependency dependency2 = extension.getDependencies().get(1);
Assert.assertEquals("dependencyid2", dependency2.getId());
Assert.assertEquals("2.0", dependency2.getConstraint());
// File
Assert.assertEquals(this.sizeOfFile, getUtil().rest().getBuffer(Resources.EXTENSION_VERSION_FILE, null, this.baseExtension.getId().getId(), this.baseExtension.getId().getVersion().getValue()).length);
// //////////////////////////////////////////
// Search
// //////////////////////////////////////////
// Empty search
extension = searchExtension(this.baseExtension.getId().getId());
if (extension == null) {
Assert.fail("Could not find extension [" + this.baseExtension.getId().getId() + "]");
}
Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
Assert.assertEquals(this.baseExtension.getType(), extension.getType());
Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
Assert.assertEquals("10.0", extension.getVersion());
// TODO: add support for dependencies in XR search
// Search pattern
Map<String, Object[]> queryParams = new HashMap<String, Object[]>();
queryParams.put(Resources.QPARAM_SEARCH_QUERY, new Object[] { "macro" });
ExtensionsSearchResult result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
Assert.assertEquals(1, result.getTotalHits());
Assert.assertEquals(0, result.getOffset());
extension = result.getExtensions().get(0);
Assert.assertEquals(this.baseExtension.getId().getId(), extension.getId());
Assert.assertEquals(this.baseExtension.getType(), extension.getType());
Assert.assertEquals(this.baseExtension.getSummary(), extension.getSummary());
Assert.assertEquals(this.baseLicense.getName(), extension.getLicenses().get(0).getName());
Assert.assertEquals(this.baseAuthor.getName(), extension.getAuthors().get(0).getName());
Assert.assertEquals(this.baseAuthor.getURL().toString(), extension.getAuthors().get(0).getUrl());
Assert.assertEquals("10.0", extension.getVersion());
// Wrong search pattern
queryParams.clear();
queryParams.put(Resources.QPARAM_SEARCH_QUERY, new Object[] { "notexisting" });
result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
Assert.assertEquals(0, result.getTotalHits());
Assert.assertEquals(0, result.getOffset());
Assert.assertEquals(0, result.getExtensions().size());
// Search limit offset
queryParams.clear();
queryParams.put(Resources.QPARAM_LIST_START, new Object[] { 1 });
result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
Assert.assertEquals(1, result.getOffset());
Assert.assertEquals(result.getTotalHits() - 1, result.getExtensions().size());
// Search limit nb
queryParams.clear();
queryParams.put(Resources.QPARAM_LIST_NUMBER, new Object[] { 0 });
result = getUtil().rest().getResource(Resources.SEARCH, queryParams);
Assert.assertTrue(result.getTotalHits() >= 1);
Assert.assertEquals(0, result.getOffset());
Assert.assertEquals(0, result.getExtensions().size());
}
use of org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionDependency 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