+ * Returns null if the site does not exist. + * + * @param shortName short name of the site + * @return Site the site, null if does not exist + */ + public Site getSite(String shortName) + { + Site site = null; + SiteInfo siteInfo = this.siteService.getSite(shortName); + if (siteInfo != null) + { + site = new Site(this.siteService, siteInfo); + } + return site; + } } diff --git a/source/java/org/alfresco/repo/site/script/Site.java b/source/java/org/alfresco/repo/site/script/Site.java index e36f546459..9e121dda97 100644 --- a/source/java/org/alfresco/repo/site/script/Site.java +++ b/source/java/org/alfresco/repo/site/script/Site.java @@ -27,6 +27,7 @@ package org.alfresco.repo.site.script; import java.io.Serializable; import org.alfresco.repo.site.SiteInfo; +import org.alfresco.repo.site.SiteService; /** * @author Roy Wetherall @@ -34,42 +35,133 @@ import org.alfresco.repo.site.SiteInfo; public class Site implements Serializable { private static final long serialVersionUID = 8013569574120957923L; - + + /** Site information */ private SiteInfo siteInfo; - public Site(SiteInfo siteInfo) + /** Site service */ + private SiteService siteService; + + /** Indicates whether there are any outstanding changes that need to be saved */ + private boolean isDirty = false; + + /** + * Constructor + * + * @param siteInfo site information + */ + /*package*/ Site(SiteService siteService, SiteInfo siteInfo) { + this.siteService = siteService; this.siteInfo = siteInfo; } + /** + * Get the site preset + * + * @return String the site preset + */ public String getSitePreset() { return this.siteInfo.getSitePreset(); } + /** + * Set the short name + * + * @return String the short name + */ public String getShortName() { return this.siteInfo.getShortName(); } + /** + * Get the title + * + * @return String the site title + */ public String getTitle() { return this.siteInfo.getTitle(); } - // TODO set title + /** + * Set the title + * + * @param title the title + */ + public void setTitle(String title) + { + this.isDirty = true; + this.siteInfo.setTitle(title); + } + /** + * Get the description + * + * @return String the description + */ public String getDescription() { return this.siteInfo.getDescription(); } - // TODO set description + /** + * Set the description + * + * @param description the description + */ + public void setDescription(String description) + { + this.isDirty = true; + this.siteInfo.setDescription(description); + } + /** + * Gets whether the site is public or not + * + * @return true is public false otherwise + */ public boolean getIsPublic() { return this.siteInfo.getIsPublic(); } - // TODO set isPublic + /** + * Set whether the site is public or not + * + * @param isPublic true the site is public false otherwise + */ + public void setIsPublic(boolean isPublic) + { + this.isDirty = true; + this.siteInfo.setIsPublic(isPublic); + } + + /** + * Saves any outstanding updates to the site details. + *
+ * If properties of the site are changed and save is not called, those changes will be lost. + */ + public void save() + { + if (this.isDirty == true) + { + // Update the site details + this.siteService.updateSite(this.siteInfo); + + // Reset the dirty flag + this.isDirty = false; + } + } + + /** + * Deletes the site + */ + public void deleteSite() + { + // Delete the site + this.siteService.deleteSite(this.siteInfo.getShortName()); + } } diff --git a/source/java/org/alfresco/repo/site/script/test_siteService.js b/source/java/org/alfresco/repo/site/script/test_siteService.js index 6271f43104..5bc162dee9 100644 --- a/source/java/org/alfresco/repo/site/script/test_siteService.js +++ b/source/java/org/alfresco/repo/site/script/test_siteService.js @@ -1,29 +1,47 @@ -var failure = ""; - -// Try and create a site -var site = siteService.createSite("sitePreset", "siteShortName", "siteTitle", "siteDescription", true); - -// Check that the site details are correct -if (site.sitePreset != "sitePreset") +function checkSite(site, sitePreset, shortName, title, description, isPublic) { - failure += "\nSite preset is not set on created site"; -} -if (site.shortName != "siteShortName") -{ - failure += "\nSite short name is not set on created site"; -} -if (site.title != "siteTitle") -{ - failure += "\nSite title is not set on created site"; -} -if (site.description != "siteDescription") -{ - failure += "\nSite description is not set on created site"; -} -if (site.isPublic != true) -{ - failure += "\nCreated site should be marked public"; + test.assertNotNull(site, "Site should not be null"); + test.assertEquals(sitePreset, site.sitePreset, "Site preset incorrect for site " + shortName); + test.assertEquals(shortName, site.shortName, "Site shortname incorrect"); + test.assertEquals(title, site.title, "Site title incorrect for site " + shortName); + test.assertEquals(description, site.description, "Site description incorrect for site " + shortName); + test.assertEquals(isPublic, site.isPublic, "Site ispublic incorrect for site " + shortName); } -// Return the failure message -failure; \ No newline at end of file +function testCRUD() +{ + // Try and get a site that doesn't exist + var site = siteService.getSite("siteShortName"); + test.assertNull(site, "Site should not have been found."); + + // Try and create a site + site = siteService.createSite("sitePreset", "siteShortName", "siteTitle", "siteDescription", true); + checkSite(site, "sitePreset", "siteShortName", "siteTitle", "siteDescription", true); + + // Try and get the created site + site = siteService.getSite("siteShortName"); + checkSite(site, "sitePreset", "siteShortName", "siteTitle", "siteDescription", true); + + // Try and update the values of the site + site.title = "abc123abc"; + site.description = "abc123abc"; + site.isPublic = false; + checkSite(site, "sitePreset", "siteShortName", "abc123abc", "abc123abc", false); + site.save(); + site = siteService.getSite("siteShortName"); + checkSite(site, "sitePreset", "siteShortName", "abc123abc", "abc123abc", false); + + // Delete the site + site.deleteSite(); + site = siteService.getSite("siteShortName"); + test.assertNull(site, ""); +} + +function testListSites() +{ + // TODO +} + +// Execute test's +testCRUD(); +testListSites(); \ No newline at end of file